KickJava   Java API By Example, From Geeks To Geeks.

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


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.events.SelectionEvent;
16 import org.eclipse.swt.events.SelectionListener;
17 import org.eclipse.swt.widgets.Table;
18
19 /**
20  * @since 1.0
21  *
22  */

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

31     public TableSingleSelectionObservableValue(Table table) {
32         super(table);
33     }
34
35     private Table getTable() {
36         return (Table) 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         getTable().addSelectionListener(selectionListener);
50     }
51
52     protected int doGetSelectionIndex() {
53         return getTable().getSelectionIndex();
54     }
55
56     protected void doSetSelectionIndex(int index) {
57         getTable().setSelection(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 && !getTable().isDisposed()) {
68             getTable().removeSelectionListener(selectionListener);
69         }
70     }
71 }
72
Popular Tags