KickJava   Java API By Example, From Geeks To Geeks.

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


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 17, 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.Binding;
37 import org.netbeans.modules.xml.wsdl.model.Port;
38 import org.netbeans.modules.xml.wsdl.model.Service;
39 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
40 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
41 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter;
42 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
43 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
44 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
45 import org.netbeans.modules.xml.wsdl.ui.view.property.BindingAttributeProperty;
46 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType;
47 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory;
48 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory;
49 import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
50 import org.openide.ErrorManager;
51 import org.openide.nodes.Node;
52 import org.openide.util.NbBundle;
53 import org.openide.util.Utilities;
54 import org.openide.util.datatransfer.NewType;
55
56
57
58 /**
59  * @author radval
60  *
61  * To change the template for this generated type comment go to
62  * Window - Preferences - Java - Code Generation - Code and Comments
63  */

64 public class PortNode extends WSDLExtensibilityElementNode {
65     
66     
67     private Port mWSDLConstruct;
68     
69     
70     private ServicePortPropertyAdapter mPropertyAdapter = null;
71     
72     private static Image JavaDoc ICON = Utilities.loadImage
73             ("org/netbeans/modules/xml/wsdl/ui/view/resources/serviceport.png");
74     
75     public PortNode(Port wsdlConstruct) {
76         super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new ServicePortNewTypesFactory());
77         mWSDLConstruct = wsdlConstruct;
78         
79         
80         this.mPropertyAdapter = new ServicePortPropertyAdapter();
81         super.setNamedPropertyAdapter(this.mPropertyAdapter);
82     }
83     
84     @Override JavaDoc
85     public String JavaDoc getNameInLayer() {
86         return WSDLExtensibilityElements.ELEMENT_SERVICE_PORT;
87     }
88     
89     @Override JavaDoc
90     public Image JavaDoc getIcon(int type) {
91         return ICON;
92     }
93     
94     @Override JavaDoc
95     public Image JavaDoc getOpenedIcon(int type) {
96         return ICON;
97     }
98     
99     @Override JavaDoc
100     protected Node.Property createAttributeProperty(QName JavaDoc attrQName) {
101         Node.Property attrValueProperty = null;
102         try {
103             String JavaDoc attrName = attrQName.getLocalPart();
104             //name
105
if(attrName.equals(NAME_PROP)) { //NOT I18N
106
//name
107
attrValueProperty = createNameProperty();
108                 
109                 
110             } else if(attrName.equals("binding")) {
111                 attrValueProperty = createBindingProperty();
112                 
113             } else {
114                 attrValueProperty = super.createAttributeProperty(attrQName);
115             }
116             
117         } catch(Exception JavaDoc ex) {
118             mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
119             ErrorManager.getDefault().notify(ex);
120         }
121         return attrValueProperty;
122     }
123     
124     @Override JavaDoc
125      protected List JavaDoc<Node.Property> createAlwaysPresentAttributeProperty() throws Exception JavaDoc {
126         ArrayList JavaDoc<Node.Property> alwaysPresentAttrProperties = new ArrayList JavaDoc<Node.Property>();
127         alwaysPresentAttrProperties.add(createNameProperty());
128         alwaysPresentAttrProperties.add(createBindingProperty());
129         return alwaysPresentAttrProperties;
130     }
131     
132     
133     private Node.Property createNameProperty() throws NoSuchMethodException JavaDoc {
134         Node.Property attrValueProperty;
135         attrValueProperty = new BaseAttributeProperty(mPropertyAdapter,
136                 String JavaDoc.class,
137                 NAME_PROP);
138         attrValueProperty.setName(NbBundle.getMessage(PortNode.class, "PROP_NAME_DISPLAYNAME"));
139         attrValueProperty.setShortDescription(NbBundle.getMessage(PortNode.class, "PORT_NAME_DESC"));
140         
141         return attrValueProperty;
142     }
143     
144     private Node.Property createBindingProperty() throws NoSuchMethodException JavaDoc {
145         Node.Property attrValueProperty;
146         attrValueProperty = new BindingAttributeProperty(mPropertyAdapter,
147                 String JavaDoc.class,
148                 "getBinding",
149                 "setBinding");
150         
151         attrValueProperty.setName(NbBundle.getMessage(PortNode.class, "PROP_BINDING_DISPLAYNAME"));
152         attrValueProperty.setShortDescription(NbBundle.getMessage(PortNode.class, "PORT_BINDING_DESC"));
153         
154         return attrValueProperty;
155     }
156     
157     
158     public class ServicePortPropertyAdapter extends ConstraintNamedPropertyAdapter {
159         
160         public ServicePortPropertyAdapter() {
161             super(mWSDLConstruct);
162         }
163         
164         @Override JavaDoc
165         public boolean isNameExists(String JavaDoc name) {
166             return NameGenerator.getInstance().isServicePortExists(name,
167                     (Service) mWSDLConstruct.getParent());
168         }
169         
170         public void setBinding(String JavaDoc bindingName) {
171             if(bindingName != null) {
172                 try {
173                     org.netbeans.modules.xml.wsdl.ui.common.QName bindingQName = org.netbeans.modules.xml.wsdl.ui.common.QName.getQNameFromString(bindingName);
174                     if(bindingQName == null) {
175                         mWSDLConstruct.getModel().startTransaction();
176                         mWSDLConstruct.setBinding(null);
177                         mWSDLConstruct.getModel().endTransaction();
178                     } else {
179                         
180                         String JavaDoc ns = bindingQName.getNamespaceURI();
181                         String JavaDoc prefix = bindingQName.getPrefix();
182                         if(ns == null || ns.trim().equals("")) {
183                             ns = Utility.getNamespaceURI(prefix, mWSDLConstruct.getModel());
184                         }
185                         
186                         
187                         QName JavaDoc qname = null;
188                         if (ns != null) {
189                             qname = new QName JavaDoc(ns, bindingQName.getLocalName());
190                         }
191                         
192                         if(qname != null) {
193                             Binding binding = mWSDLConstruct.getModel().findComponentByName(qname, Binding.class);
194                             if (binding == null) {
195                                 ErrorManager.getDefault().notify(ErrorManager.ERROR, new Exception JavaDoc("Not a valid type"));
196                             } else {
197                                 mWSDLConstruct.getModel().startTransaction();
198                                 mWSDLConstruct.setBinding(mWSDLConstruct.createReferenceTo(binding, Binding.class));
199                                 
200                                 mWSDLConstruct.getModel().endTransaction();
201                             }
202                         }
203                     }
204                     fireDisplayNameChange(null, getDisplayName());
205                 } catch (Exception JavaDoc e) {
206                     ErrorManager.getDefault().notify(e);
207                 }
208             }
209         }
210         
211         
212         public String JavaDoc getBinding() {
213             NamedComponentReference binding = mWSDLConstruct.getBinding();
214             if (binding != null) {
215                 QName JavaDoc bindingQName = binding.getQName();
216                 if(bindingQName != null) {
217                     return Utility.fromQNameToString(bindingQName);
218                 }
219             }
220             return "";
221             
222         }
223         
224         public Port getServicePort() {
225             return mWSDLConstruct;
226         }
227     }
228     
229     public static final class ServicePortNewTypesFactory implements NewTypesFactory{
230         
231         public NewType[] getNewTypes(WSDLComponent def) {
232             ArrayList JavaDoc<NewType> list = new ArrayList JavaDoc<NewType>();
233             if (def.getDocumentation() == null) {
234                 list.add(new DocumentationNewType(def));
235             }
236             
237             list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_SERVICE_PORT).getNewTypes(def)));
238             return list.toArray(new NewType[]{});
239         }
240     }
241
242     @Override JavaDoc
243     public String JavaDoc getTypeDisplayName() {
244         return NbBundle.getMessage(PortNode.class, "LBL_PortNode_TypeDisplayName");
245     }
246     
247     @Override JavaDoc
248     public String JavaDoc getHtmlDisplayName() {
249         String JavaDoc htmlDisplayName = super.getHtmlDisplayName();
250         NamedComponentReference<Binding> binding = mWSDLConstruct.getBinding();
251         
252         String JavaDoc decoration = null;
253         if (binding != null && binding.get() != null) {
254             String JavaDoc tns = binding.get().getModel().getDefinitions().getTargetNamespace();
255             decoration = NbBundle.getMessage(OperationParameterNode.class, "LBL_Binding",
256                     Utility.getNameAndDropPrefixIfInCurrentModel(tns, binding.get().getName(), mWSDLConstruct.getModel()));
257         }
258         
259         if (decoration == null) {
260             //decoration = NbBundle.getMessage(OperationParameterNode.class, "LBL_BindingNotSet");
261
return htmlDisplayName;
262         }
263         return htmlDisplayName + " <font color='#999999'>"+decoration+"</font>";
264     }
265 }
266
267
268
269
Popular Tags