1 11 package org.eclipse.debug.internal.ui.actions.breakpoints; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.debug.core.model.IWatchpoint; 17 import org.eclipse.debug.internal.ui.DebugUIPlugin; 18 import org.eclipse.debug.internal.ui.actions.ActionMessages; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.swt.widgets.Event; 23 import org.eclipse.ui.IActionDelegate2; 24 import org.eclipse.ui.IObjectActionDelegate; 25 import org.eclipse.ui.IWorkbenchPart; 26 27 30 public abstract class ModifyWatchpointAction implements IObjectActionDelegate, IActionDelegate2 { 31 32 private IStructuredSelection fWatchpoints = null; 33 34 37 public void run(IAction action) { 38 try { 39 if (fWatchpoints != null) { 40 Iterator iterator = fWatchpoints.iterator(); 41 while (iterator.hasNext()) { 42 IWatchpoint watchpoint = (IWatchpoint)iterator.next(); 43 toggleWatchpoint(watchpoint, action.isChecked()); 44 } 45 } 46 } catch (CoreException e) { 47 DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), ActionMessages.ModifyWatchpointAction_0, ActionMessages.ModifyWatchpointAction_1, e.getStatus()); } 49 50 } 51 52 58 protected abstract void toggleWatchpoint(IWatchpoint watchpoint, boolean b) throws CoreException; 59 60 63 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 64 } 65 66 69 public void selectionChanged(IAction action, ISelection selection) { 70 if (selection instanceof IStructuredSelection) { 71 fWatchpoints = (IStructuredSelection) selection; 72 if (!selection.isEmpty()) { 73 Iterator iterator = fWatchpoints.iterator(); 74 while (iterator.hasNext()) { 75 Object next = iterator.next(); 76 if (next instanceof IWatchpoint) { 77 IWatchpoint watchpoint = (IWatchpoint) next; 78 action.setChecked(isChecked(watchpoint)); 79 if (!isEnabled(watchpoint)) { 80 action.setEnabled(false); 81 return; 82 } 83 } 84 } 85 action.setEnabled(true); 86 return; 87 } 88 } 89 action.setEnabled(false); 90 } 91 92 98 protected abstract boolean isChecked(IWatchpoint watchpoint); 99 100 106 protected abstract boolean isEnabled(IWatchpoint watchpoint); 107 108 111 public void init(IAction action) { 112 } 113 114 117 public void dispose() { 118 fWatchpoints = null; 119 } 120 121 124 public void runWithEvent(IAction action, Event event) { 125 run(action); 126 } 127 } 128 | Popular Tags |