1 7 package org.jdesktop.swing.data; 8 9 import java.util.Locale ; 10 11 16 public class TestDataModelFactory { 17 18 public static String statusTypes[] = { 19 "new", "existing", "cancelled" 20 }; 21 public static String states[] = { 22 "Alabama", "Alaska", "Arizona", "Arkansas", 23 "California", "Colorado", "Connecticut", 24 "Delaware", "Florida", "Georgia", "Hawaii", 25 "Idaho", "Illinois", "Indiana", "Iowa", 26 "Kansas", "Kentucky", "Louisiana", 27 "Maine", "Mariland", "Massachusetts", "Michegan", 28 "Minnesota", "Mississippi", "Missouri", "Montana", 29 "Nebraska", "Nevada", "New Hampshire", "New Jersey", 30 "New Mexico", "New York", "North Carolina", "North Dakota", 31 "Ohio", "Oklahoma", "Oregan", "Pennsylvania", 32 "Rhode Island", "South Carolina", "South Dakota", 33 "Tennessee", "Texas", "Utah", "Vermont", "Virgina", 34 "Washington", "West Virginia", "Wisconsin", "Wyoming" }; 35 36 42 public static DataModel createDataModelWithValidator(boolean valid) { 43 DefaultDataModel model = new DefaultDataModel(); 44 model.addField(new MetaData("simpleton")); 45 model.addValidator(createValidator(valid)); 46 return model; 47 } 48 49 55 public static Validator createValidator(final boolean valid) { 56 57 Validator v = new Validator() { 58 59 public boolean validate(Object value, Locale locale, String [] error) { 60 return valid; 61 } 62 63 }; 64 return v; 65 } 66 67 public static DefaultDataModel createPersonModel() { 68 DefaultDataModel personModel = new DefaultDataModel(); 69 70 StringMetaData stringMetaData = new StringMetaData("firstname", "First Name"); 71 stringMetaData.setMinValueCount(1); stringMetaData.setDisplayWidth(14); 73 stringMetaData.setMinLength(1); 74 stringMetaData.setMaxLength(24); 75 personModel.addField(stringMetaData); 76 77 stringMetaData = new StringMetaData("middleinitial", "Middle Initial"); 78 stringMetaData.setDisplayWidth(2); 79 stringMetaData.setMinLength(1); 80 stringMetaData.setMaxLength(2); 81 personModel.addField(stringMetaData); 82 83 stringMetaData = new StringMetaData("lastname", "Last Name"); 84 stringMetaData.setMinValueCount(1); stringMetaData.setDisplayWidth(14); 86 stringMetaData.setMinLength(1); 87 stringMetaData.setMaxLength(24); 88 personModel.addField(stringMetaData); 89 90 NumberMetaData numberMetaData = new NumberMetaData("age", Integer .class, 91 "Age"); 92 numberMetaData.setMinimum(new Integer (0)); 93 numberMetaData.setMaximum(new Integer (110)); 94 personModel.addField(numberMetaData); 95 96 MetaData metaData = new MetaData("married", Boolean .class, "Married"); 97 personModel.addField(metaData); 98 99 numberMetaData = new NumberMetaData("customerid", Integer .class, "Customer ID"); 100 numberMetaData.setReadOnly(true); 101 personModel.addField(numberMetaData, new Integer (112)); 102 103 EnumeratedMetaData enumMetaData = new EnumeratedMetaData("status", String .class, "Status"); 104 enumMetaData.setEnumeration(statusTypes); 105 personModel.addField(enumMetaData, "new"); 106 107 stringMetaData = new StringMetaData("comments", "Comments"); 108 stringMetaData.setMaxLength(100); 109 stringMetaData.setMultiLine(true); 110 personModel.addField(stringMetaData); 111 112 return personModel; 113 114 } 115 116 public static DataModel createFilledPersonModel(boolean valid) { 117 DataModel model = createPersonModel(); 118 model.setValue("firstname", "Melissa"); 119 model.setValue("lastname", "Etheridge"); 120 if (valid) { 121 model.setValue("age", new Integer (46)); 122 } else { 123 model.setValue("age", new Integer (-2)); 124 } 125 model.setValue("married", Boolean.TRUE); 126 return model; 127 } 128 129 public static DefaultDataModel createAddressModel() { 130 DefaultDataModel addressModel = new DefaultDataModel(); 131 132 StringMetaData metaData = new StringMetaData("street", "Street"); 133 metaData.setMinValueCount(1); 134 metaData.setDisplayWidth(18); 135 metaData.setMaxLength(32); 136 addressModel.addField(metaData); 137 138 metaData = new StringMetaData("city", "City"); 139 metaData.setMinValueCount(1); 140 metaData.setDisplayWidth(16); 141 metaData.setMaxLength(24); 142 addressModel.addField(metaData); 143 144 EnumeratedMetaData enumMetaData = 145 new EnumeratedMetaData("state", String .class, "State"); 146 enumMetaData.setEnumeration(states); 147 enumMetaData.setMinValueCount(1); 148 addressModel.addField(enumMetaData); 149 150 metaData = 151 new StringMetaData("zipcode", "Zipcode"); 152 metaData.setMinLength(5); 153 metaData.setMaxLength(9); 154 metaData.setMinValueCount(1); 155 addressModel.addField(metaData); 156 157 return addressModel; 158 } 159 160 public static DefaultDataModel createNestedPersonModel() { 161 DefaultDataModel personModel = createPersonModel(); 162 MetaData metaData = new MetaData("address", DataModel.class, "Address"); 163 personModel.addField(metaData, createAddressModel()); 164 return personModel; 165 } 166 167 168 } 169 | Popular Tags |