1 12 package org.eclipse.core.databinding.observable.value; 13 14 import org.eclipse.core.databinding.observable.Diffs; 15 import org.eclipse.core.databinding.observable.Realm; 16 17 27 public abstract class AbstractVetoableValue extends AbstractObservableValue 28 implements IVetoableValue { 29 30 33 public AbstractVetoableValue() { 34 this(Realm.getDefault()); 35 } 36 37 40 public AbstractVetoableValue(Realm realm) { 41 super(realm); 42 } 43 44 final protected void doSetValue(Object value) { 45 Object currentValue = doGetValue(); 46 ValueDiff diff = Diffs.createValueDiff(currentValue, value); 47 boolean okToProceed = fireValueChanging(diff); 48 if (!okToProceed) { 49 throw new ChangeVetoException("Change not permitted"); } 51 doSetApprovedValue(value); 52 fireValueChange(diff); 53 } 54 55 60 protected abstract void doSetApprovedValue(Object value); 61 62 public synchronized void addValueChangingListener( 63 IValueChangingListener listener) { 64 addListener(ValueChangingEvent.TYPE, listener); 65 } 66 67 public synchronized void removeValueChangingListener( 68 IValueChangingListener listener) { 69 removeListener(ValueChangingEvent.TYPE, listener); 70 } 71 72 79 protected boolean fireValueChanging(ValueDiff diff) { 80 checkRealm(); 81 82 ValueChangingEvent event = new ValueChangingEvent(this, diff); 83 fireEvent(event); 84 return !event.veto; 85 } 86 87 public synchronized void dispose() { 88 super.dispose(); 89 } 90 91 } 92 | Popular Tags |