KickJava   Java API By Example, From Geeks To Geeks.

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


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.Service;
37 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
38 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
39 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
40 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter;
41 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
42 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
43 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType;
44 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementNewTypesFactory;
45 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory;
46 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ServicePortNewType;
47 import org.openide.ErrorManager;
48 import org.openide.nodes.Node;
49 import org.openide.util.HelpCtx;
50 import org.openide.util.NbBundle;
51 import org.openide.util.Utilities;
52 import org.openide.util.datatransfer.NewType;
53
54
55 /**
56  * @author Ritesh Adval
57  *
58  **/

59 public class ServiceNode extends WSDLExtensibilityElementNode {
60     
61     protected Service mWSDLConstruct;
62     
63     private static Image JavaDoc ICON = Utilities.loadImage
64             ("org/netbeans/modules/xml/wsdl/ui/view/resources/service.png");
65     
66     
67     private ServicePropertyAdapter mPropertyAdapter;
68     
69     public ServiceNode(Service wsdlConstruct) {
70         super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new ServiceNewTypesFactory());
71         mWSDLConstruct = wsdlConstruct;
72         
73         
74         this.mPropertyAdapter = new ServicePropertyAdapter();
75         super.setNamedPropertyAdapter(this.mPropertyAdapter);
76     }
77     
78     @Override JavaDoc
79             public String JavaDoc getNameInLayer() {
80         return WSDLExtensibilityElements.ELEMENT_SERVICE;
81     }
82     
83     @Override JavaDoc
84             public Image JavaDoc getIcon(int type) {
85         return ICON;
86     }
87     
88     @Override JavaDoc
89             public Image JavaDoc getOpenedIcon(int type) {
90         return ICON;
91     }
92     
93     @Override JavaDoc
94             protected Node.Property createAttributeProperty(QName JavaDoc attrQName) {
95         Node.Property attrValueProperty = null;
96         try {
97             String JavaDoc attrName = attrQName.getLocalPart();
98             //name
99
if(attrName.equals(NAME_PROP)) { //NOT I18N
100
//name
101
attrValueProperty = createNameProperty();
102                 
103             } else {
104                 attrValueProperty = super.createAttributeProperty(attrQName);
105             }
106             
107         } catch(Exception JavaDoc ex) {
108             mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
109             ErrorManager.getDefault().notify(ex);
110         }
111         return attrValueProperty;
112     }
113     
114     @Override JavaDoc
115             protected List JavaDoc<Node.Property> createAlwaysPresentAttributeProperty() throws Exception JavaDoc {
116         ArrayList JavaDoc<Node.Property> alwaysPresentAttrProperties = new ArrayList JavaDoc<Node.Property>();
117         alwaysPresentAttrProperties.add(createNameProperty());
118         
119         return alwaysPresentAttrProperties;
120     }
121     
122     
123     private Node.Property createNameProperty() throws NoSuchMethodException JavaDoc {
124         Node.Property attrValueProperty;
125         attrValueProperty = new BaseAttributeProperty(mPropertyAdapter,
126                 String JavaDoc.class,
127                 NAME_PROP);
128         attrValueProperty.setName(NbBundle.getMessage(ServiceNode.class, "PROP_NAME_DISPLAYNAME"));
129         attrValueProperty.setShortDescription(NbBundle.getMessage(ServiceNode.class, "SERVICE_NAME_DESC"));
130         
131         return attrValueProperty;
132     }
133     
134     @Override JavaDoc
135             public HelpCtx getHelpCtx() {
136         return new HelpCtx(ServiceNode.class);
137     }
138     
139     
140     public class ServicePropertyAdapter extends ConstraintNamedPropertyAdapter {
141         
142         public ServicePropertyAdapter() {
143             super(mWSDLConstruct);
144         }
145         
146         @Override JavaDoc
147                 public boolean isNameExists(String JavaDoc name) {
148             WSDLModel document = mWSDLConstruct.getModel();
149             return NameGenerator.getInstance().isServiceExists(name, document);
150         }
151         
152     }
153     
154     public static final class ServiceNewTypesFactory implements NewTypesFactory{
155         
156         public NewType[] getNewTypes(WSDLComponent def) {
157             
158             ArrayList JavaDoc<NewType> list = new ArrayList JavaDoc<NewType>();
159             if (def.getDocumentation() == null) {
160                 list.add(new DocumentationNewType(def));
161             }
162             list.add(new ServicePortNewType(def));
163             list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_SERVICE).getNewTypes(def)));
164             return list.toArray(new NewType[]{});
165         }
166         
167     }
168
169     @Override JavaDoc
170     public String JavaDoc getTypeDisplayName() {
171         return NbBundle.getMessage(ServiceNode.class, "LBL_ServiceNode_TypeDisplayName");
172     }
173 }
174
175
Popular Tags