KickJava   Java API By Example, From Geeks To Geeks.

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


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.AbstractVetoableValue;
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 vetoable 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 AbstractSWTVetoableValue extends AbstractVetoableValue implements ISWTObservableValue {
29
30     private final Widget widget;
31
32     /**
33      * Standard constructor for an SWT VetoableValue. Makes sure that
34      * the observable gets disposed when the SWT widget is disposed.
35      *
36      * @param widget
37      */

38     protected AbstractSWTVetoableValue(Widget widget) {
39         super(SWTObservables.getRealm(widget.getDisplay()));
40         this.widget = widget;
41         if (widget == null) {
42             throw new IllegalArgumentException JavaDoc("The widget parameter is null."); //$NON-NLS-1$
43
}
44         widget.addDisposeListener(disposeListener);
45     }
46     
47     private DisposeListener disposeListener = new DisposeListener() {
48         public void widgetDisposed(DisposeEvent e) {
49             AbstractSWTVetoableValue.this.dispose();
50         }
51     };
52
53     /**
54      * @return Returns the widget.
55      */

56     public Widget getWidget() {
57         return widget;
58     }
59 }
60
Popular Tags