view org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ProxyObservableList.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) 2007 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 208332)
 *     IBM Corporation - initial API and implementation
 *         (through ProxyObservableSet.java)
 ******************************************************************************/

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

import java.lang.all;

import org.eclipse.core.databinding.observable.IStaleListener;
import org.eclipse.core.databinding.observable.StaleEvent;
import org.eclipse.core.databinding.observable.list.*;

/**
 * Wraps an observable list. This object acts like an exact copy of the original
 * list, and tracks all the changes in the original. The only difference is that
 * disposing the wrapper will not dispose the original. You can use this
 * whenever you need to return an IObservableList from a method that expects the
 * caller to dispose the list, but you have an IObservableList that you don't
 * want disposed.
 * 
 * @since 1.1
 */
public class ProxyObservableList : ObservableList {
    private IListChangeListener listChangelistener = new class() IListChangeListener {
        public void handleListChange(ListChangeEvent event) {
            fireListChange(event.diff);
        }
    };

    private IStaleListener staleListener = new class() IStaleListener {
        public void handleStale(StaleEvent event) {
            fireStale();
        }
    };

    private IObservableList wrappedList;

    /**
     * Constructs a ProxyObservableList that tracks the state of the given list.
     * 
     * @param wrappedList
     *            the list being wrapped
     */
    public this(IObservableList wrappedList) {
        super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType());
        this.wrappedList = wrappedList;
        wrappedList.addListChangeListener(listChangelistener);
        wrappedList.addStaleListener(staleListener);
    }

    public bool isStale() {
        getterCalled();
        return wrappedList is null ? false : wrappedList.isStale();
    }

    public void dispose() {
        if (wrappedList !is null) {
            wrappedList.removeListChangeListener(listChangelistener);
            listChangelistener = null;
            wrappedList.removeStaleListener(staleListener);
            staleListener = null;
            wrappedList = null;
        }
        super.dispose();
    }
}