KickJava   Java API By Example, From Geeks To Geeks.

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


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.abe.nodes;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyEditorSupport JavaDoc;
24 import org.netbeans.modules.xml.axi.Compositor;
25 import org.netbeans.modules.xml.axi.Compositor.CompositorType;
26 import org.netbeans.modules.xml.schema.abe.CompositorPanel;
27 import org.netbeans.modules.xml.schema.abe.InstanceUIContext;
28 import org.netbeans.modules.xml.schema.abe.nodes.properties.*;
29 import org.openide.nodes.Node;
30 import org.openide.nodes.Node.Property;
31 import org.openide.nodes.Sheet;
32 import org.openide.util.NbBundle;
33
34 /**
35  *
36  * @author Ayub Khan
37  */

38 public class CompositorNode extends ABEAbstractNode {
39     
40     
41     /**
42      * Creates a new instance of CompositorNode
43      */

44     public CompositorNode(Compositor compositor, InstanceUIContext context) {
45         super(compositor, context);
46     }
47     
48     public CompositorNode(Compositor compositor) {
49         super(compositor, new ABENodeChildren(compositor));
50         CompositorType type = compositor.getType();
51         switch (type) {
52             case ALL: {
53                 setIconBaseWithExtension(
54                         "org/netbeans/modules/xml/schema/abe/resources/all.png");
55                 break;
56             }
57             case CHOICE: {
58                 setIconBaseWithExtension(
59                         "org/netbeans/modules/xml/schema/abe/resources/choice.png");
60                 break;
61             }
62             case SEQUENCE: {
63                 setIconBaseWithExtension(
64                         "org/netbeans/modules/xml/schema/abe/resources/sequence.png");
65                 break;
66             }
67             default :
68                 assert false;
69         }
70     }
71     
72     
73     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
74         if ( (evt.getSource() == getAXIComponent()) &&
75                 evt.getPropertyName().equals(Compositor.PROP_TYPE)) {
76             Object JavaDoc oldValue = evt.getOldValue();
77             String JavaDoc oldDisplayName = oldValue == null ? null : oldValue.toString();
78             fireDisplayNameChange(oldDisplayName, getDisplayName());
79         }
80     }
81     
82     protected void populateProperties(Sheet sheet) {
83         Sheet.Set set = sheet.get(Sheet.PROPERTIES);
84         if(set == null) {
85             set = sheet.createPropertiesSet();
86         }
87         
88         try {
89             //compositor type property
90
Node.Property useProp = new BaseABENodeProperty(
91                     getAXIComponent(),
92                     CompositorType.class, //as value type
93
"type", //property name
94
NbBundle.getMessage(CompositorNode.class,"PROP_CompositorNode_Name"), // display name
95
NbBundle.getMessage(CompositorNode.class,"PROP_CompositorNode_NameDesc"), // descr
96
CompositorTypeEditor.class
97                     );
98             set.put(new SchemaModelFlushWrapper(getAXIComponent(),useProp, getContext()){
99                 public java.beans.PropertyEditor JavaDoc getPropertyEditor() {
100                     java.beans.PropertyEditor JavaDoc ped = super.getPropertyEditor();
101                     if(ped instanceof CompositorNode.CompositorTypeEditor){
102                         ((CompositorNode.CompositorTypeEditor)ped).setCompositor((Compositor)getAXIComponent());
103                     }
104                     return ped;
105                 }
106             });
107             
108             if(getAXIComponent().supportsCardinality()) {
109                 // minOccurs
110
Property minOccursProp = new MinOccursProperty(
111                         getAXIComponent(),
112                         String JavaDoc.class,
113                         Compositor.PROP_MINOCCURS,
114                         NbBundle.getMessage(CompositorNode.class,"PROP_MinOccurs_DisplayName"), // display name
115
NbBundle.getMessage(CompositorNode.class,"PROP_MinOccurs_ShortDescription") // descr
116
);
117                 set.put(new SchemaModelFlushWrapper(getAXIComponent(), minOccursProp, getContext()));
118                 
119                 // maxOccurs
120
if (((Compositor)getAXIComponent()).allowsFullMultiplicity()) {
121                     Property maxOccursProp = new BaseABENodeProperty(
122                             getAXIComponent(),
123                             String JavaDoc.class,
124                             Compositor.PROP_MAXOCCURS,
125                             NbBundle.getMessage(CompositorNode.class,"PROP_MaxOccurs_DisplayName"), // display name
126
NbBundle.getMessage(CompositorNode.class,"PROP_MaxOccurs_ShortDescription"), // descr
127
MaxOccursEditor.class
128                             );
129                     set.put(new SchemaModelFlushWrapper(getAXIComponent(), maxOccursProp, getContext()));
130                 }
131             }
132         } catch (Exception JavaDoc ex) {
133         }
134         
135         sheet.put(set);
136     }
137     
138     public String JavaDoc getName(){
139         if((Compositor) super.getAXIComponent() != null &&
140                 ((Compositor) super.getAXIComponent()).getType() != null)
141             return ((Compositor) super.getAXIComponent()).getType().getName();
142         else
143             return "";
144     }
145     
146     protected String JavaDoc getTypeDisplayName() {
147         return NbBundle.getMessage(AttributeNode.class,"LBL_Compositor");
148     }
149
150     
151     public static class CompositorTypeEditor extends PropertyEditorSupport JavaDoc {
152         
153         /**
154          * Creates a new instance of CompositorTypeEditor
155          */

156         Compositor comp;
157         public CompositorTypeEditor() {
158         }
159         
160         public String JavaDoc[] getTags() {
161             /*return new String[] {
162                 Compositor.CompositorType.SEQUENCE.getName(),
163                 Compositor.CompositorType.CHOICE.getName(),
164                 Compositor.CompositorType.ALL.getName()
165             };*/

166             CompositorType[] types = CompositorPanel.filterAllIfNeeded(comp);
167             String JavaDoc ret[] = new String JavaDoc[types.length];
168             for(int i = 0; i<types.length; i++)
169                 ret[i] = types[i].getName();
170             return ret;
171             
172         }
173         
174         public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
175             if (text.equals(Compositor.CompositorType.SEQUENCE.getName())){
176                 setValue(CompositorType.SEQUENCE);
177             } else if (text.equals(Compositor.CompositorType.CHOICE.getName())){
178                 setValue(CompositorType.CHOICE);
179             } else if (text.equals(Compositor.CompositorType.ALL.getName())){
180                 setValue(CompositorType.ALL);
181             }
182         }
183         
184         public void setCompositor(Compositor comp){
185             this.comp = comp;
186         }
187         
188         
189         public Object JavaDoc getValue(){
190             return super.getValue();
191         }
192         
193         public void setValue(Object JavaDoc obj){
194             super.setValue(obj);
195         }
196         
197         public void setSource(Object JavaDoc obj){
198             super.setSource(obj);
199         }
200         public String JavaDoc getAsText() {
201             Object JavaDoc val = getValue();
202             if (val instanceof CompositorType){
203                 return val.toString();
204             }
205             // TODO how to display invalid values?
206
return NbBundle.getMessage(CompositorNode.class,"LBL_Empty");
207         }
208         
209     }
210 }
211
Popular Tags