KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > OperationNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
22
23 import java.awt.Image JavaDoc;
24 import java.beans.PropertyEditor JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Arrays JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29 import java.util.logging.Level JavaDoc;
30
31 import javax.swing.Action JavaDoc;
32 import javax.xml.namespace.QName JavaDoc;
33 import org.netbeans.modules.refactoring.api.ui.RefactoringActionsFactory;
34
35 //import org.netbeans.modules.xml.refactoring.actions.FindUsagesAction;
36
//import org.netbeans.modules.xml.refactoring.actions.RefactorAction;
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.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 /**
73  *
74  * @author Ritesh Adval
75  *
76  */

77 public abstract class OperationNode extends WSDLExtensibilityElementNode {
78     
79     
80     /** Icon for the Ip msg button. */
81     private static Image JavaDoc 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 JavaDoc PARAMETER_ORDER_PROP = "parameterOrder";//NOI18N
87

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,
98
// SystemAction.get(CreateBindingFromOperationAction.class),
99
null,
100         SystemAction.get(GoToAction.class),
101         //SystemAction.get(FindUsagesAction.class),
102
(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 JavaDoc
120     public String JavaDoc getNameInLayer() {
121         return WSDLExtensibilityElements.ELEMENT_PORTTYPE_OPERATION;
122     }
123     
124     @Override JavaDoc
125     public Image JavaDoc getIcon(int type) {
126         return ICON;
127     }
128
129     @Override JavaDoc
130     public Image JavaDoc getOpenedIcon(int type) {
131         return ICON;
132     }
133     
134     @Override JavaDoc
135     public Action JavaDoc[] getActions(boolean context) {
136         return ACTIONS;
137     }
138     
139     public Object JavaDoc getWSDLConstruct() {
140         return mWSDLConstruct;
141     }
142     
143     @Override JavaDoc
144     protected Node.Property createAttributeProperty(QName JavaDoc attrQName) {
145         Node.Property attrValueProperty = null;
146         try {
147             String JavaDoc attrName = attrQName.getLocalPart();
148             //name
149
if(attrName.equals(NAME_PROP)) {
150                 attrValueProperty = createNameProperty();
151             } else if(attrName.equals(PARAMETER_ORDER_PROP)) {
152                 //optional parameterOrder
153
attrValueProperty = createParameterOrderProperty();
154             } else {
155                 attrValueProperty = super.createAttributeProperty(attrQName);
156             }
157             
158         } catch(Exception JavaDoc 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 JavaDoc
167     protected List JavaDoc<Node.Property> createAlwaysPresentAttributeProperty() throws Exception JavaDoc {
168         ArrayList JavaDoc<Node.Property> alwaysPresentAttrProperties = new ArrayList JavaDoc<Node.Property>();
169         alwaysPresentAttrProperties.add(createNameProperty());
170         alwaysPresentAttrProperties.add(createParameterOrderProperty());
171         return alwaysPresentAttrProperties;
172     }
173     
174     
175       private Node.Property createNameProperty() throws NoSuchMethodException JavaDoc {
176           Node.Property attrValueProperty;
177           attrValueProperty = new BaseAttributeProperty(mPropertyAdapter, String JavaDoc.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 JavaDoc {
184           Node.Property attrValueProperty;
185           attrValueProperty = new ParameterOrderProperty(this, mPropertyAdapter, String JavaDoc.class, "parameterOrder"); //NOI18N
186
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 JavaDoc paramOrder) {
200              if(paramOrder != null) {
201                  ArrayList JavaDoc<String JavaDoc> parts = new ArrayList JavaDoc<String JavaDoc>();
202                  StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(paramOrder, " ");
203                  while(st.hasMoreElements()) {
204                      String JavaDoc part = (String JavaDoc) 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 JavaDoc getParameterOrder() {
215              if(mWSDLConstruct.getParameterOrder() == null) {
216                  return "";
217              }
218              
219              StringBuffer JavaDoc partList = new StringBuffer JavaDoc(10);
220              
221              List JavaDoc<String JavaDoc> parts = mWSDLConstruct.getParameterOrder();
222              for (String JavaDoc part : parts) {
223                  partList.append(part);
224                  partList.append(" ");
225              }
226              return partList.toString().trim();
227              
228          }
229          
230          @Override JavaDoc
231          public boolean isNameExists(String JavaDoc 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 JavaDoc valueType, String JavaDoc propertyName) throws NoSuchMethodException JavaDoc {
241             super(instance, valueType, propertyName);
242             this.mOperationNode = node;
243         }
244         
245         @Override JavaDoc
246         public PropertyEditor JavaDoc 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 JavaDoc<NewType> list = new ArrayList JavaDoc<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