1 7 package org.jdesktop.dataset; 8 import java.beans.PropertyChangeListener ; 9 import java.beans.PropertyChangeSupport ; 10 import java.util.logging.Logger ; 11 import org.jdesktop.dataset.NameGenerator; 12 13 17 public class DataColumn { 18 21 private static final Logger LOG = Logger.getLogger(DataColumn.class.getName()); 22 23 protected static final String DEFAULT_NAME_PREFIX = "DataColumn"; 25 29 private static final NameGenerator NAMEGEN = new NameGenerator(DEFAULT_NAME_PREFIX); 30 31 private PropertyChangeSupport pcs = new PropertyChangeSupport (this); 34 35 39 private DataTable table; 40 45 private String name = NAMEGEN.generateName(this); 46 50 private Class type = Object .class; 51 55 private boolean readOnly = false; 56 63 private boolean required = false; 64 65 69 private Object defaultValue; 70 71 76 private boolean keyColumn; 77 78 85 protected DataColumn(DataTable table) { 86 assert table != null; 87 this.table = table; 88 } 89 90 93 public DataTable getTable() { 94 return table; 95 } 96 97 100 public String getName() { 101 return name; 102 } 103 104 108 public void setName(String name) { 109 if (this.name != name) { 110 assert DataSetUtils.isValidName(name); 111 assert !table.columns.containsKey(name) && !table.selectors.containsKey(name); 112 String oldName = this.name; 113 this.name = name; 114 pcs.firePropertyChange("name", oldName, name); 115 } 116 } 117 118 121 public Class getType() { 122 return type; 123 } 124 125 129 public void setType(Class type) { 130 if (this.type != type) { 131 Class oldType = this.type; 132 this.type = type == null ? Object .class : type; 133 pcs.firePropertyChange("type", oldType, type); 134 } 135 } 136 137 140 public boolean isReadOnly() { 141 return readOnly; 142 } 143 144 148 public void setReadOnly(boolean readOnly) { 149 if (this.readOnly != readOnly) { 150 boolean oldValue = this.readOnly; 151 this.readOnly = readOnly; 152 pcs.firePropertyChange("readOnly", oldValue, readOnly); 153 } 154 } 155 156 164 public boolean isRequired() { 165 return required || keyColumn; 166 } 167 168 173 public void setRequired(boolean required) { 174 if (this.required != required) { 175 boolean oldValue = this.required; 176 this.required = required; 177 pcs.firePropertyChange("required", oldValue, required); 178 } 179 } 180 181 185 public Object getDefaultValue() { 186 return defaultValue; 187 } 188 189 193 public void setDefaultValue(Object defaultValue) { 194 if (this.defaultValue != defaultValue) { 195 Object oldVal = this.defaultValue; 196 this.defaultValue = defaultValue; 197 pcs.firePropertyChange("defaultValue", oldVal, defaultValue); 198 } 199 } 200 201 204 public boolean isKeyColumn() { 205 return keyColumn; 206 } 207 208 216 public void setKeyColumn(boolean value) { 217 if (value != keyColumn) { 218 boolean oldVal = keyColumn; 219 keyColumn = value; 220 pcs.firePropertyChange("keyColumn", oldVal, value); 221 } 222 } 223 224 public void addPropertyChangeListener(PropertyChangeListener listener) { 225 pcs.addPropertyChangeListener(listener); 226 } 227 228 public void addPropertyChangeListener(String property, PropertyChangeListener listener) { 229 pcs.addPropertyChangeListener(property, listener); 230 } 231 232 public void removePropertyChangeListener(PropertyChangeListener listener) { 233 pcs.removePropertyChangeListener(listener); 234 } 235 236 public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { 237 pcs.removePropertyChangeListener(propertyName, listener); 238 } 239 } | Popular Tags |