001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.schema.abe.nodes;
043:
044: import java.beans.PropertyChangeEvent;
045: import java.beans.PropertyEditorSupport;
046: import org.netbeans.modules.xml.axi.Compositor;
047: import org.netbeans.modules.xml.axi.Compositor.CompositorType;
048: import org.netbeans.modules.xml.schema.abe.CompositorPanel;
049: import org.netbeans.modules.xml.schema.abe.InstanceUIContext;
050: import org.netbeans.modules.xml.schema.abe.nodes.properties.*;
051: import org.openide.nodes.Node;
052: import org.openide.nodes.Node.Property;
053: import org.openide.nodes.Sheet;
054: import org.openide.util.NbBundle;
055:
056: /**
057: *
058: * @author Ayub Khan
059: */
060: public class CompositorNode extends ABEAbstractNode {
061:
062: /**
063: * Creates a new instance of CompositorNode
064: */
065: public CompositorNode(Compositor compositor,
066: InstanceUIContext context) {
067: super (compositor, context);
068: }
069:
070: public CompositorNode(Compositor compositor) {
071: super (compositor, new ABENodeChildren(compositor));
072: CompositorType type = compositor.getType();
073: switch (type) {
074: case ALL: {
075: setIconBaseWithExtension("org/netbeans/modules/xml/schema/abe/resources/all.png");
076: break;
077: }
078: case CHOICE: {
079: setIconBaseWithExtension("org/netbeans/modules/xml/schema/abe/resources/choice.png");
080: break;
081: }
082: case SEQUENCE: {
083: setIconBaseWithExtension("org/netbeans/modules/xml/schema/abe/resources/sequence.png");
084: break;
085: }
086: default:
087: assert false;
088: }
089: }
090:
091: public void propertyChange(PropertyChangeEvent evt) {
092: if ((evt.getSource() == getAXIComponent())
093: && evt.getPropertyName().equals(Compositor.PROP_TYPE)) {
094: Object oldValue = evt.getOldValue();
095: String oldDisplayName = oldValue == null ? null : oldValue
096: .toString();
097: fireDisplayNameChange(oldDisplayName, getDisplayName());
098: }
099: }
100:
101: protected void populateProperties(Sheet sheet) {
102: Sheet.Set set = sheet.get(Sheet.PROPERTIES);
103: if (set == null) {
104: set = sheet.createPropertiesSet();
105: }
106:
107: try {
108: //compositor type property
109: Node.Property useProp = new BaseABENodeProperty(
110: getAXIComponent(), CompositorType.class, //as value type
111: "type", //property name
112: NbBundle.getMessage(CompositorNode.class,
113: "PROP_CompositorNode_Name"), // display name
114: NbBundle.getMessage(CompositorNode.class,
115: "PROP_CompositorNode_NameDesc"), // descr
116: CompositorTypeEditor.class);
117: set.put(new SchemaModelFlushWrapper(getAXIComponent(),
118: useProp, getContext()) {
119: public java.beans.PropertyEditor getPropertyEditor() {
120: java.beans.PropertyEditor ped = super
121: .getPropertyEditor();
122: if (ped instanceof CompositorNode.CompositorTypeEditor) {
123: ((CompositorNode.CompositorTypeEditor) ped)
124: .setCompositor((Compositor) getAXIComponent());
125: }
126: return ped;
127: }
128: });
129:
130: if (getAXIComponent().supportsCardinality()) {
131: // minOccurs
132: Property minOccursProp = new MinOccursProperty(
133: getAXIComponent(), String.class,
134: Compositor.PROP_MINOCCURS, NbBundle.getMessage(
135: CompositorNode.class,
136: "PROP_MinOccurs_DisplayName"), // display name
137: NbBundle.getMessage(CompositorNode.class,
138: "PROP_MinOccurs_ShortDescription") // descr
139: );
140: set.put(new SchemaModelFlushWrapper(getAXIComponent(),
141: minOccursProp, getContext()));
142:
143: // maxOccurs
144: if (((Compositor) getAXIComponent())
145: .allowsFullMultiplicity()) {
146: Property maxOccursProp = new BaseABENodeProperty(
147: getAXIComponent(), String.class,
148: Compositor.PROP_MAXOCCURS,
149: NbBundle.getMessage(CompositorNode.class,
150: "PROP_MaxOccurs_DisplayName"), // display name
151: NbBundle.getMessage(CompositorNode.class,
152: "PROP_MaxOccurs_ShortDescription"), // descr
153: MaxOccursEditor.class);
154: set.put(new SchemaModelFlushWrapper(
155: getAXIComponent(), maxOccursProp,
156: getContext()));
157: }
158: }
159: } catch (Exception ex) {
160: }
161:
162: sheet.put(set);
163: }
164:
165: public String getName() {
166: if ((Compositor) super .getAXIComponent() != null
167: && ((Compositor) super .getAXIComponent()).getType() != null)
168: return ((Compositor) super .getAXIComponent()).getType()
169: .getName();
170: else
171: return "";
172: }
173:
174: protected String getTypeDisplayName() {
175: return NbBundle.getMessage(AttributeNode.class,
176: "LBL_Compositor");
177: }
178:
179: public static class CompositorTypeEditor extends
180: PropertyEditorSupport {
181:
182: /**
183: * Creates a new instance of CompositorTypeEditor
184: */
185: Compositor comp;
186:
187: public CompositorTypeEditor() {
188: }
189:
190: public String[] getTags() {
191: /*return new String[] {
192: Compositor.CompositorType.SEQUENCE.getName(),
193: Compositor.CompositorType.CHOICE.getName(),
194: Compositor.CompositorType.ALL.getName()
195: };*/
196: CompositorType[] types = CompositorPanel
197: .filterAllIfNeeded(comp);
198: String ret[] = new String[types.length];
199: for (int i = 0; i < types.length; i++)
200: ret[i] = types[i].getName();
201: return ret;
202:
203: }
204:
205: public void setAsText(String text)
206: throws IllegalArgumentException {
207: if (text.equals(Compositor.CompositorType.SEQUENCE
208: .getName())) {
209: setValue(CompositorType.SEQUENCE);
210: } else if (text.equals(Compositor.CompositorType.CHOICE
211: .getName())) {
212: setValue(CompositorType.CHOICE);
213: } else if (text.equals(Compositor.CompositorType.ALL
214: .getName())) {
215: setValue(CompositorType.ALL);
216: }
217: }
218:
219: public void setCompositor(Compositor comp) {
220: this .comp = comp;
221: }
222:
223: public Object getValue() {
224: return super .getValue();
225: }
226:
227: public void setValue(Object obj) {
228: super .setValue(obj);
229: }
230:
231: public void setSource(Object obj) {
232: super .setSource(obj);
233: }
234:
235: public String getAsText() {
236: Object val = getValue();
237: if (val instanceof CompositorType) {
238: return val.toString();
239: }
240: // TODO how to display invalid values?
241: return NbBundle.getMessage(CompositorNode.class,
242: "LBL_Empty");
243: }
244:
245: }
246: }
|