1 11 12 package org.eclipse.ui.views.tasklist; 13 14 import java.util.List ; 15 16 import org.eclipse.core.commands.operations.IUndoableOperation; 17 import org.eclipse.core.resources.IMarker; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.jface.viewers.TableViewer; 20 import org.eclipse.swt.widgets.Table; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.ide.undo.DeleteMarkersOperation; 23 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; 24 import org.eclipse.ui.internal.views.tasklist.TaskListMessages; 25 26 31 class RemoveTaskAction extends TaskAction { 32 33 39 public RemoveTaskAction(TaskList tasklist, String id) { 40 super(tasklist, id); 41 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 42 ITaskListHelpContextIds.REMOVE_TASK_ACTION); 43 } 44 45 48 public void run() { 49 TaskList taskList = getTaskList(); 50 TableViewer viewer = taskList.getTableViewer(); 51 IStructuredSelection selection = (IStructuredSelection) viewer 52 .getSelection(); 53 if (selection.isEmpty()) { 54 return; 55 } 56 taskList.cancelEditing(); 57 Table table = viewer.getTable(); 59 int focusIndex = table.getSelectionIndex(); 60 List list = selection.toList(); 61 IMarker[] markers = new IMarker[list.size()]; 62 list.toArray(markers); 63 IUndoableOperation op = new DeleteMarkersOperation(markers, TaskListMessages.RemoveTask_undoText); 64 execute(op, TaskListMessages.RemoveTask_errorMessage, null, 65 WorkspaceUndoUtil.getUIInfoAdapter(getShell())); 66 int count = table.getItemCount(); 68 if (focusIndex < count) { 69 table.setSelection(focusIndex); 70 } else if (count != 0) { 71 table.setSelection(count - 1); 72 } 73 viewer.setSelection(viewer.getSelection(), true); 75 } 76 } 77 | Popular Tags |