1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.Iterator ; 17 import java.util.List ; 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 33 public abstract class AbstractAddStepFilterAction extends ObjectActionDelegate { 34 35 38 public void run(IAction action) { 39 40 IStructuredSelection selection= getCurrentSelection(); 42 if (selection == null) { 43 return; 44 } 45 46 Iterator itr = selection.iterator(); 48 while (itr.hasNext()) { 49 IJavaStackFrame frame = (IJavaStackFrame)itr.next(); 50 String pattern = generateStepFilterPattern(frame); 51 if (pattern != null) { 52 addActiveStepFilter(pattern); 53 } 54 } 55 } 56 57 60 private void addActiveStepFilter(String pattern) { 61 62 IPreferenceStore prefStore = getPreferenceStore(); 64 String [] activeArray = JavaDebugOptionsManager.parseList(prefStore.getString(IJDIPreferencesConstants.PREF_ACTIVE_FILTERS_LIST)); 65 String [] inactiveArray = JavaDebugOptionsManager.parseList(prefStore.getString(IJDIPreferencesConstants.PREF_INACTIVE_FILTERS_LIST)); 66 List activeList = new ArrayList (Arrays.asList(activeArray)); 67 List inactiveList = new ArrayList (Arrays.asList(inactiveArray)); 68 69 if (activeList.contains(pattern)) { 72 return; 73 } 74 75 activeList.add(pattern); 77 String activePref = JavaDebugOptionsManager.serializeList((String [])activeList.toArray(new String [activeList.size()])); 78 prefStore.setValue(IJDIPreferencesConstants.PREF_ACTIVE_FILTERS_LIST, activePref); 79 80 if (inactiveList.contains(pattern)) { 83 inactiveList.remove(pattern); 84 String inactivePref = JavaDebugOptionsManager.serializeList((String [])inactiveList.toArray(new String [inactiveList.size()])); 85 prefStore.setValue(IJDIPreferencesConstants.PREF_INACTIVE_FILTERS_LIST, inactivePref); 86 } 87 } 88 89 92 private IPreferenceStore getPreferenceStore() { 93 return JDIDebugUIPlugin.getDefault().getPreferenceStore(); 94 } 95 96 106 protected abstract String generateStepFilterPattern(IJavaStackFrame frame); 107 108 } 109 | Popular Tags |