KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > databinding > observable > UnmodifiableObservableList


1 /*******************************************************************************
2  * Copyright (c) 2006 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  ******************************************************************************/

11
12 package org.eclipse.core.internal.databinding.observable;
13
14 import org.eclipse.core.databinding.observable.IStaleListener;
15 import org.eclipse.core.databinding.observable.StaleEvent;
16 import org.eclipse.core.databinding.observable.list.IListChangeListener;
17 import org.eclipse.core.databinding.observable.list.IObservableList;
18 import org.eclipse.core.databinding.observable.list.ListChangeEvent;
19 import org.eclipse.core.databinding.observable.list.ObservableList;
20
21 /**
22  * ObservableList implementation that prevents modification by consumers. Events
23  * in the originating wrapped list are propagated and thrown from this instance
24  * when appropriate. All mutators throw an UnsupportedOperationException.
25  *
26  * @since 3.2
27  */

28 /*
29  * Implementation makes the assumption that the superclass (UnmodifiableList) is
30  * unmodifiable and that all modify methods throw an
31  * UnsupportedOperationException.
32  */

33 public class UnmodifiableObservableList extends ObservableList {
34     /**
35      * List that is being made unmodifiable.
36      */

37     private final IObservableList wrappedList;
38
39     /**
40      * @param wrappedList
41      */

42     public UnmodifiableObservableList(IObservableList wrappedList) {
43         super(wrappedList.getRealm(), wrappedList, wrappedList.getElementType());
44         this.wrappedList = wrappedList;
45
46         wrappedList.addListChangeListener(new IListChangeListener() {
47             public void handleListChange(ListChangeEvent event) {
48                 // Fires a Change and then ListChange event.
49
fireListChange(event.diff);
50             }
51         });
52
53         wrappedList.addStaleListener(new IStaleListener() {
54             public void handleStale(StaleEvent event) {
55                 fireStale();
56             }
57         });
58     }
59
60     /**
61      * Because this instance is immutable staleness cannot be changed.
62      *
63      */

64     public void setStale(boolean stale) {
65         throw new UnsupportedOperationException JavaDoc();
66     }
67
68     public boolean isStale() {
69         return wrappedList.isStale();
70     }
71 }
72
Popular Tags