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.HashMap;
14: import java.util.Iterator;
15: import java.util.Map;
16:
17: import org.eclipse.core.commands.operations.IUndoableOperation;
18: import org.eclipse.core.resources.IMarker;
19: import org.eclipse.jface.viewers.ISelection;
20: import org.eclipse.jface.viewers.IStructuredSelection;
21: import org.eclipse.ui.PlatformUI;
22: import org.eclipse.ui.ide.undo.UpdateMarkersOperation;
23:
24: class MarkCompletedAction extends TaskAction {
25:
26: /**
27: * Create a MarkCompletedAction.
28: * @param tasklist
29: * @param id
30: */
31: protected MarkCompletedAction(TaskList tasklist, String id) {
32: super (tasklist, id);
33: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
34: ITaskListHelpContextIds.MARK_COMPLETED_ACTION);
35: }
36:
37: /**
38: * Sets the completed value of the currently selected
39: * actions.
40: */
41: public void run() {
42: ISelection selectedMarkers = getTaskList().getSelection();
43: if (selectedMarkers instanceof IStructuredSelection) {
44: Iterator selections = ((IStructuredSelection) selectedMarkers)
45: .iterator();
46: ArrayList markers = new ArrayList();
47: while (selections.hasNext()) {
48: Object marker = selections.next();
49: if (marker instanceof IMarker) {
50: markers.add(marker);
51: }
52: }
53: Map attrs = new HashMap();
54: attrs.put(IMarker.DONE, Boolean.TRUE);
55: IUndoableOperation op = new UpdateMarkersOperation(
56: (IMarker[]) markers.toArray(new IMarker[markers
57: .size()]), 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 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: }
|