Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0c108e89ea0d97312e83384bdf3f7a8a5c41f3f0 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2000, 2007 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.debug.internal.ui.views.launch;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IThread;

/**
 * Manages source selections and decorated editors for launch views.
 */
public class DecorationManager {

	// map of targets to lists of active decorations
	private static Map<IDebugTarget, List<Decoration>> fDecorations = new HashMap<>(10);

	/**
	 * Adds the given decoration for the given stack frame.
	 *
	 * @param decoration
	 * @param frame
	 */
	public static void addDecoration(Decoration decoration) {
		synchronized (fDecorations) {
			IDebugTarget target = decoration.getThread().getDebugTarget();
			List<Decoration> list = fDecorations.get(target);
			if (list == null) {
				list = new ArrayList<>();
				fDecorations.put(target, list);
			}
			list.add(decoration);
		}
	}

	/**
	 * Removes any decorations for the given debug target.
	 *
	 * @param target to remove editor decorations for
	 */
	public static void removeDecorations(IDebugTarget target) {
		doRemoveDecorations(target, null);
	}

	/**
	 * Removes any decorations for the given thread
	 *
	 * @param thread thread to remove decorations for
	 */
	public static void removeDecorations(IThread thread) {
		doRemoveDecorations(thread.getDebugTarget(), thread);
	}

	private static void doRemoveDecorations(IDebugTarget target, IThread thread) {
		ArrayList<Decoration> decorationsToRemove = new ArrayList<>();
		synchronized (fDecorations) {
			List<Decoration> list = fDecorations.get(target);
			if (list != null) {
				ListIterator<Decoration> iterator = list.listIterator();
				while (iterator.hasNext()) {
					Decoration decoration = iterator.next();
					if (thread == null || thread.equals(decoration.getThread())) {
						decorationsToRemove.add(decoration);
						iterator.remove();
					}
				}
				if (list.isEmpty()) {
					fDecorations.remove(target);
				}
			}
		}
		Iterator<Decoration> iter = decorationsToRemove.iterator();
		while (iter.hasNext()) {
			Decoration decoration = iter.next();
			decoration.remove();
		}
	}

}

Back to the top