KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > resource > ResourceRegistry


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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 package org.eclipse.jface.resource;
12
13 import java.util.Set JavaDoc;
14
15 import org.eclipse.core.commands.common.EventManager;
16 import org.eclipse.jface.util.IPropertyChangeListener;
17 import org.eclipse.jface.util.PropertyChangeEvent;
18
19 /**
20  * Abstract base class for various JFace registries.
21  *
22  * @since 3.0
23  */

24 public abstract class ResourceRegistry extends EventManager {
25
26     /**
27      * Adds a property change listener to this registry.
28      *
29      * @param listener a property change listener
30      */

31     public void addListener(IPropertyChangeListener listener) {
32         addListenerObject(listener);
33     }
34
35     /**
36      * Disposes all currently allocated resources.
37      */

38     protected abstract void clearCaches();
39
40     /**
41      * @return the set of keys this manager knows about. This collection
42      * should be immutable.
43      */

44     public abstract Set JavaDoc getKeySet();
45
46     /**
47      * Return whether or not the receiver has a value for the supplied key.
48      *
49      * @param key the key
50      * @return <code>true</code> if there is a value for this key
51      */

52     public abstract boolean hasValueFor(String JavaDoc key);
53
54     /**
55      * Fires a <code>PropertyChangeEvent</code>.
56      *
57      * @param name the name of the symbolic value that is changing.
58      * @param oldValue the old value.
59      * @param newValue the new value.
60      */

61     protected void fireMappingChanged(String JavaDoc name, Object JavaDoc oldValue,
62             Object JavaDoc newValue) {
63         final Object JavaDoc[] myListeners = getListeners();
64         if (myListeners.length > 0) {
65             PropertyChangeEvent event = new PropertyChangeEvent(this, name,
66                     oldValue, newValue);
67             for (int i = 0; i < myListeners.length; ++i) {
68                 try {
69                     ((IPropertyChangeListener) myListeners[i])
70                             .propertyChange(event);
71                 } catch (Exception JavaDoc e) {
72                     // TODO: how to log?
73
}
74             }
75         }
76     }
77
78     /**
79      * Removes the given listener from this registry. Has no affect if the
80      * listener is not registered.
81      *
82      * @param listener a property change listener
83      */

84     public void removeListener(IPropertyChangeListener listener) {
85         removeListenerObject(listener);
86     }
87 }
88
Popular Tags