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.markers.internal;
11:
12: import java.util.HashMap;
13: import java.util.Iterator;
14: import java.util.Map;
15:
16: import org.eclipse.core.commands.operations.IUndoableOperation;
17: import org.eclipse.core.resources.IMarker;
18: import org.eclipse.jface.viewers.ISelectionProvider;
19: import org.eclipse.jface.viewers.IStructuredSelection;
20: import org.eclipse.ui.ide.undo.UpdateMarkersOperation;
21:
22: /**
23: * ActionMarkCompleted is the action for marking task completion.
24: *
25: */
26: public class ActionMarkCompleted extends MarkerSelectionProviderAction {
27:
28: /**
29: * Create a new instance of the reciever.
30: *
31: * @param provider
32: */
33: public ActionMarkCompleted(ISelectionProvider provider) {
34: super (provider, MarkerMessages.markCompletedAction_title);
35: setEnabled(false);
36: }
37:
38: /*
39: * (non-Javadoc)
40: *
41: * @see org.eclipse.jface.action.Action#run()
42: */
43: public void run() {
44: IMarker[] markers = getSelectedMarkers();
45: Map attrs = new HashMap();
46: attrs.put(IMarker.DONE, Boolean.TRUE);
47: IUndoableOperation op = new UpdateMarkersOperation(markers,
48: attrs, getText(), true);
49: execute(op, getText(), null, null);
50:
51: }
52:
53: /*
54: * (non-Javadoc)
55: *
56: * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
57: */
58: public void selectionChanged(IStructuredSelection selection) {
59: setEnabled(false);
60: if (selection == null || selection.isEmpty()) {
61: return;
62: }
63: for (Iterator iterator = selection.iterator(); iterator
64: .hasNext();) {
65: Object obj = iterator.next();
66: if (!(obj instanceof ConcreteMarker)) {
67: return;
68: }
69: IMarker marker = ((ConcreteMarker) obj).getMarker();
70: if (!marker.getAttribute(IMarker.USER_EDITABLE, true)) {
71: return;
72: }
73: if (marker.getAttribute(IMarker.DONE, false)) {
74: return;
75: }
76: }
77: setEnabled(true);
78: }
79: }
|