KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > ViewContextManager


1 /*******************************************************************************
2  * Copyright (c) 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.views;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.ui.IWindowListener;
17 import org.eclipse.ui.IWorkbench;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.PlatformUI;
20
21 /**
22  * Manages the view context services for each window.
23  *
24  * @since 3.2
25  */

26 public class ViewContextManager implements IWindowListener {
27         
28     /**
29      * Map of services
30      */

31     private Map JavaDoc fWindowToService = new HashMap JavaDoc();
32     
33     // singleton manager
34
private static ViewContextManager fgManager;
35     
36     /**
37      * Returns the singleton view context manager.
38      *
39      * @return view manager
40      */

41     public static ViewContextManager getDefault() {
42         if (fgManager == null) {
43             fgManager = new ViewContextManager();
44         }
45         return fgManager;
46     }
47     
48     
49     private ViewContextManager() {
50         IWorkbench workbench = PlatformUI.getWorkbench();
51         IWorkbenchWindow[] workbenchWindows = workbench.getWorkbenchWindows();
52         for (int i = 0; i < workbenchWindows.length; i++) {
53             IWorkbenchWindow window = workbenchWindows[i];
54             windowOpened(window);
55         }
56         workbench.addWindowListener(this);
57     }
58     
59     /* (non-Javadoc)
60      * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
61      */

62     public void windowActivated(IWorkbenchWindow window) {
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow)
67      */

68     public void windowDeactivated(IWorkbenchWindow window) {
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow)
73      */

74     public void windowClosed(IWorkbenchWindow window) {
75         ViewContextService service = (ViewContextService) fWindowToService.get(window);
76         if (service != null) {
77             service.dispose();
78         }
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow)
83      */

84     public void windowOpened(IWorkbenchWindow window) {
85         ViewContextService service = (ViewContextService) fWindowToService.get(window);
86         if (service == null) {
87             service = new ViewContextService(window);
88             fWindowToService.put(window, service);
89         }
90     }
91     
92     /**
93      * Returns the service for the given window, or <code>null</code> if none.
94      *
95      * @param window
96      * @return view context service or <code>null</code>
97      */

98     public ViewContextService getService(IWorkbenchWindow window) {
99         return (ViewContextService) fWindowToService.get(window);
100     }
101
102 }
103
Popular Tags