1 19 20 package org.netbeans.modules.java.ui.nodes.elements; 21 22 import java.lang.reflect.InvocationTargetException ; 23 import java.lang.reflect.Modifier ; 24 import java.util.Map ; 25 import java.util.HashMap ; 26 27 import org.openide.nodes.*; 28 import org.openide.src.ElementProperties; 29 import org.netbeans.jmi.javamodel.Initializer; 30 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 31 32 import javax.jmi.reflect.JmiException; 33 34 41 public final class InitializerNode extends ElementNode { 42 43 private static final String [] ICON_AFFECTING_PROPERTIES = new String [] { 44 PROP_MODIFIERS 45 }; 46 47 private static final Map mapAttributeName; 48 49 static { 50 mapAttributeName = new HashMap (); 51 mapAttributeName.put(PROP_MODIFIERS, PROP_MODIFIERS); 52 } 53 54 58 public InitializerNode(Initializer element, boolean writeable) { 59 super(element, Children.LEAF, writeable); 60 setElementFormat0(getElementFormatProperty()); 61 superSetName("<initializer>"); } 63 64 protected String resolveIconBase() { 65 return IconResolver.getIconBaseForInitializer(getInitializer()); 66 } 67 68 protected String [] getIconAffectingProperties() { 69 return ICON_AFFECTING_PROPERTIES; 70 } 71 72 protected ElementFormat getElementFormatProperty() { 73 return getSourceOptions().getInitializerElementFormat(); 74 } 75 76 protected ElementFormat getHintElementFormat() { 77 return getSourceOptions().getInitializerElementLongFormat(); 78 } 79 80 protected Map getAttributeNameMap() { 81 return mapAttributeName; 82 } 83 84 protected Sheet createSheet () { 85 Sheet sheet = Sheet.createDefault(); 86 Sheet.Set ps = sheet.get(Sheet.PROPERTIES); 87 ps.put(createStaticProperty(writeable)); 88 return sheet; 89 } 90 91 95 public boolean canRename() { 96 return false; 97 } 98 99 103 protected Node.Property createStaticProperty(boolean canW) { 104 return new ElementNode.ElementProp(ElementProperties.PROP_STATIC, Boolean.TYPE, canW) { 105 106 public Object getValue () { 107 return Modifier.isStatic(getInitializer().getModifiers())? Boolean.TRUE : Boolean.FALSE; 108 } 109 110 111 public void setValue(final Object val) throws IllegalArgumentException , 112 IllegalAccessException , InvocationTargetException { 113 super.setValue(val); 114 115 if (!(val instanceof Boolean )) 116 throw new IllegalArgumentException (); 117 118 boolean fail = true; 119 try { 120 JavaMetamodel.getDefaultRepository().beginTrans(true); 121 try { 122 int m = getInitializer().getModifiers(); 123 124 boolean oldV = Modifier.isStatic(m); 125 boolean newV = ((Boolean ) val).booleanValue(); 126 if (oldV == newV) { 127 } else if (oldV) { 129 m -= Modifier.STATIC; 130 } else { 131 m += Modifier.STATIC; 132 } 133 134 getInitializer().setModifiers(m); 135 fail = false; 136 } finally { 137 JavaMetamodel.getDefaultRepository().endTrans(fail); 138 } 139 } catch (JmiException ex) { 140 IllegalArgumentException iaex = new IllegalArgumentException (); 141 iaex.initCause(ex); 142 throw iaex; 143 } 144 } 145 }; 146 } 147 148 private Initializer getInitializer() { 149 return (Initializer) this.element; 150 } 151 } 152 | Popular Tags |