01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.project.ui.internal;
16:
17: import java.util.concurrent.CopyOnWriteArraySet;
18:
19: import org.eclipse.emf.common.notify.AdapterFactory;
20: import org.eclipse.emf.common.notify.Notification;
21: import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
22: import org.eclipse.ui.PlatformUI;
23:
24: /**
25: * This AdapterFactory guarantees that it will not update its listeners if the workbench has been
26: * disposed.
27: *
28: * @author jgarnett
29: * @since 1.0.0
30: */
31: public class UDIGAdapterFactoryContentProvider extends
32: AdapterFactoryContentProvider {
33: /**
34: * An interface for other objects to register as listeners for when the input has changed.
35: *
36: * @author Jesse
37: * @since 1.1.0
38: */
39: public interface InputChangedListener {
40: void changed();
41: }
42:
43: CopyOnWriteArraySet<InputChangedListener> listeners = new CopyOnWriteArraySet<InputChangedListener>();
44:
45: /**
46: * Add a listener. A listener is only added once.
47: *
48: * @param newListener listener to add.
49: */
50: public void addListener(InputChangedListener newListener) {
51: listeners.add(newListener);
52: }
53:
54: /**
55: * Remove a listener.
56: *
57: * @param oldListener listener to remove
58: */
59: public void removeListener(InputChangedListener oldListener) {
60: listeners.remove(oldListener);
61: }
62:
63: public UDIGAdapterFactoryContentProvider(
64: AdapterFactory adapterFactory) {
65: super (adapterFactory);
66: }
67:
68: @Override
69: public Object[] getChildren(Object arg0) {
70: return super .getChildren(arg0);
71: }
72:
73: @SuppressWarnings("unchecked")
74: @Override
75: public void notifyChanged(Notification notification) {
76: if (PlatformUI.getWorkbench().isClosing())
77: return;
78:
79: super .notifyChanged(notification);
80: for (InputChangedListener l : listeners) {
81: l.changed();
82: }
83: }
84:
85: }
|