1 11 package org.eclipse.debug.internal.ui.actions; 12 13 import org.eclipse.debug.core.ILaunch; 14 import org.eclipse.debug.core.model.IDebugElement; 15 import org.eclipse.debug.core.model.IDebugTarget; 16 import org.eclipse.debug.core.model.IProcess; 17 import org.eclipse.debug.core.model.IStepFilters; 18 import org.eclipse.debug.internal.ui.DebugUIPlugin; 19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 20 import org.eclipse.debug.ui.DebugUITools; 21 import org.eclipse.jface.action.IAction; 22 import org.eclipse.jface.preference.IPreferenceStore; 23 import org.eclipse.jface.util.IPropertyChangeListener; 24 import org.eclipse.jface.util.PropertyChangeEvent; 25 import org.eclipse.jface.viewers.ISelection; 26 import org.eclipse.jface.viewers.IStructuredSelection; 27 import org.eclipse.ui.IActionDelegate2; 28 29 32 public class ToggleStepFiltersActionDelegate extends AbstractDebugActionDelegate implements IActionDelegate2, IPropertyChangeListener { 33 34 37 protected void doAction(Object element) { 38 } 40 41 44 public void init(IAction action) { 45 setAction(action); 46 action.setChecked(isUseStepFilters()); 47 getPreferenceStore().addPropertyChangeListener(this); 48 } 49 50 private boolean isUseStepFilters() { 51 return DebugUIPlugin.getDefault().getStepFilterManager().isUseStepFilters(); 52 } 53 54 private IPreferenceStore getPreferenceStore() { 55 return DebugUIPlugin.getDefault().getPreferenceStore(); 56 } 57 58 61 public void propertyChange(PropertyChangeEvent event) { 62 if (event.getProperty().equals(IInternalDebugUIConstants.PREF_USE_STEP_FILTERS)) { 63 Object newValue= event.getNewValue(); 64 if (newValue instanceof Boolean ) { 65 getAction().setChecked(((Boolean )(newValue)).booleanValue()); 66 } else if (newValue instanceof String ) { 67 getAction().setChecked(Boolean.valueOf((String )newValue).booleanValue()); 68 } 69 } 70 } 71 72 75 public void dispose() { 76 super.dispose(); 77 getPreferenceStore().removePropertyChangeListener(this); 78 } 79 80 83 public void run(IAction action) { 84 DebugUITools.setUseStepFilters(action.isChecked()); 85 } 86 87 90 protected boolean initialize(IAction action, ISelection selection) { 91 boolean res = super.initialize(action, selection); 92 init(action); 93 return res; 94 } 95 96 99 protected void update(IAction action, ISelection s) { 100 boolean enabled = true; 101 if (s != null && !s.isEmpty()) { 102 if (s instanceof IStructuredSelection) { 103 IStructuredSelection ss = (IStructuredSelection) s; 104 if (ss.size() == 1) { 105 Object element = ss.getFirstElement(); 106 IDebugTarget[] debugTargets = getDebugTargets(element); 107 for (int i = 0; i < debugTargets.length; i++) { 108 IDebugTarget target = debugTargets[i]; 109 110 if (target instanceof IStepFilters) { 111 IStepFilters filters = (IStepFilters) target; 112 if (filters.supportsStepFilters()) { 113 enabled = true; 114 break; } 116 } 117 enabled = false; 121 } 122 } 123 } 124 } 125 action.setEnabled(enabled); 126 } 127 128 private IDebugTarget[] getDebugTargets(Object element) { 129 if (element instanceof IDebugElement) { 130 IDebugElement debugElement = (IDebugElement) element; 131 return new IDebugTarget[] {debugElement.getDebugTarget()}; 132 } else if (element instanceof ILaunch) { 133 ILaunch launch = (ILaunch) element; 134 return launch.getDebugTargets(); 135 } else if (element instanceof IProcess) { 136 IProcess process = (IProcess) element; 137 return process.getLaunch().getDebugTargets(); 138 } else { 139 return new IDebugTarget[0]; 140 } 141 } 142 143 } 144 | Popular Tags |