KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search2 > internal > ui > text > AnnotationManagers


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
12 package org.eclipse.search2.internal.ui.text;
13
14 import java.util.HashMap JavaDoc;
15
16 import org.eclipse.search.ui.text.AbstractTextSearchResult;
17 import org.eclipse.ui.IWindowListener;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.PlatformUI;
20
21 public class AnnotationManagers {
22     static {
23         fgManagerMap = new HashMap JavaDoc();
24         IWindowListener listener = new IWindowListener() {
25             public void windowActivated(IWorkbenchWindow window) {
26                 // ignore
27
}
28
29             public void windowDeactivated(IWorkbenchWindow window) {
30                 // ignore
31
}
32
33             public void windowClosed(IWorkbenchWindow window) {
34                 disposeAnnotationManager(window);
35             }
36
37             public void windowOpened(IWorkbenchWindow window) {
38                 // ignore
39
}
40         };
41         PlatformUI.getWorkbench().addWindowListener(listener);
42     }
43
44     private static HashMap JavaDoc fgManagerMap;
45
46
47     private static void disposeAnnotationManager(IWorkbenchWindow window) {
48         WindowAnnotationManager mgr = (WindowAnnotationManager) fgManagerMap.remove(window);
49         if (mgr != null)
50             mgr.dispose();
51     }
52
53     public static void addSearchResult(IWorkbenchWindow window, AbstractTextSearchResult newResult) {
54         getWindowAnnotationManager(window).addSearchResult(newResult);
55     }
56     
57     public static void removeSearchResult(IWorkbenchWindow window, AbstractTextSearchResult result) {
58         getWindowAnnotationManager(window).removeSearchResult(result);
59     }
60     
61     private static WindowAnnotationManager getWindowAnnotationManager(IWorkbenchWindow window) {
62         WindowAnnotationManager mgr= (WindowAnnotationManager) fgManagerMap.get(window);
63         if (mgr == null) {
64             mgr= new WindowAnnotationManager(window);
65             fgManagerMap.put(window, mgr);
66         }
67         return mgr;
68     }
69     
70
71 }
72
Popular Tags