KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > tasklist > PurgeCompletedAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.tasklist;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
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 /**
30  * This action deletes all the tasks found in the registry that
31  * are marked as completed.
32  */

33 class PurgeCompletedAction extends TaskAction {
34
35     /**
36      * Creates the action.
37      *
38      * @param tasklist the task list
39      * @param id the id
40      */

41     public PurgeCompletedAction(TaskList tasklist, String JavaDoc id) {
42         super(tasklist, id);
43         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
44                 ITaskListHelpContextIds.PURGE_COMPLETED_TASK_ACTION);
45     }
46
47     /**
48      * Fetches all the completed tasks in the workspace and deletes them.
49      */

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 JavaDoc completed = new ArrayList JavaDoc();
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         // Check if there is anything to do
71
if (completed.size() == 0) {
72             MessageDialog.openInformation(getShell(), TaskListMessages.PurgeCompleted_title,
73                     TaskListMessages.PurgeCompleted_noneCompleted);
74             return;
75         }
76
77         // Verify.
78
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