view org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/UnmodifiableObservableValue.d @ 96:b74ac5dfcc06

package to module and java.lang.all import
author Frank Benoit <benoit@tionex.de>
date Tue, 21 Apr 2009 11:03:33 +0200
parents 6208d4f6a277
children
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2008 Matthew Hall 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:
 *     Matthew Hall - initial API and implementation (bug 219909)
 *     Matthew Hall - bug 237884
 ******************************************************************************/

module org.eclipse.core.internal.databinding.observable.UnmodifiableObservableValue;

import java.lang.all;

import org.eclipse.core.databinding.observable.IStaleListener;
import org.eclipse.core.databinding.observable.StaleEvent;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;

/**
 * An unmodifiable wrapper class for IObservableValue instances.
 * @since 1.1
 */
public class UnmodifiableObservableValue : AbstractObservableValue {
    private IObservableValue wrappedValue;

    /**
     * Constructs an UnmodifiableObservableValue which wraps the given
     * observable value
     * 
     * @param wrappedValue
     *            the observable value to wrap in an unmodifiable instance.
     */
    public this(IObservableValue wrappedValue) {
        super(wrappedValue.getRealm());

        this.wrappedValue = wrappedValue;
        wrappedValue.addValueChangeListener(new class() IValueChangeListener {
            public void handleValueChange(ValueChangeEvent event) {
                fireValueChange(event.diff);
            }
        });
        wrappedValue.addStaleListener(new class() IStaleListener {
            public void handleStale(StaleEvent staleEvent) {
                fireStale();
            }
        });
    }

    protected Object doGetValue() {
        return wrappedValue.getValue();
    }

    public Object getValueType() {
        return wrappedValue.getValueType();
    }

    public bool isStale() {
        return wrappedValue.isStale();
    }
}