KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > contexts > AbstractDebugContextProvider


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 package org.eclipse.debug.ui.contexts;
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 import org.eclipse.ui.IWorkbenchPart;
18
19 /**
20  * Abstract implementation of a debug context provider.
21  * <p>
22  * Clients implementing context providers should subclass this class.
23  * </p>
24  * @since 3.3
25  */

26 public abstract class AbstractDebugContextProvider implements IDebugContextProvider {
27     
28     /**
29      * Event listeners
30      */

31     private ListenerList fListeners = new ListenerList();
32     
33     /**
34      * Part or <code>null</code>
35      */

36     private IWorkbenchPart fPart;
37     
38     /**
39      * Constructs a context provider for the specified part, possibly <code>null</code>.
40      *
41      * @param part workbench part or <code>null</code>
42      */

43     public AbstractDebugContextProvider(IWorkbenchPart part) {
44         fPart = part;
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextProvider#addDebugContextEventListener(org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextEventListener)
49      */

50     public void addDebugContextListener(IDebugContextListener listener) {
51         fListeners.add(listener);
52     }
53
54     /* (non-Javadoc)
55      * @see org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextProvider#getPart()
56      */

57     public IWorkbenchPart getPart() {
58         return fPart;
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextProvider#removeDebugContextEventListener(org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextEventListener)
63      */

64     public void removeDebugContextListener(IDebugContextListener listener) {
65         fListeners.remove(listener);
66     }
67
68     /**
69      * Fires the given context event to all registered listeners.
70      *
71      * @param event debug context event
72      */

73     protected void fire(final DebugContextEvent event) {
74         Object JavaDoc[] listeners = fListeners.getListeners();
75         for (int i = 0; i < listeners.length; i++) {
76             final IDebugContextListener listener = (IDebugContextListener) listeners[i];
77             SafeRunner.run(new ISafeRunnable() {
78                 public void run() throws Exception JavaDoc {
79                     listener.debugContextChanged(event);
80                 }
81                 public void handleException(Throwable JavaDoc exception) {
82                     DebugUIPlugin.log(exception);
83                 }
84             });
85             
86         }
87     }
88 }
89
Popular Tags