1 19 20 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor; 21 22 import java.awt.Image ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import java.util.logging.Level ; 29 import javax.swing.Action ; 30 import javax.xml.XMLConstants ; 31 import org.netbeans.modules.xml.wsdl.model.Definitions; 32 import org.netbeans.modules.xml.wsdl.model.Documentation; 33 import org.netbeans.modules.xml.wsdl.model.Types; 34 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 35 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 36 import org.netbeans.modules.xml.wsdl.ui.api.property.PropertyAdapter; 37 import org.netbeans.modules.xml.wsdl.ui.commands.NamedPropertyAdapter; 38 import org.netbeans.modules.xml.wsdl.ui.common.Constants; 39 import org.netbeans.modules.xml.wsdl.ui.cookies.WSDLDefinitionNodeCookie; 40 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements; 41 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility; 42 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.BindingNewType; 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.MessageNewType; 46 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory; 47 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.PortTypeNewType; 48 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ServiceNewType; 49 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.TypesNewType; 50 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; 51 import org.openide.ErrorManager; 52 import org.openide.actions.NewAction; 53 import org.openide.actions.PropertiesAction; 54 import org.openide.explorer.ExplorerManager; 55 import org.openide.nodes.Node; 56 import org.openide.nodes.Sheet; 57 import org.openide.util.HelpCtx; 58 import org.openide.util.NbBundle; 59 import org.openide.util.Utilities; 60 import org.openide.util.actions.SystemAction; 61 import org.openide.util.datatransfer.NewType; 62 import org.openide.windows.TopComponent; 63 import com.sun.org.apache.xml.internal.utils.XMLChar; 64 import java.util.HashSet ; 65 import java.util.Set ; 66 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty; 67 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ImportSchemaNewType; 68 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.ImportWSDLNewType; 69 import org.netbeans.modules.xml.xam.ui.actions.GoToAction; 70 import org.openide.actions.CopyAction; 71 import org.openide.actions.CutAction; 72 import org.openide.actions.PasteAction; 73 74 80 public class DefinitionsNode extends WSDLExtensibilityElementNode { 81 82 83 private Image ICON = Utilities.loadImage 84 ("org/netbeans/modules/xml/wsdl/ui/netbeans/module/resources/wsdl16.png"); 85 86 private static final String TARGETNAMESPACE_PROP = "targetNamespace"; 88 private DefinitionsPropertyAdapter mPropertyAdapter; 89 90 private ExplorerManager mManager; 91 92 private TopComponent mTopComponent; 93 94 private static final SystemAction[] ACTIONS = new SystemAction[]{ 95 SystemAction.get(CutAction.class), 96 SystemAction.get(CopyAction.class), 97 SystemAction.get(PasteAction.class), 98 null, 99 SystemAction.get(NewAction.class), 100 null, 101 SystemAction.get(GoToAction.class), 106 null, 107 SystemAction.get(PropertiesAction.class) 108 }; 109 110 public DefinitionsNode(Definitions mWSDLDef, 111 ExplorerManager manager, 112 TopComponent topComponent) { 113 this(mWSDLDef); 114 this.mManager = manager; 115 this.mTopComponent = topComponent; 116 117 } 118 119 public DefinitionsNode(Definitions mWSDLDef) { 120 super(new DefinitionsChildren(mWSDLDef), mWSDLDef, new DefinitionsNewTypesFactory()); 121 122 getLookupContents().add( new WSDLDefinitionNodeCookie(this)); 123 124 this.mPropertyAdapter = new DefinitionsPropertyAdapter(); 125 super.setNamedPropertyAdapter(this.mPropertyAdapter); 126 127 } 128 129 public ExplorerManager getExplorerManager() { 130 return mManager; 131 } 132 133 public TopComponent getTopComponent() { 134 return this.mTopComponent; 135 } 136 137 @Override 138 public String getNameInLayer() { 139 return WSDLExtensibilityElements.ELEMENT_DEFINITIONS; 140 } 141 142 @Override 143 public Image getIcon(int type) { 144 return ICON; 145 } 146 147 @Override 148 public Image getOpenedIcon(int type) { 149 return ICON; 150 } 151 152 @Override 153 public Action [] getActions(boolean context) { 154 return ACTIONS; 155 } 156 157 @Override 158 public boolean canCopy() { 159 return false; 160 } 161 162 @Override 163 public boolean canCut() { 164 return false; 165 } 166 167 protected void updateDisplayName() { 168 Definitions defs = (Definitions) getWSDLComponent(); 169 String name = defs.getTargetNamespace(); 170 if (name == null) { 171 name = NbBundle.getMessage(DefinitionsNode.class, 172 "LBL_DefinitionsNode_NoTargetNamespace"); 173 } 174 setDisplayName(name); 175 } 176 177 @Override 178 protected void refreshAttributesSheetSet() { 179 Sheet.Set ss = createPropertiesSheetSet(); 180 181 try { 182 Node.Property nameProperty = new BaseAttributeProperty(mPropertyAdapter, 184 String .class, NAME_PROP); 185 nameProperty.setName(NbBundle.getMessage(DefinitionsNode.class, "PROP_NAME_DISPLAYNAME")); 186 nameProperty.setShortDescription(NbBundle.getMessage(DefinitionsNode.class, "DEFINITIONSNODE_NAME_DESCRIPTION")); 187 ss.put(nameProperty); 188 189 Node.Property targetNamespaceProperty = new BaseAttributeProperty(mPropertyAdapter, 191 String .class, TARGETNAMESPACE_PROP); 192 targetNamespaceProperty.setName(NbBundle.getMessage(DefinitionsNode.class, "PROP_TARGET_NAMESPACE_DISPLAYNAME")); 193 targetNamespaceProperty.setShortDescription(NbBundle.getMessage(DefinitionsNode.class, "DEFINITIONSNODE_TARGETNAMESPACE_DESCRIPTION")); 194 ss.put(targetNamespaceProperty); 195 196 197 Node.Property defaultNamespaceProperty = new BaseAttributeProperty(mPropertyAdapter, 199 String .class,"defaultNamespace"); if(defaultNamespaceProperty.getValue() == null) { 201 defaultNamespaceProperty.setValue(Constants.WSDL_DEFAUL_NAMESPACE); 202 } 203 204 defaultNamespaceProperty.setName(NbBundle.getMessage(DefinitionsNode.class, "PROP_DEFAULT_NAMESPACE")); defaultNamespaceProperty.setShortDescription(NbBundle.getMessage(DefinitionsNode.class, "DEFINITIONS_NODE_DEFAULTNAMESPACE_DESC")); 206 ss.put(defaultNamespaceProperty); 207 208 refreshPrefixesSheetSet(Utility.getNamespaces((Definitions) getWSDLComponent())); 210 211 } catch(Exception ex) { 212 mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex); 213 } 214 } 215 216 private void refreshPrefixesSheetSet(Map prefixToNamespaceMap) throws Exception { 217 Sheet.Set prefixesSheetSet = createPrefixesSheetSet(prefixToNamespaceMap, (Definitions) getWSDLComponent()); 218 prefixesSheetSet.remove(NbBundle.getMessage(DefinitionsNode.class, "PROP_DEFAULT_NAMESPACE")); 220 221 mSheet.remove(NbBundle.getMessage(DefinitionsNode.class, "PROP_SHEET_CATEGORY_PREFIXES")); 222 mSheet.put(prefixesSheetSet); 223 } 224 public static Sheet.Set createPrefixesSheetSet(final Map prefixToNamespaceMap, Definitions definitions) throws Exception { 225 226 Sheet.Set prefixesSheetSet = new Sheet.Set(); 227 String prefixesSheetName = NbBundle.getMessage(DefinitionsNode.class, "PROP_SHEET_CATEGORY_PREFIXES"); 228 prefixesSheetSet.setName(prefixesSheetName); 229 prefixesSheetSet.setDisplayName(prefixesSheetName); 230 231 Iterator it = prefixToNamespaceMap.keySet().iterator(); 232 while(it.hasNext()) { 233 final String prefix = (String ) it.next(); 234 PropertyAdapter pn = null; 235 Node.Property prefixToNamespaceProperty = null; 236 237 238 pn = new PrefixToNamespace(prefix, definitions); 239 240 241 242 prefixToNamespaceProperty = new BaseAttributeProperty(pn, String .class, "namespace"); if(prefix.equals(XMLConstants.XMLNS_ATTRIBUTE) || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { 244 } else { 246 prefixToNamespaceProperty.setName(prefix); 247 prefixToNamespaceProperty.setShortDescription(NbBundle.getMessage(DefinitionsNode.class, "DEFINITIONSNODE_USER_DEF_PREFIX_DESC")); 248 prefixesSheetSet.put(prefixToNamespaceProperty); 249 } 250 251 } 252 253 return prefixesSheetSet; 254 } 255 256 public static class PrefixToNamespace extends PropertyAdapter { 257 258 private Definitions mWSDLConstruct; 259 260 private String mPrefix; 261 262 public PrefixToNamespace(String prefix, Definitions definitions) { 263 super(definitions); 264 this.mPrefix = prefix; 265 this.mWSDLConstruct = definitions; 266 } 267 268 public String getPrefix() { 269 return this.mPrefix; 270 } 271 272 public void setPrefix(String prefix) { 273 274 String namespace = getNamespace(); 275 mWSDLConstruct.getModel().startTransaction(); 276 ((AbstractDocumentComponent) mWSDLConstruct).removePrefix(mPrefix); 277 ((AbstractDocumentComponent) mWSDLConstruct).addPrefix(prefix, namespace); 278 mWSDLConstruct.getModel().endTransaction(); 279 mPrefix = prefix; 280 } 281 282 public void setNamespace(String namespace) { 283 mWSDLConstruct.getModel().startTransaction(); 284 ((AbstractDocumentComponent) mWSDLConstruct).addPrefix(mPrefix, namespace); 285 mWSDLConstruct.getModel().endTransaction(); 286 } 287 288 public String getNamespace() { 289 return Utility.getNamespaceURI(this.mPrefix, mWSDLConstruct); 290 } 291 } 292 public static final class DefinitionsChildren extends GenericWSDLComponentChildren { 293 294 public DefinitionsChildren(Definitions definitions) { 295 super(definitions); 296 } 298 299 @Override 300 protected Node[] createNodes(Object key) { 301 Node node = null; 302 303 if (IMPORTS_FOLDER.equals(key)) { 304 node = new ImportFolderNode((Definitions) getWSDLComponent()); 305 } 306 if (MESSAGES_FOLDER.equals(key)) { 307 node = new MessageFolderNode((Definitions) getWSDLComponent()); 308 } 309 if (PORTTYPES_FOLDER.equals(key)) { 310 node = new PortTypeFolderNode((Definitions) getWSDLComponent()); 311 } 312 if (BINDING_FOLDER.equals(key)) { 313 node = new BindingFolderNode((Definitions) getWSDLComponent()); 314 } 315 if (SERVICES_FOLDER.equals(key)) { 316 node = new ServiceFolderNode((Definitions) getWSDLComponent()); 317 } 318 319 if (EXTENSIBILITY_ELEMENTS_FOLDER.equals(key)) { 320 node = new ExtensibilityElementsFolderNode((Definitions) getWSDLComponent()); 321 } 322 323 324 if(node != null) { 325 return new Node[] {node}; 326 } 327 return super.createNodes(key); 328 } 329 330 @Override 331 protected Collection getKeys() { 332 Collection <Object > keys = new ArrayList <Object >(); 333 334 Definitions def = ((Definitions) getWSDLComponent()); 335 Documentation doc = def.getDocumentation(); 336 if (doc != null) { 337 keys.add(doc); 338 } 339 Types types = def.getTypes(); 340 if (types != null) { 341 keys.add(types); 342 } 343 345 keys.add(IMPORTS_FOLDER); 346 keys.add(MESSAGES_FOLDER); 348 keys.add(PORTTYPES_FOLDER); 349 keys.add(BINDING_FOLDER); 350 keys.add(SERVICES_FOLDER); 351 352 353 keys.add(EXTENSIBILITY_ELEMENTS_FOLDER); 354 355 return keys; 356 } 357 358 359 360 } 361 362 public static final String IMPORTS_FOLDER = "IMPORTS_FOLDER"; public static final String MESSAGES_FOLDER = "MESSAGES_FOLDER"; public static final String PORTTYPES_FOLDER = "PORTTYPES_FOLDER"; public static final String BINDING_FOLDER = "BINDING_FOLDER"; public static final String SERVICES_FOLDER = "SERVICES_FOLDER"; public static final String EXTENSIBILITY_ELEMENTS_FOLDER = "EXTENSIBILITY_ELEMENTS_FOLDER"; 370 371 public class DefinitionsPropertyAdapter extends PropertyAdapter implements NamedPropertyAdapter { 372 373 public DefinitionsPropertyAdapter() { 374 super(getWSDLComponent()); 375 } 376 377 public void setName(String name) { 378 if (name != null && name.trim().length() == 0) { 379 name = null; 380 } 381 382 if (name != null && !XMLChar.isValidNCName(name)) { 383 ErrorManager.getDefault().notify(new Exception (NbBundle.getMessage(DefinitionsNode.class, "ERR_MSG_INVALID_NMTOKEN"))); 384 return; 385 } 386 getWSDLComponent().getModel().startTransaction(); 387 ((Definitions) getWSDLComponent()).setName(name); 388 getWSDLComponent().getModel().endTransaction(); 389 } 390 391 public String getName() { 392 String name = ((Definitions)getWSDLComponent()).getName(); 393 if(name == null) { 394 return ""; 395 } 396 397 return name; 398 } 399 400 public void setTargetNamespace(String targetNamespace) { 401 getWSDLComponent().getModel().startTransaction(); 402 ((Definitions) getWSDLComponent()).setTargetNamespace(targetNamespace); 403 getWSDLComponent().getModel().endTransaction(); 404 } 405 406 public String getTargetNamespace() { 407 String tns = ((Definitions)getWSDLComponent()).getTargetNamespace(); 408 if(tns == null) { 409 return ""; 410 } 411 412 return tns; 413 } 414 415 public void setDefaultNamespace(String defaultNamespace) { 416 WSDLModel model = getWSDLComponent().getModel(); 417 model.startTransaction(); 418 ((AbstractDocumentComponent)getWSDLComponent()).addPrefix(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespace); model.endTransaction(); 420 } 421 422 public String getDefaultNamespace() { 423 return (String ) ((AbstractDocumentComponent) getWSDLComponent()).getPrefixes().get(XMLConstants.DEFAULT_NS_PREFIX); 424 } 425 } 426 427 public static final class DefinitionsNewTypesFactory implements NewTypesFactory{ 428 429 public NewType[] getNewTypes(WSDLComponent def) { 430 431 ArrayList <NewType> list = new ArrayList <NewType>(); 432 if (def.getDocumentation() == null) { 433 list.add(new DocumentationNewType(def)); 434 } 435 if (((Definitions) def).getTypes() == null) { 436 list.add(new TypesNewType(def)); 437 } 438 list.add(new ImportSchemaNewType(def)); 439 list.add(new ImportWSDLNewType(def)); 440 list.add(new MessageNewType(def)); 441 list.add(new PortTypeNewType(def)); 442 list.add(new BindingNewType(def)); 443 list.add(new ServiceNewType(def)); 444 list.addAll(Arrays.asList(new ExtensibilityElementNewTypesFactory(WSDLExtensibilityElements.ELEMENT_DEFINITIONS).getNewTypes(def))); 445 446 return list.toArray(new NewType[list.size()]); 447 } 448 } 449 450 @Override 451 public HelpCtx getHelpCtx() { 452 return new HelpCtx(DefinitionsNode.class); 453 } 454 455 @Override 456 public String getTypeDisplayName() { 457 return NbBundle.getMessage(DefinitionsNode.class, "LBL_DefinitionsNode_TypeDisplayName"); 458 } 459 460 461 } 462 | Popular Tags |