01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.views.tasklist;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: import org.eclipse.core.commands.operations.IUndoableOperation;
16: import org.eclipse.core.resources.IMarker;
17: import org.eclipse.core.resources.IResource;
18: import org.eclipse.core.runtime.CoreException;
19: import org.eclipse.jface.dialogs.ErrorDialog;
20: import org.eclipse.jface.dialogs.MessageDialog;
21: import org.eclipse.osgi.util.NLS;
22: import org.eclipse.ui.PlatformUI;
23: import org.eclipse.ui.ide.undo.DeleteMarkersOperation;
24: import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
25: import org.eclipse.ui.internal.views.tasklist.TaskListMessages;
26:
27: /**
28: * This action deletes all the tasks found in the registry that
29: * are marked as completed.
30: */
31: class PurgeCompletedAction extends TaskAction {
32:
33: /**
34: * Creates the action.
35: *
36: * @param tasklist the task list
37: * @param id the id
38: */
39: public PurgeCompletedAction(TaskList tasklist, String id) {
40: super (tasklist, id);
41: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
42: ITaskListHelpContextIds.PURGE_COMPLETED_TASK_ACTION);
43: }
44:
45: /**
46: * Fetches all the completed tasks in the workspace and deletes them.
47: */
48: public void run() {
49: IResource resource = getTaskList().getResource();
50: int depth = getTaskList().getResourceDepth();
51: IMarker[] tasks;
52: try {
53: tasks = resource.findMarkers(IMarker.TASK, true, depth);
54: } catch (CoreException e) {
55: ErrorDialog.openError(getShell(),
56: TaskListMessages.PurgeCompleted_errorMessage, null,
57: e.getStatus());
58:
59: return;
60: }
61: final List completed = new ArrayList();
62: for (int i = 0; i < tasks.length; i++) {
63: IMarker task = tasks[i];
64: if (MarkerUtil.isComplete(task)
65: && !MarkerUtil.isReadOnly(task)) {
66: completed.add(task);
67: }
68: }
69: // Check if there is anything to do
70: if (completed.size() == 0) {
71: MessageDialog.openInformation(getShell(),
72: TaskListMessages.PurgeCompleted_title,
73: TaskListMessages.PurgeCompleted_noneCompleted);
74: return;
75: }
76:
77: // Verify.
78: if (!MessageDialog.openConfirm(getShell(),
79: TaskListMessages.PurgeCompleted_title, NLS.bind(
80: TaskListMessages.PurgeCompleted_permanent,
81: String.valueOf(completed.size())))) {
82: return;
83: }
84:
85: IMarker[] toDelete = new IMarker[completed.size()];
86: completed.toArray(toDelete);
87: IUndoableOperation op = new DeleteMarkersOperation(toDelete,
88: getText());
89: execute(op, TaskListMessages.PurgeCompleted_errorMessage, null,
90: WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
91: }
92: }
|