1 19 20 26 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor; 27 28 import java.awt.Image ; 29 import java.util.ArrayList ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 33 import javax.swing.Action ; 34 import javax.xml.namespace.QName ; 35 import org.netbeans.modules.refactoring.api.ui.RefactoringActionsFactory; 36 37 import org.netbeans.modules.xml.schema.model.Attribute; 40 import org.netbeans.modules.xml.schema.model.Element; 41 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement; 42 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 43 import org.netbeans.modules.xml.wsdl.ui.actions.RemoveAttributesAction; 44 import org.netbeans.modules.xml.wsdl.ui.actions.extensibility.AddAttributeAction; 45 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter; 46 import org.netbeans.modules.xml.wsdl.ui.commands.NamedPropertyAdapter; 47 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElement; 48 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementInfo; 49 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 50 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementsFactory; 51 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.impl.ExtensibilityUtils; 52 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility; 53 import org.netbeans.modules.xml.wsdl.ui.property.view.PropertyViewFactory; 54 import org.netbeans.modules.xml.wsdl.ui.schema.visitor.SchemaDocumentationFinderVisitor; 55 import org.netbeans.modules.xml.wsdl.ui.spi.ExtensibilityElementConfigurator; 56 import org.netbeans.modules.xml.wsdl.ui.spi.ExtensibilityElementConfiguratorFactory; 57 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ExtensibilityElementChildNewTypesFactory; 58 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory; 59 import org.netbeans.modules.xml.xam.NamedReferenceable; 60 import org.netbeans.modules.xml.xam.ui.XAMUtils; 61 import org.netbeans.modules.xml.xam.ui.actions.GoToAction; 62 import org.openide.ErrorManager; 63 import org.openide.actions.CopyAction; 64 import org.openide.actions.CutAction; 65 import org.openide.actions.DeleteAction; 66 import org.openide.actions.NewAction; 67 import org.openide.actions.PasteAction; 68 import org.openide.actions.PropertiesAction; 69 import org.openide.nodes.Node; 70 import org.openide.nodes.Sheet; 71 import org.openide.util.Utilities; 72 import org.openide.util.actions.SystemAction; 73 74 75 76 82 public class ExtensibilityElementNode extends WSDLNamedElementNode{ 83 84 85 private static final Image ICON = Utilities.loadImage 86 ("org/netbeans/modules/xml/wsdl/ui/view/resources/generic.png"); 87 88 89 private ExtensibilityElement mWSDLConstruct; 90 91 private Node mLayerDelegateNode; 92 93 private WSDLExtensibilityElement mExtensibilityElement; 94 95 private Element mSchemaElement; 96 97 private boolean canRename = false; 98 99 private QName mQName = null; 100 101 private ExtensibilityElementConfigurator mConfigurator; 102 103 public ExtensibilityElementNode(ExtensibilityElement wsdlConstruct) { 104 super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct); 105 mWSDLConstruct = wsdlConstruct; 106 QName qName = mWSDLConstruct.getQName(); 107 String namespace = null; 109 if (qName.getPrefix() != null) { 110 namespace = Utility.getNamespaceURI(qName.getPrefix(), mWSDLConstruct); 111 mQName = new QName (namespace, qName.getLocalPart(), qName.getPrefix()); 112 } else { 113 mQName = qName; 114 } 115 116 String displayName = mQName != null ? Utility.fromQNameToString(mQName) : "Missing Name"; 117 mConfigurator = new ExtensibilityElementConfiguratorFactory().getExtensibilityElementConfigurator(mQName); 118 boolean isNameSet = false; 119 if (isNamedReferenceable()) { 120 setNamedPropertyAdapter(new ExtensibilityElementConstrainedNamedPropertyAdapter()); 121 canRename = true; 122 } else { 123 if (mConfigurator != null) { 124 String attributeName = mConfigurator.getDisplayAttributeName(wsdlConstruct, mQName); 125 126 if (attributeName != null) { 127 setNamedPropertyAdapter(attributeName, new ExtensibilityElementNamedPropertyAdapter(attributeName)); 128 String value = wsdlConstruct.getAttribute(attributeName); 129 if (value != null && value.trim().length() > 0) { 130 isNameSet = true; 131 setDisplayName(value); 132 } 133 canRename = true; 134 } 135 } 136 137 if (!isNameSet) { 138 this.setDisplayName(displayName); 139 setShortDescription(mQName != null ? mQName.toString() : "Missing Name"); 140 } 141 } 142 try { 143 WSDLComponent parentComponent = mWSDLConstruct.getParent(); 144 String extensibilityElementType = ExtensibilityUtils.getExtensibilityElementType(parentComponent); 145 if(extensibilityElementType != null) { 146 WSDLExtensibilityElements elements = WSDLExtensibilityElementsFactory.getInstance().getWSDLExtensibilityElements(); 147 mExtensibilityElement = elements.getWSDLExtensibilityElement(extensibilityElementType); 148 if(mExtensibilityElement != null) { 149 WSDLExtensibilityElementInfo info = mExtensibilityElement.getWSDLExtensibilityElementInfos(mQName); 150 if(info != null && info.getElement() != null) { 151 this.mLayerDelegateNode = getLayerDelegateNode(info); 152 153 this.mSchemaElement = info.getElement(); 154 156 } 157 } 158 } else { 159 mSchemaElement = ExtensibilityUtils.getElement(mWSDLConstruct); 160 161 185 } 186 } catch(Exception ex) { 187 ErrorManager.getDefault().notify(ex); 188 } 189 190 if(this.mSchemaElement != null) { 191 SchemaDocumentationFinderVisitor sdFinder = new SchemaDocumentationFinderVisitor(); 192 this.mSchemaElement.accept(sdFinder); 193 String docStr = sdFinder.getDocumentation(); 194 if(docStr != null && !docStr.trim().equals("")) { 195 this.setShortDescription(docStr); 196 197 } 198 } 199 200 201 this.mWSDLConstruct.getModel().addComponentListener(this); 202 203 } 204 205 private Node getLayerDelegateNode(WSDLExtensibilityElementInfo elementInfo) { 206 Node delegateNode = elementInfo.getDataObject().getNodeDelegate(); 207 return delegateNode; 208 } 209 210 private boolean isNamedReferenceable() { 211 if (mWSDLConstruct instanceof NamedReferenceable) { 212 return true; 213 } 214 return false; 215 } 216 217 @Override 218 public Image getIcon(int type) { 219 if(mLayerDelegateNode != null) { 220 return mLayerDelegateNode.getIcon(type); 221 } 222 return ICON; 223 } 224 225 @Override 226 public Image getOpenedIcon(int type) { 227 if(mLayerDelegateNode != null) { 228 return mLayerDelegateNode.getOpenedIcon(type); 229 } 230 return ICON; 231 } 232 233 @Override 234 public Action [] getActions(boolean context) { 235 return createDynamicActions(); 236 } 237 238 239 240 @Override 241 public NewTypesFactory getNewTypesFactory() { 242 return new ExtensibilityElementChildNewTypesFactory(mSchemaElement); 243 } 244 245 @Override 246 public boolean canRename() { 247 return canRename; 248 } 249 250 private Action [] createDynamicActions() { 251 List <Action > actions = new ArrayList <Action >(); 252 253 actions.add(SystemAction.get(CutAction.class)); 255 actions.add(SystemAction.get(CopyAction.class)); 256 actions.add(SystemAction.get(PasteAction.class)); 257 actions.add(null); 258 actions.add(SystemAction.get(NewAction.class)); 259 actions.add(SystemAction.get(DeleteAction.class)); 260 actions.add(null); 261 if (mSchemaElement != null) { 263 if (Utils.isExtensionAttributesAllowed(mSchemaElement)) { 264 actions.add(SystemAction.get(AddAttributeAction.class)); 265 actions.add(SystemAction.get(RemoveAttributesAction.class)); 266 actions.add(null); 267 } 268 actions.add(SystemAction.get(GoToAction.class)); 269 if (isNamedReferenceable()) { 270 actions.add(RefactoringActionsFactory.whereUsedAction()); 272 actions.add(null); 273 actions.add(RefactoringActionsFactory.editorSubmenuAction()); 274 } 275 actions.add(null); 276 actions.add(SystemAction.get(PropertiesAction.class)); 277 } else { 278 actions.add(SystemAction.get(GoToAction.class)); 279 actions.add(null); 280 actions.add(SystemAction.get(PropertiesAction.class)); 281 } 282 283 return actions.toArray(new Action [actions.size()]); 284 } 285 286 @Override 287 protected void refreshAttributesSheetSet() { 288 Sheet.Set defaultSet = null; 289 if (mSchemaElement != null) { 290 try { 291 Sheet.Set[] sets = PropertyViewFactory.getInstance().getPropertySets(mWSDLConstruct, mQName, mSchemaElement); 292 if (sets != null) { 293 for (Sheet.Set set : sets) { 294 mSheet.put(set); 295 } 296 if (sets.length > 0) 297 defaultSet = sets[sets.length - 1]; 298 } 299 if (defaultSet != null) { 300 List <Node.Property> properties = createAlwaysPresentAttributeProperty(); 301 if(properties != null) { 302 Iterator <Node.Property> itP = properties.iterator(); 303 while(itP.hasNext()) { 304 Node.Property property = itP.next(); 305 if(defaultSet.get(property.getName()) == null) { 307 defaultSet.put(property); 308 } 309 } 310 } 311 } 312 } catch (Exception e) { 313 ErrorManager.getDefault().notify(e); 314 } 315 } else { 316 super.refreshAttributesSheetSet(); 317 } 318 } 319 320 321 public class ExtensibilityElementNamedPropertyAdapter implements NamedPropertyAdapter { 322 String attributeName; 323 324 325 public ExtensibilityElementNamedPropertyAdapter(String attributeName) { 326 this.attributeName = attributeName; 327 } 328 329 public void setName(String name) { 330 mWSDLConstruct.getModel().startTransaction(); 331 mWSDLConstruct.setAttribute(attributeName, name); 332 mWSDLConstruct.getModel().endTransaction(); 333 } 334 335 public String getName() { 336 return mWSDLConstruct.getAttribute(attributeName); 337 } 338 339 public boolean isWritable() { 340 return XAMUtils.isWritable(mWSDLConstruct.getModel()); 341 } 342 343 } 344 public class ExtensibilityElementConstrainedNamedPropertyAdapter extends ConstraintNamedPropertyAdapter { 345 public ExtensibilityElementConstrainedNamedPropertyAdapter() { 346 super(getWSDLComponent()); 347 } 348 349 350 @Override 351 public boolean isNameExists(String name) { 352 return false; 353 } 354 355 } 356 357 358 @Override 359 public String getTypeDisplayName() { 360 if (mConfigurator == null) return null; 361 362 return mConfigurator.getTypeDisplayName(mWSDLConstruct, mQName); 363 } 364 365 @Override 366 public String getHtmlDisplayName() { 367 String htmlDisplayName = super.getHtmlDisplayName(); 368 369 if (mConfigurator == null) 370 return htmlDisplayName; 371 372 String decoration = mConfigurator.getHtmlDisplayNameDecoration(mWSDLConstruct, mQName); 373 374 if (decoration == null) 375 return htmlDisplayName; 376 377 return htmlDisplayName + " <font color='#999999'>"+decoration+"</font>"; 378 379 } 380 } 381 382 383 384 | Popular Tags |