KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.InvocationTargetException JavaDoc;
23 import java.util.Map JavaDoc;
24 import org.openide.nodes.Children;
25 import org.openide.nodes.PropertySupport;
26 import org.openide.nodes.Sheet;
27 import org.openide.util.NbBundle;
28 import org.netbeans.modules.xml.schema.model.Import;
29 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
30 import org.netbeans.modules.xml.schema.ui.nodes.*;
31
32 /**
33  *
34  * @author Todd Fast, todd.fast@sun.com
35  */

36 public class ImportNode extends SchemaComponentNode<Import>
37 {
38     /**
39      *
40      *
41      */

42     public ImportNode(SchemaUIContext context,
43         SchemaComponentReference<Import> reference,
44         Children children)
45     {
46         super(context,reference,children);
47         setIconBaseWithExtension(
48             "org/netbeans/modules/xml/schema/ui/nodes/resources/import-include-redefine.png");
49     }
50
51
52     @Override JavaDoc
53     protected Sheet createSheet()
54     {
55         Sheet sheet = super.createSheet();
56         Sheet.Set props = sheet.get(Sheet.PROPERTIES);
57         if (props == null) {
58             props = Sheet.createPropertiesSet();
59             sheet.put(props);
60         }
61         // Namespace property
62
Property nsProp = new PropertySupport.ReadOnly(
63                 Import.NAMESPACE_PROPERTY, String JavaDoc.class,
64                 NbBundle.getMessage(ImportNode.class,"PROP_Namespace_DisplayName"),
65                 NbBundle.getMessage(ImportNode.class,"HINT_Namespace_ShortDesc")
66                 )
67         {
68             public Object JavaDoc getValue() throws
69                     IllegalAccessException JavaDoc,InvocationTargetException JavaDoc
70             {
71                 return getReference().get().getNamespace();
72             }
73         };
74         props.put(nsProp);
75         
76         // Schema Location property
77
Property slProp = new PropertySupport.ReadOnly(
78                 Import.SCHEMA_LOCATION_PROPERTY, String JavaDoc.class,
79                 NbBundle.getMessage(ImportNode.class,"PROP_SchemaLocation_DisplayName"),
80                 NbBundle.getMessage(ImportNode.class,"HINT_SchemaLocation_ShortDesc")
81                 )
82         {
83             public Object JavaDoc getValue() throws
84                     IllegalAccessException JavaDoc,InvocationTargetException JavaDoc
85             {
86                 return getReference().get().getSchemaLocation();
87             }
88         };
89         props.put(slProp);
90  
91         // Prefix property
92
Property prefixProp = new PropertySupport.ReadOnly(
93                 "prefix", //NOI18N
94
String JavaDoc.class,
95                 NbBundle.getMessage(ImportNode.class,"PROP_Prefix_DisplayName"),
96                 NbBundle.getMessage(ImportNode.class,"HINT_Prefix_ShortDesc")
97                 )
98         {
99             public Object JavaDoc getValue() throws
100                     IllegalAccessException JavaDoc,InvocationTargetException JavaDoc
101             {
102                 Map JavaDoc<String JavaDoc,String JavaDoc> prefixMap =
103                         getReference().get().getModel().getSchema().getPrefixes();
104                 String JavaDoc namespace = getReference().get().getNamespace();
105                 if(prefixMap.containsValue(namespace))
106                 {
107                     for (Map.Entry JavaDoc<String JavaDoc,String JavaDoc> entry :prefixMap.entrySet())
108                     {
109                         if (entry.getValue().equals(namespace))
110                         {
111                             return entry.getKey();
112                         }
113                     }
114                 }
115                 return null;
116             }
117         };
118         props.put(prefixProp);
119         
120         return sheet;
121     }
122
123     @Override JavaDoc
124     protected void updateDisplayName() {
125         // Force the display name to be updated.
126
fireDisplayNameChange("NotTheDefaultName", getDefaultDisplayName());
127     }
128
129     @Override JavaDoc
130     public String JavaDoc getHtmlDisplayName() {
131         String JavaDoc name = getDefaultDisplayName() +
132                 " {" + getReference().get().getNamespace() + "}";
133         return applyHighlights(name);
134     }
135
136     @Override JavaDoc
137     public String JavaDoc getTypeDisplayName() {
138         return NbBundle.getMessage(ImportNode.class,
139                 "LBL_ImportNode_TypeDisplayName");
140     }
141 }
142
Popular Tags