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.ui.nodes.schema;
043:
044: import org.netbeans.modules.xml.schema.model.AttributeReference;
045: import org.netbeans.modules.xml.schema.model.GlobalAttribute;
046: import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
047: import org.netbeans.modules.xml.schema.ui.nodes.*;
048: import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.BaseSchemaProperty;
049: import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.DefaultProperty;
050: import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.FixedProperty;
051: import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.GlobalReferenceProperty;
052: import org.openide.nodes.Children;
053: import org.openide.nodes.Node;
054: import org.openide.nodes.Sheet;
055: import org.openide.util.NbBundle;
056:
057: /**
058: *
059: * @author Todd Fast, todd.fast@sun.com
060: */
061: public class AttributeReferenceNode extends
062: SchemaComponentNode<AttributeReference> {
063: private static final String NAME = "attribute";
064:
065: /**
066: *
067: *
068: */
069: public AttributeReferenceNode(SchemaUIContext context,
070: SchemaComponentReference<AttributeReference> reference,
071: Children children) {
072: super (context, reference, children);
073:
074: setIconBaseWithExtension("org/netbeans/modules/xml/schema/ui/nodes/resources/"
075: + "attribute_reference.png");
076: }
077:
078: /**
079: *
080: *
081: */
082: @Override
083: public String getTypeDisplayName() {
084: return NbBundle.getMessage(LocalAttributeNode.class,
085: "LBL_AttributeReferenceNode_TypeDisplayName"); // NOI18N
086: }
087:
088: @Override
089: protected Sheet createSheet() {
090: Sheet sheet = super .createSheet();
091: Sheet.Set set = sheet.get(Sheet.PROPERTIES);
092: try {
093: // form and type should have a custom editor
094:
095: // fixed property
096: Node.Property fixedProp = new FixedProperty(getReference()
097: .get(), // schema component
098: NbBundle.getMessage(AttributeReferenceNode.class,
099: "PROP_Fixed_DisplayName"), // display name
100: NbBundle.getMessage(AttributeReferenceNode.class,
101: "PROP_Fixed_ShortDescription") // descr
102: );
103: set.put(new SchemaModelFlushWrapper(getReference().get(),
104: fixedProp));
105:
106: // default property
107: Node.Property defaultProp = new DefaultProperty(
108: getReference().get(), // schema component
109: NbBundle.getMessage(AttributeReferenceNode.class,
110: "PROP_Default_DisplayName"), // display name
111: NbBundle.getMessage(AttributeReferenceNode.class,
112: "PROP_Default_ShortDescription") // descr
113: );
114: set.put(new SchemaModelFlushWrapper(getReference().get(),
115: defaultProp));
116:
117: // use property
118: Node.Property useProp = new BaseSchemaProperty(
119: getReference().get(), // schema component
120: AttributeReference.Use.class, //as value type
121: AttributeReference.USE_PROPERTY, //property name
122: NbBundle.getMessage(AttributeReferenceNode.class,
123: "PROP_Use_DisplayName"), // display name
124: NbBundle.getMessage(AttributeReferenceNode.class,
125: "PROP_Use_ShortDescription"), // descr
126: LocalAttributeNode.UseEditor.class);
127: set.put(new SchemaModelFlushWrapper(getReference().get(),
128: useProp));
129:
130: //reference property
131: Node.Property refProp = new GlobalReferenceProperty<GlobalAttribute>(
132: getReference().get(),
133: AttributeReference.REF_PROPERTY, NbBundle
134: .getMessage(AttributeReferenceNode.class,
135: "PROP_Reference_DisplayName"), // display name
136: NbBundle.getMessage(AttributeReferenceNode.class,
137: "HINT_Attribute_Reference"), // descr
138: getTypeDisplayName(), // type display name
139: NbBundle.getMessage(AttributeReferenceNode.class,
140: "LBL_GlobalAttributeNode_TypeDisplayName"), // reference type display name
141: GlobalAttribute.class);
142: set.put(new SchemaModelFlushWrapper(getReference().get(),
143: refProp));
144:
145: // remove name property
146: set.remove(GlobalAttribute.NAME_PROPERTY);
147: } catch (NoSuchMethodException nsme) {
148: assert false : "properties should be defined";
149: }
150:
151: return sheet;
152: }
153:
154: @Override
155: protected GlobalAttribute getSuperDefinition() {
156: AttributeReference sc = getReference().get();
157: GlobalAttribute gt = null;
158: if (sc.getRef() != null)
159: gt = sc.getRef().get();
160: return gt;
161: }
162:
163: /**
164: *
165: *
166: */
167: public String getHtmlDisplayName() {
168: String decoration = " (->)";
169: String name = getDefaultDisplayName()
170: + " <font color='#999999'>" + decoration + "</font>";
171: return applyHighlights(name);
172: }
173:
174: /**
175: * The display name is name of reference if present
176: *
177: */
178: protected void updateDisplayName() {
179: GlobalAttribute ref = getSuperDefinition();
180: String name = ref == null ? null : ref.getName();
181: if (name == null || name.equals(""))
182: name = NAME;
183: setDisplayName(name);
184: }
185:
186: }
|