Skip to main content
summaryrefslogtreecommitdiffstats
blob: b4e7369219fcedd80dd3c39ed49c0e43bba8a606 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*******************************************************************************
 * Copyright (c) 2005, 2007-2008 Matt Carter 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:
 *     Matt Carter - initial API and implementation (bug 212518)
 *     Matthew Hall - bug 212518, 146397, 249526
 *******************************************************************************/
package org.eclipse.core.internal.databinding.observable;

import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.IDisposeListener;
import org.eclipse.core.databinding.observable.IStaleListener;
import org.eclipse.core.databinding.observable.ObservableTracker;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.runtime.Assert;

/**
 * An immutable {@link IObservableValue}.
 * 
 * @see WritableValue
 */
public class ConstantObservableValue implements IObservableValue {
	final Realm realm;
	final Object value;
	final Object type;

	/**
	 * Construct a constant value of the given type, in the default realm.
	 * 
	 * @param value
	 *            immutable value
	 * @param type
	 *            type
	 */
	public ConstantObservableValue(Object value, Object type) {
		this(Realm.getDefault(), value, type);
	}

	/**
	 * Construct a constant value of the given type, in the given realm.
	 * 
	 * @param realm
	 *            Realm
	 * @param value
	 *            immutable value
	 * @param type
	 *            type
	 */
	public ConstantObservableValue(Realm realm, Object value, Object type) {
		Assert.isNotNull(realm, "Realm cannot be null"); //$NON-NLS-1$
		this.realm = realm;
		this.value = value;
		this.type = type;
		ObservableTracker.observableCreated(this);
	}

	public Object getValueType() {
		return type;
	}

	public Object getValue() {
		ObservableTracker.getterCalled(this);
		return value;
	}

	public void setValue(Object value) {
		throw new UnsupportedOperationException();
	}

	public void addValueChangeListener(IValueChangeListener listener) {
		// ignore
	}

	public void removeValueChangeListener(IValueChangeListener listener) {
		// ignore
	}

	public void addChangeListener(IChangeListener listener) {
		// ignore
	}

	public void addDisposeListener(IDisposeListener listener) {
		// ignore
	}

	public void addStaleListener(IStaleListener listener) {
		// ignore
	}

	public boolean isDisposed() {
		return false;
	}

	public void dispose() {
		// nothing to dispose
	}

	public Realm getRealm() {
		return realm;
	}

	public boolean isStale() {
		return false;
	}

	public void removeChangeListener(IChangeListener listener) {
		// ignore
	}

	public void removeDisposeListener(IDisposeListener listener) {
		// ignore
	}

	public void removeStaleListener(IStaleListener listener) {
		// ignore
	}
}

Back to the top