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 ConstructorElementNode extends MemberElementNode { 36 40 public ConstructorElementNode(ConstructorElement element, boolean writeable) { 41 super(element, Children.LEAF, writeable); 42 setElementFormat0(sourceOptions.getConstructorElementFormat()); 43 } 44 45 public org.openide.util.HelpCtx getHelpCtx () { 46 return new org.openide.util.HelpCtx ("org.openide.src.ConstructorNode"); } 48 49 52 protected String resolveIconBase() { 53 int modif = ((ConstructorElement)element).getModifiers(); 54 if (Modifier.isPrivate(modif)) 55 return CONSTRUCTOR_PRIVATE; 56 else if (Modifier.isProtected(modif)) 57 return CONSTRUCTOR_PROTECTED; 58 else if (Modifier.isPublic(modif)) 59 return CONSTRUCTOR_PUBLIC; 60 else 61 return CONSTRUCTOR_PACKAGE; 62 } 63 64 67 protected ElementFormat getHintElementFormat() { 68 return sourceOptions.getConstructorElementLongFormat(); 69 } 70 71 72 protected Sheet createSheet () { 73 Sheet sheet = Sheet.createDefault(); 74 Sheet.Set ps = sheet.get(Sheet.PROPERTIES); 75 ps.put(createModifiersProperty(writeable)); 76 ps.put(createNameProperty(false)); 77 ps.put(createParametersProperty(writeable)); 78 ps.put(createExceptionsProperty(writeable)); 79 return sheet; 80 } 81 82 87 public void destroy() throws IOException { 88 if (!(element instanceof MethodElement)) { 89 SourceEditSupport.invokeAtomicAsUser(element, new SourceEditSupport.ExceptionalRunnable() { 90 public void run() throws SourceException { 91 ConstructorElement el = (ConstructorElement) element; 92 el.getDeclaringClass().removeConstructor(el); 93 } 94 }); 95 } 96 super.destroy(); 97 } 98 99 103 public boolean canRename() { 104 return false; 105 } 106 107 public Component getCustomizer() { 108 return new MethodCustomizer((ConstructorElement)element); 109 } 110 111 public boolean hasCustomizer() { 112 return isWriteable(); 113 } 114 115 119 protected Node.Property createParametersProperty(boolean canW) { 120 Node.Property p = new ElementProp(PROP_PARAMETERS, MethodParameter[].class, canW) { 121 122 public Object getValue () { 123 return ((ConstructorElement)element).getParameters(); 124 } 125 126 127 public void setValue(final Object val) throws IllegalArgumentException , 128 IllegalAccessException , InvocationTargetException { 129 super.setValue(val); 130 if (!(val instanceof MethodParameter[])) 131 throw new IllegalArgumentException (); 132 133 runAtomic(element, new SourceEditSupport.ExceptionalRunnable() { 134 public void run() throws SourceException { 135 ((ConstructorElement)element).setParameters((MethodParameter[])val); 136 } 137 }); 138 } 139 }; 140 p.setValue("changeImmediate" ,Boolean.FALSE); return p; 142 } 143 144 148 protected Node.Property createExceptionsProperty(boolean canW) { 149 Node.Property p = new ElementProp(PROP_EXCEPTIONS, Identifier[].class, canW) { 150 151 public Object getValue () { 152 return ((ConstructorElement)element).getExceptions(); 153 } 154 155 156 public void setValue(final Object val) throws IllegalArgumentException , 157 IllegalAccessException , InvocationTargetException { 158 super.setValue(val); 159 if (!(val instanceof Identifier[])) 160 throw new IllegalArgumentException (); 161 162 runAtomic(element, new SourceEditSupport.ExceptionalRunnable() { 163 public void run() throws SourceException { 164 ((ConstructorElement)element).setExceptions((Identifier[])val); 165 } 166 }); 167 } 168 }; 169 p.setValue("changeImmediate" ,Boolean.FALSE); return p; 171 } 172 } 173 | Popular Tags |