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.Collection ; 32 import java.util.List ; 33 import java.util.logging.Level ; 34 35 import javax.xml.namespace.QName ; 36 37 import org.netbeans.modules.xml.wsdl.model.Binding; 38 import org.netbeans.modules.xml.wsdl.model.PortType; 39 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 40 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 41 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator; 42 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter; 43 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 44 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility; 45 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty; 46 import org.netbeans.modules.xml.wsdl.ui.view.property.BindingTypeAttributeProperty; 47 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.BindingOperationNewType; 48 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType; 49 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory; 50 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory; 51 import org.netbeans.modules.xml.xam.ComponentEvent; 52 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 53 import org.openide.ErrorManager; 54 import org.openide.nodes.Node; 55 import org.openide.util.HelpCtx; 56 import org.openide.util.NbBundle; 57 import org.openide.util.Utilities; 58 import org.openide.util.datatransfer.NewType; 59 60 61 65 public class BindingNode extends WSDLExtensibilityElementNode { 66 67 68 private Binding mWSDLConstruct; 69 70 private BindingPropertyAdapter mPropertyAdapter = null; 71 72 private static Image ICON = Utilities.loadImage 73 ("org/netbeans/modules/xml/wsdl/ui/view/resources/binding.png"); 74 75 private static final String TYPE_PROP = "type"; 77 public BindingNode(Binding wsdlConstruct) { 78 super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new BindingNewTypesFactory()); 79 mWSDLConstruct = wsdlConstruct; 80 81 this.mPropertyAdapter = new BindingPropertyAdapter(); 82 this.setNamedPropertyAdapter(this.mPropertyAdapter); 83 } 84 85 @Override 86 public String getNameInLayer() { 87 return WSDLExtensibilityElements.ELEMENT_BINDING; 88 } 89 90 @Override 91 public Image getIcon(int type) { 92 return ICON; 93 } 94 95 @Override 96 public Image getOpenedIcon(int type) { 97 return ICON; 98 } 99 100 @Override 101 public void childrenAdded(ComponentEvent evt) { 102 113 } 114 115 @Override 116 public void childrenDeleted(ComponentEvent evt) { 117 128 } 129 130 @Override 131 protected Node.Property createAttributeProperty(QName attrQName) { 132 Node.Property attrValueProperty = null; 133 try { 134 String attrName = attrQName.getLocalPart(); 135 if(attrName.equals(NAME_PROP)) { attrValueProperty = createNameProperty(); 138 139 } else if(attrName.equals(TYPE_PROP)) { attrValueProperty = createTypeProperty(); 142 143 } else { 144 attrValueProperty = super.createAttributeProperty(attrQName); 145 } 146 147 } catch(Exception ex) { 148 mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex); 149 ErrorManager.getDefault().notify(ex); 150 } 151 return attrValueProperty; 152 } 153 154 @Override 155 protected List <Node.Property> createAlwaysPresentAttributeProperty() throws Exception { 156 ArrayList <Node.Property> alwaysPresentAttrProperties = new ArrayList <Node.Property>(); 157 alwaysPresentAttrProperties.add(createNameProperty()); 158 alwaysPresentAttrProperties.add(createTypeProperty()); 159 return alwaysPresentAttrProperties; 160 } 161 162 163 private Node.Property createNameProperty() throws NoSuchMethodException { 164 Node.Property attrValueProperty; 165 attrValueProperty = new BaseAttributeProperty(mPropertyAdapter, String .class, NAME_PROP); 166 attrValueProperty.setName(NbBundle.getMessage(BindingNode.class, "PROP_NAME_DISPLAYNAME")); 167 attrValueProperty.setShortDescription(NbBundle.getMessage(BindingNode.class, "BINDINGNODE_NAME_DESCRIPTION")); 168 169 return attrValueProperty; 170 } 171 172 private Node.Property createTypeProperty() throws NoSuchMethodException { 173 Node.Property attrValueProperty; 174 attrValueProperty = new BindingTypeAttributeProperty(mPropertyAdapter, 175 String .class, "getType", "setType"); 176 177 attrValueProperty.setName(NbBundle.getMessage(BindingNode.class, "PROP_TYPE_DISPLAYNAME")); 178 attrValueProperty.setShortDescription(NbBundle.getMessage(BindingNode.class, "BINDINGNODE_TYPE_DESCRIPTION")); 179 180 return attrValueProperty; 181 } 182 183 @Override 184 public HelpCtx getHelpCtx() { 185 return new HelpCtx(BindingNode.class); 186 } 187 188 public class BindingPropertyAdapter extends ConstraintNamedPropertyAdapter { 189 public BindingPropertyAdapter() { 190 super(mWSDLConstruct); 191 } 192 193 @Override 194 public boolean isNameExists(String name) { 195 WSDLModel model = mWSDLConstruct.getModel(); 196 return NameGenerator.getInstance().isBindingExists(name, model); 197 } 198 199 public void setType(String type) { 200 if(type != null) { 201 try { 202 Binding binding = (Binding) getWSDLComponent(); 203 org.netbeans.modules.xml.wsdl.ui.common.QName portTypeQName = org.netbeans.modules.xml.wsdl.ui.common.QName.getQNameFromString(type); 204 if(portTypeQName == null) { 205 binding.getModel().startTransaction(); 206 binding.setType(null); 207 binding.getModel().endTransaction(); 208 } else { 209 210 String ns = portTypeQName.getNamespaceURI(); 211 String prefix = portTypeQName.getPrefix(); 212 if(ns == null || ns.trim().equals("")) { 213 ns = Utility.getNamespaceURI(prefix, binding.getModel()); 214 } 215 216 QName qname = null; 217 if (ns != null) { 218 qname = new QName (ns, portTypeQName.getLocalName()); 219 } 220 221 if(qname != null) { 222 PortType pType = binding.getModel().findComponentByName(qname, PortType.class); 223 if (pType == null) { 224 ErrorManager.getDefault().notify(ErrorManager.ERROR, new Exception ("Not a valid type")); 225 } else { 226 binding.getModel().startTransaction(); 227 binding.setType(binding.createReferenceTo(pType, PortType.class)); 228 229 getWSDLComponent().getModel().endTransaction(); 230 } 231 } 232 } 233 } catch (Exception e) { 234 ErrorManager.getDefault().notify(e); 235 } 236 } 237 } 238 239 public String getType() { 240 NamedComponentReference pType = mWSDLConstruct.getType(); 241 if (pType != null) { 242 QName portTypeQName = pType.getQName(); 243 if(portTypeQName != null) { 244 return Utility.fromQNameToString(portTypeQName); 245 } 246 } 247 return ""; 248 } 249 250 } 251 252 253 public static final class BindingNewTypesFactory implements NewTypesFactory{ 254 255 public NewType[] getNewTypes(WSDLComponent def) { 256 Binding binding = (Binding) def; 257 ArrayList <NewType> list = new ArrayList <NewType>(); 258 if (def.getDocumentation() == null) { 259 list.add(new DocumentationNewType(def)); 260 } 261 if (isBindingOperationActionEnabled(binding)) { 262 list.add(new BindingOperationNewType(def)); 263 } 264 265 list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_BINDING).getNewTypes(def))); 266 return list.toArray(new NewType[]{}); 267 } 268 269 private boolean isBindingOperationActionEnabled(Binding binding) { 270 boolean enable = false; 271 PortType type = binding.getType() != null ? binding.getType().get() : null; 272 if (type == null) return true; 273 if (type != null) { 274 Collection operations = type.getOperations(); 275 if (operations != null) { 276 int boSize = binding.getBindingOperations() != null ? binding.getBindingOperations().size() : 0; 277 if (type.getOperations().size() > boSize) { 278 enable = true; 279 } 280 } 281 } 282 283 return enable; 284 } 285 286 287 288 } 289 290 291 @Override 292 public String getTypeDisplayName() { 293 return NbBundle.getMessage(BindingNode.class, "LBL_BindingNode_TypeDisplayName"); 294 } 295 296 @Override 297 public String getHtmlDisplayName() { 298 String htmlDisplayName = super.getHtmlDisplayName(); 299 NamedComponentReference<PortType> type = mWSDLConstruct.getType(); 300 301 String decoration = null; 302 if (type != null && type.get() != null) { 303 String tns = type.get().getModel().getDefinitions().getTargetNamespace(); 304 305 decoration = NbBundle.getMessage(OperationParameterNode.class, "LBL_PortType", 306 Utility.getNameAndDropPrefixIfInCurrentModel(tns, type.get().getName(), mWSDLConstruct.getModel())); 307 } 308 309 if (decoration == null) { 310 return htmlDisplayName; 312 } 313 return htmlDisplayName + " <font color='#999999'>"+decoration+"</font>"; 314 } 315 } 316 317 318 | Popular Tags |