1 11 12 package org.eclipse.ui.views.tasklist; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.commands.operations.IUndoableOperation; 18 import org.eclipse.core.resources.IMarker; 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.jface.dialogs.ErrorDialog; 22 import org.eclipse.jface.dialogs.MessageDialog; 23 import org.eclipse.osgi.util.NLS; 24 import org.eclipse.ui.PlatformUI; 25 import org.eclipse.ui.ide.undo.DeleteMarkersOperation; 26 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; 27 import org.eclipse.ui.internal.views.tasklist.TaskListMessages; 28 29 33 class PurgeCompletedAction extends TaskAction { 34 35 41 public PurgeCompletedAction(TaskList tasklist, String id) { 42 super(tasklist, id); 43 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 44 ITaskListHelpContextIds.PURGE_COMPLETED_TASK_ACTION); 45 } 46 47 50 public void run() { 51 IResource resource = getTaskList().getResource(); 52 int depth = getTaskList().getResourceDepth(); 53 IMarker[] tasks; 54 try { 55 tasks = resource.findMarkers(IMarker.TASK, true, depth); 56 } catch (CoreException e) { 57 ErrorDialog.openError( 58 getShell(), 59 TaskListMessages.PurgeCompleted_errorMessage, null, e.getStatus()); 60 61 return; 62 } 63 final List completed = new ArrayList (); 64 for (int i = 0; i < tasks.length; i++) { 65 IMarker task = tasks[i]; 66 if (MarkerUtil.isComplete(task) && !MarkerUtil.isReadOnly(task)) { 67 completed.add(task); 68 } 69 } 70 if (completed.size() == 0) { 72 MessageDialog.openInformation(getShell(), TaskListMessages.PurgeCompleted_title, 73 TaskListMessages.PurgeCompleted_noneCompleted); 74 return; 75 } 76 77 if (!MessageDialog.openConfirm(getShell(), TaskListMessages.PurgeCompleted_title, 79 NLS.bind(TaskListMessages.PurgeCompleted_permanent,String.valueOf(completed.size())))) { 80 return; 81 } 82 83 IMarker[] toDelete = new IMarker[completed.size()]; 84 completed.toArray(toDelete); 85 IUndoableOperation op = new DeleteMarkersOperation(toDelete, getText()); 86 execute(op, TaskListMessages.PurgeCompleted_errorMessage, null, 87 WorkspaceUndoUtil.getUIInfoAdapter(getShell())); 88 } 89 } 90 | Popular Tags |