1 19 20 26 27 package org.netbeans.modules.xml.schema.ui.nodes.schema.properties; 28 29 import java.lang.reflect.InvocationTargetException ; 30 import org.netbeans.modules.xml.schema.model.SchemaComponent; 31 import org.openide.ErrorManager; 32 import org.openide.util.NbBundle; 33 34 35 44 public class NonNegativeIntegerProperty extends BaseSchemaProperty { 45 46 59 public NonNegativeIntegerProperty(SchemaComponent component, String property, String dispName, 60 String desc) throws NoSuchMethodException { 61 this(component,Integer .class,property,dispName,desc); 62 } 63 64 protected NonNegativeIntegerProperty(SchemaComponent component, Class type, 65 String property, String dispName, String desc) 66 throws NoSuchMethodException { 67 super(component,type,property,dispName,desc,null); 68 } 69 70 protected int getLowerLimit() { 71 return 0; 72 } 73 74 protected int getDefaultValue() { 75 return 1; 76 } 77 78 82 @Override 83 public boolean isDefaultValue() { 84 try { 85 return super.getValue()==null; 86 } catch (IllegalArgumentException ex) { 87 } catch (InvocationTargetException ex) { 88 } catch (IllegalAccessException ex) { 89 } 90 return false; 91 } 92 93 96 @Override 97 public Object getValue() throws IllegalAccessException , InvocationTargetException { 98 Object o = super.getValue(); 99 return o==null?getDefaultValue():o; 100 } 101 102 106 @Override 107 public void setValue(Object o) throws 108 IllegalAccessException , InvocationTargetException { 109 if (o instanceof Integer ){ 110 int newVal = ((Integer )o).intValue(); 111 if(newVal<getLowerLimit()){ 112 String msg = NbBundle.getMessage(NonNegativeIntegerProperty.class, "MSG_Neg_Int_Value", o); IllegalArgumentException iae = new IllegalArgumentException (msg); 114 ErrorManager.getDefault().annotate(iae, ErrorManager.USER, 115 msg, msg, null, new java.util.Date ()); 116 throw iae; 117 } 118 } 119 super.setValue(o); 120 } 121 122 125 public static class Primitive extends NonNegativeIntegerProperty { 126 public Primitive(SchemaComponent component, String property, String dispName, 127 String desc) throws NoSuchMethodException { 128 super(component,int.class,property,dispName,desc); 129 } 130 131 134 @Override 135 public boolean supportsDefaultValue() { 136 return false; 137 } 138 139 } 140 141 144 public static class PrimitivePositive extends Primitive { 145 public PrimitivePositive(SchemaComponent component, String property, String dispName, 146 String desc) throws NoSuchMethodException { 147 super(component,property,dispName,desc); 148 } 149 @Override 150 protected int getLowerLimit() { 151 return 1; 152 } 153 } 154 155 } 156 | Popular Tags |