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