KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > nodes > ElementNode


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

20
21 package org.netbeans.modules.xml.schema.abe.nodes;
22
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27 import org.netbeans.modules.xml.axi.AXIContainer;
28 import org.netbeans.modules.xml.axi.AXIType;
29 import org.netbeans.modules.xml.axi.AbstractElement;
30 import org.netbeans.modules.xml.axi.Compositor;
31 import org.netbeans.modules.xml.axi.ContentModel;
32 import org.netbeans.modules.xml.axi.Element;
33 import org.netbeans.modules.xml.axi.datatype.Datatype;
34 import org.netbeans.modules.xml.schema.abe.InstanceUIContext;
35 import org.netbeans.modules.xml.schema.abe.action.AttributeOnElementNewType;
36 import org.netbeans.modules.xml.schema.abe.action.CompositorOnElementNewType;
37 import org.netbeans.modules.xml.schema.abe.action.ElementOnElementNewType;
38 import org.netbeans.modules.xml.schema.abe.nodes.properties.*;
39 import org.netbeans.modules.xml.schema.model.Form;
40 import org.openide.nodes.Node;
41 import org.openide.nodes.Node.Property;
42 import org.openide.nodes.PropertySupport;
43 import org.openide.nodes.Sheet;
44 import org.openide.util.NbBundle;
45 import org.openide.util.datatransfer.NewType;
46
47 /**
48  *
49  * @author Samaresh (Samaresh.Panda@Sun.Com)
50  */

51 public class ElementNode extends ABEAbstractNode {
52     
53     
54     /**
55      * Creates a new instance of ElementNode
56      */

57     public ElementNode(AbstractElement element, InstanceUIContext context) {
58         super(element, context);
59         initialize();
60     }
61     
62     public ElementNode(AbstractElement element) {
63         super(element, new ABENodeChildren(element));
64         setIconBaseWithExtension(
65                 "org/netbeans/modules/xml/schema/abe/resources/element.png");
66         
67     }
68     
69     private void initialize(){
70         getAXIComponent().addPropertyChangeListener(new PropertyChangeListener JavaDoc(){
71             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
72                 if(evt.getPropertyName().equals(Element.PROP_NAME)){
73                     ElementNode.this.fireNameChange((String JavaDoc) evt.getOldValue(), (String JavaDoc) evt.getNewValue());
74                     ElementNode.this.firePropertySetsChange(ElementNode.this.getPropertySets(),
75                             ElementNode.this.getPropertySets());
76                 }
77             }
78             
79         });
80     }
81     
82     protected void populateProperties(Sheet sheet) {
83         Sheet.Set set = sheet.get(Sheet.PROPERTIES);
84         if(set == null) {
85             set = sheet.createPropertiesSet();
86         }
87         
88         boolean shared = false;
89         shared = getAXIComponent().isShared();
90         boolean reference = false;
91         if(getAXIComponent() instanceof Element)
92             reference = ((Element)getAXIComponent()).isReference();
93         
94         Sheet.Set sharedSheet = null;
95         if(shared || reference){
96             //create shared sheet
97
sharedSheet = getSharedSet(sheet);
98         }else{
99             //use normal sheet for everything
100
sharedSheet = set;
101         }
102         
103         if(shared && ! reference){
104             //then all props are shared
105
set = sharedSheet;
106         }
107         
108         try {
109             //name property
110
Node.Property name = new PropertySupport.Name(
111                     this,
112                     NbBundle.getMessage(ElementNode.class, "PROP_ElementNode_Name"),
113                     NbBundle.getMessage(ElementNode.class, "PROP_ElementNode_NameDesc")
114                     );
115             sharedSheet.put(name);
116             
117             // nillable property
118
Node.Property nillableProp = new BooleanProperty(
119                     getAXIComponent(),
120                     Element.PROP_NILLABLE, // property name
121
NbBundle.getMessage(ElementNode.class,"PROP_Nillable_DisplayName"), // display name
122
NbBundle.getMessage(ElementNode.class,"PROP_Nillable_ShortDescription"), // descr
123
true // default value is false
124
);
125             set.put(new SchemaModelFlushWrapper(getAXIComponent(),nillableProp, getContext()));
126             
127             // fixed property
128
Node.Property fixedProp = new FixedProperty(
129                     getAXIComponent(),
130                     NbBundle.getMessage(ElementNode.class,"PROP_Fixed_DisplayName"), // display name
131
NbBundle.getMessage(ElementNode.class,"PROP_Fixed_ShortDescription") // descr
132
);
133             set.put(new SchemaModelFlushWrapper(getAXIComponent(),fixedProp, getContext()));
134             
135             // default property
136
Node.Property defaultProp = new DefaultProperty(
137                     getAXIComponent(),
138                     NbBundle.getMessage(ElementNode.class,"PROP_Default_DisplayName"), // display name
139
NbBundle.getMessage(ElementNode.class,"PROP_Default_ShortDescription") // descr
140
);
141             set.put(new SchemaModelFlushWrapper(getAXIComponent(),defaultProp, getContext()));
142             
143             if(getAXIComponent().supportsCardinality()) {
144                 // minOccurs
145
Node.Property minOccursProp = new MinOccursProperty(
146                         getAXIComponent(),
147                         String JavaDoc.class,
148                         Element.PROP_MINOCCURS,
149                         NbBundle.getMessage(ElementNode.class,"PROP_MinOccurs_DisplayName"), // display name
150
NbBundle.getMessage(ElementNode.class,"PROP_MinOccurs_ShortDescription") // descr
151
);
152                 set.put(new SchemaModelFlushWrapper(getAXIComponent(), minOccursProp, getContext()));
153                 
154                 // maxOccurs
155
if (getAXIComponent() instanceof AbstractElement &&
156                         ((AbstractElement)getAXIComponent()).allowsFullMultiplicity()) {
157                     Property maxOccursProp = new BaseABENodeProperty(
158                             getAXIComponent(),
159                             String JavaDoc.class,
160                             Element.PROP_MAXOCCURS,
161                             NbBundle.getMessage(ElementNode.class,"PROP_MaxOccurs_DisplayName"), // display name
162
NbBundle.getMessage(ElementNode.class,"PROP_MaxOccurs_ShortDescription"), // descr
163
MaxOccursEditor.class
164                             );
165                     set.put(new SchemaModelFlushWrapper(getAXIComponent(), maxOccursProp, getContext()));
166                 }
167             }
168             
169             // form property
170
Node.Property formProp = new BaseABENodeProperty(
171                     getAXIComponent(),
172                     Form.class, // Occur.ZeroOne.class as value type
173
Element.PROP_FORM, //property name
174
NbBundle.getMessage(ElementNode.class,"PROP_Form_DisplayName"), // display name
175
NbBundle.getMessage(ElementNode.class,"PROP_Form_ElementShortDescription"), // descr
176
FormPropertyEditor.class
177                     );
178             set.put(new SchemaModelFlushWrapper(getAXIComponent(),formProp, getContext()));
179             
180             // definition property
181
List JavaDoc<Class JavaDoc> filterTypes = new ArrayList JavaDoc<Class JavaDoc>();
182             filterTypes.add(Datatype.class);
183             filterTypes.add(ContentModel.class);
184             filterTypes.add(Element.class);
185             Node.Property typeProp = new GlobalReferenceProperty(
186                     getAXIComponent(),
187                     Element.PROP_TYPE,
188                     NbBundle.getMessage(ElementNode.class,
189                     "PROP_Type_DisplayName"), // display name
190
NbBundle.getMessage(ElementNode.class,
191                     "HINT_Type_ShortDesc"), // descr
192
NbBundle.getMessage(ElementNode.class,
193                     "LBL_ElementNode_TypeDisplayName"), // type display name
194
NbBundle.getMessage(ElementNode.class,
195                     "LBL_ContentModelNode_TypeDisplayName"),
196                     AXIType.class,
197                     filterTypes
198                     );
199             if(!getAXIComponent().isReadOnly())
200                 sharedSheet.put(new SchemaModelFlushWrapper(getAXIComponent(), typeProp, getContext()));
201             
202         } catch (Exception JavaDoc ex) {
203         }
204         
205         if(shared && !reference){
206             //everthing shared
207
sheet.put(set);
208         }else if(shared && reference){
209             //name and defn shared
210
sheet.put(set);
211             sheet.put(sharedSheet);
212         }else{
213             sheet.put(set);
214         }
215         
216     }
217     
218     public String JavaDoc getName(){
219         if((AbstractElement) super.getAXIComponent() != null)
220             return ((AbstractElement) super.getAXIComponent()).getName();
221         else
222             return "";
223     }
224     
225     public NewType[] getNewTypes() {
226         if(getAXIComponent().isReadOnly())
227             return new NewType[0];
228         List JavaDoc<NewType> ntl = new ArrayList JavaDoc<NewType>();
229         NewType nt = new ElementOnElementNewType(getContext());
230         ntl.add(nt);
231         nt = new AttributeOnElementNewType(getContext());
232         ntl.add(nt);
233         if( ((AXIContainer)getAXIComponent()).getCompositor() == null ){
234             nt = new CompositorOnElementNewType(getContext(), Compositor.
235                     CompositorType.SEQUENCE);
236             ntl.add(nt);
237             nt = new CompositorOnElementNewType(getContext(), Compositor.
238                     CompositorType.CHOICE);
239             ntl.add(nt);
240             nt = new CompositorOnElementNewType(getContext(), Compositor.
241                     CompositorType.ALL);
242             ntl.add(nt);
243         }
244         return ntl.toArray(new NewType[ntl.size()]);
245     }
246     
247     public boolean canRename() {
248         if(canWrite())
249             return true;
250         return false;
251     }
252     
253     protected String JavaDoc getTypeDisplayName() {
254         return NbBundle.getMessage(AttributeNode.class,"LBL_Element");
255     }
256     
257 }
258
Popular Tags