KickJava   Java API By Example, From Geeks To Geeks.

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


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 24, 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.Dimension JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.List JavaDoc;
32
33 import javax.swing.Action JavaDoc;
34 import javax.swing.SwingUtilities JavaDoc;
35 import javax.xml.namespace.QName JavaDoc;
36
37 import org.netbeans.modules.xml.schema.model.Element;
38 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
39 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
40 import org.netbeans.modules.xml.wsdl.ui.cookies.WSDLAttributeCookie;
41 import org.netbeans.modules.xml.wsdl.ui.cookies.WSDLOtherAttributeCookie;
42 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.impl.ExtensibilityUtils;
43 import org.netbeans.modules.xml.wsdl.ui.model.StringAttribute;
44 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
45 import org.netbeans.modules.xml.wsdl.ui.view.RemoveAttributesDialog;
46 import org.openide.ErrorManager;
47 import org.openide.nodes.Node;
48 import org.openide.util.HelpCtx;
49 import org.openide.util.NbBundle;
50 import org.openide.util.actions.CookieAction;
51 import org.openide.windows.WindowManager;
52
53
54 /**
55  * @author radval
56  *
57  * To change the template for this generated type comment go to
58  * Window - Preferences - Java - Code Generation - Code and Comments
59  */

60 public class RemoveAttributesAction extends CommonNodeAction {
61
62     /**
63      *
64      */

65     private static final long serialVersionUID = -2981770394497321880L;
66 /* private static final ImageIcon ICON = new ImageIcon
67     (Utilities.loadImage
68             ("org/netbeans/modules/xml/wsdl/ui/view/resources/remove.png"));*/

69
70     public RemoveAttributesAction() {
71   // this.setIcon(ICON);
72
this.putValue(Action.SHORT_DESCRIPTION, this.getName());
73     }
74
75     @Override JavaDoc
76     protected Class JavaDoc[] cookieClasses() {
77         return new Class JavaDoc[] {WSDLAttributeCookie.class, WSDLOtherAttributeCookie.class};
78     }
79
80     @Override JavaDoc
81     protected int mode() {
82         return CookieAction.MODE_ANY;
83     }
84
85     @Override JavaDoc
86     protected void performAction(Node[] activatedNodes) {
87         if(activatedNodes.length != 0) {
88             for(int i = 0; i < activatedNodes.length; i++) {
89                 final Node node = activatedNodes[i];
90                 WSDLAttributeCookie cookie = (WSDLAttributeCookie) node.getCookie(WSDLAttributeCookie.class);
91                 WSDLOtherAttributeCookie woaCookie = (WSDLOtherAttributeCookie) node.getCookie(WSDLOtherAttributeCookie.class);
92                 final List JavaDoc<QName JavaDoc> list = new ArrayList JavaDoc<QName JavaDoc>();
93                 final WSDLComponent comp = (cookie != null) ? cookie.getWSDLComponent() : ((woaCookie != null) ? woaCookie.getWSDLComponent() : null);
94                 if(cookie != null) {
95                     list.addAll(Utility.getExtensionAttributes(comp));
96                 }
97                 if (woaCookie != null) {
98                     Element elem = ExtensibilityUtils.getElement((ExtensibilityElement) comp);
99                     list.addAll(Utility.getOptionalAttributes(comp, elem));
100                 }
101                 if (comp!= null && list.size() > 0) {
102                     Runnable JavaDoc run = new Runnable JavaDoc() {
103                         public void run() {
104                             RemoveAttributesDialog dialog = new RemoveAttributesDialog(WindowManager.getDefault().getMainWindow(), true);
105                             dialog.setTitle(NbBundle.getMessage(getClass(), "RemoveAttributesAction_DISPLAY_NAME"));
106
107                             Dimension JavaDoc dimension = dialog.getSize();
108                             int dialogWidth = dimension.width;
109                             int dialogHeight = dimension.height;
110                             int windowWidth = WindowManager.getDefault().getMainWindow().getWidth();
111                             int windowHeight = WindowManager.getDefault().getMainWindow().getHeight();
112
113                             int dialogX = (windowWidth - dialogWidth) / 2;
114                             int dialogY = (windowHeight - dialogHeight) / 2;
115
116                             dialog.setLocation(dialogX, dialogY);
117
118                             dialog.setAttributes(list);
119                             dialog.setVisible(true);
120
121                             Object JavaDoc[] attributes = dialog.getAttributes();
122                             if (attributes != null) {
123                                 for (Object JavaDoc element : attributes) {
124                                     String JavaDoc attrName = (String JavaDoc) element;
125                                     comp.getModel().startTransaction();
126                                     comp.setAttribute(attrName, new StringAttribute(attrName), null);
127                                         comp.getModel().endTransaction();
128                                 }
129                             }
130                         }
131                     };
132                     SwingUtilities.invokeLater(run);
133                 }
134             }
135         }
136
137
138     }
139
140
141     @Override JavaDoc
142     public HelpCtx getHelpCtx() {
143         return HelpCtx.DEFAULT_HELP;
144     }
145
146     @Override JavaDoc
147     public String JavaDoc getName() {
148         return NbBundle.getMessage(RemoveAttributesAction.class, "RemoveAttributesAction_DISPLAY_NAME");
149     }
150 }
151
152
153
Popular Tags