1 19 20 package org.netbeans.modules.xml.schema.abe.nodes.properties; 21 22 import java.lang.reflect.InvocationTargetException ; 23 import java.lang.reflect.Method ; 24 import org.netbeans.modules.xml.axi.AXIComponent; 25 import org.netbeans.modules.xml.schema.abe.nodes.ABEAbstractNode; 26 import org.netbeans.modules.xml.schema.model.SchemaModel; 27 import org.netbeans.modules.xml.xam.ui.XAMUtils; 28 import org.openide.nodes.PropertySupport; 29 30 58 public class BaseABENodeProperty extends PropertySupport.Reflection { 59 60 77 public BaseABENodeProperty(Object component, 78 Class valueType, 79 String property, 80 String propDispName, 81 String propDesc, 82 Class propEditorClass) 83 throws NoSuchMethodException { 84 super(component,valueType,property); 85 super.setName(property); 86 super.setDisplayName(propDispName); 87 super.setShortDescription(propDesc); 88 if(propEditorClass!=null) 89 super.setPropertyEditorClass(propEditorClass); 90 } 91 92 109 public BaseABENodeProperty(Object component, 110 Class valueType, 111 String property, 112 String propDispName, 113 String propDesc) 114 throws NoSuchMethodException { 115 this(component, valueType, property, propDispName, propDesc, null); 116 } 117 118 136 public BaseABENodeProperty(Object component, 137 Class valueType, 138 Method getter, 139 Method setter, 140 String property, 141 String propDispName, 142 String propDesc, 143 Class propEditorClass) { 144 super(component,valueType,getter,setter); 145 super.setName(property); 146 super.setDisplayName(propDispName); 147 super.setShortDescription(propDesc); 148 if(propEditorClass!=null) 149 super.setPropertyEditorClass(propEditorClass); 150 } 151 152 156 @Override 157 public boolean canWrite() { 158 AXIComponent c = getComponent(); 160 if(c == null || (c.getModel() == null)) 161 return false; 162 163 AXIComponent o = c.getOriginal(); 164 if(c != o && c.isReadOnly()) { 165 return false; 166 } 167 168 SchemaModel model = c.getModel().getSchemaModel(); 169 return XAMUtils.isWritable(model); 170 } 171 172 179 @Override 180 public boolean isDefaultValue () { 181 try { 182 return getValue()==null; 183 } catch (IllegalArgumentException ex) { 184 } catch (InvocationTargetException ex) { 185 } catch (IllegalAccessException ex) { 186 } 187 return false; 188 } 189 190 195 @Override 196 public boolean supportsDefaultValue () { 197 return true; 198 } 199 200 205 @Override 206 public void restoreDefaultValue () throws IllegalAccessException , InvocationTargetException { 207 setValue(null); 208 } 209 210 protected AXIComponent getComponent() { 211 if(instance instanceof ABEAbstractNode){ 212 return ((ABEAbstractNode)instance).getAXIComponent(); 214 } 215 return (AXIComponent) instance; 216 } 217 218 protected void setComponent(AXIComponent sc) { 219 instance = sc; 220 } 221 222 226 public static String firstLetterToUpperCase(String s, String pref) { 227 switch (s.length()) { 228 case 0: 229 return pref; 230 231 case 1: 232 return pref + Character.toUpperCase(s.charAt(0)); 233 234 default: 235 return pref + Character.toUpperCase(s.charAt(0)) + s.substring(1); 236 } 237 } 238 239 } | Popular Tags |