1 19 20 package org.netbeans.modules.j2ee.sun.ws7.nodes; 21 22 23 import org.netbeans.modules.j2ee.sun.ws7.Constants; 24 import org.netbeans.modules.j2ee.sun.ws7.ui.Util; 25 import org.netbeans.modules.j2ee.sun.ws7.ide.editors.TaggedValue; 26 import org.netbeans.modules.j2ee.sun.ws7.ide.editors.TaggedEditor; 27 import java.awt.Component ; 28 import java.beans.PropertyDescriptor ; 29 import java.beans.PropertyEditor ; 30 import java.beans.PropertyEditorSupport ; 31 import java.lang.reflect.Method ; 32 import java.rmi.RemoteException ; 33 import java.text.MessageFormat ; 34 import java.util.HashMap ; 35 import java.util.List ; 36 import java.util.Map ; 37 import java.util.Set ; 38 39 import javax.swing.AbstractAction ; 40 41 42 import org.openide.nodes.Node; 43 import org.openide.nodes.PropertySupport; 44 import org.openide.nodes.Sheet; 45 import org.openide.util.HelpCtx; 46 import org.openide.util.NbBundle; 47 48 51 public abstract class WS70ManagedObjectBase implements Node.Cookie, Constants { 52 53 public abstract String getDisplayName(); 54 public abstract Attribute setAttribute(String attribute, Object value) throws Exception ; 55 public abstract Sheet updateSheet(Sheet sheet); 56 static Map primitivesMap = new HashMap (); 57 static { 58 primitivesMap.put("short", Short .class); primitivesMap.put("long", Long .class); primitivesMap.put("int", Integer .class); primitivesMap.put("boolean", Boolean .class); primitivesMap.put("float", Float .class); primitivesMap.put("double", Double .class); primitivesMap.put("byte", Byte .class); primitivesMap.put("char", String .class); }; 67 68 protected static Class getSupportedType(String type) { 69 try { 70 Class c = (Class ) primitivesMap.get(type); 71 72 if (c == null) { 73 c = Class.forName(type); 74 } 75 76 if (c == null) { 77 throw new ClassNotFoundException (type); 78 } 79 80 if (!String .class.isAssignableFrom(c) && 81 !Number .class.isAssignableFrom(c) && 82 !TaggedValue.class.isAssignableFrom(c)) { 83 return null; 84 } 85 86 return c; 87 } catch (ClassNotFoundException cnfe) { 88 return null; 89 } 90 } 91 private static String getLocString(String key) { 92 return NbBundle.getMessage(WS70ManagedObjectBase.class, key); 93 } 94 95 96 97 98 PropertySupport getStringArrayEditor(final Attribute a, 99 final AttributeInfo attr, 100 final String shortDescription, 101 final Class type, 102 boolean writable) { 103 PropertySupport strArrayEditor = null; 104 105 if (writable) { 106 strArrayEditor = createStringArrayWritableProperty(a, attr, 107 shortDescription, 108 type); 109 } 110 else { 111 strArrayEditor = createStringArrayReadOnlyProperty(a, attr, 112 shortDescription, 113 type); 114 } 116 strArrayEditor.setValue("helpID", "AS_RTT_StringArrayEditor"); 118 return strArrayEditor; 119 } 120 121 String getShortDescription(AttributeInfo attr) { 122 String shortDescription = attr.getDescription(); 123 124 if (shortDescription == null || 125 shortDescription.trim().equals("")) { 135 shortDescription = attr.getName(); 136 } 137 138 return shortDescription; 139 } 140 141 149 PropertySupport createReadOnlyProperty(final Attribute a, 150 final AttributeInfo attributeInfo, 151 final String shortDescription) { 152 return new PropertySupport.ReadOnly(attributeInfo.getName(), 153 String .class, 154 attributeInfo.getName(), 155 shortDescription) { 156 Attribute attribute = a; 157 158 public Object getValue() { 159 Object value = null; 160 161 try { 162 value = attribute.getValue(); 163 164 if (value != null && !(value instanceof String )) { 165 value = value.toString(); 166 } 167 } catch (Exception e) {} 168 169 return (value == null) ? "" : value; } 171 }; 172 } 173 174 PropertySupport createWritableProperty(final Attribute a, 175 final AttributeInfo attr, 176 final String shortDescription, 177 final Class type) { 178 return new PropertySupport.ReadWrite(attr.getName(), 179 type, 180 attr.getName(), 181 shortDescription) { 182 Attribute attribute = a; 183 184 public Object getValue() { 185 return attribute.getValue(); 186 } 187 188 public void setValue(Object value) { 189 try { 190 String attributeName = getName(); 191 attribute = setAttribute(getName(), 192 value); 193 } catch (Exception e) { 194 Util.showError(e.getLocalizedMessage()); 195 } 196 } 197 }; 198 } 199 200 PropertySupport createStringArrayWritableProperty(final Attribute a, 201 final AttributeInfo attr, 202 final String shortDescription, 203 final Class type) { 204 return new PropertySupport.ReadWrite(attr.getName(), 205 type, 206 attr.getName(), 207 shortDescription) { 208 Attribute attribute = a; 209 210 public Object getValue() { 211 return attribute.getValue(); 212 } 213 214 public void setValue(Object value) { 215 try { 216 attribute = setAttribute(getName(), 217 value); 218 } catch (Exception e) { 219 Util.showError(e.getLocalizedMessage()); 220 } 221 } 222 }; 223 } 224 225 PropertySupport createStringArrayReadOnlyProperty(final Attribute a, 226 final AttributeInfo attr, 227 final String shortDescription, 228 final Class type) { 229 return new PropertySupport.ReadOnly(attr.getName(), 230 type, 231 attr.getName(), 232 shortDescription) { 233 Attribute attribute = a; 234 235 public Object getValue() { 236 return attribute.getValue(); 237 } 238 }; 239 } 240 241 242 PropertySupport createTaggedProperty(final Attribute a, 243 final AttributeInfo attr, 244 final String shortDescription, 245 final Class type) { 246 return new PropertySupport.ReadWrite(attr.getName(), 247 type, 248 attr.getName(), 249 shortDescription) { 250 Attribute attribute = a; 251 252 public Object getValue() { 253 return attribute.getValue(); 254 } 255 256 public void setValue(Object value) { 257 try { 258 attribute = setAttribute(getName(), value); 259 } catch (Exception e) { 260 Util.showError(e.getLocalizedMessage()); 261 } 262 } 263 264 public PropertyEditor getPropertyEditor() { 265 return new TaggedEditor(attribute.getValue().getClass()); 266 } 267 }; 268 } 269 public static class Boolean extends TaggedValue { 270 private boolean value; 271 272 private Boolean(boolean value) { 273 this.value = value; 274 } 275 276 private static final Boolean TRUE = 277 new Boolean (true); 278 private static final Boolean FALSE = 279 new Boolean (false); 280 private static final Boolean [] values = 281 new Boolean []{ TRUE, FALSE }; 282 283 public static TaggedValue getValue(String s) { 284 if ("true".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s)) { return TRUE; 286 } 289 return FALSE; 290 } 291 public static TaggedValue getValue(java.lang.Boolean b) { 292 if (b.toString().equals("true")|| b.toString().equals("on")) { return TRUE; 294 } 295 296 return FALSE; 297 } 298 public static TaggedValue[] getChoices() { 299 return values; 300 } 301 302 public boolean booleanValue() { 303 return value; 304 } 305 306 public String toString() { 307 if (value) { 308 return "true"; } 311 return "false"; } 313 } 314 } 315 | Popular Tags |