KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > actions > CommonAddExtensibilityAttributeAction


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  * Created on Jun 14, 2005
22  *
23  * To change the template for this generated file go to
24  * Window - Preferences - Java - Code Generation - Code and Comments
25  */

26 package org.netbeans.modules.xml.wsdl.ui.actions;
27
28 import java.awt.Dialog JavaDoc;
29 import java.beans.PropertyChangeEvent JavaDoc;
30 import java.beans.PropertyChangeListener JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Set JavaDoc;
35 import java.util.Vector JavaDoc;
36
37 import javax.swing.Action JavaDoc;
38 import javax.swing.ImageIcon JavaDoc;
39 import javax.xml.namespace.QName JavaDoc;
40
41 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
42 import org.netbeans.modules.xml.wsdl.ui.common.Constants;
43 import org.netbeans.modules.xml.wsdl.ui.cookies.WSDLElementCookie;
44 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
45 import org.netbeans.modules.xml.wsdl.ui.view.AttributePanel;
46 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
47 import org.openide.DialogDescriptor;
48 import org.openide.DialogDisplayer;
49 import org.openide.ErrorManager;
50 import org.openide.nodes.Node;
51 import org.openide.util.HelpCtx;
52 import org.openide.util.NbBundle;
53 import org.openide.util.Utilities;
54
55
56
57 /**
58  * @author radval
59  *
60  * To change the template for this generated type comment go to
61  * Window - Preferences - Java - Code Generation - Code and Comments
62  */

63 public class CommonAddExtensibilityAttributeAction extends CommonNodeAction {
64
65     /**
66      *
67      */

68     private static final long serialVersionUID = 2110730939475660217L;
69     private static final ImageIcon JavaDoc ICON = new ImageIcon JavaDoc
70     (Utilities.loadImage
71      ("org/netbeans/modules/xml/wsdl/ui/view/resources/message.png"));
72
73     public CommonAddExtensibilityAttributeAction() {
74         this.setIcon(ICON);
75         this.putValue(Action.SHORT_DESCRIPTION, this.getName());
76     }
77
78     @Override JavaDoc
79     protected Class JavaDoc[] cookieClasses() {
80         return new Class JavaDoc[] {WSDLElementCookie.class};
81     }
82
83     @Override JavaDoc
84     protected int mode() {
85         return MODE_EXACTLY_ONE;
86     }
87
88     @Override JavaDoc
89     protected void performAction(Node[] activatedNodes) {
90         if(activatedNodes.length != 0) {
91             Node node = activatedNodes[0];
92             WSDLElementCookie cookie = (WSDLElementCookie) node.getCookie(WSDLElementCookie.class);
93             if(cookie != null) {
94                 WSDLComponent wsdlComponent = cookie.getWSDLComponent();
95                 Vector JavaDoc namespaces = getNamespaces(wsdlComponent);
96
97                 final AttributePanel panel = new AttributePanel(isNamespaceRequired(), namespaces, wsdlComponent);
98                 final DialogDescriptor dd = new DialogDescriptor(panel,
99                         NbBundle.getMessage(CommonAddExtensibilityAttributeAction.class, "CommonAddExtensibilityAttributeAction_TITLE"));
100                 panel.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
101
102                     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
103                         if (evt.getPropertyName().equals(AttributePanel.STATE_CHANGED)) {
104                             dd.setValid(panel.isStateValid());
105                         }
106
107                     }
108
109                 });
110
111
112                 Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dd);
113 /* dd.setClosingOptions(new Object[]{DialogDescriptor.CANCEL_OPTION});*/
114                 dd.setValid(false);
115
116                 dialog.setVisible(true);
117                 dialog.toFront();
118
119                 boolean cancelled = dd.getValue() != DialogDescriptor.OK_OPTION;
120                 if (!cancelled) {
121                     String JavaDoc name = panel.getAttributeName();
122                     String JavaDoc namespace = panel.getNamespace();
123
124                     QName JavaDoc attrQName = new QName JavaDoc(namespace, name);
125                     WSDLComponent element = cookie.getWSDLComponent();
126                     element.getModel().startTransaction();
127
128                     if(Utility.getNamespacePrefix(namespace, wsdlComponent) == null) {
129                             String JavaDoc prefixName = NameGenerator.getInstance().generateNamespacePrefix(null, wsdlComponent);
130                             ((AbstractDocumentComponent) element).addPrefix(prefixName, namespace);
131                     }
132
133                     ((AbstractDocumentComponent) element).setAnyAttribute(attrQName, "");
134                         element.getModel().endTransaction();
135                 }
136 /* AttributeView attrView = new AttributeView(node, wsdlComponent);
137                 attrView.setNamespaceRequired(isNamespaceRequired());
138                 //Vector namespaces = getNamespaces(wsdlComponent);
139                 attrView.setNamespaces(namespaces);
140
141                 GenericDialog gd = new GenericDialog(attrView,
142                         NbBundle.getMessage(CommonAddExtensibiltyElementAction.class, "CommonAddExtensibilityAttributeAction_TITLE"),
143                         true);
144
145                 gd.enableOkButton(false);
146
147                 int dialogWidth = 400;
148                 int dialogHeight = 250;
149
150                 gd.getDialog().setSize(new Dimension(dialogWidth, dialogHeight));
151                 int windowWidth = WindowManager.getDefault().getMainWindow().getWidth();
152                 int windowHeight = WindowManager.getDefault().getMainWindow().getHeight();
153
154                 int dialogX = (windowWidth - dialogWidth) /2;
155                 int dialogY = (windowHeight - dialogHeight) /2;
156
157                 gd.getDialog().setLocation(dialogX, dialogY);
158                 gd.getDialog().setVisible(true);
159
160                 if(gd.getButtonState() == GenericDialog.OK_BUTTON) {*/

161 /* String name = attrView.getNewAttributeName();
162                                         String namespace = attrView.getNewNamespace();
163
164                                         QName attrQName = new QName(namespace, name);
165                                         WSDLComponent element = cookie.getWSDLComponent();
166                                         element.getModel().startTransaction();
167
168                                         if(Utility.getNamespacePrefix(namespace, wsdlComponent) == null) {
169                                                 String prefixName = NameGenerator.getInstance().generateNamespacePrefix(null, wsdlComponent);
170                                                 ((AbstractDocumentComponent) element).addPrefix(prefixName, namespace);
171                                         }
172
173                                         ((AbstractDocumentComponent) element).setAnyAttribute(attrQName, "");
174                                         try {
175                                             element.getModel().endTransaction();
176                                         } catch (IOException e) {
177                                             ErrorManager.getDefault().notify(e);
178                                         }*/

179
180                 //}
181
}
182         }
183     }
184
185     @Override JavaDoc
186     public HelpCtx getHelpCtx() {
187         return HelpCtx.DEFAULT_HELP;
188     }
189
190     @Override JavaDoc
191     public String JavaDoc getName() {
192         return NbBundle.getMessage(CommonAddExtensibilityAttributeAction.class, "CommonAddExtensibilityAttributeAction_DISPLAY_NAME");
193     }
194
195     protected boolean isNamespaceRequired() {
196         return true;
197     }
198
199     protected Vector JavaDoc<String JavaDoc> getNamespaces(WSDLComponent wsdlComponent) {
200         Map JavaDoc<String JavaDoc, String JavaDoc> prefixToNameSpaceMap = Utility.getPrefixes(wsdlComponent);
201         Set JavaDoc<String JavaDoc> namespaceSet = new HashSet JavaDoc<String JavaDoc>(prefixToNameSpaceMap.values());
202         namespaceSet.remove(Constants.WSDL_DEFAUL_NAMESPACE);
203
204         return new Vector JavaDoc<String JavaDoc>(namespaceSet);
205     }
206
207
208 }
209
210
211
212
Popular Tags