1 19 20 21 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor; 22 23 import java.awt.Image ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 import java.util.logging.Level ; 27 28 import javax.swing.Action ; 29 import javax.xml.namespace.QName ; 30 import org.netbeans.modules.refactoring.api.ui.RefactoringActionsFactory; 31 32 import org.netbeans.modules.xml.wsdl.model.PortType; 35 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 36 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 37 import org.netbeans.modules.xml.wsdl.ui.actions.CommonAddExtensibilityAttributeAction; 38 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator; 39 import org.netbeans.modules.xml.wsdl.ui.actions.RemoveAttributesAction; 40 import org.netbeans.modules.xml.wsdl.ui.commands.ConstraintNamedPropertyAdapter; 41 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty; 42 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.BindingAndServiceNewType; 43 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType; 44 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory; 45 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.PortTypeOperationNewType; 46 import org.netbeans.modules.xml.xam.ui.actions.GoToAction; 47 import org.openide.ErrorManager; 48 import org.openide.actions.CopyAction; 49 import org.openide.actions.CutAction; 50 import org.openide.actions.DeleteAction; 51 import org.openide.actions.NewAction; 52 import org.openide.actions.PasteAction; 53 import org.openide.actions.PropertiesAction; 54 import org.openide.nodes.Node; 55 import org.openide.util.HelpCtx; 56 import org.openide.util.NbBundle; 57 import org.openide.util.Utilities; 58 import org.openide.util.actions.SystemAction; 59 import org.openide.util.datatransfer.NewType; 60 61 62 63 67 public class PortTypeNode extends WSDLNamedElementNode { 68 69 private PortType mWSDLConstruct; 70 71 private static Image ICON = Utilities.loadImage 72 ("org/netbeans/modules/xml/wsdl/ui/view/resources/portType.png"); 73 74 private PortTypePropertyAdapter mPropertyAdapter; 75 76 private static final SystemAction[] ACTIONS = new SystemAction[] { 77 SystemAction.get(CutAction.class), 78 SystemAction.get(CopyAction.class), 79 SystemAction.get(PasteAction.class), 80 null, 81 SystemAction.get(NewAction.class), 82 SystemAction.get(DeleteAction.class), 83 null, 84 SystemAction.get(CommonAddExtensibilityAttributeAction.class), 85 SystemAction.get(RemoveAttributesAction.class), 86 null, 87 SystemAction.get(GoToAction.class), 88 (SystemAction)RefactoringActionsFactory.whereUsedAction(), 90 null, 91 (SystemAction)RefactoringActionsFactory.editorSubmenuAction(), 92 null, 94 SystemAction.get(PropertiesAction.class) 95 }; 96 97 public PortTypeNode(PortType wsdlConstruct) { 98 super(new GenericWSDLComponentChildren(wsdlConstruct), wsdlConstruct, new PortTypeNewTypesFactory()); 99 mWSDLConstruct = wsdlConstruct; 100 101 this.mPropertyAdapter = new PortTypePropertyAdapter(); 102 super.setNamedPropertyAdapter(this.mPropertyAdapter); 103 } 104 105 106 @Override 107 public Image getIcon(int type) { 108 return ICON; 109 } 110 111 @Override 112 public Image getOpenedIcon(int type) { 113 return ICON; 114 } 115 116 @Override 117 public Action [] getActions(boolean context) { 118 return ACTIONS; 119 } 120 121 @Override 122 protected Node.Property createAttributeProperty(QName attrQName) { 123 Node.Property attrValueProperty = null; 124 try { 125 String attrName = attrQName.getLocalPart(); 126 if(attrName.equals(NAME_PROP)) { 128 attrValueProperty = createNameProperty(); 130 } else { 131 attrValueProperty = super.createAttributeProperty(attrQName); 132 } 133 134 } catch(Exception ex) { 135 mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex); 136 ErrorManager.getDefault().notify(ex); 137 } 138 return attrValueProperty; 139 } 140 141 142 @Override 143 protected List <Node.Property> createAlwaysPresentAttributeProperty() throws Exception { 144 ArrayList <Node.Property> alwaysPresentAttrProperties = new ArrayList <Node.Property>(); 145 alwaysPresentAttrProperties.add(createNameProperty()); 146 147 return alwaysPresentAttrProperties; 148 } 149 150 151 private Node.Property createNameProperty() throws NoSuchMethodException { 152 Node.Property attrValueProperty; 153 attrValueProperty = new BaseAttributeProperty(mPropertyAdapter, String .class, NAME_PROP); 154 attrValueProperty.setName(NbBundle.getMessage(PortTypeNode.class, "PROP_NAME_DISPLAYNAME")); 155 attrValueProperty.setShortDescription(NbBundle.getMessage(PortTypeNode.class, "PORTTYPE_NAME_DESC")); 156 157 return attrValueProperty; 158 } 159 160 @Override 161 public HelpCtx getHelpCtx() { 162 return new HelpCtx(PortTypeNode.class); 163 } 164 165 166 public class PortTypePropertyAdapter extends ConstraintNamedPropertyAdapter { 167 168 public PortTypePropertyAdapter() { 169 super(mWSDLConstruct); 170 } 171 172 @Override 173 public boolean isNameExists(String name) { 174 WSDLModel document = mWSDLConstruct.getModel(); 175 return NameGenerator.getInstance().isPortTypeExists(name, document); 176 } 177 } 178 179 public static final class PortTypeNewTypesFactory implements NewTypesFactory{ 180 181 public NewType[] getNewTypes(WSDLComponent def) { 182 ArrayList <NewType> list = new ArrayList <NewType>(); 183 list.add(new PortTypeOperationNewType(def)); 184 list.add(new BindingAndServiceNewType(def)); 185 if (def.getDocumentation() == null) { 186 list.add(new DocumentationNewType(def)); 187 } 188 return list.toArray(new NewType[]{}); 189 } 190 191 } 192 193 @Override 194 public String getTypeDisplayName() { 195 return NbBundle.getMessage(PortTypeNode.class, "LBL_PortTypeNode_TypeDisplayName"); 196 } 197 } 198 | Popular Tags |