1 11 package org.eclipse.debug.internal.ui.actions.breakpoints; 12 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 17 import org.eclipse.core.resources.IWorkspaceRunnable; 18 import org.eclipse.core.resources.ResourcesPlugin; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.core.runtime.jobs.Job; 24 import org.eclipse.debug.core.DebugPlugin; 25 import org.eclipse.debug.core.model.IBreakpoint; 26 import org.eclipse.debug.internal.ui.DebugUIPlugin; 27 import org.eclipse.debug.internal.ui.actions.AbstractRemoveActionDelegate; 28 import org.eclipse.debug.internal.ui.actions.ActionMessages; 29 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; 30 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointContainer; 31 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView; 32 import org.eclipse.debug.internal.ui.views.breakpoints.WorkingSetCategory; 33 import org.eclipse.jface.action.IAction; 34 import org.eclipse.jface.dialogs.IDialogConstants; 35 import org.eclipse.jface.dialogs.MessageDialog; 36 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 37 import org.eclipse.jface.preference.IPreferenceStore; 38 import org.eclipse.jface.viewers.IStructuredSelection; 39 import org.eclipse.ui.IWorkbenchWindow; 40 import org.eclipse.ui.IWorkingSet; 41 import org.eclipse.ui.PlatformUI; 42 43 public class RemoveBreakpointAction extends AbstractRemoveActionDelegate { 44 45 48 public void run(IAction action) { 49 IStructuredSelection selection = getSelection(); 50 if (selection.isEmpty()) { 51 return; 52 } 53 final Iterator itr= selection.iterator(); 54 final CoreException[] exception= new CoreException[1]; 55 IWorkspaceRunnable runnable= new IWorkspaceRunnable() { 56 public void run(IProgressMonitor monitor) { 57 ArrayList breakpointsToDelete = new ArrayList (); 58 ArrayList groupsToDelete = new ArrayList (); 59 boolean deleteAll = false; 60 boolean deleteContainer = false; 61 boolean prompted = false; 62 while (itr.hasNext()) { 63 Object next= itr.next(); 64 if (next instanceof IBreakpoint) { 65 breakpointsToDelete.add(next); 66 } else if (next instanceof BreakpointContainer) { 67 BreakpointContainer bpc = (BreakpointContainer) next; 69 if(bpc.getCategory() instanceof WorkingSetCategory) { 70 IWorkingSet set = ((WorkingSetCategory)bpc.getCategory()).getWorkingSet(); 71 if(!prompted) { 72 prompted = true; 73 DeleteWorkingsetsMessageDialog dialog = new DeleteWorkingsetsMessageDialog(getView().getSite().getShell(), 74 ActionMessages.RemoveBreakpointAction_3, 75 null, 76 ActionMessages.RemoveBreakpointAction_4, 77 MessageDialog.QUESTION, 78 new String [] {ActionMessages.RemoveBreakpointAction_5, ActionMessages.RemoveBreakpointAction_6}, 79 0); 80 if(dialog.open() == 0) { 81 deleteAll = dialog.deleteAllBreakpoints(); 82 deleteContainer = dialog.deleteWorkingset(); 83 } 84 } 85 if(deleteContainer) { 86 groupsToDelete.add(set); 87 } 88 } 89 else { 90 if(!prompted) { 91 IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); 92 prompted = store.getBoolean(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_BREAKPOINTS_FROM_CONTAINER); 93 if(prompted) { 94 MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(getView().getSite().getShell(), ActionMessages.RemoveBreakpointAction_0, 95 ActionMessages.RemoveBreakpointAction_1, ActionMessages.RemoveAllBreakpointsAction_3, !prompted, null, null); 96 if(mdwt.getReturnCode() == IDialogConstants.NO_ID) { 97 deleteAll = false; 98 } 99 else { 100 store.setValue(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_BREAKPOINTS_FROM_CONTAINER, !mdwt.getToggleState()); 101 deleteAll = true; 102 } 103 } 104 else { 105 deleteAll = !prompted; 106 } 107 } 108 } 109 if(deleteAll) { 110 IBreakpoint[] breakpoints = bpc.getBreakpoints(); 111 for (int i = 0; i < breakpoints.length; i++) { 112 breakpointsToDelete.add(breakpoints[i]); 113 } 114 } 115 } 116 } 117 final IBreakpoint[] breakpoints = (IBreakpoint[]) breakpointsToDelete.toArray(new IBreakpoint[0]); 118 final IWorkingSet[] sets = (IWorkingSet[])groupsToDelete.toArray(new IWorkingSet[groupsToDelete.size()]); 119 if(breakpoints.length > 0) { 120 ((BreakpointsView)getView()).preserveSelection(getSelection()); 121 } 122 new Job(ActionMessages.RemoveBreakpointAction_2) { 123 protected IStatus run(IProgressMonitor pmonitor) { 124 try { 125 DebugPlugin.getDefault().getBreakpointManager().removeBreakpoints(breakpoints, true); 126 for (int i = 0; i < sets.length; i++) { 127 PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(sets[i]); 128 } 129 return Status.OK_STATUS; 130 } catch (CoreException e) { 131 DebugUIPlugin.log(e); 132 } 133 return Status.CANCEL_STATUS; 134 } 135 }.schedule(); 136 } 137 }; 138 try { 139 ResourcesPlugin.getWorkspace().run(runnable, null, 0, null); 140 } catch (CoreException ce) { 141 exception[0]= ce; 142 } 143 if (exception[0] != null) { 144 IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); 145 if (window != null) { 146 DebugUIPlugin.errorDialog(window.getShell(), ActionMessages.RemoveBreakpointAction_Removing_a_breakpoint_4,ActionMessages.RemoveBreakpointAction_Exceptions_occurred_attempting_to_remove_a_breakpoint__5 , exception[0]); 147 } else { 148 DebugUIPlugin.log(exception[0]); 149 } 150 } 151 } 152 153 156 protected boolean isEnabledFor(Object element) { 157 if (element instanceof BreakpointContainer) { 158 if(((BreakpointContainer)element).getCategory() instanceof WorkingSetCategory) { 159 return true; 160 } 161 return ((BreakpointContainer)element).getChildren().length > 0; 162 } 163 return super.isEnabledFor(element); 164 } 165 } 166 | Popular Tags |