KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.xml.schema.model.ElementReference;
23 import org.netbeans.modules.xml.schema.model.GlobalElement;
24 import org.netbeans.modules.xml.schema.model.LocalElement;
25 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
26 import org.netbeans.modules.xml.schema.ui.basic.editors.MaxOccursEditor;
27 import org.netbeans.modules.xml.schema.ui.nodes.*;
28 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.BaseSchemaProperty;
29 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.GlobalReferenceProperty;
30 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.NonNegativeIntegerProperty;
31 import org.openide.nodes.Children;
32 import org.openide.nodes.Node;
33 import org.openide.nodes.Node.Property;
34 import org.openide.nodes.Sheet;
35 import org.openide.util.NbBundle;
36
37 /**
38  *
39  * @author Todd Fast, todd.fast@sun.com
40  * @author Nathan Fiedler
41  */

42 public class ElementReferenceNode extends SchemaComponentNode<ElementReference>
43 {
44     private static final String JavaDoc NAME = "element";
45     /**
46      *
47      *
48      */

49     public ElementReferenceNode(SchemaUIContext context,
50         SchemaComponentReference<ElementReference> reference,
51         Children children) {
52         super(context,reference,children);
53
54         setIconBaseWithExtension(
55             "org/netbeans/modules/xml/schema/ui/nodes/resources/element_reference.png");
56     }
57
58
59     @Override JavaDoc
60     protected GlobalElement getSuperDefinition()
61     {
62         ElementReference sc = getReference().get();
63         GlobalElement gt = null;
64         if(sc.getRef()!=null)
65             gt = sc.getRef().get();
66         return gt;
67     }
68     
69     /**
70      *
71      *
72      */

73     @Override JavaDoc
74     public String JavaDoc getTypeDisplayName() {
75         return NbBundle.getMessage(LocalElementNode.class,
76             "LBL_ElementReferenceNode_TypeDisplayName"); // NOI18N
77
}
78     
79     @Override JavaDoc
80     protected Sheet createSheet() {
81         Sheet sheet = super.createSheet();
82         Sheet.Set set = sheet.get(Sheet.PROPERTIES);
83         try {
84             // The methods are used because the Node.Property support for
85
// netbeans doesn't recognize the is.. for boolean properties
86

87             if (getReference().get().allowsFullMultiplicity()) {
88
89                 // maxOccurs
90
Property maxOccursProp = new BaseSchemaProperty(
91                         getReference().get(), // schema component
92
String JavaDoc.class,
93                         ElementReference.MAX_OCCURS_PROPERTY,
94                         NbBundle.getMessage(ElementReferenceNode.class,"PROP_MaxOccurs_DisplayName"), // display name
95
NbBundle.getMessage(ElementReferenceNode.class,"PROP_MaxOccurs_ShortDescription"), // descr
96
MaxOccursEditor.class
97                         );
98                 set.put(new SchemaModelFlushWrapper(getReference().get(), maxOccursProp));
99
100             }
101
102             //TODO
103
// if (getReference().get().allowsFullMultiplicity()) {
104
// Add code here to support only zero or one for min occurs
105
///
106
// }
107

108             // minOccurs
109
Property minOccursProp = new NonNegativeIntegerProperty(
110                     getReference().get(), // schema component
111
LocalElement.MIN_OCCURS_PROPERTY,
112                     NbBundle.getMessage(ElementReferenceNode.class,"PROP_MinOccurs_DisplayName"), // display name
113
NbBundle.getMessage(ElementReferenceNode.class,"PROP_MinOccurs_ShortDescription") // descr
114
);
115             set.put(new SchemaModelFlushWrapper(getReference().get(), minOccursProp));
116
117             //reference property
118
Node.Property refProp = new GlobalReferenceProperty<GlobalElement>(
119                     getReference().get(),
120                     LocalElement.REF_PROPERTY,
121                     NbBundle.getMessage(ElementReferenceNode.class,
122                     "PROP_Reference_DisplayName"), // display name
123
NbBundle.getMessage(ElementReferenceNode.class,
124                     "HINT_Element_Reference"), // descr
125
getTypeDisplayName(), // type display name
126
NbBundle.getMessage(ElementReferenceNode.class,
127                     "LBL_GlobalElementNode_TypeDisplayName"), // reference type display name
128
GlobalElement.class
129                     );
130             set.put(new SchemaModelFlushWrapper(getReference().get(), refProp));
131
132             // remove name property
133
set.remove(LocalElement.NAME_PROPERTY);
134         } catch (NoSuchMethodException JavaDoc nsme) {
135             assert false : "properties should be defined";
136         }
137
138         return sheet;
139     }
140
141     /**
142      *
143      *
144      */

145     @Override JavaDoc
146     public String JavaDoc getHtmlDisplayName()
147     {
148         ElementReference element=getReference().get();
149         
150         String JavaDoc max=element.getMaxOccursEffective();
151         if (max.equals("unbounded"))
152             max="*";
153         
154         String JavaDoc decoration="["+element.getMinOccursEffective()+".."+max+"]"+" (-&gt;)";
155         String JavaDoc name = getDefaultDisplayName()+" <font color='#999999'>"+decoration+"</font>";
156         return applyHighlights(name);
157     }
158
159     /**
160      * The display name is name of reference if present
161      *
162      */

163     protected void updateDisplayName()
164     {
165         GlobalElement ref = getSuperDefinition();
166         String JavaDoc name = ref==null?null:ref.getName();
167         if(name==null||name.equals(""))
168             name = NAME;
169         setDisplayName(name);
170     }
171     
172 }
173
Popular Tags