1 19 20 package org.openide.src.nodes; 21 22 import java.awt.Component ; 23 import java.beans.*; 24 import java.io.IOException ; 25 import java.lang.reflect.Modifier ; 26 import java.lang.reflect.InvocationTargetException ; 27 28 import org.openide.src.*; 29 import org.openide.nodes.*; 30 31 35 public class FieldElementNode extends MemberElementNode { 36 40 public FieldElementNode(FieldElement element, boolean writeable) { 41 super(element, Children.LEAF, writeable); 42 setElementFormat0(sourceOptions.getFieldElementFormat()); 43 } 44 45 public org.openide.util.HelpCtx getHelpCtx () { 46 return new org.openide.util.HelpCtx ("org.openide.src.nodes.FieldNode"); } 48 49 52 protected String resolveIconBase() { 53 int modif = ((FieldElement)element).getModifiers(); 54 if (!Modifier.isStatic(modif)) { 55 if (Modifier.isPrivate(modif)) 57 return FIELD_PRIVATE; 58 else if (Modifier.isProtected(modif)) 59 return FIELD_PROTECTED; 60 else if (Modifier.isPublic(modif)) 61 return FIELD_PUBLIC; 62 else 63 return FIELD_PACKAGE; 64 } 65 else { 66 if (Modifier.isPrivate(modif)) 68 return FIELD_ST_PRIVATE; 69 else if (Modifier.isProtected(modif)) 70 return FIELD_ST_PROTECTED; 71 else if (Modifier.isPublic(modif)) 72 return FIELD_ST_PUBLIC; 73 else 74 return FIELD_ST_PACKAGE; 75 } 76 } 77 78 81 protected ElementFormat getHintElementFormat() { 82 return sourceOptions.getFieldElementLongFormat(); 83 } 84 85 86 protected Sheet createSheet () { 87 Sheet sheet = Sheet.createDefault(); 88 Sheet.Set ps = sheet.get(Sheet.PROPERTIES); 89 ps.put(createModifiersProperty(writeable)); 90 ps.put(createNameProperty(writeable)); 91 ps.put(createTypeProperty(writeable)); 92 ps.put(createInitValueProperty(writeable)); 93 return sheet; 94 } 95 96 101 public void destroy() throws IOException { 102 SourceEditSupport.invokeAtomicAsUser(element, new SourceEditSupport.ExceptionalRunnable() { 103 public void run() throws SourceException { 104 FieldElement el = (FieldElement) element; 105 el.getDeclaringClass().removeField(el); 106 } 107 }); 108 super.destroy(); 109 } 110 111 public Component getCustomizer() { 112 return new FieldCustomizer((FieldElement)element); 113 } 114 115 public boolean hasCustomizer() { 116 return isWriteable(); 117 } 118 119 123 protected Node.Property createTypeProperty(boolean canW) { 124 Node.Property prop = new ElementProp(PROP_TYPE, Type.class, canW) { 125 126 public Object getValue () { 127 return ((FieldElement)element).getType(); 128 } 129 130 131 public void setValue(final Object val) throws IllegalArgumentException , 132 IllegalAccessException , InvocationTargetException { 133 super.setValue(val); 134 if (!(val instanceof Type)) 135 throw new IllegalArgumentException (); 136 137 runAtomic(element, new SourceEditSupport.ExceptionalRunnable() { 138 public void run() throws SourceException { 139 ((FieldElement)element).setType((Type)val); 140 } 141 }); 142 } 143 }; 144 prop.setValue("acceptVoidType", Boolean.FALSE); return prop; 146 } 147 148 152 protected Node.Property createInitValueProperty(boolean canW) { 153 return new ElementProp(PROP_INIT_VALUE, String .class, canW) { 154 155 public Object getValue () { 156 return ((FieldElement)element).getInitValue(); 157 } 158 159 160 public void setValue(final Object val) throws IllegalArgumentException , 161 IllegalAccessException , InvocationTargetException { 162 super.setValue(val); 163 if (!(val instanceof String )) 164 throw new IllegalArgumentException (); 165 166 runAtomic(element, new SourceEditSupport.ExceptionalRunnable() { 167 public void run() throws SourceException { 168 ((FieldElement)element).setInitValue((String )val); 169 } 170 }); 171 } 172 }; 173 } 174 } 175 | Popular Tags |