1 13 package org.eclipse.jface.internal.databinding.internal.swt; 14 15 import org.eclipse.swt.events.SelectionEvent; 16 import org.eclipse.swt.events.SelectionListener; 17 import org.eclipse.swt.widgets.Combo; 18 19 23 public class ComboSingleSelectionObservableValue extends 24 SingleSelectionObservableValue { 25 26 private SelectionListener selectionListener; 27 28 31 public ComboSingleSelectionObservableValue(Combo combo) { 32 super(combo); 33 } 34 35 private Combo getCombo() { 36 return (Combo) 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 getCombo().addSelectionListener(selectionListener); 50 } 51 52 protected int doGetSelectionIndex() { 53 return getCombo().getSelectionIndex(); 54 } 55 56 protected void doSetSelectionIndex(int index) { 57 getCombo().select(index); 58 } 59 60 65 public synchronized void dispose() { 66 super.dispose(); 67 if (selectionListener != null && !getCombo().isDisposed()) { 68 getCombo().removeSelectionListener(selectionListener); 69 } 70 } 71 } 72 | Popular Tags |