KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > provisional > swt > AbstractSWTObservableValue


1 /*******************************************************************************
2  * Copyright (c) 2006 The Pampered Chef, Inc. 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  * The Pampered Chef, Inc. - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.jface.internal.databinding.provisional.swt;
13
14 import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
15 import org.eclipse.jface.databinding.swt.ISWTObservableValue;
16 import org.eclipse.jface.databinding.swt.SWTObservables;
17 import org.eclipse.swt.events.DisposeEvent;
18 import org.eclipse.swt.events.DisposeListener;
19 import org.eclipse.swt.widgets.Widget;
20
21 /**
22  * NON-API - An abstract superclass for observable values that gurantees that the
23  * observable will be disposed when the control to which it is attached is
24  * disposed.
25  *
26  * @since 1.1
27  */

28 public abstract class AbstractSWTObservableValue extends AbstractObservableValue implements ISWTObservableValue {
29
30     private final Widget widget;
31
32     /**
33      * Standard constructor for an SWT ObservableValue. Makes sure that
34      * the observable gets disposed when the SWT widget is disposed.
35      *
36      * @param widget
37      */

38     protected AbstractSWTObservableValue(Widget widget) {
39         super(SWTObservables.getRealm(widget.getDisplay()));
40         this.widget = widget;
41         widget.addDisposeListener(disposeListener);
42     }
43     
44     private DisposeListener disposeListener = new DisposeListener() {
45         public void widgetDisposed(DisposeEvent e) {
46             AbstractSWTObservableValue.this.dispose();
47         }
48     };
49
50     /**
51      * @return Returns the widget.
52      */

53     public Widget getWidget() {
54         return widget;
55     }
56 }
57
Popular Tags