1 11 package org.eclipse.debug.internal.ui.actions; 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.jface.action.IAction; 19 import org.eclipse.jface.viewers.ISelection; 20 import org.eclipse.jface.viewers.IStructuredSelection; 21 import org.eclipse.swt.widgets.Event; 22 import org.eclipse.ui.IActionDelegate2; 23 import org.eclipse.ui.IObjectActionDelegate; 24 import org.eclipse.ui.IWorkbenchPart; 25 26 29 public abstract class ModifyWatchpointAction implements IObjectActionDelegate, IActionDelegate2 { 30 31 private IStructuredSelection fWatchpoints = null; 32 33 36 public void run(IAction action) { 37 try { 38 if (fWatchpoints != null) { 39 Iterator iterator = fWatchpoints.iterator(); 40 while (iterator.hasNext()) { 41 IWatchpoint watchpoint = (IWatchpoint)iterator.next(); 42 toggleWatchpoint(watchpoint, action.isChecked()); 43 } 44 } 45 } catch (CoreException e) { 46 DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), ActionMessages.ModifyWatchpointAction_0, ActionMessages.ModifyWatchpointAction_1, e.getStatus()); } 48 49 } 50 51 57 protected abstract void toggleWatchpoint(IWatchpoint watchpoint, boolean b) throws CoreException; 58 59 62 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 63 } 64 65 68 public void selectionChanged(IAction action, ISelection selection) { 69 if (selection instanceof IStructuredSelection) { 70 fWatchpoints = (IStructuredSelection) selection; 71 if (!selection.isEmpty()) { 72 Iterator iterator = fWatchpoints.iterator(); 73 while (iterator.hasNext()) { 74 Object next = iterator.next(); 75 if (next instanceof IWatchpoint) { 76 IWatchpoint watchpoint = (IWatchpoint) next; 77 action.setChecked(isChecked(watchpoint)); 78 if (!isEnabled(watchpoint)) { 79 action.setEnabled(false); 80 return; 81 } 82 } 83 } 84 action.setEnabled(true); 85 return; 86 } 87 } 88 action.setEnabled(false); 89 } 90 91 97 protected abstract boolean isChecked(IWatchpoint watchpoint); 98 99 105 protected abstract boolean isEnabled(IWatchpoint watchpoint); 106 107 110 public void init(IAction action) { 111 } 112 113 116 public void dispose() { 117 fWatchpoints = null; 118 } 119 120 123 public void runWithEvent(IAction action, Event event) { 124 run(action); 125 } 126 } 127 | Popular Tags |