KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.datatransfer.Transferable JavaDoc;
23 import java.lang.reflect.InvocationTargetException JavaDoc;
24 import java.util.List JavaDoc;
25 import org.openide.nodes.Children;
26 import org.openide.nodes.Node;
27 import org.openide.nodes.Sheet;
28 import org.openide.util.NbBundle;
29
30 //local imports
31
import org.netbeans.modules.xml.schema.model.Schema;
32 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
33 import org.netbeans.modules.xml.schema.model.Form;
34 import org.netbeans.modules.xml.schema.ui.basic.editors.FormPropertyEditor;
35 import org.netbeans.modules.xml.schema.ui.basic.editors.StringEditor;
36 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.BaseSchemaProperty;
37 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.DerivationTypeProperty;
38 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.NamespaceProperty;
39 import org.netbeans.modules.xml.schema.ui.nodes.*;
40
41 /**
42  *
43  * @author Todd Fast, todd.fast@sun.com
44  */

45 public class SchemaNode extends SchemaComponentNode<Schema>
46 {
47     /**
48      *
49      *
50      */

51     public SchemaNode(SchemaUIContext context,
52         SchemaComponentReference<Schema> reference,
53         Children children)
54     {
55         super(context,reference,children);
56
57         setIconBaseWithExtension(
58             "org/netbeans/modules/xml/schema/core/resources/"+
59             "Schema_File.png");
60     }
61
62
63     /**
64      *
65      *
66      */

67     protected void updateDisplayName()
68     {
69         String JavaDoc name = getReference().get().getTargetNamespace();
70         if (name == null) {
71             name = NbBundle.getMessage(SchemaNode.class,
72                 "LBL_SchemaNode_NoTargetNamespace");
73         }
74
75         setDisplayName(name);
76     }
77
78
79     /**
80      *
81      *
82      */

83     @Override JavaDoc
84     public String JavaDoc getTypeDisplayName()
85     {
86         return NbBundle.getMessage(SchemaNode.class,
87             "LBL_SchemaNode_TypeDisplayName"); // NOI18N
88
}
89
90     @Override JavaDoc
91     protected Sheet createSheet()
92     {
93         Sheet sheet = super.createSheet();
94         Sheet.Set props = sheet.get(Sheet.PROPERTIES);
95         if (props == null) {
96             props = Sheet.createPropertiesSet();
97             sheet.put(props);
98         }
99         try {
100             // attribute form property
101
Node.Property attrFormProp = new BaseSchemaProperty(
102                     getReference().get(), // schema component
103
Form.class, // value type
104
Schema.ATTRIBUTE_FORM_DEFAULT_PROPERTY, //property name
105
NbBundle.getMessage(SchemaNode.class,"PROP_AttributeFormDefault_DisplayName"), // display name
106
NbBundle.getMessage(SchemaNode.class,"PROP_AttributeFormDefault_ShortDescription"), // descr
107
FormPropertyEditor.SchemaFormPropertyEditor.class); // editor class
108
props.put(new SchemaModelFlushWrapper(getReference().get(),attrFormProp));
109
110             // element form property
111
Node.Property elemFormProp = new BaseSchemaProperty(
112                     getReference().get(), // schema component
113
Form.class, // value type
114
Schema.ELEMENT_FORM_DEFAULT_PROPERTY, //property name
115
NbBundle.getMessage(SchemaNode.class,"PROP_ElementFormDefault_DisplayName"), // display name
116
NbBundle.getMessage(SchemaNode.class,"PROP_ElementFormDefault_ShortDescription"), // descr
117
FormPropertyEditor.SchemaFormPropertyEditor.class); // editor class
118
props.put(new SchemaModelFlushWrapper(getReference().get(),elemFormProp));
119
120             // block default property
121
Node.Property blockDefaultProp = new DerivationTypeProperty(
122                     getReference().get(),
123                     Schema.BLOCK_DEFAULT_PROPERTY,
124                     NbBundle.getMessage(SchemaNode.class,"PROP_BlockDefault_DisplayName"), // display name
125
NbBundle.getMessage(SchemaNode.class,"HINT_BlockDefault_ShortDesc"), // descr
126
getTypeDisplayName()
127                     );
128             props.put(new SchemaModelFlushWrapper(getReference().get(), blockDefaultProp));
129
130             // final default property
131
Node.Property finalDefaultProp = new DerivationTypeProperty(
132                     getReference().get(),
133                     Schema.FINAL_DEFAULT_PROPERTY,
134                     NbBundle.getMessage(SchemaNode.class,"PROP_FinalDefault_DisplayName"), // display name
135
NbBundle.getMessage(SchemaNode.class,"HINT_FinalDefault_ShortDesc"), // descr
136
getTypeDisplayName()
137                     );
138             props.put(new SchemaModelFlushWrapper(getReference().get(), finalDefaultProp));
139
140             // version property
141
Node.Property versionProp = new BaseSchemaProperty(
142                     getReference().get(),
143                     String JavaDoc.class,
144                     Schema.VERSION_PROPERTY,
145                     NbBundle.getMessage(SchemaNode.class,"PROP_Version_DisplayName"), // display name
146
NbBundle.getMessage(SchemaNode.class,"PROP_Version_ShortDescription"), // descr
147
StringEditor.class
148                     );
149             props.put(new SchemaModelFlushWrapper(getReference().get(), versionProp));
150
151             // version property
152
Node.Property tnsProp = new NamespaceProperty(
153                     getReference().get(),
154                     Schema.TARGET_NAMESPACE_PROPERTY,
155                     NbBundle.getMessage(SchemaNode.class,"PROP_TargetNamespace_DisplayName"), // display name
156
NbBundle.getMessage(SchemaNode.class,"PROP_TargetNamespace_ShortDescription"), // descr
157
getTypeDisplayName() // type display name
158
) {
159                 public void setValue(Object JavaDoc o) throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
160                     if(o instanceof String JavaDoc && "".equals(o)) {
161                         super.setValue(null);
162                     } else super.setValue(o);
163                 }
164             };
165             props.put(new SchemaModelFlushWrapper(getReference().get(), tnsProp));
166         } catch (NoSuchMethodException JavaDoc nsme) {
167             assert false : "properties should be defined";
168         }
169         
170 // PropertiesNotifier.addChangeListener(listener = new
171
// ChangeListener() {
172
// public void stateChanged(ChangeEvent ev) {
173
// firePropertyChange("value", null, null);
174
// }
175
// });
176
return sheet;
177     }
178
179     @Override JavaDoc
180     protected void createPasteTypes(Transferable JavaDoc transferable, List JavaDoc list) {
181         // We do not allow pasting on the root node.
182
list.clear();
183     }
184
185     @Override JavaDoc
186     public boolean canCut() {
187         return false;
188     }
189
190     @Override JavaDoc
191     public boolean canCopy() {
192         return false;
193     }
194 }
195
Popular Tags