78
|
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 {
|
85
|
36 private IListChangeListener listChangelistener;
|
|
37 class ListChangeListener : IListChangeListener {
|
78
|
38 public void handleListChange(ListChangeEvent event) {
|
|
39 fireListChange(event.diff);
|
|
40 }
|
|
41 };
|
|
42
|
85
|
43 private IStaleListener staleListener;
|
|
44 class StaleListener : IStaleListener {
|
78
|
45 public void handleStale(StaleEvent event) {
|
|
46 fireStale();
|
|
47 }
|
|
48 };
|
|
49
|
|
50 private IObservableList wrappedList;
|
|
51
|
|
52 /**
|
|
53 * Constructs a ProxyObservableList that tracks the state of the given list.
|
|
54 *
|
|
55 * @param wrappedList
|
|
56 * the list being wrapped
|
|
57 */
|
|
58 public this(IObservableList wrappedList) {
|
85
|
59 listChangelistener = new ListChangeListener();
|
|
60 staleListener = new StaleListener();
|
78
|
61 super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType());
|
|
62 this.wrappedList = wrappedList;
|
|
63 wrappedList.addListChangeListener(listChangelistener);
|
|
64 wrappedList.addStaleListener(staleListener);
|
|
65 }
|
|
66
|
|
67 public bool isStale() {
|
|
68 getterCalled();
|
|
69 return wrappedList is null ? false : wrappedList.isStale();
|
|
70 }
|
|
71
|
|
72 public void dispose() {
|
|
73 if (wrappedList !is null) {
|
|
74 wrappedList.removeListChangeListener(listChangelistener);
|
|
75 listChangelistener = null;
|
|
76 wrappedList.removeStaleListener(staleListener);
|
|
77 staleListener = null;
|
|
78 wrappedList = null;
|
|
79 }
|
|
80 super.dispose();
|
|
81 }
|
|
82 }
|