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.Arrays ; 31 import java.util.List ; 32 import java.util.logging.Level ; 33 34 import javax.xml.namespace.QName ; 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 59 public class ServiceNode extends WSDLExtensibilityElementNode { 60 61 protected Service mWSDLConstruct; 62 63 private static Image 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 79 public String getNameInLayer() { 80 return WSDLExtensibilityElements.ELEMENT_SERVICE; 81 } 82 83 @Override 84 public Image getIcon(int type) { 85 return ICON; 86 } 87 88 @Override 89 public Image getOpenedIcon(int type) { 90 return ICON; 91 } 92 93 @Override 94 protected Node.Property createAttributeProperty(QName attrQName) { 95 Node.Property attrValueProperty = null; 96 try { 97 String attrName = attrQName.getLocalPart(); 98 if(attrName.equals(NAME_PROP)) { attrValueProperty = createNameProperty(); 102 103 } else { 104 attrValueProperty = super.createAttributeProperty(attrQName); 105 } 106 107 } catch(Exception 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 115 protected List <Node.Property> createAlwaysPresentAttributeProperty() throws Exception { 116 ArrayList <Node.Property> alwaysPresentAttrProperties = new ArrayList <Node.Property>(); 117 alwaysPresentAttrProperties.add(createNameProperty()); 118 119 return alwaysPresentAttrProperties; 120 } 121 122 123 private Node.Property createNameProperty() throws NoSuchMethodException { 124 Node.Property attrValueProperty; 125 attrValueProperty = new BaseAttributeProperty(mPropertyAdapter, 126 String .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 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 147 public boolean isNameExists(String 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 <NewType> list = new ArrayList <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 170 public String getTypeDisplayName() { 171 return NbBundle.getMessage(ServiceNode.class, "LBL_ServiceNode_TypeDisplayName"); 172 } 173 } 174 175 | Popular Tags |