Skip to main content
summaryrefslogtreecommitdiffstats
blob: 15f69f08e1828e06b0ac9374f043ef003b5da53e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*******************************************************************************
 * Copyright (c) 2000, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.search2.internal.ui.text;

import java.util.HashMap;

import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

import org.eclipse.search.ui.text.AbstractTextSearchResult;

public class AnnotationManagers {
	static {
		fgManagerMap = new HashMap();
		IWindowListener listener = new IWindowListener() {
			@Override
			public void windowActivated(IWorkbenchWindow window) {
				// ignore
			}

			@Override
			public void windowDeactivated(IWorkbenchWindow window) {
				// ignore
			}

			@Override
			public void windowClosed(IWorkbenchWindow window) {
				disposeAnnotationManager(window);
			}

			@Override
			public void windowOpened(IWorkbenchWindow window) {
				// ignore
			}
		};
		PlatformUI.getWorkbench().addWindowListener(listener);
	}

	private static HashMap fgManagerMap;


	private static void disposeAnnotationManager(IWorkbenchWindow window) {
		WindowAnnotationManager mgr = (WindowAnnotationManager) fgManagerMap.remove(window);
		if (mgr != null)
			mgr.dispose();
	}

	public static void addSearchResult(IWorkbenchWindow window, AbstractTextSearchResult newResult) {
		getWindowAnnotationManager(window).addSearchResult(newResult);
	}

	public static void removeSearchResult(IWorkbenchWindow window, AbstractTextSearchResult result) {
		getWindowAnnotationManager(window).removeSearchResult(result);
	}

	private static WindowAnnotationManager getWindowAnnotationManager(IWorkbenchWindow window) {
		WindowAnnotationManager mgr= (WindowAnnotationManager) fgManagerMap.get(window);
		if (mgr == null) {
			mgr= new WindowAnnotationManager(window);
			fgManagerMap.put(window, mgr);
		}
		return mgr;
	}


}

Back to the top