1 46 package groovy.model; 47 48 import java.beans.PropertyChangeListener ; 49 import java.beans.PropertyChangeSupport ; 50 51 58 public class ValueHolder implements ValueModel { 59 private Object value; 60 private Class type; 61 private PropertyChangeSupport propertyChangeSupport; 62 private boolean editable = true; 63 64 public ValueHolder() { 65 this(Object .class); 66 } 67 68 public ValueHolder(Class type) { 69 this.type = type; 70 } 71 72 public ValueHolder(Object value) { 73 this.value = value; 74 this.type = (value != null) ? value.getClass() : Object .class; 75 } 76 77 81 public void addPropertyChangeListener(PropertyChangeListener listener) { 82 if ( propertyChangeSupport == null ) { 83 propertyChangeSupport = new PropertyChangeSupport (this); 84 } 85 propertyChangeSupport.addPropertyChangeListener(listener); 86 } 87 88 92 public void removePropertyChangeListener(PropertyChangeListener listener) { 93 if ( propertyChangeSupport != null ) { 94 propertyChangeSupport.removePropertyChangeListener(listener); 95 } 96 } 97 98 99 public Object getValue() { 100 return value; 101 } 102 103 public void setValue(Object value) { 104 Object oldValue = this.value; 105 this.value = value; 106 if ( propertyChangeSupport != null ) { 107 propertyChangeSupport.firePropertyChange("value", oldValue, value); 108 } 109 } 110 111 public Class getType() { 112 return type; 113 } 114 115 public boolean isEditable() { 116 return editable; 117 } 118 119 public void setEditable(boolean editable) { 120 this.editable = editable; 121 } 122 123 } 124 | Popular Tags |