Mercurial > projects > dwt2
diff org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ConstantObservableValue.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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ConstantObservableValue.d Tue Apr 21 10:55:51 2009 +0200 @@ -0,0 +1,110 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +package org.eclipse.core.internal.databinding.observable; + +import org.eclipse.core.databinding.observable.IChangeListener; +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 : 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 this(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 this(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; + } + + 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 addStaleListener(IStaleListener listener) { + // ignore + } + + public void dispose() { + // nothing to dispose + } + + public Realm getRealm() { + return realm; + } + + public bool isStale() { + return false; + } + + public void removeChangeListener(IChangeListener listener) { + // ignore + } + + public void removeStaleListener(IStaleListener listener) { + // ignore + } +}