blob: 438f111b664ffe6ff7eb5836c02050fe94929fbf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*****************************************************************************
* Copyright (c) 2015, 2016 Christian W. Damus 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:
* Christian W. Damus - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.tools.databinding;
import java.util.Objects;
import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.Diffs;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.WritableValue;
/**
* An analogue of the {@link WritableValue} that supports "touches" to send
* change events even though the value is not replaced.
*/
public class TouchableValue<T> extends ReferenceCountedObservable.Value<T> {
private final Class<? extends T> type;
private T value;
public TouchableValue(Realm realm, Class<? extends T> type) {
super(realm);
this.type = type;
}
public TouchableValue(Realm realm, Class<? extends T> type, T initialValue) {
super(realm);
this.type = type;
this.value = initialValue;
}
@Override
public Object getValueType() {
return type;
}
@Override
protected T doGetValue() {
return value;
}
@Override
protected void doSetValue(T value) {
if (!Objects.equals(this.value, value)) {
T oldValue = this.value;
this.value = value;
fireValueChange(Diffs.createValueDiff(oldValue, value));
}
}
/**
* Indicates that some kind of change has happened to the observable's value
* that observers should know about, but for which specific change details
* are not available.
*/
public void touch() {
checkRealm();
fireEvent(new ChangeEvent(this));
}
}
|