78
|
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 module org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTVetoableValue;
|
|
13
|
|
14 import java.lang.all;
|
|
15
|
|
16 import org.eclipse.core.databinding.observable.Realm;
|
|
17 import org.eclipse.core.databinding.observable.value.AbstractVetoableValue;
|
|
18 import org.eclipse.jface.databinding.swt.ISWTObservableValue;
|
|
19 import org.eclipse.jface.databinding.swt.SWTObservables;
|
|
20 import org.eclipse.swt.events.DisposeEvent;
|
|
21 import org.eclipse.swt.events.DisposeListener;
|
|
22 import org.eclipse.swt.widgets.Widget;
|
|
23
|
|
24 /**
|
|
25 * NON-API - An abstract superclass for vetoable values that gurantees that the
|
|
26 * observable will be disposed when the control to which it is attached is
|
|
27 * disposed.
|
|
28 *
|
|
29 * @since 1.1
|
|
30 */
|
|
31 public abstract class AbstractSWTVetoableValue : AbstractVetoableValue , ISWTObservableValue {
|
|
32
|
|
33 private final Widget widget;
|
|
34
|
|
35 /**
|
|
36 * Standard constructor for an SWT VetoableValue. Makes sure that
|
|
37 * the observable gets disposed when the SWT widget is disposed.
|
|
38 *
|
|
39 * @param widget
|
|
40 */
|
|
41 protected this(Widget widget) {
|
|
42 this(SWTObservables.getRealm(widget.getDisplay()), widget);
|
|
43 }
|
|
44
|
|
45 /**
|
|
46 * Constructs a new instance for the provided <code>realm</code> and <code>widget</code>.
|
|
47 *
|
|
48 * @param realm
|
|
49 * @param widget
|
|
50 * @since 1.2
|
|
51 */
|
|
52 protected this(Realm realm, Widget widget) {
|
|
53 super(realm);
|
|
54 this.widget = widget;
|
|
55 if (widget is null) {
|
|
56 throw new IllegalArgumentException("The widget parameter is null."); //$NON-NLS-1$
|
|
57 }
|
|
58 widget.addDisposeListener(disposeListener);
|
|
59 }
|
|
60
|
|
61 private DisposeListener disposeListener = new class() DisposeListener {
|
|
62 public void widgetDisposed(DisposeEvent e) {
|
|
63 this.outer.dispose();
|
|
64 }
|
|
65 };
|
|
66
|
|
67 /**
|
|
68 * @return Returns the widget.
|
|
69 */
|
|
70 public Widget getWidget() {
|
|
71 return widget;
|
|
72 }
|
|
73 }
|