comparison 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
comparison
equal deleted inserted replaced
76:f05e6e8b2f2d 78:0a55d2d5a946
1 /*******************************************************************************
2 * Copyright (c) 2007 Matthew Hall 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 * Matthew Hall - initial API and implementation (bug 207844)
10 * IBM Corporation - initial API and implementation
11 * Brad Reynolds - initial API and implementation
12 * Matthew Hall - bug 212235
13 *******************************************************************************/
14 module org.eclipse.jface.internal.databinding.swt.ShellObservableValue;
15
16 import java.lang.all;
17
18 import org.eclipse.core.databinding.observable.Diffs;
19 import org.eclipse.core.databinding.observable.Realm;
20 import org.eclipse.core.databinding.observable.value.IObservableValue;
21 import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue;
22 import org.eclipse.swt.widgets.Shell;
23
24 /**
25 * An {@link IObservableValue} that tracks the text of a Shell.
26 *
27 * @since 1.2
28 */
29 public class ShellObservableValue : AbstractSWTObservableValue {
30
31 private final Shell shell;
32
33 /**
34 * Constructs a ShellObservableValue which tracks the text of the given
35 * Shell.
36 *
37 * @param shell
38 * the shell to track
39 */
40 public this(Shell shell) {
41 super(shell);
42 this.shell = shell;
43 }
44
45 /**
46 * Constructs a ShellObservableValue belonging to the given realm, which
47 * tracks the text of the given shell.
48 *
49 * @param realm
50 * the realm of the constructed observable
51 * @param shell
52 * the shell to track
53 */
54 public this(Realm realm, Shell shell) {
55 super(realm, shell);
56 this.shell = shell;
57 }
58
59 protected void doSetValue(Object value) {
60 String oldValue = shell.getText();
61 String newValue = value is null ? "" : value.toString(); //$NON-NLS-1$
62 shell.setText(newValue);
63
64 if (!newValue.opEquals(oldValue)) {
65 fireValueChange(Diffs.createValueDiff(oldValue, newValue));
66 }
67 }
68
69 protected Object doGetValue() {
70 return shell.getText();
71 }
72
73 public Object getValueType() {
74 return String.classinfo;
75 }
76 }