KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.core.internal.databinding.observable;
13
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.databinding.observable.set.AbstractObservableSet;
17 import org.eclipse.core.databinding.observable.set.IObservableSet;
18 import org.eclipse.core.databinding.observable.set.ISetChangeListener;
19 import org.eclipse.core.databinding.observable.set.SetChangeEvent;
20
21 /**
22  * Wraps an observable set. This object acts like an exact copy of the original
23  * set, and tracks all the changes in the original. The only difference is that
24  * disposing the wrapper will not dispose the original. You can use this whenever
25  * you need to return an IObservableSet from a method that expects the caller
26  * to dispose the set, but you have an IObservableSet that you don't want disposed.
27  */

28 public final class ProxyObservableSet extends AbstractObservableSet {
29
30     private IObservableSet toDelegateTo;
31     private ISetChangeListener listener = new ISetChangeListener() {
32         /* (non-Javadoc)
33          * @see org.eclipse.jface.internal.databinding.provisional.observable.set.ISetChangeListener#handleSetChange(org.eclipse.jface.internal.databinding.provisional.observable.set.IObservableSet, org.eclipse.jface.internal.databinding.provisional.observable.set.SetDiff)
34          */

35         public void handleSetChange(SetChangeEvent event) {
36             fireSetChange(event.diff);
37         }
38     };
39     
40     /**
41      * Constructs a DelegatingObservableSet that tracks the state of the given set.
42      *
43      * @param toDelegate
44      */

45     public ProxyObservableSet(IObservableSet toDelegate) {
46         super(toDelegate.getRealm());
47         this.toDelegateTo = toDelegate;
48         toDelegate.addSetChangeListener(listener);
49     }
50     
51     /* (non-Javadoc)
52      * @see org.eclipse.jface.internal.databinding.provisional.observable.set.AbstractObservableSet#getWrappedSet()
53      */

54     protected Set JavaDoc getWrappedSet() {
55         return toDelegateTo;
56     }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.jface.internal.databinding.provisional.observable.set.IObservableSet#getElementType()
60      */

61     public Object JavaDoc getElementType() {
62         return toDelegateTo.getElementType();
63     }
64     
65     /* (non-Javadoc)
66      * @see org.eclipse.jface.internal.databinding.provisional.observable.set.AbstractObservableSet#dispose()
67      */

68     public void dispose() {
69         toDelegateTo.removeSetChangeListener(listener);
70         super.dispose();
71     }
72 }
73
Popular Tags