1 11 12 package org.eclipse.ui.views.tasklist; 13 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.Map ; 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 33 protected MarkCompletedAction(TaskList tasklist, String id) { 34 super(tasklist, id); 35 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 36 ITaskListHelpContextIds.MARK_COMPLETED_ACTION); 37 } 38 39 43 public void run() { 44 ISelection selectedMarkers = getTaskList().getSelection(); 45 if (selectedMarkers instanceof IStructuredSelection) { 46 Iterator selections = ((IStructuredSelection) selectedMarkers).iterator(); 47 ArrayList markers = new ArrayList (); 48 while (selections.hasNext()) { 49 Object marker = selections.next(); 50 if (marker instanceof IMarker) { 51 markers.add(marker); 52 } 53 } 54 Map attrs = new HashMap (); 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 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 } 86 | Popular Tags |