KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > launch > DecorationManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.launch;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.ListIterator JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import org.eclipse.debug.core.model.IDebugTarget;
21 import org.eclipse.debug.core.model.IThread;
22
23 /**
24  * Manages source selections and decorated editors for launch views.
25  */

26 public class DecorationManager {
27
28     // map of targets to lists of active decorations
29
private static Map JavaDoc fDecorations = new HashMap JavaDoc(10);
30
31     /**
32      * Adds the given decoration for the given stack frame.
33      *
34      * @param decoration
35      * @param frame
36      */

37     public static void addDecoration(Decoration decoration) {
38         synchronized (fDecorations) {
39             IDebugTarget target = decoration.getThread().getDebugTarget();
40             List JavaDoc list = (List JavaDoc) fDecorations.get(target);
41             if (list == null) {
42                 list = new ArrayList JavaDoc();
43                 fDecorations.put(target, list);
44             }
45             list.add(decoration);
46         }
47     }
48
49     /**
50      * Removes any decorations for the given debug target.
51      *
52      * @param target
53      * to remove editor decorations for
54      */

55     public static void removeDecorations(IDebugTarget target) {
56         doRemoveDecorations(target, null);
57     }
58     
59     /**
60      * Removes any decorations for the given thread
61      *
62      * @param thread
63      * thread to remove decorations for
64      */

65     public static void removeDecorations(IThread thread) {
66         doRemoveDecorations(thread.getDebugTarget(), thread);
67     }
68
69     private static void doRemoveDecorations(IDebugTarget target, IThread thread) {
70         ArrayList JavaDoc decorationsToRemove = new ArrayList JavaDoc();
71         synchronized (fDecorations) {
72             List JavaDoc list = (List JavaDoc) fDecorations.get(target);
73             if (list != null) {
74                 ListIterator JavaDoc iterator = list.listIterator();
75                 while (iterator.hasNext()) {
76                     Decoration decoration = (Decoration) iterator.next();
77                     if (thread == null || thread.equals(decoration.getThread())) {
78                         decorationsToRemove.add(decoration);
79                         iterator.remove();
80                     }
81                 }
82                 if (list.isEmpty()) {
83                     fDecorations.remove(target);
84                 }
85             }
86         }
87         Iterator JavaDoc iter = decorationsToRemove.iterator();
88         while (iter.hasNext())
89         {
90             Decoration decoration = (Decoration)iter.next();
91             decoration.remove();
92         }
93     }
94     
95 }
96
Popular Tags