KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > FormOthersNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.form;
21
22 import java.util.ArrayList JavaDoc;
23 import java.awt.datatransfer.*;
24
25 import org.openide.nodes.*;
26 import org.openide.cookies.*;
27 import org.openide.actions.*;
28 import org.openide.util.actions.SystemAction;
29
30 import org.netbeans.modules.form.actions.AddAction;
31 import org.netbeans.modules.form.project.ClassSource;
32
33 /**
34  * This class represents the root node of "Other Components".
35  *
36  * @author Tomas Pavek
37  */

38
39 class FormOthersNode extends FormNode {
40
41     public FormOthersNode(FormModel formModel) {
42         super(new OthersChildren(formModel), formModel);
43
44         getCookieSet().add(new OthersIndex((OthersChildren)getChildren()));
45         setIconBase("org/netbeans/modules/form/resources/formNonVisual"); // NOI18N
46
setName("Others Node"); // NOI18N
47
setName(FormUtils.getBundleString("CTL_NonVisualComponents")); // NOI18N
48
}
49
50     public javax.swing.Action JavaDoc[] getActions(boolean context) {
51         if (systemActions == null) { // from AbstractNode
52
ArrayList JavaDoc actions = new ArrayList JavaDoc(10);
53
54             if (!getFormModel().isReadOnly()) {
55                 actions.add(SystemAction.get(AddAction.class));
56                 actions.add(null);
57                 actions.add(SystemAction.get(PasteAction.class));
58                 actions.add(null);
59                 actions.add(SystemAction.get(ReorderAction.class));
60                 actions.add(null);
61             }
62
63             javax.swing.Action JavaDoc[] superActions = super.getActions(context);
64             for (int i=0; i < superActions.length; i++)
65                 actions.add(superActions[i]);
66
67             systemActions = new SystemAction[actions.size()];
68             actions.toArray(systemActions);
69         }
70
71         return systemActions;
72     }
73
74     protected void createPasteTypes(Transferable t, java.util.List JavaDoc s) {
75         FormModel formModel = getFormModel();
76         if (formModel.isReadOnly())
77             return;
78
79         boolean copy = t.isDataFlavorSupported(
80                              CopySupport.getComponentCopyFlavor());
81         boolean cut = t.isDataFlavorSupported(
82                             CopySupport.getComponentCutFlavor());
83
84         if (copy || cut) { // copy or cut some RADComponent
85
RADComponent transComp = null;
86             try {
87                 Object JavaDoc data = t.getTransferData(t.getTransferDataFlavors()[0]);
88                 if (data instanceof RADComponent)
89                     transComp = (RADComponent) data;
90             }
91             catch (UnsupportedFlavorException e) {} // should not happen
92
catch (java.io.IOException JavaDoc e) {} // should not happen
93

94             if (transComp != null
95                 && (!cut || CopySupport.canPasteCut(transComp, formModel, null)))
96             {
97                 s.add(new CopySupport.RADPaste(t, formModel, null));
98             }
99         }
100         else { // java or class node could be copied
101
ClassSource classSource = CopySupport.getCopiedBeanClassSource(t);
102             if (classSource != null) {
103                 s.add(new CopySupport.ClassPaste(t, classSource, formModel, null));
104             }
105         }
106     }
107
108     // -------------
109

110     static class OthersChildren extends FormNodeChildren {
111
112         private FormModel formModel;
113
114         protected OthersChildren(FormModel formModel) {
115             this.formModel = formModel;
116             updateKeys();
117         }
118
119         // FormNodeChildren implementation
120
protected void updateKeys() {
121             setKeys(formModel.getOtherComponents().toArray());
122         }
123
124         protected Node[] createNodes(Object JavaDoc key) {
125             Node node = new RADComponentNode((RADComponent)key);
126             node.getChildren().getNodes(); // enforce subnodes creation
127
return new Node[] { node };
128         }
129
130         protected final FormModel getFormModel() {
131             return formModel;
132         }
133     }
134
135     // -------------
136

137     static final class OthersIndex extends org.openide.nodes.Index.Support {
138         private OthersChildren children;
139
140         public OthersIndex(OthersChildren children) {
141             this.children = children;
142         }
143
144         public Node[] getNodes() {
145             return children.getNodes();
146         }
147
148         public int getNodesCount() {
149             return getNodes().length;
150         }
151
152         public void reorder(int[] perm) {
153             ComponentContainer cont = children.getFormModel().getModelContainer();
154             cont.reorderSubComponents(perm);
155             children.getFormModel().fireComponentsReordered(cont, perm);
156 // children.updateKeys();
157
}
158     }
159 }
160
Popular Tags