78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2005, 2008 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 module org.eclipse.jface.internal.databinding.swt.CComboSingleSelectionObservableValue;
|
85
|
14 import org.eclipse.jface.internal.databinding.swt.SingleSelectionObservableValue;
|
78
|
15
|
|
16 import java.lang.all;
|
|
17
|
|
18 import org.eclipse.core.databinding.observable.Realm;
|
|
19 import org.eclipse.swt.custom.CCombo;
|
|
20 import org.eclipse.swt.events.SelectionEvent;
|
|
21 import org.eclipse.swt.events.SelectionListener;
|
|
22
|
|
23 /**
|
|
24 * @since 1.0
|
|
25 *
|
|
26 */
|
|
27 public class CComboSingleSelectionObservableValue :
|
|
28 SingleSelectionObservableValue {
|
|
29
|
|
30 private SelectionListener selectionListener;
|
|
31
|
|
32 /**
|
|
33 * @param combo
|
|
34 */
|
|
35 public this(CCombo combo) {
|
|
36 super(combo);
|
|
37 }
|
|
38
|
|
39 /**
|
|
40 * @param realm
|
|
41 * @param combo
|
|
42 */
|
|
43 public this(Realm realm, CCombo combo) {
|
|
44 super(realm, combo);
|
|
45 }
|
|
46
|
|
47 private CCombo getCCombo() {
|
|
48 return cast(CCombo) getWidget();
|
|
49 }
|
|
50
|
|
51 protected void doAddSelectionListener(Runnable runnable) {
|
|
52 selectionListener = new class(runnable) SelectionListener {
|
|
53 Runnable runnable_;
|
|
54 this(Runnable r ){ runnable_=r; }
|
|
55 public void widgetDefaultSelected(SelectionEvent e) {
|
|
56 runnable_.run();
|
|
57 }
|
|
58
|
|
59 public void widgetSelected(SelectionEvent e) {
|
|
60 runnable_.run();
|
|
61 }
|
|
62 };
|
|
63 getCCombo().addSelectionListener(selectionListener);
|
|
64 }
|
|
65
|
|
66 protected int doGetSelectionIndex() {
|
|
67 return getCCombo().getSelectionIndex();
|
|
68 }
|
|
69
|
|
70 protected void doSetSelectionIndex(int index) {
|
|
71 getCCombo().setText(getCCombo().getItem(index));
|
|
72 }
|
|
73
|
|
74 /*
|
|
75 * (non-Javadoc)
|
|
76 *
|
|
77 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose()
|
|
78 */
|
|
79 public synchronized void dispose() {
|
|
80 super.dispose();
|
|
81 if (selectionListener !is null && !getCCombo().isDisposed()) {
|
|
82 getCCombo().removeSelectionListener(selectionListener);
|
|
83 }
|
|
84
|
|
85 }
|
|
86 }
|