1 12 package org.eclipse.jface.internal.databinding.internal.swt; 13 14 import org.eclipse.core.databinding.observable.Diffs; 15 import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; 16 import org.eclipse.swt.widgets.Control; 17 18 22 abstract public class SingleSelectionObservableValue extends 23 AbstractSWTObservableValue { 24 25 private boolean updating = false; 26 27 private int currentSelection; 28 29 33 public SingleSelectionObservableValue(Control control) { 34 super(control); 35 36 currentSelection = doGetSelectionIndex(); 37 doAddSelectionListener(new Runnable (){ 38 public void run() { 39 if (!updating) { 40 int newSelection = doGetSelectionIndex(); 41 fireValueChange(Diffs.createValueDiff(new Integer ( 42 currentSelection), new Integer (newSelection))); 43 currentSelection = newSelection; 44 } 45 } 46 }); 47 } 48 49 52 protected abstract void doAddSelectionListener(Runnable runnable); 53 54 public void doSetValue(Object value) { 55 try { 56 updating = true; 57 int intValue = ((Integer ) value).intValue(); 58 doSetSelectionIndex(intValue); 59 currentSelection = intValue; 60 } finally { 61 updating = false; 62 } 63 } 64 65 69 protected abstract void doSetSelectionIndex(int intValue); 70 71 public Object doGetValue() { 72 return new Integer (doGetSelectionIndex()); 73 } 74 75 78 protected abstract int doGetSelectionIndex(); 79 80 public Object getValueType() { 81 return Integer.TYPE; 82 } 83 84 } 85 | Popular Tags |