1 19 20 21 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor; 22 23 import java.awt.Image ; 24 import java.beans.PropertyEditor ; 25 import java.lang.reflect.InvocationTargetException ; 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.List ; 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 59 public class WSDLImportNode extends ImportNode { 60 61 @SuppressWarnings ("hiding") Image 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 70 public Image getIcon(int type) { 71 return ICON; 72 } 73 74 @Override 75 public Image getOpenedIcon(int type) { 76 return ICON; 77 } 78 79 @Override 80 public String getTypeDisplayName() { 81 return NbBundle.getMessage(WSDLImportNode.class, "LBL_WSDLImportNode_TypeDisplayName"); 82 } 83 84 @Override 85 public boolean hasCustomizer() { 86 return true; 87 } 88 89 @Override 90 public CustomizerProvider getCustomizerProvider() { 91 return new CustomizerProvider() { 92 public Customizer getCustomizer() { 93 return new ImportWSDLCustomizer((Import) getWSDLComponent()); 94 } 95 }; 96 } 97 98 @Override 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 114 protected Node[] createNodes(Object key) { 115 if(key instanceof WSDLModel) { 116 WSDLModel document = (WSDLModel) key; 117 Definitions definitions = document.getDefinitions(); 118 try { 119 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 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 143 @SuppressWarnings ("unchecked") 144 protected Collection getKeys() { 145 ArrayList keys = new ArrayList (); 146 List <WSDLModel> models = this.mWsdlConstruct.getModel().findWSDLModel(mWsdlConstruct.getNamespace()); 147 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 168 public javax.swing.Action [] getActions(boolean context) { 169 return new javax.swing.Action [] {}; 170 } 171 172 173 @Override 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 185 public boolean canRename() 186 { 187 return false; 188 } 189 190 @Override 191 public boolean canDestroy() 192 { 193 return false; 194 } 195 196 @Override 197 public boolean canCut() 198 { 199 return false; 200 } 201 202 @Override 203 public boolean canCopy() 204 { 205 return false; 206 } 207 208 @Override 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 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 248 public boolean equals(Object property) { 249 return this.mDelegate.equals(property); 250 } 251 252 @Override 253 public String getHtmlDisplayName() { 254 return this.mDelegate.getHtmlDisplayName(); 255 } 256 257 @Override 258 public PropertyEditor getPropertyEditor() { 259 return this.mDelegate.getPropertyEditor(); 260 } 261 262 @Override 263 public Class getValueType() { 264 return this.mDelegate.getValueType(); 265 } 266 267 @Override 268 public int hashCode() { 269 return this.mDelegate.hashCode(); 270 } 271 272 @Override 273 public boolean isDefaultValue() { 274 return this.mDelegate.isDefaultValue(); 275 } 276 277 @Override 278 public void restoreDefaultValue() throws IllegalAccessException , 279 InvocationTargetException { 280 this.mDelegate.restoreDefaultValue(); 281 } 282 283 @Override 284 public boolean supportsDefaultValue() { 285 return this.mDelegate.supportsDefaultValue(); 286 } 287 288 @Override 289 public boolean canRead() { 290 return true; 291 } 292 293 @Override 294 public boolean canWrite() { 295 return false; 296 } 297 298 @Override 299 public Object getValue() throws IllegalAccessException , 300 InvocationTargetException { 301 return mDelegate.getValue(); 302 } 303 304 @Override 305 public void setValue(Object val) throws IllegalAccessException , 306 IllegalArgumentException , InvocationTargetException { 307 } 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 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 |