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