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.util.logging.Level ; 26 27 import javax.swing.Action ; 28 29 import org.netbeans.modules.xml.wsdl.model.Import; 30 import org.netbeans.modules.xml.wsdl.ui.actions.CommonAddExtensibilityAttributeAction; 31 import org.netbeans.modules.xml.wsdl.ui.actions.RemoveAttributesAction; 32 import org.netbeans.modules.xml.wsdl.ui.api.property.PropertyAdapter; 33 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty; 34 import org.netbeans.modules.xml.wsdl.ui.view.property.ImportLocationPropertyEditor; 35 import org.netbeans.modules.xml.xam.ui.actions.GoToAction; 36 import org.openide.actions.CopyAction; 37 import org.openide.actions.CutAction; 38 import org.openide.actions.DeleteAction; 39 import org.openide.actions.NewAction; 40 import org.openide.actions.PasteAction; 41 import org.openide.actions.PropertiesAction; 42 import org.openide.nodes.Children; 43 import org.openide.nodes.Node; 44 import org.openide.nodes.Sheet; 45 import org.openide.util.NbBundle; 46 import org.openide.util.Utilities; 47 import org.openide.util.actions.SystemAction; 48 49 50 56 public class ImportNode extends WSDLElementContainerNode { 57 58 private static final String NAMESPACE_PROP = "namespace"; private Import mWSDLConstruct; 60 61 Image ICON = Utilities.loadImage 62 ("org/netbeans/modules/xml/wsdl/ui/view/resources/import-include-redefine.png"); 63 64 private ImportPropertyAdapter mPropertyAdapter; 65 66 private static final SystemAction[] ACTIONS = new SystemAction[]{ 67 SystemAction.get(CutAction.class), 68 SystemAction.get(CopyAction.class), 69 SystemAction.get(PasteAction.class), 70 null, 71 SystemAction.get(NewAction.class), 72 SystemAction.get(DeleteAction.class), 73 null, 74 SystemAction.get(CommonAddExtensibilityAttributeAction.class), 75 SystemAction.get(RemoveAttributesAction.class), 76 null, 77 SystemAction.get(GoToAction.class), 78 null, 79 SystemAction.get(PropertiesAction.class) 80 }; 81 82 public ImportNode(Children children, 83 Import wsdlConstruct) { 84 super(children, wsdlConstruct); 85 mWSDLConstruct = wsdlConstruct; 86 this.mPropertyAdapter = new ImportPropertyAdapter(); 87 } 88 89 90 @Override 91 public Image getIcon(int type) { 92 return ICON; 93 } 94 95 @Override 96 public Image getOpenedIcon(int type) { 97 return ICON; 98 } 99 100 @Override 101 public Action [] getActions(boolean context) { 102 return ACTIONS; 103 } 104 105 public Object getWSDLConstruct() { 106 return mWSDLConstruct; 107 } 108 109 @Override 110 protected void refreshAttributesSheetSet() { 111 Sheet.Set ss = createPropertiesSheetSet(); 112 113 try { 114 Node.Property namespaceProperty = new BaseAttributeProperty(mPropertyAdapter, 116 String .class, 117 NAMESPACE_PROP); 118 namespaceProperty.setName(NbBundle.getMessage(ImportNode.class, "PROP_NAMESPACE_DISPLAYNAME")); 119 namespaceProperty.setShortDescription(NbBundle.getMessage(ImportNode.class, "NAMESPACE_DESC")); 120 ss.put(namespaceProperty); 121 122 Node.Property locationProperty = new ImportLocationProperty(mPropertyAdapter, 124 String .class, 125 "getLocation", 126 "setLocation"); locationProperty.setName(NbBundle.getMessage(ImportNode.class, "PROP_LOCATION_DISPLAYNAME")); 128 locationProperty.setShortDescription(NbBundle.getMessage(ImportNode.class, "LOCATION_DESC")); 129 ss.put(locationProperty); 130 131 132 133 } catch(Exception ex) { 134 mLogger.log(Level.SEVERE, "failed to create property sheet for "+ mWSDLConstruct, ex); 135 } 136 } 137 138 @Override 139 protected void updateDisplayName() { 140 setDisplayName(mWSDLConstruct.getNamespace()); 141 } 142 143 public class ImportPropertyAdapter extends PropertyAdapter { 144 145 public ImportPropertyAdapter() { 146 super(getWSDLComponent()); 147 } 148 149 public void setLocation(String location) { 150 getWSDLComponent().getModel().startTransaction(); 151 ((Import) getWSDLComponent()).setLocation(location); 152 getWSDLComponent().getModel().endTransaction(); 153 } 154 155 public String getLocation() { 156 if(mWSDLConstruct.getLocation() == null) { 157 return ""; 158 } 159 160 return mWSDLConstruct.getLocation(); 161 } 162 163 public void setNamespace(String namespace) { 164 getWSDLComponent().getModel().startTransaction(); 165 ((Import) getWSDLComponent()).setNamespace(namespace); 166 getWSDLComponent().getModel().endTransaction(); 167 } 168 169 public String getNamespace() { 170 if(mWSDLConstruct.getNamespace() == null) { 171 return ""; 172 } 173 174 return mWSDLConstruct.getNamespace(); 175 } 176 177 } 178 179 private final class ImportLocationProperty 180 extends BaseAttributeProperty { 181 182 public ImportLocationProperty(PropertyAdapter instance, Class valueType, 183 String getter, String setter) throws NoSuchMethodException { 184 super(instance, valueType, getter, setter); 185 } 186 187 @Override 188 public PropertyEditor getPropertyEditor() { 189 return new ImportLocationPropertyEditor(mWSDLConstruct); 190 } 191 } 192 193 @Override 194 public String getTypeDisplayName() { 195 return NbBundle.getMessage(ImportNode.class, "LBL_UnrecognizedImport_TypeDisplayName"); 196 } 197 198 } 199 | Popular Tags |