Mercurial > projects > dwt2
comparison org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/WritableValue.d @ 95:6208d4f6a277
Added trees for databinding.beans and observable
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 21 Apr 2009 10:55:51 +0200 |
parents | |
children | b74ac5dfcc06 |
comparison
equal
deleted
inserted
replaced
94:1d37a7813832 | 95:6208d4f6a277 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2006, 2007 IBM Corporation 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 * IBM Corporation - initial API and implementation | |
10 * Brad Reynolds - bug 158687 | |
11 * Brad Reynolds - bug 164653, 147515 | |
12 *******************************************************************************/ | |
13 | |
14 package org.eclipse.core.databinding.observable.value; | |
15 | |
16 import org.eclipse.core.databinding.observable.Diffs; | |
17 import org.eclipse.core.databinding.observable.Realm; | |
18 | |
19 /** | |
20 * Mutable (writable) implementation of {@link IObservableValue} that will maintain a value and fire | |
21 * change events when the value changes. | |
22 * <p> | |
23 * This class is thread safe. All state accessing methods must be invoked from | |
24 * the {@link Realm#isCurrent() current realm}. Methods for adding and removing | |
25 * listeners may be invoked from any thread. | |
26 * </p> | |
27 * @since 1.0 | |
28 */ | |
29 public class WritableValue : AbstractObservableValue { | |
30 | |
31 private final Object valueType; | |
32 | |
33 /** | |
34 * Constructs a new instance with the default realm, a <code>null</code> | |
35 * value type, and a <code>null</code> value. | |
36 */ | |
37 public this() { | |
38 this(null, null); | |
39 } | |
40 | |
41 /** | |
42 * Constructs a new instance with the default realm. | |
43 * | |
44 * @param initialValue | |
45 * can be <code>null</code> | |
46 * @param valueType | |
47 * can be <code>null</code> | |
48 */ | |
49 public this(Object initialValue, Object valueType) { | |
50 this(Realm.getDefault(), initialValue, valueType); | |
51 } | |
52 | |
53 /** | |
54 * Constructs a new instance with the provided <code>realm</code>, a | |
55 * <code>null</code> value type, and a <code>null</code> initial value. | |
56 * | |
57 * @param realm | |
58 */ | |
59 public this(Realm realm) { | |
60 this(realm, null, null); | |
61 } | |
62 | |
63 /** | |
64 * Constructs a new instance. | |
65 * | |
66 * @param realm | |
67 * @param initialValue | |
68 * can be <code>null</code> | |
69 * @param valueType | |
70 * can be <code>null</code> | |
71 */ | |
72 public this(Realm realm, Object initialValue, Object valueType) { | |
73 super(realm); | |
74 this.valueType = valueType; | |
75 this.value = initialValue; | |
76 } | |
77 | |
78 private Object value = null; | |
79 | |
80 public Object doGetValue() { | |
81 return value; | |
82 } | |
83 | |
84 /** | |
85 * @param value | |
86 * The value to set. | |
87 */ | |
88 public void doSetValue(Object value) { | |
89 bool changed = false; | |
90 | |
91 if (this.value is null && value !is null) { | |
92 changed = true; | |
93 } else if (this.value !is null && !this.value.equals(value)) { | |
94 changed = true; | |
95 } | |
96 | |
97 if (changed) { | |
98 fireValueChange(Diffs.createValueDiff(this.value, this.value = value)); | |
99 } | |
100 } | |
101 | |
102 public Object getValueType() { | |
103 return valueType; | |
104 } | |
105 | |
106 /** | |
107 * @param elementType can be <code>null</code> | |
108 * @return new instance with the default realm and a value of <code>null</code> | |
109 */ | |
110 public static WritableValue withValueType(Object elementType) { | |
111 return new WritableValue(Realm.getDefault(), null, elementType); | |
112 } | |
113 } |