--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ a22c435d3518 Thu Aug 25 19:33:06 2011 +0400 @@ -0,0 +1,113 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.vk; + +import java.awt.Image; +import org.netbeans.core.spi.multiview.CloseOperationHandler; +import org.netbeans.core.spi.multiview.CloseOperationState; +import org.netbeans.core.spi.multiview.MultiViewDescription; +import org.netbeans.core.spi.multiview.MultiViewFactory; +import org.netbeans.modules.cnd.source.spi.CndPaneProvider; +import org.openide.loaders.DataObject; +import org.openide.text.CloneableEditorSupport; +import org.openide.text.CloneableEditorSupport.Pane; +import org.openide.text.DataEditorSupport; +import org.openide.util.ImageUtilities; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author vk155633 + */ +@ServiceProvider(service=CndPaneProvider.class) +public class VkPaneProviderImpl implements CndPaneProvider { + + private Image icon; + + public VkPaneProviderImpl() { + icon = ImageUtilities.loadImageIcon("org/netbeans/modules/vk/vkfile.gif", false).getImage(); // NOI18N + } + + @Override + public Pane createPane(DataEditorSupport dataEditorSupport) { + DataObject dataObject = dataEditorSupport.getDataObject(); + if (!dataObject.getPrimaryFile().getName().endsWith("_vk")) { + return null; + } + CloneableEditorSupport.Pane pane; + //pane = super.createPane(); + MultiViewDescription[] descriptions = { + new VkSourceViewDescription(dataEditorSupport), + new VkVisualViewDescription(dataEditorSupport) + }; + + pane = (CloneableEditorSupport.Pane) MultiViewFactory.createCloneableMultiView( + descriptions, descriptions[1], new CloseHandler(dataObject)); + //pane.getComponent().setIcon(getDataObject().getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16)); + pane.getComponent().setIcon(icon); + return pane; + + } + + /** Implementation of CloseOperationHandler for multiview. Ensures both form + * and java editor are correctly closed, data saved, etc. Holds a reference + * to form DataObject only - to be serializable with the multiview + * TopComponent without problems. + */ + private static class CloseHandler implements CloseOperationHandler { + + private DataObject dao; + + private CloseHandler() { + } + + public CloseHandler(DataObject dao) { + this.dao = dao; + } + + @Override + public boolean resolveCloseOperation(CloseOperationState[] elements) { + System.err.printf("NO NO NO PLEASE, DON'T CLOSE ME !!!\n"); + return true; + } + } +} --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ a22c435d3518 Thu Aug 25 19:33:06 2011 +0400 @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + */ + +package org.netbeans.modules.vk; + +import java.awt.Component; +import java.io.Serializable; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JEditorPane; +import javax.swing.JPanel; +import javax.swing.JToolBar; +import javax.swing.text.Document; +import org.netbeans.core.spi.multiview.CloseOperationState; +import org.netbeans.core.spi.multiview.MultiViewElement; +import org.netbeans.core.spi.multiview.MultiViewElementCallback; +import org.netbeans.core.spi.multiview.MultiViewFactory; +import org.openide.loaders.DataObject; +import org.openide.nodes.Node; +import org.openide.text.CloneableEditor; +import org.openide.text.DataEditorSupport; +import org.openide.text.NbDocument; +import org.openide.util.Lookup; +import org.openide.util.Mutex; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; +import org.openide.windows.TopComponent; + +/** + * @author Vladimir Kvashin + */ +public class VkSourceEditor extends CloneableEditor + implements MultiViewElement, Serializable { + + private static final long serialVersionUID = 3848164248009100955L; + + private JComponent toolbar; + private MultiViewElementCallback callback; + + public VkSourceEditor(DataEditorSupport dataEditorSupport) { + super(dataEditorSupport); + } + + private DataEditorSupport getSupport() { + return (DataEditorSupport) cloneableEditorSupport(); + } + + @Override + public JComponent getVisualRepresentation() { + return this; + } + + /** Return the editor's custom tool bar, so our toggle button could integrate with it */ + @Override + public JComponent getToolbarRepresentation() { + if (toolbar == null) { + JEditorPane p = getEditorPane(); + if (p != null) { + Document doc = p.getDocument(); + if (doc instanceof NbDocument.CustomToolbar) { + toolbar = ((NbDocument.CustomToolbar)doc).createToolbar(p); + } + } + if (toolbar == null) { + // attempt to create own toolbar?? + toolbar = new JPanel(); + } + } + return toolbar; + } + + @Override + public void setMultiViewCallback(MultiViewElementCallback callback) { + this.callback = callback; + updateName(); + } + + @Override + public void componentOpened() { + super.componentOpened(); + } + + @Override + public void componentClosed() { + super.componentClosed(); + } + + @Override + public void componentShowing() { + super.componentShowing(); + } + + @Override + public void componentHidden() { + super.componentHidden(); + } + + @Override + public void componentActivated() { + super.componentActivated(); + } + + @Override + public void componentDeactivated() { + super.componentDeactivated(); + } + + @Override + public CloseOperationState canCloseElement() { + return MultiViewFactory.createUnsafeCloseState( + "ID_UBB_SOURCE_CLOSING", // dummy ID // NOI18N + MultiViewFactory.NOOP_CLOSE_ACTION, + MultiViewFactory.NOOP_CLOSE_ACTION); + } + + @Override + public void updateName() { + Mutex.EVENT.readAccess(new Runnable() { + @Override + public void run() { + MultiViewElementCallback c = callback; + if (c == null) { + return; + } + TopComponent tc = c.getTopComponent(); + if (tc == null) { + return; + } + VkSourceEditor.super.updateName(); + tc.setName(VkSourceEditor.this.getName()); + tc.setDisplayName(VkSourceEditor.this.getDisplayName()); + tc.setHtmlDisplayName(VkSourceEditor.this.getHtmlDisplayName()); + } + }); + } + + @Override + public Lookup getLookup() { + DataObject dao = getSupport().getDataObject(); + Node node = dao.getNodeDelegate(); + Lookup nodeLookup = node.getLookup(); + //UbbUtils.dumpLookup("UbbSourceEditor node lookup", nodeLookup); + Lookup superLookup = super.getLookup(); + //UbbUtils.dumpLookup("UbbSourceEditor super lookup", superLookup); + Lookup result = new ProxyLookup(nodeLookup, superLookup, Lookups.singleton(node)); + //UbbUtils.dumpLookup("UbbSourceEditor merged lookup", result); + return result; + } +} --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ a22c435d3518 Thu Aug 25 19:33:06 2011 +0400 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + */ + +package org.netbeans.modules.vk; + +import java.awt.Image; +import java.io.Serializable; +import javax.swing.JToolBar; +import org.netbeans.core.spi.multiview.MultiViewDescription; +import org.netbeans.core.spi.multiview.MultiViewElement; +import org.openide.text.DataEditorSupport; +import org.openide.util.HelpCtx; +import org.openide.util.ImageUtilities; +import org.openide.windows.TopComponent; + +public class VkSourceViewDescription implements MultiViewDescription, Serializable { + + static final long serialVersionUID = -1135988488489108703L; + + + private final DataEditorSupport dataEditorSupport; + private VkSourceEditor editor; + private JToolBar toolbar; + + public VkSourceViewDescription(DataEditorSupport dataEditorSupport) { + this.dataEditorSupport = dataEditorSupport; + //this.support = support; + } + + @Override + public int getPersistenceType() { + return TopComponent.PERSISTENCE_ONLY_OPENED; + } + + @Override + public String getDisplayName() { + return "Source"; + } + + @Override + public Image getIcon() { + return ImageUtilities.loadImageIcon("org/netbeans/modules/vk/HDataIcon.gif", false).getImage(); // NOI18N + } + + @Override + public String preferredID() { + return "text"; + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + public MultiViewElement createElement() { + if (editor == null) { + editor = new VkSourceEditor(dataEditorSupport); + } +// Node[] nodes = editor.getActivatedNodes(); +// if ((nodes == null) || (nodes.length == 0)) { +// editor.setActivatedNodes(new Node[] {support.getDataObject().getNodeDelegate()}); +// } + return editor; + } +} --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ a22c435d3518 Thu Aug 25 19:33:06 2011 +0400 @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + */ + +package org.netbeans.modules.vk; + +import java.awt.BorderLayout; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.Serializable; +import javax.swing.Action; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JToolBar; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import org.netbeans.core.spi.multiview.CloseOperationState; +import org.netbeans.core.spi.multiview.MultiViewElement; +import org.netbeans.core.spi.multiview.MultiViewElementCallback; +import org.openide.awt.UndoRedo; +import org.openide.loaders.DataObject; +import org.openide.nodes.Node; +import org.openide.text.DataEditorSupport; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ProxyLookup; + +/** + * @author Vladimir Kvashin + */ +public class VkVisualEditor extends JPanel + implements MultiViewElement, PropertyChangeListener, Serializable, ChangeListener { + + private static final long serialVersionUID = 3280748743140605180L; + private static final String SPLITTER_POSITION_PREF_NAME = "dividerLocation"; // NOI18N + + private final DataEditorSupport dataEditorSupport; + + private JToolBar toolbar; + private MultiViewElementCallback callback; + + + public VkVisualEditor(DataEditorSupport dataEditorSupport) { + this.dataEditorSupport = dataEditorSupport; + setLayout(new BorderLayout()); + add(new JButton("Press Me")); + toolbar = new JToolBar(JToolBar.HORIZONTAL); + toolbar.add(new JButton("1")); + toolbar.add(new JButton("2")); + toolbar.add(new JButton("3")); + } + + // MultiViewElement implementation start + @Override + public void componentActivated() { + } + + @Override + public void componentDeactivated() { + } + + @Override + public void componentClosed() { + } + + @Override + public void componentHidden() { + } + + @Override + public void componentOpened() { + } + + @Override + public void componentShowing() { + } + + @Override + public Action[] getActions() { + return new Action[0]; + } + // MultiViewElement implementation end + + + @Override + public void stateChanged(ChangeEvent e) { + } + + + @Override + public void propertyChange(PropertyChangeEvent evt) { + } + + + @Override + public JComponent getVisualRepresentation() { + return this; + } + + @Override + public JComponent getToolbarRepresentation() { + return toolbar; + } + + @Override + public UndoRedo getUndoRedo() { + return null; + } + + @Override + public CloseOperationState canCloseElement() { + System.err.printf("I'M CLOSING\n"); + return CloseOperationState.STATE_OK; + } + + @Override + public Lookup getLookup() { + DataObject dao = dataEditorSupport.getDataObject(); + Node node = dao.getNodeDelegate(); + Lookup nodeLookup = node.getLookup(); + //UbbUtils.dumpLookup("UbbSourceEditor node lookup", nodeLookup); + Lookup result = new ProxyLookup(nodeLookup, Lookups.singleton(node), dao.getLookup()); + return result; + } + + @Override + public void setMultiViewCallback(MultiViewElementCallback callback) { + this.callback = callback; +// updateName(); + } +} --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ a22c435d3518 Thu Aug 25 19:33:06 2011 +0400 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + */ + +package org.netbeans.modules.vk; + +import java.awt.Image; +import java.io.Serializable; +import org.netbeans.core.spi.multiview.MultiViewDescription; +import org.netbeans.core.spi.multiview.MultiViewElement; +import org.openide.text.DataEditorSupport; +import org.openide.util.HelpCtx; +import org.openide.util.ImageUtilities; +import org.openide.windows.TopComponent; + +public class VkVisualViewDescription implements MultiViewDescription, Serializable { + + static final long serialVersionUID = 6758876646105130771L; + private VkVisualEditor editor; + private final DataEditorSupport dataEditorSupport; + + public VkVisualViewDescription(DataEditorSupport dataEditorSupport) { + this.dataEditorSupport = dataEditorSupport; + } + + @Override + public int getPersistenceType() { + return TopComponent.PERSISTENCE_ONLY_OPENED; + } + + @Override + public String getDisplayName() { + return "Visual"; + } + + @Override + public Image getIcon() { + return ImageUtilities.loadImageIcon("org/netbeans/modules/vk/vkfile.gif", false).getImage(); // NOI18N + } + + @Override + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + public String preferredID() { + return "visual"; + } + + @Override + public MultiViewElement createElement() { + if (editor == null) { + editor = new VkVisualEditor(dataEditorSupport); + } + return editor; + } +}