KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > schema > LocalAttributeNode


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 package org.netbeans.modules.xml.schema.ui.nodes.schema;
21
22 import java.beans.PropertyEditorSupport JavaDoc;
23 import org.netbeans.modules.xml.schema.model.GlobalSimpleType;
24 import org.netbeans.modules.xml.schema.model.LocalAttribute;
25 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
26 import org.netbeans.modules.xml.schema.ui.nodes.*;
27 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.BaseSchemaProperty;
28 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.DefaultProperty;
29 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.FixedProperty;
30 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.FormProperty;
31 import org.openide.nodes.Children;
32 import org.openide.nodes.Node;
33 import org.openide.nodes.Sheet;
34 import org.openide.util.NbBundle;
35 /**
36  *
37  * @author Todd Fast, todd.fast@sun.com
38  */

39 public class LocalAttributeNode extends SchemaComponentNode<LocalAttribute>
40 {
41     /**
42      *
43      *
44      */

45     public LocalAttributeNode(SchemaUIContext context,
46         SchemaComponentReference<LocalAttribute> reference,
47         Children children) {
48         super(context,reference,children);
49     
50         setIconBaseWithExtension(
51         "org/netbeans/modules/xml/schema/ui/nodes/resources/"+
52         "attribute.png");
53     }
54     
55     
56     /**
57      *
58      *
59      */

60     @Override JavaDoc
61         public String JavaDoc getTypeDisplayName() {
62     return NbBundle.getMessage(LocalAttributeNode.class,
63         "LBL_LocalAttributeNode_TypeDisplayName"); // NOI18N
64
}
65     
66     @Override JavaDoc
67     protected GlobalSimpleType getSuperDefinition()
68     {
69         LocalAttribute sc = getReference().get();
70         GlobalSimpleType gt = null;
71         if(sc.getType()!=null)
72             gt = sc.getType().get();
73         return gt;
74     }
75     
76     @Override JavaDoc
77         protected Sheet createSheet() {
78     Sheet sheet = super.createSheet();
79     Sheet.Set set = sheet.get(Sheet.PROPERTIES);
80     try {
81         // form and type should have a custom editor
82

83         // fixed property
84
Node.Property fixedProp = new FixedProperty(
85             getReference().get(), // schema component
86
NbBundle.getMessage(LocalAttributeNode.class,"PROP_Fixed_DisplayName"), // display name
87
NbBundle.getMessage(LocalAttributeNode.class,"PROP_Fixed_ShortDescription") // descr
88
);
89         set.put(new SchemaModelFlushWrapper(getReference().get(),fixedProp));
90         
91         // default property
92
Node.Property defaultProp = new DefaultProperty(
93             getReference().get(), // schema component
94
NbBundle.getMessage(LocalAttributeNode.class,"PROP_Default_DisplayName"), // display name
95
NbBundle.getMessage(LocalAttributeNode.class,"PROP_Default_ShortDescription") // descr
96
);
97         set.put(new SchemaModelFlushWrapper(getReference().get(),defaultProp));
98         
99         // use property
100
Node.Property useProp = new BaseSchemaProperty(
101             getReference().get(), // schema component
102
LocalAttribute.Use.class, //as value type
103
LocalAttribute.USE_PROPERTY, //property name
104
NbBundle.getMessage(LocalAttributeNode.class,"PROP_Use_DisplayName"), // display name
105
NbBundle.getMessage(LocalAttributeNode.class,"PROP_Use_ShortDescription"), // descr
106
UseEditor.class);
107         set.put(new SchemaModelFlushWrapper(getReference().get(),useProp));
108         
109         // form property
110
Node.Property formProp = new FormProperty(
111             getReference().get(), // schema component
112
LocalAttribute.FORM_PROPERTY, //property name
113
NbBundle.getMessage(LocalAttributeNode.class,"PROP_Form_DisplayName"), // display name
114
NbBundle.getMessage(LocalAttributeNode.class,"PROP_Form_ElementShortDescription") // descr
115
);
116         set.put(new SchemaModelFlushWrapper(getReference().get(),formProp));
117         
118         // type property
119

120     } catch (NoSuchMethodException JavaDoc nsme) {
121         assert false : "properties should be defined";
122     }
123     
124     return sheet;
125     }
126     
127     public static class UseEditor extends PropertyEditorSupport JavaDoc {
128     
129     /**
130      * Creates a new instance of ProcessContentsEditor
131      */

132     public UseEditor() {
133     }
134     
135     public String JavaDoc[] getTags() {
136         return new String JavaDoc[] {NbBundle.getMessage(LocalAttributeNode.class,"LBL_Empty"),
137         NbBundle.getMessage(LocalAttributeNode.class,"LBL_Prohibited"),
138         NbBundle.getMessage(LocalAttributeNode.class,"LBL_Optional"),
139         NbBundle.getMessage(LocalAttributeNode.class,"LBL_Required")};
140     }
141     
142     public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
143         if (text.equals(NbBundle.getMessage(LocalAttributeNode.class,"LBL_Empty"))){
144         setValue(null);
145         } else if (text.equals(NbBundle.getMessage(LocalAttributeNode.class,"LBL_Prohibited"))){
146         setValue(LocalAttribute.Use.PROHIBITED);
147         } else if (text.equals(NbBundle.getMessage(LocalAttributeNode.class,"LBL_Optional"))){
148         setValue(LocalAttribute.Use.OPTIONAL);
149         } else if (text.equals(NbBundle.getMessage(LocalAttributeNode.class,"LBL_Required"))){
150         setValue(LocalAttribute.Use.REQUIRED);
151         }
152     }
153     
154     public String JavaDoc getAsText() {
155         Object JavaDoc val = getValue();
156         if (val instanceof LocalAttribute.Use){
157         if (LocalAttribute.Use.PROHIBITED.equals(val)) {
158             return NbBundle.getMessage(LocalAttributeNode.class,"LBL_Prohibited");
159         } else if (LocalAttribute.Use.OPTIONAL.equals(val)) {
160             return NbBundle.getMessage(LocalAttributeNode.class,"LBL_Optional");
161         } else if (LocalAttribute.Use.REQUIRED.equals(val)) {
162             return NbBundle.getMessage(LocalAttributeNode.class,"LBL_Required");
163         }
164         }
165         // TODO how to display invalid values?
166
return NbBundle.getMessage(LocalAttributeNode.class,"LBL_Empty");
167     }
168     }
169 }
170
Popular Tags