KickJava   Java API By Example, From Geeks To Geeks.

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


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.ComplexContent;
23 import org.netbeans.modules.xml.schema.model.ComplexContentDefinition;
24 import org.netbeans.modules.xml.schema.model.ComplexContentRestriction;
25 import org.netbeans.modules.xml.schema.model.ComplexExtension;
26 import org.netbeans.modules.xml.schema.model.ComplexTypeDefinition;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Node.Property;
29 import org.openide.nodes.Sheet;
30 import org.openide.util.NbBundle;
31
32 import org.netbeans.modules.xml.schema.model.GlobalComplexType;
33 import org.netbeans.modules.xml.schema.model.GlobalType;
34 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
35 import org.netbeans.modules.xml.schema.model.SimpleContent;
36 import org.netbeans.modules.xml.schema.model.SimpleContentDefinition;
37 import org.netbeans.modules.xml.schema.model.SimpleContentRestriction;
38 import org.netbeans.modules.xml.schema.model.SimpleExtension;
39 import org.netbeans.modules.xml.schema.ui.nodes.*;
40 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.BooleanProperty;
41 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.DerivationTypeProperty;
42
43 /**
44  *
45  * @author Todd Fast, todd.fast@sun.com
46  */

47 public class GlobalComplexTypeNode extends SchemaComponentNode<GlobalComplexType>
48 {
49     /**
50      *
51      *
52      */

53     public GlobalComplexTypeNode(SchemaUIContext context,
54         SchemaComponentReference<GlobalComplexType> reference,
55         Children children) {
56         super(context,reference,children);
57         
58         setIconBaseWithExtension(
59             "org/netbeans/modules/xml/schema/ui/nodes/resources/"+
60             "complextype.png");
61     }
62
63     
64     /**
65      *
66      *
67      */

68     @Override JavaDoc
69     public String JavaDoc getTypeDisplayName() {
70         return NbBundle.getMessage(GlobalComplexTypeNode.class,
71             "LBL_GlobalComplexTypeNode_TypeDisplayName"); // NOI18N
72
}
73     
74     protected GlobalType getSuperDefinition()
75     {
76         ComplexTypeDefinition definition = getReference().get().getDefinition();
77         GlobalType gt = null;
78         if(definition instanceof ComplexContent)
79         {
80             ComplexContentDefinition contentDef =
81                     ((ComplexContent)definition).getLocalDefinition();
82             if (contentDef instanceof ComplexContentRestriction)
83             {
84                 ComplexContentRestriction ccr = (ComplexContentRestriction)contentDef;
85                 if(ccr.getBase()!= null)
86                 {
87                     gt=ccr.getBase().get();
88                 }
89             }
90             if (contentDef instanceof ComplexExtension)
91             {
92                 ComplexExtension ce = (ComplexExtension)contentDef;
93                 if(ce.getBase()!= null)
94                 {
95                     gt=ce.getBase().get();
96                 }
97             }
98         }
99         else if(definition instanceof SimpleContent)
100         {
101             SimpleContentDefinition contentDef =
102                     ((SimpleContent)definition).getLocalDefinition();
103             if (contentDef instanceof SimpleContentRestriction)
104             {
105                 SimpleContentRestriction scr = (SimpleContentRestriction)contentDef;
106                 if(scr.getBase()!= null)
107                 {
108                     gt=scr.getBase().get();
109                 }
110             }
111             if (contentDef instanceof SimpleExtension)
112             {
113                 SimpleExtension se = (SimpleExtension)contentDef;
114                 if(se.getBase()!= null)
115                 {
116                     gt=se.getBase().get();
117                 }
118             }
119         }
120         return gt;
121     }
122
123         protected String JavaDoc getSuperDefinitionName()
124         {
125             String JavaDoc rawString = null;
126         ComplexTypeDefinition definition = getReference().get().getDefinition();
127         if(definition instanceof ComplexContent)
128         {
129             ComplexContentDefinition contentDef =
130                     ((ComplexContent)definition).getLocalDefinition();
131             if (contentDef instanceof ComplexContentRestriction)
132             {
133                 ComplexContentRestriction ccr = (ComplexContentRestriction)contentDef;
134                 if(ccr.getBase()!= null)
135                 {
136                     rawString=ccr.getBase().getRefString();
137                 }
138             }
139             if (contentDef instanceof ComplexExtension)
140             {
141                 ComplexExtension ce = (ComplexExtension)contentDef;
142                 if(ce.getBase()!= null)
143                 {
144                     rawString=ce.getBase().getRefString();
145                 }
146             }
147         }
148         else if(definition instanceof SimpleContent)
149         {
150             SimpleContentDefinition contentDef =
151                     ((SimpleContent)definition).getLocalDefinition();
152             if (contentDef instanceof SimpleContentRestriction)
153             {
154                 SimpleContentRestriction scr = (SimpleContentRestriction)contentDef;
155                 if(scr.getBase()!= null)
156                 {
157                     rawString=scr.getBase().getRefString();
158                 }
159             }
160             if (contentDef instanceof SimpleExtension)
161             {
162                 SimpleExtension se = (SimpleExtension)contentDef;
163                 if(se.getBase()!= null)
164                 {
165                     rawString=se.getBase().getRefString();
166                 }
167             }
168         }
169             int i = rawString!=null?rawString.indexOf(':'):-1;
170             if (i != -1 && i < rawString.length()) {
171                 rawString = rawString.substring(i);
172             }
173             return rawString;
174         }
175         
176     @Override JavaDoc
177     protected Sheet createSheet() {
178         Sheet sheet = super.createSheet();
179         Sheet.Set set = sheet.get(Sheet.PROPERTIES);
180         try {
181             // The methods are used because the Node.Property support for
182
// netbeans doesn't recognize the is.. for boolean properties
183

184             
185             // Abstract property
186
Property abstractProp = new BooleanProperty(
187                     getReference().get(), // schema component
188
GlobalComplexType.ABSTRACT_PROPERTY, // property name
189
NbBundle.getMessage(GlobalComplexTypeNode.class,"PROP_Abstract_DisplayName"), // display name
190
NbBundle.getMessage(GlobalComplexTypeNode.class,"PROP_Abstract_ShortDescription"), // descr
191
true // default value is false
192
);
193             set.put(new SchemaModelFlushWrapper(getReference().get(), abstractProp));
194             
195             // Mixed property
196
Property mixedProp = new BooleanProperty(
197                     getReference().get(), // schema component
198
GlobalComplexType.MIXED_PROPERTY, // property name
199
NbBundle.getMessage(GlobalComplexTypeNode.class,"PROP_Mixed_DisplayName"), // display name
200
NbBundle.getMessage(GlobalComplexTypeNode.class,"PROP_Mixed_ShortDescription"), // descr
201
true // default value is false
202
);
203             set.put(new SchemaModelFlushWrapper(getReference().get(), mixedProp));
204             
205             // final property
206
Property finalProp = new DerivationTypeProperty(
207                     getReference().get(),
208                     GlobalComplexType.FINAL_PROPERTY,
209                     NbBundle.getMessage(GlobalComplexTypeNode.class,"PROP_Final_DisplayName"), // display name
210
NbBundle.getMessage(GlobalComplexTypeNode.class,"HINT_Final_ShortDesc"), // descr
211
getTypeDisplayName()
212                     );
213             set.put(new SchemaModelFlushWrapper(getReference().get(), finalProp));
214             
215             // block property
216
Property blockProp = new DerivationTypeProperty(
217                     getReference().get(),
218                     GlobalComplexType.BLOCK_PROPERTY,
219                     NbBundle.getMessage(GlobalComplexTypeNode.class,"PROP_Block_DisplayName"), // display name
220
NbBundle.getMessage(GlobalComplexTypeNode.class,"HINT_Block_ShortDesc"), // descr
221
getTypeDisplayName()
222                     );
223             set.put(new SchemaModelFlushWrapper(getReference().get(), blockProp));
224         } catch (NoSuchMethodException JavaDoc nsme) {
225             assert false : "properties should be defined";
226         }
227         
228         return sheet;
229     }
230
231 }
232
Popular Tags