KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > AbstractAddStepFilterAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.debug.ui.actions;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Arrays JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.eclipse.jdt.debug.core.IJavaStackFrame;
20 import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
21 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
22 import org.eclipse.jdt.internal.debug.ui.JavaDebugOptionsManager;
23 import org.eclipse.jface.action.IAction;
24 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.jface.viewers.IStructuredSelection;
26
27 /**
28  * This abstract class defines the behavior common to actions that allow the
29  * user to add step filters dynamically, as they are debugging.
30  *
31  * @since 2.1
32  */

33 public abstract class AbstractAddStepFilterAction extends ObjectActionDelegate {
34
35     /**
36      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
37      */

38     public void run(IAction action) {
39         
40         // Make sure there is a current selection
41
IStructuredSelection selection= getCurrentSelection();
42         if (selection == null) {
43             return;
44         }
45
46         // For each selected stack frame, add a corresponding active step filter
47
Iterator JavaDoc itr = selection.iterator();
48         while (itr.hasNext()) {
49             IJavaStackFrame frame = (IJavaStackFrame)itr.next();
50             String JavaDoc pattern = generateStepFilterPattern(frame);
51             if (pattern != null) {
52                 addActiveStepFilter(pattern);
53             }
54         }
55     }
56     
57     /**
58      * Make the specified pattern an active step filter.
59      */

60     private void addActiveStepFilter(String JavaDoc pattern) {
61         
62         // Get the active & inactive filter preferences and convert them to Lists
63
IPreferenceStore prefStore = getPreferenceStore();
64         String JavaDoc[] activeArray = JavaDebugOptionsManager.parseList(prefStore.getString(IJDIPreferencesConstants.PREF_ACTIVE_FILTERS_LIST));
65         String JavaDoc[] inactiveArray = JavaDebugOptionsManager.parseList(prefStore.getString(IJDIPreferencesConstants.PREF_INACTIVE_FILTERS_LIST));
66         List JavaDoc activeList = new ArrayList JavaDoc(Arrays.asList(activeArray));
67         List JavaDoc inactiveList = new ArrayList JavaDoc(Arrays.asList(inactiveArray));
68         
69         // If the pattern is already in the active list, there's nothing to do
70
// (it can't/shouldn't be in the inactive list)
71
if (activeList.contains(pattern)) {
72             return;
73         }
74         
75         // Add the pattern to the active list and update the preference store
76
activeList.add(pattern);
77         String JavaDoc activePref = JavaDebugOptionsManager.serializeList((String JavaDoc[])activeList.toArray(new String JavaDoc[activeList.size()]));
78         prefStore.setValue(IJDIPreferencesConstants.PREF_ACTIVE_FILTERS_LIST, activePref);
79     
80         // If the pattern was present in the inactive list, remove it since we just
81
// added it to the active list
82
if (inactiveList.contains(pattern)) {
83             inactiveList.remove(pattern);
84             String JavaDoc inactivePref = JavaDebugOptionsManager.serializeList((String JavaDoc[])inactiveList.toArray(new String JavaDoc[inactiveList.size()]));
85             prefStore.setValue(IJDIPreferencesConstants.PREF_INACTIVE_FILTERS_LIST, inactivePref);
86         }
87     }
88     
89     /**
90      * Convenience method to get the preference store.
91      */

92     private IPreferenceStore getPreferenceStore() {
93         return JDIDebugUIPlugin.getDefault().getPreferenceStore();
94     }
95     
96     /**
97      * Generate an appropriate String pattern for the specified Java stack
98      * frame or return null if generation failed. For example, the pattern for
99      * a type might look like, "com. example.MyType", while the pattern for a
100      * package might look like, "com. example.*".
101      *
102      * @param frame the Java stack frame used to generate a String pattern
103      * @return String the pattern or <code>null</code> if one could not be
104      * generated
105      */

106     protected abstract String JavaDoc generateStepFilterPattern(IJavaStackFrame frame);
107
108 }
109
Popular Tags