KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.eclipse.core.commands.operations.IUndoableOperation;
19 import org.eclipse.core.resources.IMarker;
20 import org.eclipse.jface.viewers.ISelectionProvider;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.ui.ide.undo.UpdateMarkersOperation;
23
24 /**
25  * ActionMarkCompleted is the action for marking task completion.
26  *
27  */

28 public class ActionMarkCompleted extends MarkerSelectionProviderAction {
29
30     /**
31      * Create a new instance of the reciever.
32      *
33      * @param provider
34      */

35     public ActionMarkCompleted(ISelectionProvider provider) {
36         super(provider, MarkerMessages.markCompletedAction_title);
37         setEnabled(false);
38     }
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see org.eclipse.jface.action.Action#run()
44      */

45     public void run() {
46         IMarker[] markers = getSelectedMarkers();
47         Map JavaDoc attrs = new HashMap JavaDoc();
48         attrs.put(IMarker.DONE, Boolean.TRUE);
49         IUndoableOperation op = new UpdateMarkersOperation(markers, attrs,
50                 getText(), true);
51         execute(op, getText(), null, null);
52
53     }
54
55     /*
56      * (non-Javadoc)
57      *
58      * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
59      */

60     public void selectionChanged(IStructuredSelection selection) {
61         setEnabled(false);
62         if (selection == null || selection.isEmpty()) {
63             return;
64         }
65         for (Iterator JavaDoc iterator = selection.iterator(); iterator.hasNext();) {
66             Object JavaDoc obj = iterator.next();
67             if (!(obj instanceof ConcreteMarker)) {
68                 return;
69             }
70             IMarker marker = ((ConcreteMarker) obj).getMarker();
71             if (!marker.getAttribute(IMarker.USER_EDITABLE, true)) {
72                 return;
73             }
74             if (marker.getAttribute(IMarker.DONE, false)) {
75                 return;
76             }
77         }
78         setEnabled(true);
79     }
80 }
81
Popular Tags