KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > ActionDeleteCompleted


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.markers.internal;
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.jface.dialogs.MessageDialog;
20 import org.eclipse.jface.viewers.ISelectionProvider;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.osgi.util.NLS;
23 import org.eclipse.ui.ide.undo.DeleteMarkersOperation;
24 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
25
26 /**
27  * ActionDeleteCompleted is the action for deleting completed markers.
28  *
29  */

30 public class ActionDeleteCompleted extends MarkerSelectionProviderAction {
31
32     private TaskView part;
33
34     /**
35      * Constructs an ActionDeleteCompleted instance
36      *
37      * @param part
38      * @param provider
39      */

40     public ActionDeleteCompleted(TaskView part, ISelectionProvider provider) {
41         super(provider, MarkerMessages.deleteCompletedAction_title);
42         this.part = part;
43         setEnabled(false);
44     }
45
46     /*
47      * (non-Javadoc)
48      *
49      * @see org.eclipse.jface.action.Action#run()
50      */

51     public void run() {
52         final List JavaDoc completed = getCompletedTasks();
53         // Check if there is anything to do
54
if (completed.size() == 0) {
55             MessageDialog.openInformation(part.getSite().getShell(),
56                     MarkerMessages.deleteCompletedTasks_dialogTitle,
57                     MarkerMessages.deleteCompletedTasks_noneCompleted);
58             return;
59         }
60         String JavaDoc message;
61         if (completed.size() == 1) {
62             message = MarkerMessages.deleteCompletedTasks_permanentSingular;
63         } else {
64             message = NLS.bind(
65                     MarkerMessages.deleteCompletedTasks_permanentPlural, String
66                             .valueOf(completed.size()));
67         }
68         // Verify.
69
if (!MessageDialog.openConfirm(part.getSite().getShell(),
70                 MarkerMessages.deleteCompletedTasks_dialogTitle, message)) {
71             return;
72         }
73         IMarker[] markers = (IMarker[]) completed.toArray(new IMarker[completed
74                 .size()]);
75         IUndoableOperation op = new DeleteMarkersOperation(markers, getText());
76         execute(op, MarkerMessages.deleteCompletedTasks_errorMessage, null,
77                 WorkspaceUndoUtil.getUIInfoAdapter(part.getSite().getShell()));
78     }
79
80     private List JavaDoc getCompletedTasks() {
81         List JavaDoc completed = new ArrayList JavaDoc();
82
83         MarkerList markerList = part.getVisibleMarkers();
84
85         ConcreteMarker[] markers = markerList.toArray();
86
87         for (int i = 0; i < markers.length; i++) {
88             ConcreteMarker marker = markers[i];
89             if (marker instanceof TaskMarker) {
90                 TaskMarker taskMarker = (TaskMarker) marker;
91
92                 if (taskMarker.getDone() == 1) {
93                     completed.add(taskMarker.getMarker());
94                 }
95             }
96         }
97
98         return completed;
99     }
100
101     /*
102      * (non-Javadoc)
103      *
104      * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
105      */

106     public void selectionChanged(IStructuredSelection selection) {
107         setEnabled(!selection.isEmpty());
108     }
109
110 }
111
Popular Tags