KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
21  * NamespaceNode.java
22  *
23  * Created on July 21, 2006, 5:15 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.abe.nodes;
30
31 import java.io.IOException JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.List JavaDoc;
34 import javax.swing.Action JavaDoc;
35 import org.netbeans.modules.xml.axi.AXIComponent;
36 import org.netbeans.modules.xml.axi.AXIDocument;
37 import org.netbeans.modules.xml.axi.SchemaGenerator;
38 import org.netbeans.modules.xml.schema.abe.InstanceUIContext;
39 import org.netbeans.modules.xml.schema.abe.NamespacePanel;
40 import org.netbeans.modules.xml.schema.abe.nodes.properties.BaseABENodeProperty;
41 import org.netbeans.modules.xml.schema.abe.nodes.properties.DesignPatternProperty;
42 import org.netbeans.modules.xml.schema.abe.nodes.properties.FormPropertyEditor;
43 import org.netbeans.modules.xml.schema.abe.nodes.properties.NamespaceProperty;
44 import org.netbeans.modules.xml.schema.abe.nodes.properties.StringEditor;
45 import org.netbeans.modules.xml.schema.abe.wizard.SchemaTransformPatternSelectionUI;
46 import org.netbeans.modules.xml.schema.model.Form;
47 import org.netbeans.modules.xml.xam.ui.actions.GoToAction;
48 import org.openide.actions.NewAction;
49 import org.openide.actions.PropertiesAction;
50 import org.openide.nodes.Node;
51 import org.openide.nodes.Sheet;
52 import org.openide.util.NbBundle;
53 import org.openide.util.actions.SystemAction;
54 import org.openide.util.datatransfer.NewType;
55
56 /**
57  *
58  * @author girix
59  */

60 public class NamespaceNode extends ABEAbstractNode{
61     
62     /** Creates a new instance of NamespaceNode */
63     public NamespaceNode(AXIComponent axiComponent, InstanceUIContext instanceUIContext) {
64         super(axiComponent, instanceUIContext);
65     }
66     
67     protected void populateProperties(Sheet sheet) {
68         Sheet.Set set = sheet.get(Sheet.PROPERTIES);
69         if(set == null) {
70             set = sheet.createPropertiesSet();
71         }
72         
73         try {
74             // attribute form property
75
Node.Property attrFormProp = new BaseABENodeProperty(
76                     getAXIComponent(),
77                     Form.class, // Occur.ZeroOne.class as value type
78
AXIDocument.PROP_ATTRIBUTE_FORM_DEFAULT, //property name
79
NbBundle.getMessage(NamespaceNode.class,"PROP_AttributeFormDefault_DisplayName"), // display name
80
NbBundle.getMessage(NamespaceNode.class,"PROP_AttributeFormDefault_ShortDescription"), // descr
81
FormPropertyEditor.class
82                     );
83             set.put(new SchemaModelFlushWrapper(getAXIComponent(),attrFormProp, getContext()));
84             
85             // element form property
86
Node.Property elementFormProp = new BaseABENodeProperty(
87                     getAXIComponent(),
88                     Form.class, // Occur.ZeroOne.class as value type
89
AXIDocument.PROP_ELEMENT_FORM_DEFAULT, //property name
90
NbBundle.getMessage(NamespaceNode.class,"PROP_ElementFormDefault_DisplayName"), // display name
91
NbBundle.getMessage(NamespaceNode.class,"PROP_ElementFormDefault_ShortDescription"), // descr
92
FormPropertyEditor.class
93                     );
94             set.put(new SchemaModelFlushWrapper(getAXIComponent(),elementFormProp, getContext()));
95             
96             // version property
97
Node.Property versionProp = new BaseABENodeProperty(
98                     getAXIComponent(),
99                     String JavaDoc.class,
100                     AXIDocument.PROP_VERSION,
101                     NbBundle.getMessage(NamespaceNode.class,"PROP_Version_DisplayName"), // display name
102
NbBundle.getMessage(NamespaceNode.class,"PROP_Version_ShortDescription"), // descr
103
StringEditor.class
104                     );
105             set.put(new SchemaModelFlushWrapper(getAXIComponent(), versionProp, getContext()));
106             
107             //namespace
108
Node.Property tnsProp = new NamespaceProperty(
109                     getAXIComponent(),
110                     AXIDocument.PROP_TARGET_NAMESPACE,
111                     NbBundle.getMessage(NamespaceNode.class,"PROP_TargetNamespace_DisplayName"), // display name
112
NbBundle.getMessage(NamespaceNode.class,"PROP_TargetNamespace_ShortDescription"), // descr
113
NbBundle.getMessage(NamespaceNode.class,"LBL_NamespaceNode_TypeDisplayName") // type display name
114
);
115             set.put(new SchemaModelFlushWrapper(getAXIComponent(), tnsProp, getContext()));
116             
117 // //schema design pattern
118
// Node.Property schemaDesignPatternProp = new DesignPatternProperty(
119
// getAXIComponent(),
120
// AXIDocument.PROP_SCHEMA_DESIGN_PATTERN,
121
// NbBundle.getMessage(NamespaceNode.class,"PROP_SchemaDesignPattern_DisplayName"), // display name
122
// NbBundle.getMessage(NamespaceNode.class,"PROP_SchemaDesignPattern_ShortDescription") // descr
123
// );
124
// set.put(new SchemaModelFlushWrapper(getAXIComponent(), schemaDesignPatternProp));
125
} catch (Exception JavaDoc ex) {
126         }
127         
128         sheet.put(set);
129     }
130     
131     public Action JavaDoc[] getActions(boolean b) {
132         return ALL_ACTIONS;
133     }
134     
135     public String JavaDoc getName(){
136         String JavaDoc namespace = "";
137         AXIDocument root = (AXIDocument) super.getAXIComponent();
138         if(root != null) {
139             namespace = ((AXIDocument) super.getAXIComponent()).
140                     getTargetNamespace();
141             if(namespace == null)
142                 namespace = NbBundle.getMessage(
143                         NamespacePanel.class, "LBL_NO_NAMESPACE");
144         }
145         return namespace;
146     }
147     
148     private static final SystemAction[] ALL_ACTIONS=
149             new SystemAction[]
150     {
151         SystemAction.get(NewAction.class),
152         null,
153         SystemAction.get(GoToAction.class),
154         null,
155         SystemAction.get(PropertiesAction.class)
156     };
157     
158     public NewType[] getNewTypes() {
159         if(!canWrite())
160             return new NewType[0];
161         List JavaDoc<NewType> ntl = new ArrayList JavaDoc<NewType>();
162         //create new GE
163
NewType nt = new NewType(){
164             public void create() throws IOException JavaDoc {
165                 getContext().setUserInducedEventMode(true);
166                 try{
167                     getContext().getNamespacePanel().addElement();
168                 }finally{
169                     getContext().setUserInducedEventMode(false);
170                 }
171             }
172             public String JavaDoc getName() {
173                 return NbBundle.getMessage(NamespaceNode.class, "LBL_NEW_GLOBAL_ELEMENT_ACTION");
174             }
175         };
176         ntl.add(nt);
177         //create new GCT
178
nt = new NewType(){
179             public void create() throws IOException JavaDoc {
180                 getContext().setUserInducedEventMode(true);
181                 try{
182                     getContext().getNamespacePanel().addComplexType();
183                 }finally{
184                     getContext().setUserInducedEventMode(false);
185                 }
186             }
187             public String JavaDoc getName() {
188                 return NbBundle.getMessage(NamespaceNode.class, "LBL_NEW_GLOBAL_COMPLEX_TYPE_ACTION");
189             }
190         };
191         ntl.add(nt);
192         return ntl.toArray(new NewType[ntl.size()]);
193     }
194     
195     protected String JavaDoc getTypeDisplayName() {
196         return NbBundle.getMessage(AttributeNode.class,"LBL_Document");
197     }
198     
199     public void destroy() throws IOException JavaDoc {
200         //dont let it delete
201
}
202 }
203
Popular Tags