KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Created on May 24, 2005
22  *
23  * To change the template for this generated file go to
24  * Window - Preferences - Java - Code Generation - Code and Comments
25  */

26 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
27
28 import java.awt.Image JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Arrays JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.logging.Level JavaDoc;
33
34 import javax.xml.namespace.QName JavaDoc;
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 /**
61  * @author radval
62  *
63  * To change the template for this generated type comment go to
64  * Window - Preferences - Java - Code Generation - Code and Comments
65  */

66 public class BindingOperationNode extends WSDLExtensibilityElementNode {
67     private BindingOperation mWSDLConstruct;
68     private BindingOperationPropertyAdapter mPropertyAdapter;
69     private Image JavaDoc ICON;
70
71     public BindingOperationNode(BindingOperation wsdlConstruct) {
72         super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new BindingOperationNewTypesFactory());
73         mWSDLConstruct = wsdlConstruct;
74         // Must set the icon to something to honor getIcon() contract.
75
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 JavaDoc
88     public String JavaDoc 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 JavaDoc
112     public Image JavaDoc getIcon(int type) {
113         return ICON;
114     }
115
116     @Override JavaDoc
117     public Image JavaDoc getOpenedIcon(int type) {
118         return ICON;
119     }
120
121     @Override JavaDoc
122     protected Node.Property createAttributeProperty(QName JavaDoc attrQName) {
123             Node.Property attrValueProperty = null;
124             try {
125             String JavaDoc attrName = attrQName.getLocalPart();
126              //name
127
if(attrName.equals(NAME_PROP)) { //NOT I18N
128
//name
129
attrValueProperty = createNameProperty();
130             
131             } else {
132                 attrValueProperty = super.createAttributeProperty(attrQName);
133              }
134             
135             } catch(Exception JavaDoc 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 JavaDoc
144     protected List JavaDoc<Node.Property> createAlwaysPresentAttributeProperty() throws Exception JavaDoc {
145             ArrayList JavaDoc<Node.Property> alwaysPresentAttrProperties = new ArrayList JavaDoc<Node.Property>();
146             alwaysPresentAttrProperties.add(createNameProperty());
147             
148             return alwaysPresentAttrProperties;
149     }
150     
151     
152       private Node.Property createNameProperty() throws NoSuchMethodException JavaDoc {
153           Node.Property attrValueProperty;
154           attrValueProperty = new BaseAttributeProperty(mPropertyAdapter, String JavaDoc.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 JavaDoc name) {
169             getWSDLComponent().getModel().startTransaction();
170             ((BindingOperation) getWSDLComponent()).setName(name);
171                 getWSDLComponent().getModel().endTransaction();
172         }
173          
174         public String JavaDoc 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 JavaDoc<NewType> list = new ArrayList JavaDoc<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 JavaDoc
235     public String JavaDoc getTypeDisplayName() {
236         return NbBundle.getMessage(BindingOperationNode.class, "LBL_BindingOperationNode_TypeDisplayName");
237     }
238 }
239
240
241
242
Popular Tags