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;
|
85
|
23 import org.eclipse.core.databinding.observable.value.IValueChangeListener;
|
78
|
24
|
|
25 /**
|
|
26 * NON-API - An abstract superclass for vetoable values that gurantees that the
|
|
27 * observable will be disposed when the control to which it is attached is
|
|
28 * disposed.
|
|
29 *
|
|
30 * @since 1.1
|
|
31 */
|
|
32 public abstract class AbstractSWTVetoableValue : AbstractVetoableValue , ISWTObservableValue {
|
85
|
33 public override Object getValue(){
|
|
34 return super.getValue();
|
|
35 }
|
|
36 public override void setValue( Object v ){
|
|
37 super.setValue(v);
|
|
38 }
|
|
39 public void addValueChangeListener(IValueChangeListener listener) {
|
|
40 super.addValueChangeListener(listener);
|
|
41 }
|
|
42 public void removeValueChangeListener(IValueChangeListener listener) {
|
|
43 super.removeValueChangeListener(listener);
|
|
44 }
|
78
|
45
|
|
46 private final Widget widget;
|
|
47
|
|
48 /**
|
|
49 * Standard constructor for an SWT VetoableValue. Makes sure that
|
|
50 * the observable gets disposed when the SWT widget is disposed.
|
|
51 *
|
|
52 * @param widget
|
|
53 */
|
|
54 protected this(Widget widget) {
|
|
55 this(SWTObservables.getRealm(widget.getDisplay()), widget);
|
|
56 }
|
|
57
|
|
58 /**
|
|
59 * Constructs a new instance for the provided <code>realm</code> and <code>widget</code>.
|
|
60 *
|
|
61 * @param realm
|
|
62 * @param widget
|
|
63 * @since 1.2
|
|
64 */
|
|
65 protected this(Realm realm, Widget widget) {
|
85
|
66 disposeListener = new _DisposeListener();
|
78
|
67 super(realm);
|
|
68 this.widget = widget;
|
|
69 if (widget is null) {
|
|
70 throw new IllegalArgumentException("The widget parameter is null."); //$NON-NLS-1$
|
|
71 }
|
|
72 widget.addDisposeListener(disposeListener);
|
|
73 }
|
|
74
|
85
|
75 private DisposeListener disposeListener;
|
|
76 class _DisposeListener : DisposeListener {
|
78
|
77 public void widgetDisposed(DisposeEvent e) {
|
|
78 this.outer.dispose();
|
|
79 }
|
|
80 };
|
|
81
|
|
82 /**
|
|
83 * @return Returns the widget.
|
|
84 */
|
|
85 public Widget getWidget() {
|
|
86 return widget;
|
|
87 }
|
|
88 }
|