1 /******************************************************************************* 2 * Copyright (c) 2007, 2015 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.ui.internal.views.markers; 15 16 import org.eclipse.core.commands.ExecutionEvent; 17 import org.eclipse.core.commands.operations.IUndoableOperation; 18 import org.eclipse.core.resources.IMarker; 19 import org.eclipse.core.resources.WorkspaceJob; 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.jface.dialogs.IDialogConstants; 24 import org.eclipse.jface.dialogs.MessageDialog; 25 import org.eclipse.ui.ide.undo.DeleteMarkersOperation; 26 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; 27 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 28 import org.eclipse.ui.views.markers.MarkerSupportView; 29 import org.eclipse.ui.views.markers.MarkerViewHandler; 30 import org.eclipse.ui.views.markers.internal.MarkerMessages; 31 32 /** 33 * DeleteHandler is the handler for the deletion of a marker. 34 * 35 * @since 3.4 36 * 37 */ 38 public class DeleteHandler extends MarkerViewHandler { 39 40 @Override execute(ExecutionEvent event)41 public Object execute(ExecutionEvent event) { 42 43 final MarkerSupportView view = getView(event); 44 if (view == null) 45 return this; 46 47 final IMarker[] selected = getSelectedMarkers(event); 48 49 // Verify. 50 MessageDialog dialog = new MessageDialog( 51 view.getSite().getShell(), 52 MarkerMessages.deleteActionConfirmTitle, 53 null, // icon 54 MarkerMessages.deleteActionConfirmMessage, 55 MessageDialog.WARNING, 56 0, 57 MarkerMessages.deleteActionConfirm_buttonDeleteLabel, IDialogConstants.CANCEL_LABEL); 58 59 if (dialog.open() != IDialogConstants.OK_ID) { 60 return view; 61 } 62 63 WorkspaceJob deleteJob= new WorkspaceJob(IDEWorkbenchMessages.MarkerDeleteHandler_JobTitle) { //See Bug#250807 64 @Override 65 public IStatus runInWorkspace(IProgressMonitor monitor) { 66 monitor.beginTask(IDEWorkbenchMessages.MarkerDeleteHandler_JobMessageLabel, 10 * selected.length); 67 try { 68 IUndoableOperation op= new DeleteMarkersOperation(selected, view.getDeleteOperationName(selected)); 69 op.addContext(view.getUndoContext()); 70 execute(op, MarkerMessages.deleteMarkers_errorMessage, monitor, WorkspaceUndoUtil.getUIInfoAdapter(view.getSite().getShell())); 71 } finally { 72 monitor.done(); 73 } 74 return Status.OK_STATUS; 75 } 76 }; 77 deleteJob.setUser(true); 78 deleteJob.schedule(); 79 80 return this; 81 } 82 } 83