Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 201208 | Differences between
and this patch

Collapse All | Expand All

(-)cnd.modelui/src/org/netbeans/modules/vk/VkPaneProviderImpl.java (+113 lines)
Added Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.vk;
43
44
import java.awt.Image;
45
import org.netbeans.core.spi.multiview.CloseOperationHandler;
46
import org.netbeans.core.spi.multiview.CloseOperationState;
47
import org.netbeans.core.spi.multiview.MultiViewDescription;
48
import org.netbeans.core.spi.multiview.MultiViewFactory;
49
import org.netbeans.modules.cnd.source.spi.CndPaneProvider;
50
import org.openide.loaders.DataObject;
51
import org.openide.text.CloneableEditorSupport;
52
import org.openide.text.CloneableEditorSupport.Pane;
53
import org.openide.text.DataEditorSupport;
54
import org.openide.util.ImageUtilities;
55
import org.openide.util.lookup.ServiceProvider;
56
57
/**
58
 *
59
 * @author vk155633
60
 */
61
@ServiceProvider(service=CndPaneProvider.class)
62
public class VkPaneProviderImpl implements CndPaneProvider {
63
64
    private Image icon;
65
    
66
    public VkPaneProviderImpl() {
67
        icon = ImageUtilities.loadImageIcon("org/netbeans/modules/vk/vkfile.gif", false).getImage(); // NOI18N
68
    }
69
    
70
    @Override
71
    public Pane createPane(DataEditorSupport dataEditorSupport) {
72
        DataObject dataObject = dataEditorSupport.getDataObject();
73
        if (!dataObject.getPrimaryFile().getName().endsWith("_vk")) {
74
            return null;
75
        }
76
        CloneableEditorSupport.Pane pane;
77
        //pane = super.createPane();
78
        MultiViewDescription[] descriptions = {
79
            new VkSourceViewDescription(dataEditorSupport),
80
            new VkVisualViewDescription(dataEditorSupport)
81
        };
82
        
83
        pane = (CloneableEditorSupport.Pane) MultiViewFactory.createCloneableMultiView(
84
                descriptions, descriptions[1], new CloseHandler(dataObject));
85
        //pane.getComponent().setIcon(getDataObject().getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16));
86
        pane.getComponent().setIcon(icon);
87
        return pane;
88
        
89
    }    
90
91
    /** Implementation of CloseOperationHandler for multiview. Ensures both form
92
     * and java editor are correctly closed, data saved, etc. Holds a reference
93
     * to form DataObject only - to be serializable with the multiview
94
     * TopComponent without problems.
95
     */
96
    private static class CloseHandler implements CloseOperationHandler {
97
98
        private DataObject dao;
99
        
100
        private CloseHandler() {
101
        }
102
103
        public CloseHandler(DataObject dao) {
104
            this.dao = dao;
105
        }
106
107
        @Override
108
        public boolean resolveCloseOperation(CloseOperationState[] elements) {
109
            System.err.printf("NO NO NO PLEASE, DON'T CLOSE ME !!!\n");
110
            return true;
111
        }
112
    }    
113
}
(-)cnd.modelui/src/org/netbeans/modules/vk/VkSourceEditor.java (+150 lines)
Added Link Here 
1
/*
2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3
 */
4
5
package org.netbeans.modules.vk;
6
7
import java.awt.Component;
8
import java.io.Serializable;
9
import javax.swing.JButton;
10
import javax.swing.JComponent;
11
import javax.swing.JEditorPane;
12
import javax.swing.JPanel;
13
import javax.swing.JToolBar;
14
import javax.swing.text.Document;
15
import org.netbeans.core.spi.multiview.CloseOperationState;
16
import org.netbeans.core.spi.multiview.MultiViewElement;
17
import org.netbeans.core.spi.multiview.MultiViewElementCallback;
18
import org.netbeans.core.spi.multiview.MultiViewFactory;
19
import org.openide.loaders.DataObject;
20
import org.openide.nodes.Node;
21
import org.openide.text.CloneableEditor;
22
import org.openide.text.DataEditorSupport;
23
import org.openide.text.NbDocument;
24
import org.openide.util.Lookup;
25
import org.openide.util.Mutex;
26
import org.openide.util.lookup.Lookups;
27
import org.openide.util.lookup.ProxyLookup;
28
import org.openide.windows.TopComponent;
29
30
/**
31
 * @author Vladimir Kvashin
32
 */
33
public class VkSourceEditor extends CloneableEditor 
34
        implements  MultiViewElement, Serializable {
35
36
    private static final long serialVersionUID = 3848164248009100955L;
37
38
    private JComponent toolbar;
39
    private MultiViewElementCallback callback;
40
41
    public VkSourceEditor(DataEditorSupport dataEditorSupport) {
42
        super(dataEditorSupport);
43
    }
44
45
    private DataEditorSupport getSupport() {
46
        return (DataEditorSupport) cloneableEditorSupport();
47
    }
48
49
    @Override
50
    public JComponent getVisualRepresentation() {
51
        return this;
52
    }
53
54
    /** Return the editor's custom tool bar, so our toggle button could integrate with it */
55
    @Override
56
    public JComponent getToolbarRepresentation() {
57
        if (toolbar == null) {
58
            JEditorPane p = getEditorPane();
59
            if (p != null) {
60
                Document doc = p.getDocument();
61
                if (doc instanceof NbDocument.CustomToolbar) {
62
                    toolbar = ((NbDocument.CustomToolbar)doc).createToolbar(p);
63
                }
64
            }
65
            if (toolbar == null) {
66
                // attempt to create own toolbar??
67
                toolbar = new JPanel();
68
            }
69
        }
70
        return toolbar;        
71
    }
72
73
    @Override
74
    public void setMultiViewCallback(MultiViewElementCallback callback) {
75
        this.callback = callback;
76
        updateName();
77
    }
78
79
    @Override
80
    public void componentOpened() {
81
        super.componentOpened();
82
    }
83
84
    @Override
85
    public void componentClosed() {
86
        super.componentClosed();
87
    }
88
89
    @Override
90
    public void componentShowing() {
91
        super.componentShowing();
92
    }
93
94
    @Override
95
    public void componentHidden() {
96
        super.componentHidden();
97
    }
98
99
    @Override
100
    public void componentActivated() {
101
        super.componentActivated();
102
    }
103
104
    @Override
105
    public void componentDeactivated() {
106
        super.componentDeactivated();
107
    }
108
109
    @Override
110
    public CloseOperationState canCloseElement() {
111
        return MultiViewFactory.createUnsafeCloseState(
112
            "ID_UBB_SOURCE_CLOSING", // dummy ID // NOI18N
113
            MultiViewFactory.NOOP_CLOSE_ACTION,
114
            MultiViewFactory.NOOP_CLOSE_ACTION);
115
    }
116
117
    @Override
118
    public void updateName() {
119
        Mutex.EVENT.readAccess(new Runnable() {
120
            @Override
121
            public void run() {
122
                MultiViewElementCallback c = callback;
123
                if (c == null) {
124
                    return;
125
                }
126
                TopComponent tc = c.getTopComponent();
127
                if (tc == null) {
128
                    return;
129
                }
130
                VkSourceEditor.super.updateName();
131
                tc.setName(VkSourceEditor.this.getName());
132
                tc.setDisplayName(VkSourceEditor.this.getDisplayName());
133
                tc.setHtmlDisplayName(VkSourceEditor.this.getHtmlDisplayName());
134
            }
135
        });
136
    }
137
138
    @Override
139
    public Lookup getLookup() {
140
        DataObject dao = getSupport().getDataObject();
141
        Node node = dao.getNodeDelegate();
142
        Lookup nodeLookup = node.getLookup();
143
        //UbbUtils.dumpLookup("UbbSourceEditor node lookup", nodeLookup);
144
        Lookup superLookup = super.getLookup();
145
        //UbbUtils.dumpLookup("UbbSourceEditor super lookup", superLookup);
146
        Lookup result = new ProxyLookup(nodeLookup, superLookup, Lookups.singleton(node));
147
        //UbbUtils.dumpLookup("UbbSourceEditor merged lookup", result);
148
        return result;
149
    }
150
}
(-)cnd.modelui/src/org/netbeans/modules/vk/VkSourceViewDescription.java (+67 lines)
Added Link Here 
1
/*
2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3
 */
4
5
package org.netbeans.modules.vk;
6
7
import java.awt.Image;
8
import java.io.Serializable;
9
import javax.swing.JToolBar;
10
import org.netbeans.core.spi.multiview.MultiViewDescription;
11
import org.netbeans.core.spi.multiview.MultiViewElement;
12
import org.openide.text.DataEditorSupport;
13
import org.openide.util.HelpCtx;
14
import org.openide.util.ImageUtilities;
15
import org.openide.windows.TopComponent;
16
17
public class VkSourceViewDescription implements MultiViewDescription, Serializable {
18
19
    static final long serialVersionUID = -1135988488489108703L;
20
    
21
    
22
    private final DataEditorSupport dataEditorSupport;
23
    private VkSourceEditor editor;
24
    private JToolBar toolbar;
25
26
    public VkSourceViewDescription(DataEditorSupport dataEditorSupport) {
27
        this.dataEditorSupport = dataEditorSupport;
28
        //this.support = support;
29
    }
30
31
    @Override
32
    public int getPersistenceType() {
33
        return TopComponent.PERSISTENCE_ONLY_OPENED;
34
    }
35
36
    @Override
37
    public String getDisplayName() {
38
        return "Source";
39
    }
40
41
    @Override
42
    public Image getIcon() {
43
        return ImageUtilities.loadImageIcon("org/netbeans/modules/vk/HDataIcon.gif", false).getImage(); // NOI18N
44
    }
45
46
    @Override
47
    public String preferredID() {
48
        return "text";
49
    }
50
51
    @Override
52
    public HelpCtx getHelpCtx() {
53
        return HelpCtx.DEFAULT_HELP;
54
    }
55
56
    @Override
57
    public MultiViewElement createElement() {
58
        if (editor == null) {
59
            editor = new VkSourceEditor(dataEditorSupport);
60
        }
61
//        Node[] nodes = editor.getActivatedNodes();
62
//        if ((nodes == null) || (nodes.length == 0)) {
63
//            editor.setActivatedNodes(new Node[] {support.getDataObject().getNodeDelegate()});
64
//        }
65
        return editor;
66
    }
67
}
(-)cnd.modelui/src/org/netbeans/modules/vk/VkVisualEditor.java (+132 lines)
Added Link Here 
1
/*
2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3
 */
4
5
package org.netbeans.modules.vk;
6
7
import java.awt.BorderLayout;
8
import java.beans.PropertyChangeEvent;
9
import java.beans.PropertyChangeListener;
10
import java.io.Serializable;
11
import javax.swing.Action;
12
import javax.swing.JButton;
13
import javax.swing.JComponent;
14
import javax.swing.JPanel;
15
import javax.swing.JToolBar;
16
import javax.swing.event.ChangeEvent;
17
import javax.swing.event.ChangeListener;
18
import org.netbeans.core.spi.multiview.CloseOperationState;
19
import org.netbeans.core.spi.multiview.MultiViewElement;
20
import org.netbeans.core.spi.multiview.MultiViewElementCallback;
21
import org.openide.awt.UndoRedo;
22
import org.openide.loaders.DataObject;
23
import org.openide.nodes.Node;
24
import org.openide.text.DataEditorSupport;
25
import org.openide.util.Lookup;
26
import org.openide.util.lookup.Lookups;
27
import org.openide.util.lookup.ProxyLookup;
28
29
/**
30
 * @author Vladimir Kvashin
31
 */
32
public class VkVisualEditor extends JPanel  
33
        implements MultiViewElement, PropertyChangeListener, Serializable, ChangeListener {
34
35
    private static final long serialVersionUID = 3280748743140605180L;
36
    private static final String SPLITTER_POSITION_PREF_NAME = "dividerLocation"; // NOI18N
37
    
38
    private final DataEditorSupport dataEditorSupport;
39
40
    private JToolBar toolbar;
41
    private MultiViewElementCallback callback;
42
43
44
    public VkVisualEditor(DataEditorSupport dataEditorSupport) {
45
        this.dataEditorSupport = dataEditorSupport;
46
        setLayout(new BorderLayout());
47
        add(new JButton("Press Me"));
48
        toolbar = new JToolBar(JToolBar.HORIZONTAL);
49
        toolbar.add(new JButton("1"));
50
        toolbar.add(new JButton("2"));
51
        toolbar.add(new JButton("3"));
52
    }
53
54
    // MultiViewElement implementation start
55
    @Override
56
    public void componentActivated() {
57
    }
58
59
    @Override
60
    public void componentDeactivated() {
61
    }
62
63
    @Override
64
    public void componentClosed() {
65
    }
66
67
    @Override
68
    public void componentHidden() {
69
    }
70
71
    @Override
72
    public void componentOpened() {
73
    }
74
75
    @Override
76
    public void componentShowing() {
77
    }
78
79
    @Override
80
    public Action[] getActions() {
81
        return new Action[0];
82
    }
83
    // MultiViewElement implementation end
84
    
85
    
86
    @Override
87
    public void stateChanged(ChangeEvent e) {
88
    }
89
90
91
    @Override
92
    public void propertyChange(PropertyChangeEvent evt) {
93
    }
94
95
96
    @Override
97
    public JComponent getVisualRepresentation() {
98
        return this;
99
    }
100
101
    @Override
102
    public JComponent getToolbarRepresentation() {
103
        return toolbar;
104
    }
105
106
    @Override
107
    public UndoRedo getUndoRedo() {
108
        return null;
109
    }
110
111
    @Override
112
    public CloseOperationState canCloseElement() {
113
        System.err.printf("I'M CLOSING\n");
114
        return CloseOperationState.STATE_OK;
115
    }
116
117
    @Override
118
    public Lookup getLookup() {
119
        DataObject dao = dataEditorSupport.getDataObject();
120
        Node node = dao.getNodeDelegate();
121
        Lookup nodeLookup = node.getLookup();
122
        //UbbUtils.dumpLookup("UbbSourceEditor node lookup", nodeLookup);
123
        Lookup result = new ProxyLookup(nodeLookup, Lookups.singleton(node), dao.getLookup());
124
        return result;
125
    }
126
127
    @Override
128
    public void setMultiViewCallback(MultiViewElementCallback callback) {
129
        this.callback = callback;
130
//        updateName();
131
    }
132
}
(-)cnd.modelui/src/org/netbeans/modules/vk/VkVisualViewDescription.java (+58 lines)
Added Link Here 
1
/*
2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3
 */
4
5
package org.netbeans.modules.vk;
6
7
import java.awt.Image;
8
import java.io.Serializable;
9
import org.netbeans.core.spi.multiview.MultiViewDescription;
10
import org.netbeans.core.spi.multiview.MultiViewElement;
11
import org.openide.text.DataEditorSupport;
12
import org.openide.util.HelpCtx;
13
import org.openide.util.ImageUtilities;
14
import org.openide.windows.TopComponent;
15
16
public class VkVisualViewDescription  implements MultiViewDescription, Serializable  {
17
18
    static final long serialVersionUID = 6758876646105130771L;
19
    private VkVisualEditor editor;
20
    private final DataEditorSupport dataEditorSupport;
21
22
    public VkVisualViewDescription(DataEditorSupport dataEditorSupport) {
23
        this.dataEditorSupport = dataEditorSupport;
24
    }
25
26
    @Override
27
    public int getPersistenceType() {
28
        return TopComponent.PERSISTENCE_ONLY_OPENED;
29
    }
30
31
    @Override
32
    public String getDisplayName() {
33
        return "Visual";
34
    }
35
36
    @Override
37
    public Image getIcon() {
38
        return ImageUtilities.loadImageIcon("org/netbeans/modules/vk/vkfile.gif", false).getImage(); // NOI18N
39
    }
40
41
    @Override
42
    public HelpCtx getHelpCtx() {
43
        return HelpCtx.DEFAULT_HELP;
44
    }
45
46
    @Override
47
    public String preferredID() {
48
        return "visual";
49
    }
50
51
    @Override
52
    public MultiViewElement createElement() {
53
        if (editor == null) {
54
            editor = new VkVisualEditor(dataEditorSupport);
55
        }
56
        return editor;
57
    }
58
}

Return to bug 201208
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo