78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006-2008 Cerner Corporation 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 * Brad Reynolds - initial API and implementation
|
|
10 * Matthew Hall - bug 208332
|
|
11 ******************************************************************************/
|
|
12
|
|
13 module org.eclipse.core.internal.databinding.observable.UnmodifiableObservableList;
|
|
14
|
|
15 import java.lang.all;
|
|
16
|
|
17 import org.eclipse.core.databinding.observable.IStaleListener;
|
|
18 import org.eclipse.core.databinding.observable.StaleEvent;
|
|
19 import org.eclipse.core.databinding.observable.list.IListChangeListener;
|
|
20 import org.eclipse.core.databinding.observable.list.IObservableList;
|
|
21 import org.eclipse.core.databinding.observable.list.ListChangeEvent;
|
|
22 import org.eclipse.core.databinding.observable.list.ObservableList;
|
|
23
|
|
24 /**
|
|
25 * ObservableList implementation that prevents modification by consumers. Events
|
|
26 * in the originating wrapped list are propagated and thrown from this instance
|
|
27 * when appropriate. All mutators throw an UnsupportedOperationException.
|
|
28 *
|
|
29 * @since 1.0
|
|
30 */
|
|
31 /*
|
|
32 * Implementation makes the assumption that the superclass cast(ObservableList) is
|
|
33 * unmodifiable and that all modify methods throw an
|
|
34 * UnsupportedOperationException.
|
|
35 */
|
|
36 public class UnmodifiableObservableList : ObservableList {
|
|
37 /**
|
|
38 * List that is being made unmodifiable.
|
|
39 */
|
|
40 private IObservableList wrappedList;
|
|
41
|
|
42 private IListChangeListener listChangeListener = new class() IListChangeListener {
|
|
43 public void handleListChange(ListChangeEvent event) {
|
|
44 // Fires a Change and then ListChange event.
|
|
45 fireListChange(event.diff);
|
|
46 }
|
|
47 };
|
|
48
|
|
49 private IStaleListener staleListener = new class() IStaleListener {
|
|
50 public void handleStale(StaleEvent event) {
|
|
51 fireStale();
|
|
52 }
|
|
53 };
|
|
54
|
|
55 /**
|
|
56 * @param wrappedList
|
|
57 */
|
|
58 public this(IObservableList wrappedList) {
|
|
59 super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType());
|
|
60 this.wrappedList = wrappedList;
|
|
61
|
|
62 wrappedList.addListChangeListener(listChangeListener);
|
|
63
|
|
64 wrappedList.addStaleListener(staleListener);
|
|
65 }
|
|
66
|
|
67 /**
|
|
68 * Because this instance is immutable staleness cannot be changed.
|
|
69 *
|
|
70 * @throws UnsupportedOperationException
|
|
71 * because this instance is unmodifiable.
|
|
72 */
|
|
73 public void setStale(bool stale) {
|
|
74 throw new UnsupportedOperationException();
|
|
75 }
|
|
76
|
|
77 public bool isStale() {
|
|
78 getterCalled();
|
|
79 return wrappedList is null ? false : wrappedList.isStale();
|
|
80 }
|
|
81
|
|
82 public synchronized void dispose() {
|
|
83 if (wrappedList !is null) {
|
|
84 wrappedList.removeListChangeListener(listChangeListener);
|
|
85 wrappedList.removeStaleListener(staleListener);
|
|
86 wrappedList = null;
|
|
87 }
|
|
88 listChangeListener = null;
|
|
89 staleListener = null;
|
|
90 super.dispose();
|
|
91 }
|
|
92 }
|