1 19 20 21 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor; 22 23 import java.awt.Image ; 24 import java.beans.PropertyEditor ; 25 import java.util.ArrayList ; 26 import java.util.Arrays ; 27 import java.util.List ; 28 import java.util.StringTokenizer ; 29 import java.util.logging.Level ; 30 31 import javax.swing.Action ; 32 import javax.xml.namespace.QName ; 33 import org.netbeans.modules.refactoring.api.ui.RefactoringActionsFactory; 34 35 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.PortType; 41 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation; 42 import org.netbeans.modules.xml.wsdl.model.SolicitResponseOperation; 43 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 44 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator; 45 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter; 46 import org.netbeans.modules.xml.wsdl.ui.commands.NamedPropertyAdapter; 47 import org.netbeans.modules.xml.wsdl.ui.cookies.CreateBindingFromOperationCookie; 48 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 49 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty; 50 import org.netbeans.modules.xml.wsdl.ui.view.property.ParameterOrderPropertyEditor; 51 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType; 52 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory; 53 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.FaultNewType; 54 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.InputNewType; 55 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory; 56 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.OutputNewType; 57 import org.netbeans.modules.xml.xam.ui.actions.GoToAction; 58 import org.openide.ErrorManager; 59 import org.openide.actions.CopyAction; 60 import org.openide.actions.CutAction; 61 import org.openide.actions.DeleteAction; 62 import org.openide.actions.NewAction; 63 import org.openide.actions.PasteAction; 64 import org.openide.actions.PropertiesAction; 65 import org.openide.nodes.Node; 66 import org.openide.util.NbBundle; 67 import org.openide.util.Utilities; 68 import org.openide.util.actions.SystemAction; 69 import org.openide.util.datatransfer.NewType; 70 71 72 77 public abstract class OperationNode extends WSDLExtensibilityElementNode { 78 79 80 81 private static Image ICON = Utilities.loadImage 82 ("org/netbeans/modules/xml/wsdl/ui/view/resources/operation.png"); 83 84 protected Operation mWSDLConstruct; 85 86 private static final String PARAMETER_ORDER_PROP = "parameterOrder"; 88 private OperationPropertyAdapter mPropertyAdapter; 89 90 private static final SystemAction[] ACTIONS = new SystemAction[]{ 91 SystemAction.get(CutAction.class), 92 SystemAction.get(CopyAction.class), 93 SystemAction.get(PasteAction.class), 94 null, 95 SystemAction.get(NewAction.class), 96 SystemAction.get(DeleteAction.class), 97 null, 100 SystemAction.get(GoToAction.class), 101 (SystemAction)RefactoringActionsFactory.whereUsedAction(), 103 null, 104 (SystemAction)RefactoringActionsFactory.editorSubmenuAction(), 105 null, 106 SystemAction.get(PropertiesAction.class) 107 }; 108 109 public OperationNode(Operation wsdlConstruct) { 110 super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new OperationNewTypesFactory()); 111 mWSDLConstruct = wsdlConstruct; 112 113 114 this.mPropertyAdapter = new OperationPropertyAdapter(); 115 super.setNamedPropertyAdapter(this.mPropertyAdapter); 116 getLookupContents().add(new CreateBindingFromOperationCookie(mWSDLConstruct)); 117 } 118 119 @Override 120 public String getNameInLayer() { 121 return WSDLExtensibilityElements.ELEMENT_PORTTYPE_OPERATION; 122 } 123 124 @Override 125 public Image getIcon(int type) { 126 return ICON; 127 } 128 129 @Override 130 public Image getOpenedIcon(int type) { 131 return ICON; 132 } 133 134 @Override 135 public Action [] getActions(boolean context) { 136 return ACTIONS; 137 } 138 139 public Object getWSDLConstruct() { 140 return mWSDLConstruct; 141 } 142 143 @Override 144 protected Node.Property createAttributeProperty(QName attrQName) { 145 Node.Property attrValueProperty = null; 146 try { 147 String attrName = attrQName.getLocalPart(); 148 if(attrName.equals(NAME_PROP)) { 150 attrValueProperty = createNameProperty(); 151 } else if(attrName.equals(PARAMETER_ORDER_PROP)) { 152 attrValueProperty = createParameterOrderProperty(); 154 } else { 155 attrValueProperty = super.createAttributeProperty(attrQName); 156 } 157 158 } catch(Exception ex) { 159 mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex); 160 ErrorManager.getDefault().notify(ex); 161 } 162 return attrValueProperty; 163 } 164 165 166 @Override 167 protected List <Node.Property> createAlwaysPresentAttributeProperty() throws Exception { 168 ArrayList <Node.Property> alwaysPresentAttrProperties = new ArrayList <Node.Property>(); 169 alwaysPresentAttrProperties.add(createNameProperty()); 170 alwaysPresentAttrProperties.add(createParameterOrderProperty()); 171 return alwaysPresentAttrProperties; 172 } 173 174 175 private Node.Property createNameProperty() throws NoSuchMethodException { 176 Node.Property attrValueProperty; 177 attrValueProperty = new BaseAttributeProperty(mPropertyAdapter, String .class, NAME_PROP); 178 attrValueProperty.setName(NbBundle.getMessage(OperationNode.class, "PROP_NAME_DISPLAYNAME")); 179 attrValueProperty.setShortDescription(NbBundle.getMessage(OperationNode.class, "OPERATION_NAME_DESC")); 180 return attrValueProperty; 181 } 182 183 private Node.Property createParameterOrderProperty() throws NoSuchMethodException { 184 Node.Property attrValueProperty; 185 attrValueProperty = new ParameterOrderProperty(this, mPropertyAdapter, String .class, "parameterOrder"); attrValueProperty.setName(NbBundle.getMessage(OperationNode.class, "PROP_PARAMETER_ORDER_DISPLAYNAME")); 187 attrValueProperty.setShortDescription(NbBundle.getMessage(OperationNode.class, "OPERATION_PARAM_ORDER_DESC")); 188 189 return attrValueProperty; 190 } 191 192 193 public class OperationPropertyAdapter extends ConstraintNamedPropertyAdapter implements NamedPropertyAdapter { 194 195 public OperationPropertyAdapter() { 196 super(getWSDLComponent()); 197 } 198 199 public void setParameterOrder(String paramOrder) { 200 if(paramOrder != null) { 201 ArrayList <String > parts = new ArrayList <String >(); 202 StringTokenizer st = new StringTokenizer (paramOrder, " "); 203 while(st.hasMoreElements()) { 204 String part = (String ) st.nextElement(); 205 parts.add(part); 206 } 207 getWSDLComponent().getModel().startTransaction(); 208 mWSDLConstruct.setParameterOrder(parts); 209 getWSDLComponent().getModel().endTransaction(); 210 } 211 212 } 213 214 public String getParameterOrder() { 215 if(mWSDLConstruct.getParameterOrder() == null) { 216 return ""; 217 } 218 219 StringBuffer partList = new StringBuffer (10); 220 221 List <String > parts = mWSDLConstruct.getParameterOrder(); 222 for (String part : parts) { 223 partList.append(part); 224 partList.append(" "); 225 } 226 return partList.toString().trim(); 227 228 } 229 230 @Override 231 public boolean isNameExists(String name) { 232 return NameGenerator.getInstance().isOperationExists(name, (PortType) mWSDLConstruct.getParent()); 233 } 234 } 235 236 237 public class ParameterOrderProperty extends BaseAttributeProperty { 238 private OperationNode mOperationNode; 239 240 public ParameterOrderProperty(OperationNode node, OperationPropertyAdapter instance, Class valueType, String propertyName) throws NoSuchMethodException { 241 super(instance, valueType, propertyName); 242 this.mOperationNode = node; 243 } 244 245 @Override 246 public PropertyEditor getPropertyEditor() { 247 return new ParameterOrderPropertyEditor(mOperationNode); 248 } 249 250 251 252 } 253 254 public static final class OperationNewTypesFactory implements NewTypesFactory{ 255 256 public NewType[] getNewTypes(WSDLComponent def) { 257 258 ArrayList <NewType> list = new ArrayList <NewType>(); 259 if (def.getDocumentation() == null) { 260 list.add(new DocumentationNewType(def)); 261 } 262 Operation operation = (Operation) def; 263 if (def instanceof NotificationOperation) { 264 if (operation.getOutput() == null) { 265 list.add(new OutputNewType(operation)); 266 } 267 } 268 269 if (def instanceof OneWayOperation) { 270 if (operation.getInput() == null) { 271 list.add(new InputNewType(operation)); 272 } 273 } 274 275 if (def instanceof RequestResponseOperation) { 276 if (operation.getInput() == null) { 277 list.add(new InputNewType(operation)); 278 } 279 if (operation.getOutput() == null) { 280 list.add(new OutputNewType(operation)); 281 } 282 list.add(new FaultNewType(def)); 283 } 284 285 if (def instanceof SolicitResponseOperation) { 286 if (operation.getOutput() == null) { 287 list.add(new OutputNewType(operation)); 288 } 289 if (operation.getInput() == null) { 290 list.add(new InputNewType(operation)); 291 } 292 list.add(new FaultNewType(def)); 293 } 294 list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_PORTTYPE_OPERATION).getNewTypes(def))); 295 return list.toArray(new NewType[]{}); 296 } 297 298 } 299 } 300 | Popular Tags |