comparison org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/ProxyObservableList.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
comparison
equal deleted inserted replaced
94:1d37a7813832 95:6208d4f6a277
1 /*******************************************************************************
2 * Copyright (c) 2007 Matthew Hall and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Matthew Hall - initial API and implementation (bug 208332)
10 * IBM Corporation - initial API and implementation
11 * (through ProxyObservableSet.java)
12 ******************************************************************************/
13
14 package org.eclipse.core.internal.databinding.observable;
15
16 import org.eclipse.core.databinding.observable.IStaleListener;
17 import org.eclipse.core.databinding.observable.StaleEvent;
18 import org.eclipse.core.databinding.observable.list.*;
19
20 /**
21 * Wraps an observable list. This object acts like an exact copy of the original
22 * list, and tracks all the changes in the original. The only difference is that
23 * disposing the wrapper will not dispose the original. You can use this
24 * whenever you need to return an IObservableList from a method that expects the
25 * caller to dispose the list, but you have an IObservableList that you don't
26 * want disposed.
27 *
28 * @since 1.1
29 */
30 public class ProxyObservableList : ObservableList {
31 private IListChangeListener listChangelistener = new class() IListChangeListener {
32 public void handleListChange(ListChangeEvent event) {
33 fireListChange(event.diff);
34 }
35 };
36
37 private IStaleListener staleListener = new class() IStaleListener {
38 public void handleStale(StaleEvent event) {
39 fireStale();
40 }
41 };
42
43 private IObservableList wrappedList;
44
45 /**
46 * Constructs a ProxyObservableList that tracks the state of the given list.
47 *
48 * @param wrappedList
49 * the list being wrapped
50 */
51 public this(IObservableList wrappedList) {
52 super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType());
53 this.wrappedList = wrappedList;
54 wrappedList.addListChangeListener(listChangelistener);
55 wrappedList.addStaleListener(staleListener);
56 }
57
58 public bool isStale() {
59 getterCalled();
60 return wrappedList is null ? false : wrappedList.isStale();
61 }
62
63 public void dispose() {
64 if (wrappedList !is null) {
65 wrappedList.removeListChangeListener(listChangelistener);
66 listChangelistener = null;
67 wrappedList.removeStaleListener(staleListener);
68 staleListener = null;
69 wrappedList = null;
70 }
71 super.dispose();
72 }
73 }