KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > memory > AbstractMemoryRenderingBindingsProvider


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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.debug.ui.memory;
12
13 import org.eclipse.core.runtime.ISafeRunnable;
14 import org.eclipse.core.runtime.ListenerList;
15 import org.eclipse.core.runtime.SafeRunner;
16 import org.eclipse.debug.internal.ui.DebugUIPlugin;
17
18 /**
19  * Common function for a dynamic memory rendering bindings provider.
20  * <p>
21  * Clients may subclass this class.
22  * </p>
23  * @see org.eclipse.debug.ui.memory.IMemoryRenderingBindingsProvider
24  * @since 3.1
25  */

26 public abstract class AbstractMemoryRenderingBindingsProvider implements IMemoryRenderingBindingsProvider {
27         
28     // list of binding listeners
29
private ListenerList fListeners;
30         
31     /* (non-Javadoc)
32      * @see org.eclipse.debug.ui.memory.IMemoryRenderingBindingsProvider#addListener(org.eclipse.debug.ui.memory.IMemoryRenderingBindingsListener)
33      */

34     public void addListener(IMemoryRenderingBindingsListener listener) {
35         if (fListeners == null) {
36             fListeners = new ListenerList();
37         }
38         fListeners.add(listener);
39     }
40     /* (non-Javadoc)
41      * @see org.eclipse.debug.ui.memory.IMemoryRenderingBindingsProvider#removeListener(org.eclipse.debug.ui.memory.IMemoryRenderingBindingsListener)
42      */

43     public void removeListener(IMemoryRenderingBindingsListener listener) {
44         if (fListeners != null) {
45             fListeners.remove(listener);
46         }
47     }
48     
49     /**
50      * Notifies all registered listeners that bindings have changed.
51      */

52     protected void fireBindingsChanged() {
53         if (fListeners == null) {
54             return;
55         }
56         
57         Object JavaDoc[] listeners = fListeners.getListeners();
58         
59         for (int i=0; i<listeners.length; i++) {
60             if (listeners[i] instanceof IMemoryRenderingBindingsListener) {
61                 final IMemoryRenderingBindingsListener listener = (IMemoryRenderingBindingsListener)listeners[i];
62                 ISafeRunnable runnable = new ISafeRunnable () {
63                     public void handleException(Throwable JavaDoc exception) {
64                         DebugUIPlugin.log(exception);
65                     }
66                     public void run() throws Exception JavaDoc {
67                         listener.memoryRenderingBindingsChanged();
68                     }};
69                 SafeRunner.run(runnable);
70             }
71         }
72     }
73 }
74
Popular Tags