comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/ProxyObservableList.d @ 78:0a55d2d5a946

Added file for databinding
author Frank Benoit <benoit@tionex.de>
date Tue, 14 Apr 2009 11:35:29 +0200
parents
children 6be48cf9f95c
comparison
equal deleted inserted replaced
76:f05e6e8b2f2d 78:0a55d2d5a946
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 module org.eclipse.core.internal.databinding.observable.ProxyObservableList;
15
16 import java.lang.all;
17
18 import org.eclipse.core.databinding.observable.IStaleListener;
19 import org.eclipse.core.databinding.observable.StaleEvent;
20 import org.eclipse.core.databinding.observable.list.IListChangeListener;
21 import org.eclipse.core.databinding.observable.list.IObservableList;
22 import org.eclipse.core.databinding.observable.list.ListChangeEvent;
23 import org.eclipse.core.databinding.observable.list.ObservableList;
24
25 /**
26 * Wraps an observable list. This object acts like an exact copy of the original
27 * list, and tracks all the changes in the original. The only difference is that
28 * disposing the wrapper will not dispose the original. You can use this
29 * whenever you need to return an IObservableList from a method that expects the
30 * caller to dispose the list, but you have an IObservableList that you don't
31 * want disposed.
32 *
33 * @since 1.1
34 */
35 public class ProxyObservableList : ObservableList {
36 private IListChangeListener listChangelistener = new class() IListChangeListener {
37 public void handleListChange(ListChangeEvent event) {
38 fireListChange(event.diff);
39 }
40 };
41
42 private IStaleListener staleListener = new class() IStaleListener {
43 public void handleStale(StaleEvent event) {
44 fireStale();
45 }
46 };
47
48 private IObservableList wrappedList;
49
50 /**
51 * Constructs a ProxyObservableList that tracks the state of the given list.
52 *
53 * @param wrappedList
54 * the list being wrapped
55 */
56 public this(IObservableList wrappedList) {
57 super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType());
58 this.wrappedList = wrappedList;
59 wrappedList.addListChangeListener(listChangelistener);
60 wrappedList.addStaleListener(staleListener);
61 }
62
63 public bool isStale() {
64 getterCalled();
65 return wrappedList is null ? false : wrappedList.isStale();
66 }
67
68 public void dispose() {
69 if (wrappedList !is null) {
70 wrappedList.removeListChangeListener(listChangelistener);
71 listChangelistener = null;
72 wrappedList.removeStaleListener(staleListener);
73 staleListener = null;
74 wrappedList = null;
75 }
76 super.dispose();
77 }
78 }