KickJava   Java API By Example, From Geeks To Geeks.

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


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.AttributeReference;
23 import org.netbeans.modules.xml.schema.model.GlobalAttribute;
24 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
25 import org.netbeans.modules.xml.schema.ui.nodes.*;
26 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.BaseSchemaProperty;
27 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.DefaultProperty;
28 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.FixedProperty;
29 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.GlobalReferenceProperty;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Node;
32 import org.openide.nodes.Sheet;
33 import org.openide.util.NbBundle;
34 /**
35  *
36  * @author Todd Fast, todd.fast@sun.com
37  */

38 public class AttributeReferenceNode extends SchemaComponentNode<AttributeReference>
39 {
40     private static final String JavaDoc NAME = "attribute";
41     /**
42      *
43      *
44      */

45     public AttributeReferenceNode(SchemaUIContext context,
46         SchemaComponentReference<AttributeReference> reference,
47         Children children) {
48     super(context,reference,children);
49
50     setIconBaseWithExtension(
51         "org/netbeans/modules/xml/schema/ui/nodes/resources/"+
52         "attribute_reference.png");
53     }
54     
55     
56     /**
57      *
58      *
59      */

60     @Override JavaDoc
61         public String JavaDoc getTypeDisplayName() {
62     return NbBundle.getMessage(LocalAttributeNode.class,
63         "LBL_AttributeReferenceNode_TypeDisplayName"); // NOI18N
64
}
65     
66     @Override JavaDoc
67         protected Sheet createSheet() {
68     Sheet sheet = super.createSheet();
69     Sheet.Set set = sheet.get(Sheet.PROPERTIES);
70     try {
71         // form and type should have a custom editor
72

73         // fixed property
74
Node.Property fixedProp = new FixedProperty(
75             getReference().get(), // schema component
76
NbBundle.getMessage(AttributeReferenceNode.class,"PROP_Fixed_DisplayName"), // display name
77
NbBundle.getMessage(AttributeReferenceNode.class,"PROP_Fixed_ShortDescription") // descr
78
);
79         set.put(new SchemaModelFlushWrapper(getReference().get(),fixedProp));
80         
81         // default property
82
Node.Property defaultProp = new DefaultProperty(
83             getReference().get(), // schema component
84
NbBundle.getMessage(AttributeReferenceNode.class,"PROP_Default_DisplayName"), // display name
85
NbBundle.getMessage(AttributeReferenceNode.class,"PROP_Default_ShortDescription") // descr
86
);
87         set.put(new SchemaModelFlushWrapper(getReference().get(),defaultProp));
88         
89         // use property
90
Node.Property useProp = new BaseSchemaProperty(
91             getReference().get(), // schema component
92
AttributeReference.Use.class, //as value type
93
AttributeReference.USE_PROPERTY, //property name
94
NbBundle.getMessage(AttributeReferenceNode.class,"PROP_Use_DisplayName"), // display name
95
NbBundle.getMessage(AttributeReferenceNode.class,"PROP_Use_ShortDescription"), // descr
96
LocalAttributeNode.UseEditor.class);
97         set.put(new SchemaModelFlushWrapper(getReference().get(),useProp));
98         
99         //reference property
100
Node.Property refProp = new GlobalReferenceProperty<GlobalAttribute>(
101                 getReference().get(),
102                 AttributeReference.REF_PROPERTY,
103                 NbBundle.getMessage(AttributeReferenceNode.class,
104                 "PROP_Reference_DisplayName"), // display name
105
NbBundle.getMessage(AttributeReferenceNode.class,
106                 "HINT_Attribute_Reference"), // descr
107
getTypeDisplayName(), // type display name
108
NbBundle.getMessage(AttributeReferenceNode.class,
109                 "LBL_GlobalAttributeNode_TypeDisplayName"), // reference type display name
110
GlobalAttribute.class
111                 );
112         set.put(new SchemaModelFlushWrapper(getReference().get(), refProp));
113         
114         // remove name property
115
set.remove(GlobalAttribute.NAME_PROPERTY);
116     } catch (NoSuchMethodException JavaDoc nsme) {
117         assert false : "properties should be defined";
118     }
119     
120     return sheet;
121     }
122     
123     @Override JavaDoc
124     protected GlobalAttribute getSuperDefinition()
125     {
126         AttributeReference sc = getReference().get();
127         GlobalAttribute gt = null;
128         if(sc.getRef()!=null)
129             gt = sc.getRef().get();
130         return gt;
131     }
132
133     /**
134      *
135      *
136      */

137     public String JavaDoc getHtmlDisplayName()
138     {
139         String JavaDoc decoration=" (-&gt;)";
140         String JavaDoc name = getDefaultDisplayName()+" <font color='#999999'>"+decoration+"</font>";
141         return applyHighlights(name);
142     }
143     
144     /**
145      * The display name is name of reference if present
146      *
147      */

148     protected void updateDisplayName()
149     {
150         GlobalAttribute ref = getSuperDefinition();
151         String JavaDoc name = ref==null?null:ref.getName();
152         if(name==null||name.equals(""))
153             name = NAME;
154         setDisplayName(name);
155     }
156
157 }
158
Popular Tags