KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > contexts > DebugContextManager


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.internal.ui.contexts;
12
13 import java.util.Collection JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.runtime.ListenerList;
18 import org.eclipse.debug.internal.ui.views.ViewContextManager;
19 import org.eclipse.debug.ui.contexts.IDebugContextListener;
20 import org.eclipse.debug.ui.contexts.IDebugContextManager;
21 import org.eclipse.debug.ui.contexts.IDebugContextService;
22 import org.eclipse.ui.IWindowListener;
23 import org.eclipse.ui.IWorkbenchWindow;
24 import org.eclipse.ui.PlatformUI;
25
26 /**
27  * @since 3.2
28  */

29 public class DebugContextManager implements IDebugContextManager {
30     
31     private static DebugContextManager fgDefault;
32     private Map JavaDoc fServices = new HashMap JavaDoc();
33     private ListenerList fGlobalListeners = new ListenerList();
34     
35     private class WindowListener implements IWindowListener {
36
37         /* (non-Javadoc)
38          * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
39          */

40         public void windowActivated(IWorkbenchWindow window) {
41         }
42
43         /* (non-Javadoc)
44          * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow)
45          */

46         public void windowDeactivated(IWorkbenchWindow window) {
47         }
48
49         /* (non-Javadoc)
50          * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow)
51          */

52         public void windowClosed(IWorkbenchWindow window) {
53             DebugWindowContextService service = (DebugWindowContextService) fServices.remove(window);
54             if (service != null) {
55                 service.dispose();
56             }
57         }
58
59         /* (non-Javadoc)
60          * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow)
61          */

62         public void windowOpened(IWorkbenchWindow window) {
63         }
64         
65     }
66     
67     private DebugContextManager() {
68         PlatformUI.getWorkbench().addWindowListener(new WindowListener());
69     }
70     
71     public static IDebugContextManager getDefault() {
72         if (fgDefault == null) {
73             fgDefault = new DebugContextManager();
74             // create the model context bindigg manager at the same time
75
DebugModelContextBindingManager.getDefault();
76             // create view manager
77
ViewContextManager.getDefault();
78         }
79         return fgDefault;
80     }
81     
82     protected DebugWindowContextService createService(IWorkbenchWindow window) {
83         DebugWindowContextService service = (DebugWindowContextService) fServices.get(window);
84         if (service == null) {
85             service = new DebugWindowContextService(window);
86             fServices.put(window, service);
87             // register global listeners
88
Object JavaDoc[] listeners = fGlobalListeners.getListeners();
89             for (int i = 0; i < listeners.length; i++) {
90                 IDebugContextListener listener = (IDebugContextListener) listeners[i];
91                 service.addDebugContextListener(listener);
92             }
93         }
94         return service;
95     }
96     
97     protected IDebugContextService getService(IWorkbenchWindow window) {
98         return (DebugWindowContextService) fServices.get(window);
99     }
100
101     /* (non-Javadoc)
102      * @see org.eclipse.debug.internal.ui.contexts.IDebugContextManager#addDebugContextListener(org.eclipse.debug.internal.ui.contexts.IDebugContextListener)
103      */

104     public void addDebugContextListener(IDebugContextListener listener) {
105         fGlobalListeners.add(listener);
106         DebugWindowContextService[] services = getServices();
107         for (int i = 0; i < services.length; i++) {
108             DebugWindowContextService service = services[i];
109             service.addDebugContextListener(listener);
110         }
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.debug.internal.ui.contexts.IDebugContextManager#removeDebugContextListener(org.eclipse.debug.internal.ui.contexts.IDebugContextListener)
115      */

116     public void removeDebugContextListener(IDebugContextListener listener) {
117         fGlobalListeners.remove(listener);
118         DebugWindowContextService[] services = getServices();
119         for (int i = 0; i < services.length; i++) {
120             DebugWindowContextService service = services[i];
121             service.removeDebugContextListener(listener);
122         }
123     }
124     
125     /**
126      * Returns the existing context services.
127      *
128      * @return existing context services
129      */

130     private DebugWindowContextService[] getServices() {
131         Collection JavaDoc sevices = fServices.values();
132         return (DebugWindowContextService[]) sevices.toArray(new DebugWindowContextService[sevices.size()]);
133     }
134
135     /* (non-Javadoc)
136      * @see org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextManager#getContextService(org.eclipse.ui.IWorkbenchWindow)
137      */

138     public IDebugContextService getContextService(IWorkbenchWindow window) {
139         return createService(window);
140     }
141     
142 }
143
Popular Tags