1 11 package org.eclipse.debug.internal.ui.actions; 12 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.core.resources.IWorkspaceRunnable; 19 import org.eclipse.core.resources.ResourcesPlugin; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IProgressMonitor; 22 import org.eclipse.core.runtime.IStatus; 23 import org.eclipse.core.runtime.Status; 24 import org.eclipse.core.runtime.jobs.Job; 25 import org.eclipse.debug.core.DebugPlugin; 26 import org.eclipse.debug.core.model.IBreakpoint; 27 import org.eclipse.debug.internal.ui.DebugUIPlugin; 28 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointContainer; 29 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView; 30 import org.eclipse.jface.action.IAction; 31 import org.eclipse.jface.dialogs.MessageDialog; 32 import org.eclipse.jface.viewers.IStructuredSelection; 33 import org.eclipse.ui.IWorkbenchWindow; 34 35 public class RemoveBreakpointAction extends AbstractRemoveActionDelegate { 36 37 40 public void run(IAction action) { 41 IStructuredSelection selection= getSelection(); 42 if (selection.isEmpty()) { 43 return; 44 } 45 final List state = ((BreakpointsView)getView()).getSelectionState(); 46 final Iterator itr= selection.iterator(); 47 final CoreException[] exception= new CoreException[1]; 48 IWorkspaceRunnable runnable= new IWorkspaceRunnable() { 49 public void run(IProgressMonitor monitor) { 50 List breakpointsToDelete= new ArrayList (); 51 boolean deleteContainers= false; 52 while (itr.hasNext()) { 53 Object next= itr.next(); 54 if (next instanceof IBreakpoint) { 55 breakpointsToDelete.add(next); 56 } else if (next instanceof BreakpointContainer) { 57 if (!deleteContainers) { 58 deleteContainers = MessageDialog.openConfirm(getView().getSite().getShell(), ActionMessages.RemoveBreakpointAction_0, ActionMessages.RemoveBreakpointAction_1); if (!deleteContainers) { 61 return; 63 } 64 } 65 IBreakpoint[] breakpoints = ((BreakpointContainer) next).getBreakpoints(); 67 for (int i = 0; i < breakpoints.length; i++) { 68 breakpointsToDelete.add(breakpoints[i]); 69 } 70 } 71 } 72 final IBreakpoint[] breakpoints= (IBreakpoint[]) breakpointsToDelete.toArray(new IBreakpoint[0]); 73 new Job(ActionMessages.RemoveBreakpointAction_2) { protected IStatus run(IProgressMonitor pmonitor) { 75 try { 76 DebugPlugin.getDefault().getBreakpointManager().removeBreakpoints(breakpoints, true); 77 if (state != null) { 78 Runnable r = new Runnable () { 79 80 public void run() { 81 ((BreakpointsView) getView()).preserveSelectionState(state); 82 } 83 }; 84 DebugUIPlugin.getStandardDisplay().asyncExec(r); 85 } 86 return Status.OK_STATUS; 87 } catch (CoreException e) { 88 DebugUIPlugin.log(e); 89 } 90 return Status.CANCEL_STATUS; 91 } 92 }.schedule(); 93 } 94 }; 95 try { 96 ResourcesPlugin.getWorkspace().run(runnable, null, 0, null); 97 } catch (CoreException ce) { 98 exception[0]= ce; 99 } 100 if (exception[0] != null) { 101 IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); 102 if (window != null) { 103 DebugUIPlugin.errorDialog(window.getShell(), ActionMessages.RemoveBreakpointAction_Removing_a_breakpoint_4,ActionMessages.RemoveBreakpointAction_Exceptions_occurred_attempting_to_remove_a_breakpoint__5 , exception[0]); } else { 105 DebugUIPlugin.log(exception[0]); 106 } 107 } 108 } 109 110 113 protected void doAction(Object element) { 114 } 116 117 protected boolean isEnabledFor(Object element) { 118 if (element instanceof BreakpointContainer) 119 return ((BreakpointContainer)element).getChildren().length > 0; 120 return super.isEnabledFor(element); 121 } 122 } 123 | Popular Tags |