KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > internal > swt > CComboSingleSelectionObservableValue


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Brad Reynolds - bug 164653
11  * Ashley Cambrell - bug 198904
12  *******************************************************************************/

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 /**
20  * @since 1.0
21  *
22  */

23 public class CComboSingleSelectionObservableValue extends
24         SingleSelectionObservableValue {
25
26     private SelectionListener selectionListener;
27
28     /**
29      * @param combo
30      */

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 JavaDoc 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     /*
61      * (non-Javadoc)
62      *
63      * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
64      */

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