001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: * Created on Jun 14, 2005
022: *
023: * To change the template for this generated file go to
024: * Window - Preferences - Java - Code Generation - Code and Comments
025: */
026: package org.netbeans.modules.xml.wsdl.ui.actions;
027:
028: import java.awt.Dialog;
029: import java.beans.PropertyChangeEvent;
030: import java.beans.PropertyChangeListener;
031: import java.util.HashSet;
032: import java.util.Map;
033: import java.util.Set;
034: import java.util.Vector;
035:
036: import javax.swing.Action;
037: import javax.swing.ImageIcon;
038: import javax.xml.namespace.QName;
039:
040: import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
041: import org.netbeans.modules.xml.wsdl.model.Import;
042: import org.netbeans.modules.xml.wsdl.model.OperationParameter;
043: import org.netbeans.modules.xml.wsdl.model.Part;
044: import org.netbeans.modules.xml.wsdl.model.PortType;
045: import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
046: import org.netbeans.modules.xml.wsdl.ui.common.Constants;
047: import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
048: import org.netbeans.modules.xml.wsdl.ui.view.AttributePanel;
049: import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
050: import org.openide.DialogDescriptor;
051: import org.openide.DialogDisplayer;
052: import org.openide.nodes.Node;
053: import org.openide.util.HelpCtx;
054: import org.openide.util.NbBundle;
055: import org.openide.util.Utilities;
056:
057: /**
058: * @author radval
059: *
060: * To change the template for this generated type comment go to
061: * Window - Preferences - Java - Code Generation - Code and Comments
062: */
063: public class CommonAddExtensibilityAttributeAction extends
064: CommonNodeAction {
065:
066: /**
067: *
068: */
069: private static final long serialVersionUID = 2110730939475660217L;
070: private static final ImageIcon ICON = new ImageIcon(
071: Utilities
072: .loadImage("org/netbeans/modules/xml/wsdl/ui/view/resources/message.png"));
073:
074: public CommonAddExtensibilityAttributeAction() {
075: this .setIcon(ICON);
076: this .putValue(Action.SHORT_DESCRIPTION, this .getName());
077: }
078:
079: @Override
080: protected Class<?>[] cookieClasses() {
081: return new Class[] { Import.class, OperationParameter.class,
082: Part.class, PortType.class, ExtensibilityElement.class };
083: }
084:
085: @Override
086: protected int mode() {
087: return MODE_EXACTLY_ONE;
088: }
089:
090: @Override
091: protected void performAction(Node[] activatedNodes) {
092: if (activatedNodes.length != 0) {
093: Node node = activatedNodes[0];
094: WSDLComponent wsdlComponent = node.getLookup().lookup(
095: WSDLComponent.class);
096: if (wsdlComponent != null) {
097: Vector namespaces = getNamespaces(wsdlComponent);
098:
099: final AttributePanel panel = new AttributePanel(
100: isNamespaceRequired(), namespaces,
101: wsdlComponent);
102: final DialogDescriptor dd = new DialogDescriptor(
103: panel,
104: NbBundle
105: .getMessage(
106: CommonAddExtensibilityAttributeAction.class,
107: "CommonAddExtensibilityAttributeAction_TITLE"));
108: panel
109: .addPropertyChangeListener(new PropertyChangeListener() {
110:
111: public void propertyChange(
112: PropertyChangeEvent evt) {
113: if (evt.getPropertyName().equals(
114: AttributePanel.STATE_CHANGED)) {
115: dd.setValid(panel.isStateValid());
116: }
117:
118: }
119:
120: });
121:
122: Dialog dialog = DialogDisplayer.getDefault()
123: .createDialog(dd);
124: dialog.getAccessibleContext().setAccessibleDescription(
125: dd.getTitle());
126: dd.setValid(false);
127:
128: dialog.setVisible(true);
129: dialog.toFront();
130:
131: boolean cancelled = dd.getValue() != DialogDescriptor.OK_OPTION;
132: if (!cancelled) {
133: String name = panel.getAttributeName();
134: String namespace = panel.getNamespace();
135:
136: QName attrQName = new QName(namespace, name);
137: WSDLComponent element = wsdlComponent;
138: element.getModel().startTransaction();
139:
140: if (Utility.getNamespacePrefix(namespace,
141: wsdlComponent) == null) {
142: String prefixName = NameGenerator.getInstance()
143: .generateNamespacePrefix(null,
144: wsdlComponent);
145: ((AbstractDocumentComponent) element)
146: .addPrefix(prefixName, namespace);
147: }
148:
149: ((AbstractDocumentComponent) element)
150: .setAnyAttribute(attrQName, "");
151: element.getModel().endTransaction();
152: }
153: /* AttributeView attrView = new AttributeView(node, wsdlComponent);
154: attrView.setNamespaceRequired(isNamespaceRequired());
155: //Vector namespaces = getNamespaces(wsdlComponent);
156: attrView.setNamespaces(namespaces);
157:
158: GenericDialog gd = new GenericDialog(attrView,
159: NbBundle.getMessage(CommonAddExtensibiltyElementAction.class, "CommonAddExtensibilityAttributeAction_TITLE"),
160: true);
161:
162: gd.enableOkButton(false);
163:
164: int dialogWidth = 400;
165: int dialogHeight = 250;
166:
167: gd.getDialog().setSize(new Dimension(dialogWidth, dialogHeight));
168: int windowWidth = WindowManager.getDefault().getMainWindow().getWidth();
169: int windowHeight = WindowManager.getDefault().getMainWindow().getHeight();
170:
171: int dialogX = (windowWidth - dialogWidth) /2;
172: int dialogY = (windowHeight - dialogHeight) /2;
173:
174: gd.getDialog().setLocation(dialogX, dialogY);
175: gd.getDialog().setVisible(true);
176:
177: if(gd.getButtonState() == GenericDialog.OK_BUTTON) {*/
178: /* String name = attrView.getNewAttributeName();
179: String namespace = attrView.getNewNamespace();
180:
181: QName attrQName = new QName(namespace, name);
182: WSDLComponent element = cookie.getWSDLComponent();
183: element.getModel().startTransaction();
184:
185: if(Utility.getNamespacePrefix(namespace, wsdlComponent) == null) {
186: String prefixName = NameGenerator.getInstance().generateNamespacePrefix(null, wsdlComponent);
187: ((AbstractDocumentComponent) element).addPrefix(prefixName, namespace);
188: }
189:
190: ((AbstractDocumentComponent) element).setAnyAttribute(attrQName, "");
191: try {
192: element.getModel().endTransaction();
193: } catch (IOException e) {
194: ErrorManager.getDefault().notify(e);
195: }*/
196:
197: //}
198: }
199: }
200: }
201:
202: @Override
203: public HelpCtx getHelpCtx() {
204: return HelpCtx.DEFAULT_HELP;
205: }
206:
207: @Override
208: public String getName() {
209: return NbBundle.getMessage(
210: CommonAddExtensibilityAttributeAction.class,
211: "CommonAddExtensibilityAttributeAction_DISPLAY_NAME");
212: }
213:
214: protected boolean isNamespaceRequired() {
215: return true;
216: }
217:
218: protected Vector<String> getNamespaces(WSDLComponent wsdlComponent) {
219: Map<String, String> prefixToNameSpaceMap = Utility
220: .getPrefixes(wsdlComponent);
221: Set<String> namespaceSet = new HashSet<String>(
222: prefixToNameSpaceMap.values());
223: namespaceSet.remove(Constants.WSDL_DEFAUL_NAMESPACE);
224:
225: return new Vector<String>(namespaceSet);
226: }
227: }
|