1 19 20 26 package org.netbeans.modules.xml.wsdl.ui.actions; 27 28 import java.awt.Dialog ; 29 import java.beans.PropertyChangeEvent ; 30 import java.beans.PropertyChangeListener ; 31 import java.io.IOException ; 32 import java.util.HashSet ; 33 import java.util.Map ; 34 import java.util.Set ; 35 import java.util.Vector ; 36 37 import javax.swing.Action ; 38 import javax.swing.ImageIcon ; 39 import javax.xml.namespace.QName ; 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 63 public class CommonAddExtensibilityAttributeAction extends CommonNodeAction { 64 65 68 private static final long serialVersionUID = 2110730939475660217L; 69 private static final ImageIcon ICON = new ImageIcon 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 79 protected Class [] cookieClasses() { 80 return new Class [] {WSDLElementCookie.class}; 81 } 82 83 @Override 84 protected int mode() { 85 return MODE_EXACTLY_ONE; 86 } 87 88 @Override 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 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 () { 101 102 public void propertyChange(PropertyChangeEvent evt) { 103 if (evt.getPropertyName().equals(AttributePanel.STATE_CHANGED)) { 104 dd.setValid(panel.isStateValid()); 105 } 106 107 } 108 109 }); 110 111 112 Dialog dialog = DialogDisplayer.getDefault().createDialog(dd); 113 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 name = panel.getAttributeName(); 122 String namespace = panel.getNamespace(); 123 124 QName attrQName = new QName (namespace, name); 125 WSDLComponent element = cookie.getWSDLComponent(); 126 element.getModel().startTransaction(); 127 128 if(Utility.getNamespacePrefix(namespace, wsdlComponent) == null) { 129 String 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 161 179 180 } 182 } 183 } 184 185 @Override 186 public HelpCtx getHelpCtx() { 187 return HelpCtx.DEFAULT_HELP; 188 } 189 190 @Override 191 public String getName() { 192 return NbBundle.getMessage(CommonAddExtensibilityAttributeAction.class, "CommonAddExtensibilityAttributeAction_DISPLAY_NAME"); 193 } 194 195 protected boolean isNamespaceRequired() { 196 return true; 197 } 198 199 protected Vector <String > getNamespaces(WSDLComponent wsdlComponent) { 200 Map <String , String > prefixToNameSpaceMap = Utility.getPrefixes(wsdlComponent); 201 Set <String > namespaceSet = new HashSet <String >(prefixToNameSpaceMap.values()); 202 namespaceSet.remove(Constants.WSDL_DEFAUL_NAMESPACE); 203 204 return new Vector <String >(namespaceSet); 205 } 206 207 208 } 209 210 211 212 | Popular Tags |