1 13 14 package org.eclipse.core.databinding.observable.value; 15 16 import org.eclipse.core.databinding.observable.Diffs; 17 import org.eclipse.core.databinding.observable.Realm; 18 19 29 public class WritableValue extends AbstractObservableValue { 30 31 private final Object valueType; 32 33 37 public WritableValue() { 38 this(null, null); 39 } 40 41 49 public WritableValue(Object initialValue, Object valueType) { 50 this(Realm.getDefault(), initialValue, valueType); 51 } 52 53 59 public WritableValue(Realm realm) { 60 this(realm, null, null); 61 } 62 63 72 public WritableValue(Realm realm, Object initialValue, Object valueType) { 73 super(realm); 74 this.valueType = valueType; 75 this.value = initialValue; 76 } 77 78 private Object value = null; 79 80 public Object doGetValue() { 81 return value; 82 } 83 84 88 public void doSetValue(Object value) { 89 boolean changed = false; 90 91 if (this.value == null && value != null) { 92 changed = true; 93 } else if (this.value != null && !this.value.equals(value)) { 94 changed = true; 95 } 96 97 if (changed) { 98 fireValueChange(Diffs.createValueDiff(this.value, this.value = value)); 99 } 100 } 101 102 public Object getValueType() { 103 return valueType; 104 } 105 106 110 public static WritableValue withValueType(Object elementType) { 111 return new WritableValue(Realm.getDefault(), null, elementType); 112 } 113 } 114 | Popular Tags |