KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.InvocationTargetException JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.netbeans.modules.xml.wsdl.model.Definitions;
31 import org.netbeans.modules.xml.wsdl.model.Import;
32 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
33 import org.netbeans.modules.xml.wsdl.ui.actions.ActionHelper;
34 import org.netbeans.modules.xml.wsdl.ui.cookies.SaveCookieDelegate;
35 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.WSDLDataObject;
36 import org.netbeans.modules.xml.wsdl.ui.view.ImportWSDLCustomizer;
37 import org.netbeans.modules.xml.xam.ui.customizer.Customizer;
38 import org.netbeans.modules.xml.xam.ui.customizer.CustomizerProvider;
39 import org.openide.cookies.SaveCookie;
40 import org.openide.filesystems.FileObject;
41 import org.openide.loaders.DataObject;
42 import org.openide.nodes.AbstractNode;
43 import org.openide.nodes.Children;
44 import org.openide.nodes.FilterNode;
45 import org.openide.nodes.Node;
46 import org.openide.util.Lookup;
47 import org.openide.util.NbBundle;
48 import org.openide.util.Utilities;
49 import org.openide.util.lookup.AbstractLookup;
50 import org.openide.util.lookup.InstanceContent;
51
52
53 /**
54  * @author radval
55  *
56  * To change the template for this generated type comment go to
57  * Window - Preferences - Java - Code Generation - Code and Comments
58  */

59 public class WSDLImportNode extends ImportNode {
60     
61      @SuppressWarnings JavaDoc("hiding") Image JavaDoc ICON = Utilities.loadImage
62      ("org/netbeans/modules/xml/wsdl/ui/view/resources/import-wsdl.png");
63    
64     public WSDLImportNode(Import wsdlConstruct) {
65         super(new WSDLImportNodeChildren(wsdlConstruct),
66               wsdlConstruct);
67     }
68         
69     @Override JavaDoc
70     public Image JavaDoc getIcon(int type) {
71         return ICON;
72     }
73
74     @Override JavaDoc
75     public Image JavaDoc getOpenedIcon(int type) {
76         return ICON;
77     }
78     
79     @Override JavaDoc
80     public String JavaDoc getTypeDisplayName() {
81         return NbBundle.getMessage(WSDLImportNode.class, "LBL_WSDLImportNode_TypeDisplayName");
82     }
83
84     @Override JavaDoc
85     public boolean hasCustomizer() {
86         return true;
87     }
88
89     @Override JavaDoc
90     public CustomizerProvider getCustomizerProvider() {
91         return new CustomizerProvider() {
92             public Customizer getCustomizer() {
93                 return new ImportWSDLCustomizer((Import) getWSDLComponent());
94             }
95         };
96     }
97
98     @Override JavaDoc
99     protected void updateDisplayName() {
100         Import imp = (Import) getWSDLComponent();
101         setDisplayName(imp.getLocation());
102     }
103
104      public static class WSDLImportNodeChildren extends GenericWSDLComponentChildren {
105         
106         private Import mWsdlConstruct;
107     
108         public WSDLImportNodeChildren(Import wsdlConstruct) {
109             super(wsdlConstruct);
110             this.mWsdlConstruct = wsdlConstruct;
111         }
112         
113         @Override JavaDoc
114         protected Node[] createNodes(Object JavaDoc key) {
115             if(key instanceof WSDLModel) {
116                 WSDLModel document = (WSDLModel) key;
117                 Definitions definitions = document.getDefinitions();
118                 try {
119                     // Create a lookup with save cookie of parent wsdl, so that save can be called on imported wsdl's nodes
120
DataObject dobj = ActionHelper.getDataObject(mWsdlConstruct.getModel());
121                     InstanceContent content = new InstanceContent();
122                     content.add(new SaveCookieDelegate(dobj));
123                     Lookup parentLookup = new AbstractLookup(content);
124                     
125                     DataObject dataObj = DataObject.find((FileObject) document.getModelSource().getLookup().lookup(FileObject.class));
126                     if(dataObj != null && dataObj instanceof WSDLDataObject) {
127                         DefinitionsNode node = new DefinitionsNode(definitions);
128                         FilterNode filterNode = new ReadOnlyNode(node, parentLookup);
129                         return new Node[] {filterNode};
130                     }
131                 } catch(Exception JavaDoc ex) {
132                     AbstractNode node = new AbstractNode(Children.LEAF) {};
133                     node.setDisplayName("Error: could not load wsdl" );
134                     return new Node[] {node};
135                 }
136             }
137             
138             return super.createNodes(key);
139             
140         }
141         
142         @Override JavaDoc
143         @SuppressWarnings JavaDoc("unchecked")
144         protected Collection JavaDoc getKeys() {
145             ArrayList JavaDoc keys = new ArrayList JavaDoc();
146             List JavaDoc<WSDLModel> models = this.mWsdlConstruct.getModel().findWSDLModel(mWsdlConstruct.getNamespace());
147             //getImportedObject();
148
for (WSDLModel model : models) {
149                 if(model != null && model.getDefinitions() != null) {
150                     keys.add(model);
151                 }
152             }
153             keys.addAll(super.getKeys());
154             return keys;
155         }
156         
157     
158     }
159      
160      public static class ReadOnlyNode extends FilterNode {
161          
162          public ReadOnlyNode(Node original, Lookup lookup) {
163              super(original, new ReadOnlyChildren(original, lookup), lookup);
164              
165          }
166          
167          @Override JavaDoc
168         public javax.swing.Action JavaDoc[] getActions(boolean context) {
169              return new javax.swing.Action JavaDoc[] {};
170          }
171          
172           
173         @Override JavaDoc
174         public PropertySet[] getPropertySets () {
175             PropertySet[] propertySet = super.getPropertySets();
176             for(int i = 0; i < propertySet.length; i++) {
177                 PropertySet pSet = propertySet[i];
178                 ReadOnlyPropertySet rpSet = new ReadOnlyPropertySet(pSet);
179                 propertySet[i] = rpSet;
180             }
181             return propertySet;
182         }
183         
184         @Override JavaDoc
185         public boolean canRename()
186         {
187             return false;
188         }
189         
190         @Override JavaDoc
191         public boolean canDestroy()
192         {
193             return false;
194         }
195         
196         @Override JavaDoc
197         public boolean canCut()
198         {
199             return false;
200         }
201         
202         @Override JavaDoc
203         public boolean canCopy()
204         {
205             return false;
206         }
207         
208         @Override JavaDoc
209         public boolean hasCustomizer()
210         {
211             return false;
212         }
213      }
214      
215      
216      public static class ReadOnlyChildren extends FilterNode.Children {
217         
218          Lookup lookup;
219          
220         public ReadOnlyChildren(Node node, Lookup lookup) {
221             super(node);
222             this.lookup = lookup;
223         }
224         
225         @Override JavaDoc
226         protected Node[] createNodes(Node n) {
227              return new Node[] {new ReadOnlyNode(n, lookup)};
228         }
229     }
230     
231     public static class ReadOnlyProperty extends Node.Property {
232             
233         private Node.Property mDelegate;
234             
235         public ReadOnlyProperty(Node.Property delegate) {
236             super(delegate.getClass());
237             this.mDelegate = delegate;
238             this.setDisplayName(this.mDelegate.getDisplayName());
239             this.setName(this.mDelegate.getName());
240             this.setShortDescription(this.mDelegate.getShortDescription());
241             this.setExpert(this.mDelegate.isExpert());
242             this.setHidden(this.mDelegate.isHidden());
243             this.setPreferred(this.mDelegate.isPreferred());
244             
245         }
246         
247         @Override JavaDoc
248         public boolean equals(Object JavaDoc property) {
249             return this.mDelegate.equals(property);
250         }
251         
252         @Override JavaDoc
253         public String JavaDoc getHtmlDisplayName() {
254             return this.mDelegate.getHtmlDisplayName();
255         }
256         
257         @Override JavaDoc
258         public PropertyEditor JavaDoc getPropertyEditor() {
259             return this.mDelegate.getPropertyEditor();
260         }
261         
262         @Override JavaDoc
263         public Class JavaDoc getValueType() {
264             return this.mDelegate.getValueType();
265         }
266         
267         @Override JavaDoc
268         public int hashCode() {
269             return this.mDelegate.hashCode();
270         }
271         
272         @Override JavaDoc
273         public boolean isDefaultValue() {
274             return this.mDelegate.isDefaultValue();
275         }
276         
277         @Override JavaDoc
278         public void restoreDefaultValue() throws IllegalAccessException JavaDoc,
279                 InvocationTargetException JavaDoc {
280             this.mDelegate.restoreDefaultValue();
281         }
282         
283         @Override JavaDoc
284         public boolean supportsDefaultValue() {
285             return this.mDelegate.supportsDefaultValue();
286         }
287         
288         @Override JavaDoc
289         public boolean canRead() {
290             return true;
291         }
292         
293         @Override JavaDoc
294         public boolean canWrite() {
295             return false;
296         }
297         
298         @Override JavaDoc
299         public Object JavaDoc getValue() throws IllegalAccessException JavaDoc,
300                 InvocationTargetException JavaDoc {
301             return mDelegate.getValue();
302         }
303         
304         @Override JavaDoc
305         public void setValue(Object JavaDoc val) throws IllegalAccessException JavaDoc,
306                 IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
307             //do nothing
308
}
309     }
310     
311     public static class ReadOnlyPropertySet extends Node.PropertySet {
312             
313         private Node.PropertySet mDelegate;
314         
315         public ReadOnlyPropertySet(Node.PropertySet delegate) {
316             super(delegate.getName(), delegate.getDisplayName(), delegate.getShortDescription());
317             this.mDelegate = delegate;
318         }
319         
320         @Override JavaDoc
321         public Property[] getProperties() {
322             Property[] properties = this.mDelegate.getProperties();
323             for(int i = 0; i < properties.length; i++) {
324                 Property p = properties[i];
325                 ReadOnlyProperty rp = new ReadOnlyProperty(p);
326                 properties[i] = rp;
327             }
328             
329             return properties;
330         }
331     }
332 }
333
334
Popular Tags