1 19 20 26 package org.netbeans.modules.xml.wsdl.ui.actions; 27 28 import java.awt.Dimension ; 29 import java.io.IOException ; 30 import java.util.ArrayList ; 31 import java.util.List ; 32 33 import javax.swing.Action ; 34 import javax.swing.SwingUtilities ; 35 import javax.xml.namespace.QName ; 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 60 public class RemoveAttributesAction extends CommonNodeAction { 61 62 65 private static final long serialVersionUID = -2981770394497321880L; 66 69 70 public RemoveAttributesAction() { 71 this.putValue(Action.SHORT_DESCRIPTION, this.getName()); 73 } 74 75 @Override 76 protected Class [] cookieClasses() { 77 return new Class [] {WSDLAttributeCookie.class, WSDLOtherAttributeCookie.class}; 78 } 79 80 @Override 81 protected int mode() { 82 return CookieAction.MODE_ANY; 83 } 84 85 @Override 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 <QName > list = new ArrayList <QName >(); 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 run = new Runnable () { 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 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 [] attributes = dialog.getAttributes(); 122 if (attributes != null) { 123 for (Object element : attributes) { 124 String attrName = (String ) 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 142 public HelpCtx getHelpCtx() { 143 return HelpCtx.DEFAULT_HELP; 144 } 145 146 @Override 147 public String getName() { 148 return NbBundle.getMessage(RemoveAttributesAction.class, "RemoveAttributesAction_DISPLAY_NAME"); 149 } 150 } 151 152 153 | Popular Tags |