1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.commands.operations.IUndoableOperation; 18 import org.eclipse.core.resources.IMarker; 19 import org.eclipse.jface.dialogs.MessageDialog; 20 import org.eclipse.jface.viewers.ISelectionProvider; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.ui.ide.undo.DeleteMarkersOperation; 24 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; 25 26 30 public class ActionDeleteCompleted extends MarkerSelectionProviderAction { 31 32 private TaskView part; 33 34 40 public ActionDeleteCompleted(TaskView part, ISelectionProvider provider) { 41 super(provider, MarkerMessages.deleteCompletedAction_title); 42 this.part = part; 43 setEnabled(false); 44 } 45 46 51 public void run() { 52 final List completed = getCompletedTasks(); 53 if (completed.size() == 0) { 55 MessageDialog.openInformation(part.getSite().getShell(), 56 MarkerMessages.deleteCompletedTasks_dialogTitle, 57 MarkerMessages.deleteCompletedTasks_noneCompleted); 58 return; 59 } 60 String message; 61 if (completed.size() == 1) { 62 message = MarkerMessages.deleteCompletedTasks_permanentSingular; 63 } else { 64 message = NLS.bind( 65 MarkerMessages.deleteCompletedTasks_permanentPlural, String 66 .valueOf(completed.size())); 67 } 68 if (!MessageDialog.openConfirm(part.getSite().getShell(), 70 MarkerMessages.deleteCompletedTasks_dialogTitle, message)) { 71 return; 72 } 73 IMarker[] markers = (IMarker[]) completed.toArray(new IMarker[completed 74 .size()]); 75 IUndoableOperation op = new DeleteMarkersOperation(markers, getText()); 76 execute(op, MarkerMessages.deleteCompletedTasks_errorMessage, null, 77 WorkspaceUndoUtil.getUIInfoAdapter(part.getSite().getShell())); 78 } 79 80 private List getCompletedTasks() { 81 List completed = new ArrayList (); 82 83 MarkerList markerList = part.getVisibleMarkers(); 84 85 ConcreteMarker[] markers = markerList.toArray(); 86 87 for (int i = 0; i < markers.length; i++) { 88 ConcreteMarker marker = markers[i]; 89 if (marker instanceof TaskMarker) { 90 TaskMarker taskMarker = (TaskMarker) marker; 91 92 if (taskMarker.getDone() == 1) { 93 completed.add(taskMarker.getMarker()); 94 } 95 } 96 } 97 98 return completed; 99 } 100 101 106 public void selectionChanged(IStructuredSelection selection) { 107 setEnabled(!selection.isEmpty()); 108 } 109 110 } 111 | Popular Tags |