KickJava   Java API By Example, From Geeks To Geeks.

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


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * AttributeNode.java
22  *
23  * Created on April 17, 2006, 4:24 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.abe.nodes;
30
31 import java.beans.PropertyEditorSupport JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.List JavaDoc;
34 import org.netbeans.modules.xml.axi.AXIType;
35 import org.netbeans.modules.xml.axi.AbstractAttribute;
36 import org.netbeans.modules.xml.axi.AnyAttribute;
37 import org.netbeans.modules.xml.axi.Attribute;
38 import org.netbeans.modules.xml.axi.Element;
39 import org.netbeans.modules.xml.axi.datatype.Datatype;
40 import org.netbeans.modules.xml.schema.abe.InstanceUIContext;
41 import org.netbeans.modules.xml.schema.abe.StartTagPanel;
42 import org.netbeans.modules.xml.schema.abe.UIUtilities;
43 import org.netbeans.modules.xml.schema.abe.nodes.properties.BaseABENodeProperty;
44 import org.netbeans.modules.xml.schema.abe.nodes.properties.DefaultProperty;
45 import org.netbeans.modules.xml.schema.abe.nodes.properties.FixedProperty;
46 import org.netbeans.modules.xml.schema.abe.nodes.properties.FormPropertyEditor;
47 import org.netbeans.modules.xml.schema.abe.nodes.properties.GlobalReferenceProperty;
48 import org.netbeans.modules.xml.schema.abe.nodes.properties.NameProperty;
49 import org.netbeans.modules.xml.schema.model.Form;
50 import org.netbeans.modules.xml.schema.model.Attribute.Use;
51 import org.openide.nodes.Node;
52 import org.openide.nodes.PropertySupport;
53 import org.openide.nodes.Sheet;
54 import org.openide.util.NbBundle;
55
56 /**
57  *
58  * @author Samaresh (Samaresh.Panda@Sun.Com)
59  */

60 public class AttributeNode extends ABEAbstractNode {
61     
62     
63     /**
64      * Creates a new instance of AttributeNode
65      */

66     public AttributeNode(AbstractAttribute attribute, InstanceUIContext context) {
67         super(attribute, context);
68     }
69     
70     
71     public AttributeNode(AbstractAttribute attribute) {
72         super(attribute, new ABENodeChildren(attribute));
73         setIconBaseWithExtension(
74                 "org/netbeans/modules/xml/schema/abe/resources/attribute.png");
75         
76     }
77     protected void populateProperties(Sheet sheet) {
78         if(getAXIComponent() instanceof AnyAttribute)
79             //right now there is no props for AnyAttribute
80
return;
81         Sheet.Set set = sheet.get(Sheet.PROPERTIES);
82         if(set == null) {
83             set = sheet.createPropertiesSet();
84         }
85         
86         boolean shared = false;
87         shared = getAXIComponent().isShared();
88         boolean reference = false;
89         if(getAXIComponent() instanceof Attribute)
90             reference = ((Attribute)getAXIComponent()).isReference();
91         
92         Sheet.Set sharedSheet = null;
93         if(shared || reference){
94             //create shared sheet
95
sharedSheet = getSharedSet(sheet);
96         }else{
97             //use normal sheet for everything
98
sharedSheet = set;
99         }
100         
101         if(shared && ! reference){
102             //then all props are shared
103
set = sharedSheet;
104         }
105         
106         
107         try {
108             //name property
109
Node.Property name = new NameProperty(
110                     this,
111                     String JavaDoc.class,
112                     Attribute.PROP_NAME,
113                     NbBundle.getMessage(AttributeNode.class, "PROP_AttributeNode_Name"),
114                     NbBundle.getMessage(AttributeNode.class, "PROP_AttributeNode_NameDesc"));
115             sharedSheet.put(name);
116             
117             // fixed property
118
Node.Property fixedProp = new FixedProperty(
119                     getAXIComponent(),
120                     NbBundle.getMessage(AttributeNode.class,"PROP_Fixed_DisplayName"), // display name
121
NbBundle.getMessage(AttributeNode.class,"PROP_Fixed_ShortDescription") // descr
122
);
123             set.put(new SchemaModelFlushWrapper(getAXIComponent(),fixedProp, getContext()));
124             
125             // default property
126
Node.Property defaultProp = new DefaultProperty(
127                     getAXIComponent(),
128                     NbBundle.getMessage(AttributeNode.class,"PROP_Default_DisplayName"), // display name
129
NbBundle.getMessage(AttributeNode.class,"PROP_Default_ShortDescription") // descr
130
);
131             set.put(new SchemaModelFlushWrapper(getAXIComponent(),defaultProp, getContext()));
132             
133             // use property
134
Node.Property useProp = new BaseABENodeProperty(
135                     getAXIComponent(),
136                     Use.class, //as value type
137
Attribute.PROP_USE, //property name
138
NbBundle.getMessage(AttributeNode.class,"PROP_Use_DisplayName"), // display name
139
NbBundle.getMessage(AttributeNode.class,"PROP_Use_ShortDescription"), // descr
140
UseEditor.class
141                     );
142             set.put(new SchemaModelFlushWrapper(getAXIComponent(),useProp, getContext()));
143             
144             // form property
145
Node.Property formProp = new BaseABENodeProperty(
146                     getAXIComponent(),
147                     Form.class, // Occur.ZeroOne.class as value type
148
Attribute.PROP_FORM, //property name
149
NbBundle.getMessage(AttributeNode.class,"PROP_Form_DisplayName"), // display name
150
NbBundle.getMessage(AttributeNode.class,"PROP_Form_ElementShortDescription"), // descr
151
FormPropertyEditor.class
152                     );
153             set.put(new SchemaModelFlushWrapper(getAXIComponent(),formProp, getContext()));
154             
155             //definition
156
List JavaDoc<Class JavaDoc> filterTypes = new ArrayList JavaDoc<Class JavaDoc>();
157             filterTypes.add(Datatype.class);
158             filterTypes.add(Attribute.class);
159             Node.Property typeProp = new GlobalReferenceProperty(
160                     getAXIComponent(),
161                     Attribute.PROP_TYPE,
162                     NbBundle.getMessage(AttributeNode.class,
163                     "PROP_Type_DisplayName"), // display name
164
NbBundle.getMessage(AttributeNode.class,
165                     "HINT_Type_ShortDesc"), // descr
166
NbBundle.getMessage(AttributeNode.class,
167                     "LBL_AttributeNode_TypeDisplayName"), // type display name
168
NbBundle.getMessage(AttributeNode.class,
169                     "LBL_ContentModelNode_TypeDisplayName"),
170                     AXIType.class,
171                     filterTypes
172                     );
173             if(!getAXIComponent().isReadOnly())
174                 sharedSheet.put(new SchemaModelFlushWrapper(getAXIComponent(), typeProp, getContext()));
175             
176         } catch (Exception JavaDoc ex) {
177             ex.printStackTrace();
178         }
179         
180         if(shared && !reference){
181             //everthing shared
182
sheet.put(set);
183         }else if(shared && reference){
184             //name and defn shared
185
sheet.put(set);
186             sheet.put(sharedSheet);
187         }else{
188             sheet.put(set);
189         }
190     }
191     
192     public String JavaDoc getName(){
193         if((AbstractAttribute) super.getAXIComponent() != null)
194             return ((AbstractAttribute) super.getAXIComponent()).getName();
195         else
196             return "";
197     }
198     
199     protected String JavaDoc getTypeDisplayName() {
200         return NbBundle.getMessage(AttributeNode.class,"LBL_Attribute");
201     }
202     
203     public static class UseEditor extends PropertyEditorSupport JavaDoc {
204         
205         /**
206          * Creates a new instance of ProcessContentsEditor
207          */

208         public UseEditor() {
209         }
210         
211         public String JavaDoc[] getTags() {
212             return new String JavaDoc[] {NbBundle.getMessage(AttributeNode.class,"LBL_Empty"),
213             NbBundle.getMessage(AttributeNode.class,"LBL_Prohibited"),
214             NbBundle.getMessage(AttributeNode.class,"LBL_Optional"),
215             NbBundle.getMessage(AttributeNode.class,"LBL_Required")};
216         }
217         
218         public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
219             if (text.equals(NbBundle.getMessage(AttributeNode.class,"LBL_Empty"))){
220                 setValue(null);
221             } else if (text.equals(NbBundle.getMessage(AttributeNode.class,"LBL_Prohibited"))){
222                 setValue(Use.PROHIBITED);
223             } else if (text.equals(NbBundle.getMessage(AttributeNode.class,"LBL_Optional"))){
224                 setValue(Use.OPTIONAL);
225             } else if (text.equals(NbBundle.getMessage(AttributeNode.class,"LBL_Required"))){
226                 setValue(Use.REQUIRED);
227             }
228         }
229         
230         public String JavaDoc getAsText() {
231             Object JavaDoc val = getValue();
232             if (val instanceof Use){
233                 if (Use.PROHIBITED.equals(val)) {
234                     return NbBundle.getMessage(AttributeNode.class,"LBL_Prohibited");
235                 } else if (Use.OPTIONAL.equals(val)) {
236                     return NbBundle.getMessage(AttributeNode.class,"LBL_Optional");
237                 } else if (Use.REQUIRED.equals(val)) {
238                     return NbBundle.getMessage(AttributeNode.class,"LBL_Required");
239                 }
240             }
241             // TODO how to display invalid values?
242
return NbBundle.getMessage(AttributeNode.class,"LBL_Empty");
243         }
244     }
245 }
246
Popular Tags