1 19 20 26 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor; 27 28 import java.awt.Image ; 29 import java.util.ArrayList ; 30 import java.util.Arrays ; 31 import java.util.List ; 32 import java.util.logging.Level ; 33 34 import javax.xml.namespace.QName ; 35 36 import org.netbeans.modules.xml.wsdl.model.Binding; 37 import org.netbeans.modules.xml.wsdl.model.Port; 38 import org.netbeans.modules.xml.wsdl.model.Service; 39 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 40 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator; 41 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter; 42 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 43 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility; 44 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty; 45 import org.netbeans.modules.xml.wsdl.ui.view.property.BindingAttributeProperty; 46 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType; 47 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory; 48 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory; 49 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 50 import org.openide.ErrorManager; 51 import org.openide.nodes.Node; 52 import org.openide.util.NbBundle; 53 import org.openide.util.Utilities; 54 import org.openide.util.datatransfer.NewType; 55 56 57 58 64 public class PortNode extends WSDLExtensibilityElementNode { 65 66 67 private Port mWSDLConstruct; 68 69 70 private ServicePortPropertyAdapter mPropertyAdapter = null; 71 72 private static Image ICON = Utilities.loadImage 73 ("org/netbeans/modules/xml/wsdl/ui/view/resources/serviceport.png"); 74 75 public PortNode(Port wsdlConstruct) { 76 super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new ServicePortNewTypesFactory()); 77 mWSDLConstruct = wsdlConstruct; 78 79 80 this.mPropertyAdapter = new ServicePortPropertyAdapter(); 81 super.setNamedPropertyAdapter(this.mPropertyAdapter); 82 } 83 84 @Override 85 public String getNameInLayer() { 86 return WSDLExtensibilityElements.ELEMENT_SERVICE_PORT; 87 } 88 89 @Override 90 public Image getIcon(int type) { 91 return ICON; 92 } 93 94 @Override 95 public Image getOpenedIcon(int type) { 96 return ICON; 97 } 98 99 @Override 100 protected Node.Property createAttributeProperty(QName attrQName) { 101 Node.Property attrValueProperty = null; 102 try { 103 String attrName = attrQName.getLocalPart(); 104 if(attrName.equals(NAME_PROP)) { attrValueProperty = createNameProperty(); 108 109 110 } else if(attrName.equals("binding")) { 111 attrValueProperty = createBindingProperty(); 112 113 } else { 114 attrValueProperty = super.createAttributeProperty(attrQName); 115 } 116 117 } catch(Exception ex) { 118 mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex); 119 ErrorManager.getDefault().notify(ex); 120 } 121 return attrValueProperty; 122 } 123 124 @Override 125 protected List <Node.Property> createAlwaysPresentAttributeProperty() throws Exception { 126 ArrayList <Node.Property> alwaysPresentAttrProperties = new ArrayList <Node.Property>(); 127 alwaysPresentAttrProperties.add(createNameProperty()); 128 alwaysPresentAttrProperties.add(createBindingProperty()); 129 return alwaysPresentAttrProperties; 130 } 131 132 133 private Node.Property createNameProperty() throws NoSuchMethodException { 134 Node.Property attrValueProperty; 135 attrValueProperty = new BaseAttributeProperty(mPropertyAdapter, 136 String .class, 137 NAME_PROP); 138 attrValueProperty.setName(NbBundle.getMessage(PortNode.class, "PROP_NAME_DISPLAYNAME")); 139 attrValueProperty.setShortDescription(NbBundle.getMessage(PortNode.class, "PORT_NAME_DESC")); 140 141 return attrValueProperty; 142 } 143 144 private Node.Property createBindingProperty() throws NoSuchMethodException { 145 Node.Property attrValueProperty; 146 attrValueProperty = new BindingAttributeProperty(mPropertyAdapter, 147 String .class, 148 "getBinding", 149 "setBinding"); 150 151 attrValueProperty.setName(NbBundle.getMessage(PortNode.class, "PROP_BINDING_DISPLAYNAME")); 152 attrValueProperty.setShortDescription(NbBundle.getMessage(PortNode.class, "PORT_BINDING_DESC")); 153 154 return attrValueProperty; 155 } 156 157 158 public class ServicePortPropertyAdapter extends ConstraintNamedPropertyAdapter { 159 160 public ServicePortPropertyAdapter() { 161 super(mWSDLConstruct); 162 } 163 164 @Override 165 public boolean isNameExists(String name) { 166 return NameGenerator.getInstance().isServicePortExists(name, 167 (Service) mWSDLConstruct.getParent()); 168 } 169 170 public void setBinding(String bindingName) { 171 if(bindingName != null) { 172 try { 173 org.netbeans.modules.xml.wsdl.ui.common.QName bindingQName = org.netbeans.modules.xml.wsdl.ui.common.QName.getQNameFromString(bindingName); 174 if(bindingQName == null) { 175 mWSDLConstruct.getModel().startTransaction(); 176 mWSDLConstruct.setBinding(null); 177 mWSDLConstruct.getModel().endTransaction(); 178 } else { 179 180 String ns = bindingQName.getNamespaceURI(); 181 String prefix = bindingQName.getPrefix(); 182 if(ns == null || ns.trim().equals("")) { 183 ns = Utility.getNamespaceURI(prefix, mWSDLConstruct.getModel()); 184 } 185 186 187 QName qname = null; 188 if (ns != null) { 189 qname = new QName (ns, bindingQName.getLocalName()); 190 } 191 192 if(qname != null) { 193 Binding binding = mWSDLConstruct.getModel().findComponentByName(qname, Binding.class); 194 if (binding == null) { 195 ErrorManager.getDefault().notify(ErrorManager.ERROR, new Exception ("Not a valid type")); 196 } else { 197 mWSDLConstruct.getModel().startTransaction(); 198 mWSDLConstruct.setBinding(mWSDLConstruct.createReferenceTo(binding, Binding.class)); 199 200 mWSDLConstruct.getModel().endTransaction(); 201 } 202 } 203 } 204 fireDisplayNameChange(null, getDisplayName()); 205 } catch (Exception e) { 206 ErrorManager.getDefault().notify(e); 207 } 208 } 209 } 210 211 212 public String getBinding() { 213 NamedComponentReference binding = mWSDLConstruct.getBinding(); 214 if (binding != null) { 215 QName bindingQName = binding.getQName(); 216 if(bindingQName != null) { 217 return Utility.fromQNameToString(bindingQName); 218 } 219 } 220 return ""; 221 222 } 223 224 public Port getServicePort() { 225 return mWSDLConstruct; 226 } 227 } 228 229 public static final class ServicePortNewTypesFactory implements NewTypesFactory{ 230 231 public NewType[] getNewTypes(WSDLComponent def) { 232 ArrayList <NewType> list = new ArrayList <NewType>(); 233 if (def.getDocumentation() == null) { 234 list.add(new DocumentationNewType(def)); 235 } 236 237 list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_SERVICE_PORT).getNewTypes(def))); 238 return list.toArray(new NewType[]{}); 239 } 240 } 241 242 @Override 243 public String getTypeDisplayName() { 244 return NbBundle.getMessage(PortNode.class, "LBL_PortNode_TypeDisplayName"); 245 } 246 247 @Override 248 public String getHtmlDisplayName() { 249 String htmlDisplayName = super.getHtmlDisplayName(); 250 NamedComponentReference<Binding> binding = mWSDLConstruct.getBinding(); 251 252 String decoration = null; 253 if (binding != null && binding.get() != null) { 254 String tns = binding.get().getModel().getDefinitions().getTargetNamespace(); 255 decoration = NbBundle.getMessage(OperationParameterNode.class, "LBL_Binding", 256 Utility.getNameAndDropPrefixIfInCurrentModel(tns, binding.get().getName(), mWSDLConstruct.getModel())); 257 } 258 259 if (decoration == null) { 260 return htmlDisplayName; 262 } 263 return htmlDisplayName + " <font color='#999999'>"+decoration+"</font>"; 264 } 265 } 266 267 268 269 | Popular Tags |