Mercurial > projects > dwt2
diff org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/ShellObservableValue.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/swt/ShellObservableValue.d Tue Apr 14 11:35:29 2009 +0200 @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2007 Matthew Hall 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: + * Matthew Hall - initial API and implementation (bug 207844) + * IBM Corporation - initial API and implementation + * Brad Reynolds - initial API and implementation + * Matthew Hall - bug 212235 + *******************************************************************************/ +module org.eclipse.jface.internal.databinding.swt.ShellObservableValue; + +import java.lang.all; + +import org.eclipse.core.databinding.observable.Diffs; +import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; +import org.eclipse.swt.widgets.Shell; + +/** + * An {@link IObservableValue} that tracks the text of a Shell. + * + * @since 1.2 + */ +public class ShellObservableValue : AbstractSWTObservableValue { + + private final Shell shell; + + /** + * Constructs a ShellObservableValue which tracks the text of the given + * Shell. + * + * @param shell + * the shell to track + */ + public this(Shell shell) { + super(shell); + this.shell = shell; + } + + /** + * Constructs a ShellObservableValue belonging to the given realm, which + * tracks the text of the given shell. + * + * @param realm + * the realm of the constructed observable + * @param shell + * the shell to track + */ + public this(Realm realm, Shell shell) { + super(realm, shell); + this.shell = shell; + } + + protected void doSetValue(Object value) { + String oldValue = shell.getText(); + String newValue = value is null ? "" : value.toString(); //$NON-NLS-1$ + shell.setText(newValue); + + if (!newValue.opEquals(oldValue)) { + fireValueChange(Diffs.createValueDiff(oldValue, newValue)); + } + } + + protected Object doGetValue() { + return shell.getText(); + } + + public Object getValueType() { + return String.classinfo; + } +}