Mercurial > projects > dwt2
comparison org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionObservableValue.d @ 78:0a55d2d5a946
Added file for databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 14 Apr 2009 11:35:29 +0200 |
parents | |
children | 6be48cf9f95c |
comparison
equal
deleted
inserted
replaced
76:f05e6e8b2f2d | 78:0a55d2d5a946 |
---|---|
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 - bugs 198903, 198904 | |
12 *******************************************************************************/ | |
13 module org.eclipse.jface.internal.databinding.swt.ComboSingleSelectionObservableValue; | |
14 | |
15 import java.lang.all; | |
16 | |
17 import org.eclipse.swt.events.SelectionEvent; | |
18 import org.eclipse.swt.events.SelectionListener; | |
19 import org.eclipse.swt.widgets.Combo; | |
20 | |
21 /** | |
22 * @since 1.0 | |
23 * | |
24 */ | |
25 public class ComboSingleSelectionObservableValue : | |
26 SingleSelectionObservableValue { | |
27 | |
28 private SelectionListener selectionListener; | |
29 | |
30 /** | |
31 * @param combo | |
32 */ | |
33 public this(Combo combo) { | |
34 super(combo); | |
35 } | |
36 | |
37 private Combo getCombo() { | |
38 return cast(Combo) getWidget(); | |
39 } | |
40 | |
41 protected void doAddSelectionListener(Runnable runnable) { | |
42 selectionListener = new class(runnable) SelectionListener { | |
43 Runnable runnable_; | |
44 this(Runnable r ){ runnable_=r; } | |
45 public void widgetDefaultSelected(SelectionEvent e) { | |
46 runnable_.run(); | |
47 } | |
48 | |
49 public void widgetSelected(SelectionEvent e) { | |
50 runnable_.run(); | |
51 } | |
52 }; | |
53 getCombo().addSelectionListener(selectionListener); | |
54 } | |
55 | |
56 protected int doGetSelectionIndex() { | |
57 return getCombo().getSelectionIndex(); | |
58 } | |
59 | |
60 protected void doSetSelectionIndex(int index) { | |
61 getCombo().select(index); | |
62 } | |
63 | |
64 /* | |
65 * (non-Javadoc) | |
66 * | |
67 * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() | |
68 */ | |
69 public synchronized void dispose() { | |
70 super.dispose(); | |
71 if (selectionListener !is null && !getCombo().isDisposed()) { | |
72 getCombo().removeSelectionListener(selectionListener); | |
73 } | |
74 } | |
75 } |