1 12 13 package org.eclipse.core.databinding.observable.value; 14 15 import org.eclipse.core.databinding.observable.AbstractObservable; 16 import org.eclipse.core.databinding.observable.ObservableTracker; 17 import org.eclipse.core.databinding.observable.Realm; 18 19 29 abstract public class AbstractObservableValue extends AbstractObservable implements IObservableValue { 30 33 public AbstractObservableValue() { 34 this(Realm.getDefault()); 35 } 36 37 40 public AbstractObservableValue(Realm realm) { 41 super(realm); 42 } 43 44 public synchronized void addValueChangeListener(IValueChangeListener listener) { 45 addListener(ValueChangeEvent.TYPE, listener); 46 } 47 48 public synchronized void removeValueChangeListener(IValueChangeListener listener) { 49 removeListener(ValueChangeEvent.TYPE, listener); 50 } 51 52 final public void setValue(Object value) { 53 checkRealm(); 54 doSetValue(value); 55 } 56 57 63 protected void doSetValue(Object value) { 64 throw new UnsupportedOperationException (); 65 } 66 67 protected void fireValueChange(ValueDiff diff) { 68 super.fireChange(); 70 fireEvent(new ValueChangeEvent(this, diff)); 71 } 72 73 public final Object getValue() { 74 ObservableTracker.getterCalled(this); 75 return doGetValue(); 76 } 77 78 abstract protected Object doGetValue(); 79 80 public boolean isStale() { 81 return false; 82 } 83 84 protected void fireChange() { 85 throw new RuntimeException ( 86 "fireChange should not be called, use fireValueChange() instead"); } 88 89 public synchronized void dispose() { 90 super.dispose(); 91 } 92 } 93 | Popular Tags |