KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > breakpoints > BreakpointWorkingSetCache


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
12 package org.eclipse.debug.internal.ui.views.breakpoints;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Vector JavaDoc;
16
17 import org.eclipse.core.resources.IMarker;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.debug.core.DebugPlugin;
20 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
21 import org.eclipse.debug.internal.ui.importexport.breakpoints.IImportExportConstants;
22 import org.eclipse.ui.IWorkingSet;
23 import org.eclipse.ui.IWorkingSetManager;
24 import org.eclipse.ui.PlatformUI;
25
26 /**
27  * Class to cache the breakpoint to workingset information in its underlying
28  * marker as breakpoints are moved between breakpoint working sets.
29  * It resolves the need for constant attribute lookup and parsing to
30  * fix bug 103731
31  *
32  * @since 3.2
33  */

34 public class BreakpointWorkingSetCache {
35
36     /**
37      * the entire cache
38      * key: marker
39      * value: vector of workingsets the marker belongs to
40      */

41     HashMap JavaDoc fCache = null;
42     
43     /**
44      * Default constructor
45      * @param organizer the oprganizer that owns this cache
46      */

47     public BreakpointWorkingSetCache() {
48         fCache = new HashMap JavaDoc(15);
49     }
50     
51     /**
52      * Adds an entry into the cache
53      * @param marker the marker to add the workingset information about
54      * @param entry the entry to add to the cache
55      */

56     public void addEntry(IMarker marker, Object JavaDoc entry) {
57         Vector JavaDoc list = (Vector JavaDoc)fCache.get(marker);
58         if (list == null) {
59             list = new Vector JavaDoc();
60             list.addElement(entry);
61             fCache.put(marker, list);
62         }
63         else {
64             if(!list.contains(entry)) {
65                 list.addElement(entry);
66             }
67         }
68     }
69     
70     /**
71      * Removes an item from the list contained under the marker key, not the marker entry
72      * @param marker the marker key to remove the item from
73      * @param entry the entry to remove
74      */

75     public void removeMappedEntry(IMarker marker, Object JavaDoc entry) {
76         Vector JavaDoc list = (Vector JavaDoc)fCache.get(marker);
77         if(list != null) {
78             list.remove(entry);
79         }
80     }
81     
82     /**
83      * Flushes the cache of only the sepcified marker
84      * @param marker the marker whose cache is to be flushed
85      */

86     public void flushMarkerCache(IMarker marker) {
87         IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
88         Vector JavaDoc list = (Vector JavaDoc)fCache.get(marker);
89         if(list != null) {
90             String JavaDoc names = IImportExportConstants.DELIMITER;
91             String JavaDoc ids = IImportExportConstants.DELIMITER;
92             for(int i = 0; i < list.size(); i++) {
93                 String JavaDoc name = (String JavaDoc)list.elementAt(i);
94                 IWorkingSet ws = manager.getWorkingSet(name);
95                 if(ws != null) {
96                     names += name+IImportExportConstants.DELIMITER;
97                     ids += ws.getId()+IImportExportConstants.DELIMITER;
98                 }
99             }
100             try {
101                 marker.setAttribute(IInternalDebugUIConstants.WORKING_SET_NAME, names);
102                 marker.setAttribute(IInternalDebugUIConstants.WORKING_SET_ID, ids);
103             }
104             catch(CoreException e) {DebugPlugin.log(e);}
105         }
106     }
107     
108 }
109
Popular Tags