Mercurial > projects > dwt2
diff org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.d @ 78:0a55d2d5a946
Added file for databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 14 Apr 2009 11:35:29 +0200 |
parents | |
children | 6be48cf9f95c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.d Tue Apr 14 11:35:29 2009 +0200 @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2006 The Pampered Chef, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * The Pampered Chef, Inc. - initial API and implementation + ******************************************************************************/ + +module org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; + +import java.lang.all; + +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.value.AbstractObservableValue; +import org.eclipse.jface.databinding.swt.ISWTObservableValue; +import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.widgets.Widget; + +/** + * NON-API - An abstract superclass for observable values that gurantees that the + * observable will be disposed when the control to which it is attached is + * disposed. + * + * @since 1.1 + */ +public abstract class AbstractSWTObservableValue : AbstractObservableValue , ISWTObservableValue { + + private final Widget widget; + + /** + * Standard constructor for an SWT ObservableValue. Makes sure that + * the observable gets disposed when the SWT widget is disposed. + * + * @param widget + */ + protected this(Widget widget) { + this(SWTObservables.getRealm(widget.getDisplay()), widget); + } + + /** + * Constructor that allows for the setting of the realm. Makes sure that the + * observable gets disposed when the SWT widget is disposed. + * + * @param realm + * @param widget + * @since 1.2 + */ + protected this(Realm realm, Widget widget) { + super(realm); + this.widget = widget; + widget.addDisposeListener(disposeListener); + } + + private DisposeListener disposeListener = new class() DisposeListener { + public void widgetDisposed(DisposeEvent e) { + this.outer.dispose(); + } + }; + + /** + * @return Returns the widget. + */ + public Widget getWidget() { + return widget; + } +}