comparison org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionObservableValue.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 - bug 198904
12 *******************************************************************************/
13 module org.eclipse.jface.internal.databinding.swt.ListSingleSelectionObservableValue;
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.List;
20
21 /**
22 * @since 1.0
23 *
24 */
25 public class ListSingleSelectionObservableValue :
26 SingleSelectionObservableValue {
27
28 private SelectionListener selectionListener;
29
30 /**
31 * @param combo
32 */
33 public this(List combo) {
34 super(combo);
35 }
36
37 private List getList() {
38 return cast(List) 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 getList().addSelectionListener(selectionListener);
54 }
55
56 protected int doGetSelectionIndex() {
57 return getList().getSelectionIndex();
58 }
59
60 protected void doSetSelectionIndex(int index) {
61 getList().setSelection(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 && !getList().isDisposed()) {
72 getList().removeSelectionListener(selectionListener);
73 }
74 }
75 }