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 * Brad Reynolds - initial API and implementation
|
|
11 * (through UnmodifiableObservableList.java)
|
|
12 ******************************************************************************/
|
|
13
|
|
14 module org.eclipse.core.internal.databinding.observable.UnmodifiableObservableSet;
|
|
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.set.IObservableSet;
|
|
21 import org.eclipse.core.databinding.observable.set.ISetChangeListener;
|
|
22 import org.eclipse.core.databinding.observable.set.ObservableSet;
|
|
23 import org.eclipse.core.databinding.observable.set.SetChangeEvent;
|
|
24
|
|
25 /**
|
|
26 * ObservableList implementation that prevents modification by consumers. Events
|
|
27 * in the originating wrapped list are propagated and thrown from this instance
|
|
28 * when appropriate. All mutators throw an UnsupportedOperationException.
|
|
29 *
|
|
30 * @since 1.1
|
|
31 */
|
|
32 public class UnmodifiableObservableSet : ObservableSet {
|
|
33 private ISetChangeListener setChangeListener = new class() ISetChangeListener {
|
|
34 public void handleSetChange(SetChangeEvent event) {
|
|
35 fireSetChange(event.diff);
|
|
36 }
|
|
37 };
|
|
38
|
|
39 private IStaleListener staleListener = new class() IStaleListener {
|
|
40 public void handleStale(StaleEvent event) {
|
|
41 fireStale();
|
|
42 }
|
|
43 };
|
|
44
|
|
45 private IObservableSet wrappedSet;
|
|
46
|
|
47 /**
|
|
48 * @param wrappedSet
|
|
49 */
|
|
50 public this(IObservableSet wrappedSet) {
|
|
51 super(wrappedSet.getRealm(), wrappedSet, wrappedSet.getElementType());
|
|
52
|
|
53 this.wrappedSet = wrappedSet;
|
|
54
|
|
55 wrappedSet.addSetChangeListener(setChangeListener);
|
|
56 wrappedSet.addStaleListener(staleListener);
|
|
57 }
|
|
58
|
|
59 /**
|
|
60 * Because this instance is immutable staleness cannot be changed.
|
|
61 */
|
|
62 public void setStale(bool stale) {
|
|
63 throw new UnsupportedOperationException();
|
|
64 }
|
|
65
|
|
66 public bool isStale() {
|
|
67 getterCalled();
|
|
68 return wrappedSet is null ? false : wrappedSet.isStale();
|
|
69 }
|
|
70
|
|
71 public synchronized void dispose() {
|
|
72 if (wrappedSet !is null) {
|
|
73 wrappedSet.removeSetChangeListener(setChangeListener);
|
|
74 wrappedSet.removeStaleListener(staleListener);
|
|
75 wrappedSet = null;
|
|
76 }
|
|
77 setChangeListener = null;
|
|
78 staleListener = null;
|
|
79 super.dispose();
|
|
80 }
|
|
81 }
|