1 19 20 package org.openide.src.nodes; 21 22 import java.io.IOException ; 23 import java.beans.*; 24 import java.lang.reflect.InvocationTargetException ; 25 26 import org.openide.src.*; 27 import org.openide.nodes.*; 28 29 34 public class InitializerElementNode extends ElementNode { 35 36 private static final String [] ICON_AFFECTING_PROPERTIES = new String [] { 37 PROP_STATIC 38 }; 39 40 44 public InitializerElementNode(InitializerElement element, boolean writeable) { 45 super(element, Children.LEAF, writeable); 46 setElementFormat0(sourceOptions.getInitializerElementFormat()); 47 superSetName("<initializer>"); } 49 50 51 public org.openide.util.HelpCtx getHelpCtx () { 52 return new org.openide.util.HelpCtx ("org.openide.src.nodes.InitializerNode"); } 54 55 58 protected String resolveIconBase() { 59 return ((InitializerElement)element).isStatic() ? INITIALIZER_ST : INITIALIZER; 60 } 61 62 66 protected String [] getIconAffectingProperties() { 67 return ICON_AFFECTING_PROPERTIES; 68 } 69 70 73 protected ElementFormat getHintElementFormat() { 74 return sourceOptions.getInitializerElementLongFormat(); 75 } 76 77 78 protected Sheet createSheet () { 79 Sheet sheet = Sheet.createDefault(); 80 Sheet.Set ps = sheet.get(Sheet.PROPERTIES); 81 ps.put(createStaticProperty(writeable)); 82 return sheet; 83 } 84 85 89 public boolean canRename() { 90 return false; 91 } 92 93 98 public void destroy() throws IOException { 99 SourceEditSupport.invokeAtomicAsUser(element, new SourceEditSupport.ExceptionalRunnable() { 100 public void run() throws SourceException { 101 InitializerElement el = (InitializerElement) element; 102 el.getDeclaringClass().removeInitializer(el); 103 } 104 }); 105 super.destroy(); 106 } 107 108 112 protected Node.Property createStaticProperty(boolean canW) { 113 return new ElementProp(ElementProperties.PROP_STATIC, Boolean.TYPE, canW) { 114 115 public Object getValue () { 116 return ((InitializerElement)element).isStatic() ? Boolean.TRUE : Boolean.FALSE; 117 } 118 119 120 public void setValue(final Object val) throws IllegalArgumentException , 121 IllegalAccessException , InvocationTargetException { 122 super.setValue(val); 123 124 if (!(val instanceof Boolean )) 125 throw new IllegalArgumentException (); 126 127 runAtomic(element, new SourceEditSupport.ExceptionalRunnable() { 128 public void run() throws SourceException { 129 ((InitializerElement)element).setStatic(((Boolean )val).booleanValue()); 130 } 131 }); 132 } 133 }; 134 } 135 } 136 | Popular Tags |