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.BindingOperation; 37 import org.netbeans.modules.xml.wsdl.model.NotificationOperation; 38 import org.netbeans.modules.xml.wsdl.model.OneWayOperation; 39 import org.netbeans.modules.xml.wsdl.model.Operation; 40 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation; 41 import org.netbeans.modules.xml.wsdl.model.SolicitResponseOperation; 42 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 43 import org.netbeans.modules.xml.wsdl.ui.api.property.PropertyAdapter; 44 import org.netbeans.modules.xml.wsdl.ui.commands.NamedPropertyAdapter; 45 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 46 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty; 47 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.BindingOperationFaultNewType; 48 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.BindingOperationInputNewType; 49 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.BindingOperationOutputNewType; 50 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType; 51 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory; 52 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory; 53 import org.openide.ErrorManager; 54 import org.openide.nodes.Node; 55 import org.openide.util.NbBundle; 56 import org.openide.util.Utilities; 57 import org.openide.util.datatransfer.NewType; 58 59 60 66 public class BindingOperationNode extends WSDLExtensibilityElementNode { 67 private BindingOperation mWSDLConstruct; 68 private BindingOperationPropertyAdapter mPropertyAdapter; 69 private Image ICON; 70 71 public BindingOperationNode(BindingOperation wsdlConstruct) { 72 super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new BindingOperationNewTypesFactory()); 73 mWSDLConstruct = wsdlConstruct; 74 ICON = Utilities.loadImage( 76 "org/netbeans/modules/xml/wsdl/ui/view/resources/bindingoperation.png"); 77 mPropertyAdapter = new BindingOperationPropertyAdapter(); 78 super.setNamedPropertyAdapter(this.mPropertyAdapter); 79 if (wsdlConstruct.getOperation() != null) { 80 Operation operation = wsdlConstruct.getOperation().get(); 81 if (operation != null) { 82 setIcon(operation); 83 } 84 } 85 } 86 87 @Override 88 public String getNameInLayer() { 89 return WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION; 90 } 91 92 private void setIcon(Operation operation){ 93 if (operation instanceof RequestResponseOperation) { 94 ICON = Utilities.loadImage 95 ("org/netbeans/modules/xml/wsdl/ui/view/resources/requestresponse_operation.png"); 96 } else if (operation instanceof OneWayOperation) { 97 ICON = Utilities.loadImage 98 ("org/netbeans/modules/xml/wsdl/ui/view/resources/oneway_operation.png"); 99 } else if (operation instanceof NotificationOperation) { 100 ICON = Utilities.loadImage 101 ("org/netbeans/modules/xml/wsdl/ui/view/resources/notification_operation.png"); 102 } else if (operation instanceof SolicitResponseOperation) { 103 ICON = Utilities.loadImage 104 ("org/netbeans/modules/xml/wsdl/ui/view/resources/solicitresponse_operation.png"); 105 } else { 106 ICON = Utilities.loadImage 107 ("org/netbeans/modules/xml/wsdl/ui/view/resources/bindingoperation.png"); 108 } 109 } 110 111 @Override 112 public Image getIcon(int type) { 113 return ICON; 114 } 115 116 @Override 117 public Image getOpenedIcon(int type) { 118 return ICON; 119 } 120 121 @Override 122 protected Node.Property createAttributeProperty(QName attrQName) { 123 Node.Property attrValueProperty = null; 124 try { 125 String attrName = attrQName.getLocalPart(); 126 if(attrName.equals(NAME_PROP)) { attrValueProperty = createNameProperty(); 130 131 } else { 132 attrValueProperty = super.createAttributeProperty(attrQName); 133 } 134 135 } catch(Exception ex) { 136 mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex); 137 ErrorManager.getDefault().notify(ex); 138 } 139 return attrValueProperty; 140 } 141 142 143 @Override 144 protected List <Node.Property> createAlwaysPresentAttributeProperty() throws Exception { 145 ArrayList <Node.Property> alwaysPresentAttrProperties = new ArrayList <Node.Property>(); 146 alwaysPresentAttrProperties.add(createNameProperty()); 147 148 return alwaysPresentAttrProperties; 149 } 150 151 152 private Node.Property createNameProperty() throws NoSuchMethodException { 153 Node.Property attrValueProperty; 154 attrValueProperty = new BaseAttributeProperty(mPropertyAdapter, String .class, NAME_PROP); 155 attrValueProperty.setName(NbBundle.getMessage(BindingOperationNode.class, "PROP_NAME_DISPLAYNAME")); 156 attrValueProperty.setShortDescription(NbBundle.getMessage(BindingOperationNode.class, "BINDINGOPERATION_NAME_DESCRIPTION")); 157 158 return attrValueProperty; 159 } 160 161 162 public class BindingOperationPropertyAdapter extends PropertyAdapter implements NamedPropertyAdapter { 163 164 public BindingOperationPropertyAdapter() { 165 super(mWSDLConstruct); 166 } 167 168 public void setName(String name) { 169 getWSDLComponent().getModel().startTransaction(); 170 ((BindingOperation) getWSDLComponent()).setName(name); 171 getWSDLComponent().getModel().endTransaction(); 172 } 173 174 public String getName() { 175 if(mWSDLConstruct.getName() == null) { 176 return ""; 177 } 178 179 return mWSDLConstruct.getName(); 180 } 181 182 } 183 184 public static final class BindingOperationNewTypesFactory implements NewTypesFactory{ 185 186 public NewType[] getNewTypes(WSDLComponent def) { 187 188 ArrayList <NewType> list = new ArrayList <NewType>(); 189 if (def.getDocumentation() == null) { 190 list.add(new DocumentationNewType(def)); 191 } 192 BindingOperation bo = (BindingOperation) def; 193 if (bo.getOperation() != null && bo.getOperation().get() != null) { 194 if (needInput(bo)){ 195 list.add(new BindingOperationInputNewType(def)); 196 } 197 if (needOutput(bo)){ 198 list.add(new BindingOperationOutputNewType(def)); 199 } 200 if (needFault(bo)){ 201 list.add(new BindingOperationFaultNewType(def)); 202 } 203 } 204 list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_BINDING_OPERATION).getNewTypes(def))); 205 return list.toArray(new NewType[]{}); 206 } 207 private boolean needInput(BindingOperation bo){ 208 if (bo.getBindingInput() == null) { 209 Operation operation = bo.getOperation().get(); 210 return operation.getInput() != null; 211 } 212 return false; 213 } 214 private boolean needOutput(BindingOperation bo){ 215 if (bo.getBindingOutput() == null) { 216 Operation operation = bo.getOperation().get(); 217 return operation.getOutput() != null; 218 } 219 return false; 220 } 221 private boolean needFault(BindingOperation bo){ 222 Operation operation = bo.getOperation().get(); 223 int operationFaultsSize = operation.getFaults() != null ? operation.getFaults().size() : 0; 224 if (operationFaultsSize > 0) { 225 if (bo.getBindingFaults() != null) { 226 return operationFaultsSize > bo.getBindingFaults().size(); 227 } 228 } 229 return false; 230 } 231 232 } 233 234 @Override 235 public String getTypeDisplayName() { 236 return NbBundle.getMessage(BindingOperationNode.class, "LBL_BindingOperationNode_TypeDisplayName"); 237 } 238 } 239 240 241 242 | Popular Tags |