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: /*
043: * NamespaceNode.java
044: *
045: * Created on July 21, 2006, 5:15 PM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.modules.xml.schema.abe.nodes;
052:
053: import java.io.IOException;
054: import java.util.ArrayList;
055: import java.util.List;
056: import javax.swing.Action;
057: import org.netbeans.modules.xml.axi.AXIComponent;
058: import org.netbeans.modules.xml.axi.AXIDocument;
059: import org.netbeans.modules.xml.axi.SchemaGenerator;
060: import org.netbeans.modules.xml.schema.abe.InstanceUIContext;
061: import org.netbeans.modules.xml.schema.abe.NamespacePanel;
062: import org.netbeans.modules.xml.schema.abe.nodes.properties.BaseABENodeProperty;
063: import org.netbeans.modules.xml.schema.abe.nodes.properties.DesignPatternProperty;
064: import org.netbeans.modules.xml.schema.abe.nodes.properties.FormPropertyEditor;
065: import org.netbeans.modules.xml.schema.abe.nodes.properties.NamespaceProperty;
066: import org.netbeans.modules.xml.schema.abe.nodes.properties.StringEditor;
067: import org.netbeans.modules.xml.schema.abe.wizard.SchemaTransformPatternSelectionUI;
068: import org.netbeans.modules.xml.schema.model.Form;
069: import org.netbeans.modules.xml.xam.ui.actions.GoToAction;
070: import org.openide.actions.NewAction;
071: import org.openide.actions.PropertiesAction;
072: import org.openide.nodes.Node;
073: import org.openide.nodes.Sheet;
074: import org.openide.util.NbBundle;
075: import org.openide.util.actions.SystemAction;
076: import org.openide.util.datatransfer.NewType;
077:
078: /**
079: *
080: * @author girix
081: */
082: public class NamespaceNode extends ABEAbstractNode {
083:
084: /** Creates a new instance of NamespaceNode */
085: public NamespaceNode(AXIComponent axiComponent,
086: InstanceUIContext instanceUIContext) {
087: super (axiComponent, instanceUIContext);
088: }
089:
090: protected void populateProperties(Sheet sheet) {
091: Sheet.Set set = sheet.get(Sheet.PROPERTIES);
092: if (set == null) {
093: set = sheet.createPropertiesSet();
094: }
095:
096: try {
097: // attribute form property
098: Node.Property attrFormProp = new BaseABENodeProperty(
099: getAXIComponent(),
100: Form.class, // Occur.ZeroOne.class as value type
101: AXIDocument.PROP_ATTRIBUTE_FORM_DEFAULT, //property name
102: NbBundle.getMessage(NamespaceNode.class,
103: "PROP_AttributeFormDefault_DisplayName"), // display name
104: NbBundle
105: .getMessage(NamespaceNode.class,
106: "PROP_AttributeFormDefault_ShortDescription"), // descr
107: FormPropertyEditor.class);
108: set.put(new SchemaModelFlushWrapper(getAXIComponent(),
109: attrFormProp, getContext()));
110:
111: // element form property
112: Node.Property elementFormProp = new BaseABENodeProperty(
113: getAXIComponent(),
114: Form.class, // Occur.ZeroOne.class as value type
115: AXIDocument.PROP_ELEMENT_FORM_DEFAULT, //property name
116: NbBundle.getMessage(NamespaceNode.class,
117: "PROP_ElementFormDefault_DisplayName"), // display name
118: NbBundle.getMessage(NamespaceNode.class,
119: "PROP_ElementFormDefault_ShortDescription"), // descr
120: FormPropertyEditor.class);
121: set.put(new SchemaModelFlushWrapper(getAXIComponent(),
122: elementFormProp, getContext()));
123:
124: // version property
125: Node.Property versionProp = new BaseABENodeProperty(
126: getAXIComponent(), String.class,
127: AXIDocument.PROP_VERSION, NbBundle.getMessage(
128: NamespaceNode.class,
129: "PROP_Version_DisplayName"), // display name
130: NbBundle.getMessage(NamespaceNode.class,
131: "PROP_Version_ShortDescription"), // descr
132: StringEditor.class);
133: set.put(new SchemaModelFlushWrapper(getAXIComponent(),
134: versionProp, getContext()));
135:
136: //namespace
137: Node.Property tnsProp = new NamespaceProperty(
138: getAXIComponent(),
139: AXIDocument.PROP_TARGET_NAMESPACE,
140: NbBundle.getMessage(NamespaceNode.class,
141: "PROP_TargetNamespace_DisplayName"), // display name
142: NbBundle.getMessage(NamespaceNode.class,
143: "PROP_TargetNamespace_ShortDescription"), // descr
144: NbBundle.getMessage(NamespaceNode.class,
145: "LBL_NamespaceNode_TypeDisplayName") // type display name
146: );
147: set.put(new SchemaModelFlushWrapper(getAXIComponent(),
148: tnsProp, getContext()));
149:
150: // //schema design pattern
151: // Node.Property schemaDesignPatternProp = new DesignPatternProperty(
152: // getAXIComponent(),
153: // AXIDocument.PROP_SCHEMA_DESIGN_PATTERN,
154: // NbBundle.getMessage(NamespaceNode.class,"PROP_SchemaDesignPattern_DisplayName"), // display name
155: // NbBundle.getMessage(NamespaceNode.class,"PROP_SchemaDesignPattern_ShortDescription") // descr
156: // );
157: // set.put(new SchemaModelFlushWrapper(getAXIComponent(), schemaDesignPatternProp));
158: } catch (Exception ex) {
159: }
160:
161: sheet.put(set);
162: }
163:
164: public Action[] getActions(boolean b) {
165: return ALL_ACTIONS;
166: }
167:
168: public String getName() {
169: String namespace = "";
170: AXIDocument root = (AXIDocument) super .getAXIComponent();
171: if (root != null) {
172: namespace = ((AXIDocument) super .getAXIComponent())
173: .getTargetNamespace();
174: if (namespace == null)
175: namespace = NbBundle.getMessage(NamespacePanel.class,
176: "LBL_NO_NAMESPACE");
177: }
178: return namespace;
179: }
180:
181: private static final SystemAction[] ALL_ACTIONS = new SystemAction[] {
182: SystemAction.get(NewAction.class), null,
183: SystemAction.get(GoToAction.class), null,
184: SystemAction.get(PropertiesAction.class) };
185:
186: public NewType[] getNewTypes() {
187: if (!canWrite())
188: return new NewType[0];
189: List<NewType> ntl = new ArrayList<NewType>();
190: //create new GE
191: NewType nt = new NewType() {
192: public void create() throws IOException {
193: getContext().setUserInducedEventMode(true);
194: try {
195: getContext().getNamespacePanel().addElement();
196: } finally {
197: getContext().setUserInducedEventMode(false);
198: }
199: }
200:
201: public String getName() {
202: return NbBundle.getMessage(NamespaceNode.class,
203: "LBL_NEW_GLOBAL_ELEMENT_ACTION");
204: }
205: };
206: ntl.add(nt);
207: //create new GCT
208: nt = new NewType() {
209: public void create() throws IOException {
210: getContext().setUserInducedEventMode(true);
211: try {
212: getContext().getNamespacePanel().addComplexType();
213: } finally {
214: getContext().setUserInducedEventMode(false);
215: }
216: }
217:
218: public String getName() {
219: return NbBundle.getMessage(NamespaceNode.class,
220: "LBL_NEW_GLOBAL_COMPLEX_TYPE_ACTION");
221: }
222: };
223: ntl.add(nt);
224: return ntl.toArray(new NewType[ntl.size()]);
225: }
226:
227: protected String getTypeDisplayName() {
228: return NbBundle.getMessage(AttributeNode.class, "LBL_Document");
229: }
230:
231: public void destroy() throws IOException {
232: //dont let it delete
233: }
234: }
|