KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > SourceLookupManager


1 /*******************************************************************************
2  * Copyright (c) 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.debug.internal.ui.sourcelookup;
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.IWorkbenchPage;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.PlatformUI;
21
22 /**
23  * Starts a source lookup service in each workbench window.
24  *
25  * @since 3.2
26  */

27 public class SourceLookupManager implements IWindowListener {
28
29     private static SourceLookupManager fgDefault;
30     
31     /**
32      * Services per window
33      */

34     private Map JavaDoc fServices = new HashMap JavaDoc();
35     
36     private SourceLookupManager() {
37         IWorkbench workbench = PlatformUI.getWorkbench();
38         IWorkbenchWindow[] workbenchWindows = workbench.getWorkbenchWindows();
39         for (int i = 0; i < workbenchWindows.length; i++) {
40             IWorkbenchWindow window = workbenchWindows[i];
41             windowOpened(window);
42         }
43         workbench.addWindowListener(this);
44     }
45         
46     /**
47      * Returns the default source lookup manager.
48      *
49      * @return
50      */

51     public static SourceLookupManager getDefault() {
52         if (fgDefault == null) {
53             fgDefault = new SourceLookupManager();
54         }
55         return fgDefault;
56     }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
60      */

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

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

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

83     public void windowOpened(IWorkbenchWindow window) {
84         SourceLookupService service = new SourceLookupService(window);
85         fServices.put(window, service);
86     }
87     
88     /* (non-Javadoc)
89      * @see org.eclipse.debug.internal.ui.contexts.ISourceDisplayAdapter#displaySource(java.lang.Object, org.eclipse.ui.IWorkbenchPage, boolean)
90      */

91     public void displaySource(Object JavaDoc context, IWorkbenchPage page, boolean forceSourceLookup) {
92         IWorkbenchWindow window = page.getWorkbenchWindow();
93         SourceLookupService service = (SourceLookupService) fServices.get(window);
94         if (service != null) {
95             service.displaySource(context, page, forceSourceLookup);
96         }
97     }
98 }
99
Popular Tags