1 19 20 28 29 package org.netbeans.modules.xml.schema.abe.nodes.properties; 30 31 import java.beans.FeatureDescriptor ; 32 import java.beans.PropertyEditorSupport ; 33 import org.openide.ErrorManager; 34 import org.openide.explorer.propertysheet.ExPropertyEditor; 35 import org.openide.explorer.propertysheet.PropertyEnv; 36 import org.openide.util.NbBundle; 37 38 42 public class MaxOccursEditor extends PropertyEditorSupport 43 implements ExPropertyEditor 44 { 45 46 public MaxOccursEditor() { 47 } 48 49 @Override 50 public String [] getTags() { 51 return new String [] {NbBundle.getMessage(MaxOccursEditor.class,"LBL_Unbounded")}; 52 } 53 54 @Override 55 public void setAsText(String text) throws IllegalArgumentException { 56 if ( NbBundle.getMessage(MaxOccursEditor.class,"LBL_DefaultValueOne").equals(text) && 57 getValue() == null ) 58 return; 59 if (text.matches("[0-9]*")) { if (Integer.valueOf(text).intValue() < 0) { 62 throwError(text); 64 } 65 else { 66 setValue(text); 67 } 68 } 69 else { 70 if (text.equals("unbounded") || text.equals("*")){ setValue("unbounded"); 73 } 74 else { 75 throwError(text); 76 } 77 } 78 } 79 80 private void throwError(String text){ 81 String msg = NbBundle.getMessage(MaxOccursEditor.class, "LBL_Illegal_MaxOccurs_Value", text); IllegalArgumentException iae = new IllegalArgumentException (msg); 83 ErrorManager.getDefault().annotate(iae, ErrorManager.USER, 84 msg, msg, null, new java.util.Date ()); 85 throw iae; 86 87 } 88 89 @Override 90 public String getAsText() { 91 Object val = getValue(); 92 return val==null?NbBundle.getMessage(MaxOccursEditor.class,"LBL_DefaultValueOne"):val.toString(); 93 } 94 95 96 97 102 public void attachEnv(PropertyEnv env ) { 103 FeatureDescriptor desc = env.getFeatureDescriptor(); 104 desc.setValue("canEditAsText", Boolean.TRUE); } 107 } 108 | Popular Tags |