1 13 package org.eclipse.jface.internal.databinding.internal.swt; 14 15 import org.eclipse.swt.custom.CCombo; 16 import org.eclipse.swt.events.SelectionEvent; 17 import org.eclipse.swt.events.SelectionListener; 18 19 23 public class CComboSingleSelectionObservableValue extends 24 SingleSelectionObservableValue { 25 26 private SelectionListener selectionListener; 27 28 31 public CComboSingleSelectionObservableValue(CCombo combo) { 32 super(combo); 33 } 34 35 private CCombo getCCombo() { 36 return (CCombo) getWidget(); 37 } 38 39 protected void doAddSelectionListener(final Runnable runnable) { 40 selectionListener = new SelectionListener() { 41 public void widgetDefaultSelected(SelectionEvent e) { 42 runnable.run(); 43 } 44 45 public void widgetSelected(SelectionEvent e) { 46 runnable.run(); 47 } 48 }; 49 getCCombo().addSelectionListener(selectionListener); 50 } 51 52 protected int doGetSelectionIndex() { 53 return getCCombo().getSelectionIndex(); 54 } 55 56 protected void doSetSelectionIndex(int index) { 57 getCCombo().setText(getCCombo().getItem(index)); 58 } 59 60 65 public synchronized void dispose() { 66 super.dispose(); 67 if (selectionListener != null && !getCCombo().isDisposed()) { 68 getCCombo().removeSelectionListener(selectionListener); 69 } 70 71 } 72 } 73 | Popular Tags |