KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.eclipse.core.commands.operations.IUndoableOperation;
20 import org.eclipse.core.resources.IMarker;
21 import org.eclipse.jface.viewers.ISelection;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.ide.undo.UpdateMarkersOperation;
25
26 class MarkCompletedAction extends TaskAction {
27
28     /**
29      * Create a MarkCompletedAction.
30      * @param tasklist
31      * @param id
32      */

33     protected MarkCompletedAction(TaskList tasklist, String JavaDoc id) {
34         super(tasklist, id);
35         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
36                 ITaskListHelpContextIds.MARK_COMPLETED_ACTION);
37     }
38
39     /**
40      * Sets the completed value of the currently selected
41      * actions.
42      */

43     public void run() {
44         ISelection selectedMarkers = getTaskList().getSelection();
45         if (selectedMarkers instanceof IStructuredSelection) {
46             Iterator JavaDoc selections = ((IStructuredSelection) selectedMarkers).iterator();
47             ArrayList JavaDoc markers = new ArrayList JavaDoc();
48             while (selections.hasNext()) {
49                 Object JavaDoc marker = selections.next();
50                 if (marker instanceof IMarker) {
51                     markers.add(marker);
52                 }
53             }
54             Map JavaDoc attrs = new HashMap JavaDoc();
55             attrs.put(IMarker.DONE, Boolean.TRUE);
56             IUndoableOperation op = new UpdateMarkersOperation((IMarker [])markers.toArray(new IMarker [markers.size()]),
57                     attrs, getText(), true);
58             execute(op, getText(), null, null);
59
60         }
61         
62     }
63
64     /**
65      * Returns whether this action should be enabled for the given selection.
66      *
67      * @param selection the selection
68      * @return enablement
69      */

70     public boolean shouldEnable(IStructuredSelection selection) {
71         if (selection.isEmpty()) {
72             return false;
73         }
74         for (Iterator JavaDoc i = selection.iterator(); i.hasNext();) {
75             IMarker marker = (IMarker) i.next();
76             if (!(MarkerUtil.isMarkerType(marker, IMarker.TASK)
77                     && !MarkerUtil.isComplete(marker) && MarkerUtil
78                     .isEditable(marker))) {
79                 return false;
80             }
81         }
82         return true;
83     }
84
85 }
86
Popular Tags