KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.openide.nodes.*;
23 import org.openide.actions.PropertiesAction;
24 import org.openide.util.actions.SystemAction;
25
26 import org.netbeans.modules.form.actions.*;
27
28 /**
29  * This class represents the root node of the form (displayed as root in
30  * Component Inspector).
31  *
32  * @author Tomas Pavek
33  */

34
35 class FormRootNode extends FormNode {
36     private Node.Property[] codeGenProperties;
37     private Node.Property[] i18nProperties;
38     private Node.Property[] allProperties;
39
40     public FormRootNode(FormModel formModel) {
41         super(new RootChildren(formModel), formModel);
42         setName("Form Root Node"); // NOI18N
43
setIconBaseWithExtension("org/netbeans/modules/form/resources/formDesigner.gif"); // NOI18N
44
updateName(formModel.getName());
45     }
46
47     // TODO: icons for visual and non-visual forms
48
// public Image getIcon(int iconType) {
49
// }
50

51     public boolean canRename() {
52         return false;
53     }
54
55     public boolean canDestroy() {
56         return false;
57     }
58
59     public javax.swing.Action JavaDoc[] getActions(boolean context) {
60         if (systemActions == null) // from AbstractNode
61
systemActions = new SystemAction[] {
62                 SystemAction.get(ReloadAction.class),
63                 null,
64                 SystemAction.get(PropertiesAction.class)
65             };
66         return systemActions;
67     }
68
69     void updateName(String JavaDoc name) {
70         setDisplayName(FormUtils.getFormattedBundleString("FMT_FormNodeName", // NOI18N
71
new Object JavaDoc[] { name }));
72     }
73
74     FormOthersNode getOthersNode() {
75         return ((RootChildren)getChildren()).othersNode;
76     }
77     
78     public Node.PropertySet[] getPropertySets() {
79         Node.PropertySet codeSet = new Node.PropertySet(
80                 "codeGeneration", // NOI18N
81
FormUtils.getBundleString("CTL_SyntheticTab"), // NOI18N
82
FormUtils.getBundleString("CTL_SyntheticTabHint")) // NOI18N
83
{
84             public Node.Property[] getProperties() {
85                 return getCodeGenProperties();
86             }
87         };
88         Node.PropertySet i18nSet = new Node.PropertySet(
89                 "i18n", // NOI18N
90
FormUtils.getBundleString("CTL_I18nTab"), // NOI18N
91
FormUtils.getBundleString("CTL_I18nTabHint")) // NOI18N
92
{
93             public Node.Property[] getProperties() {
94                 return getI18nProperties();
95             }
96         };
97         return new Node.PropertySet[] { codeSet, i18nSet };
98     }
99
100     Node.Property[] getCodeGenProperties() {
101         if (codeGenProperties == null)
102             codeGenProperties = createCodeGenProperties();
103         return codeGenProperties;
104     }
105     
106     private Node.Property[] createCodeGenProperties() {
107         return FormEditor.getCodeGenerator(getFormModel()).getSyntheticProperties(null);
108     }
109
110     Node.Property[] getI18nProperties() {
111         if (i18nProperties == null)
112             i18nProperties = createI18nProperties();
113         return i18nProperties;
114     }
115     
116     private Node.Property[] createI18nProperties() {
117         return FormEditor.getI18nSupport(getFormModel()).createFormProperties();
118     }
119
120     Node.Property[] getAllProperties() {
121         if (allProperties == null) {
122             int codeGenCount = getCodeGenProperties().length;
123             int i18nCount = getI18nProperties().length;
124             allProperties = new Node.Property[codeGenCount + i18nCount];
125             System.arraycopy(codeGenProperties, 0, allProperties, 0, codeGenCount);
126             System.arraycopy(i18nProperties, 0, allProperties, codeGenCount, i18nCount);
127         }
128         return allProperties;
129     }
130
131     // ----------------
132

133     static class RootChildren extends Children.Keys {
134
135         static final Object JavaDoc OTHERS_ROOT = new Object JavaDoc();
136         static final Object JavaDoc MAIN_VISUAL_ROOT = new Object JavaDoc();
137
138         private FormModel formModel;
139         private FormOthersNode othersNode;
140
141         protected RootChildren(FormModel formModel) {
142             this.formModel = formModel;
143             setKeys(formModel.getTopRADComponent() != null ?
144                         new Object JavaDoc[] { OTHERS_ROOT, MAIN_VISUAL_ROOT } :
145                         new Object JavaDoc[] { OTHERS_ROOT } );
146         }
147
148         protected Node[] createNodes(Object JavaDoc key) {
149             Node node;
150             if (key == MAIN_VISUAL_ROOT)
151                 node = new RADComponentNode(formModel.getTopRADComponent());
152             else // OTHERS_ROOT
153
node = othersNode = new FormOthersNode(formModel);
154
155             node.getChildren().getNodes(); // enforce subnodes creation
156
return new Node[] { node };
157         }
158
159         protected final FormModel getFormModel() {
160             return formModel;
161         }
162     }
163     
164 }
165
Popular Tags