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.tasklist;
11:
12: import java.util.List;
13:
14: import org.eclipse.core.commands.operations.IUndoableOperation;
15: import org.eclipse.core.resources.IMarker;
16: import org.eclipse.jface.viewers.IStructuredSelection;
17: import org.eclipse.jface.viewers.TableViewer;
18: import org.eclipse.swt.widgets.Table;
19: import org.eclipse.ui.PlatformUI;
20: import org.eclipse.ui.ide.undo.DeleteMarkersOperation;
21: import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
22: import org.eclipse.ui.internal.views.tasklist.TaskListMessages;
23:
24: /**
25: * This action removes the selected task(s) from the task list.
26: * Only tasks can be removed. Problems can only disappear from
27: * the task list when they are fixed in the associated code.
28: */
29: class RemoveTaskAction extends TaskAction {
30:
31: /**
32: * Creates the action.
33: *
34: * @param tasklist the task list
35: * @param id the id
36: */
37: public RemoveTaskAction(TaskList tasklist, String id) {
38: super (tasklist, id);
39: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
40: ITaskListHelpContextIds.REMOVE_TASK_ACTION);
41: }
42:
43: /**
44: * Removes all the tasks in the current selection from the task list.
45: */
46: public void run() {
47: TaskList taskList = getTaskList();
48: TableViewer viewer = taskList.getTableViewer();
49: IStructuredSelection selection = (IStructuredSelection) viewer
50: .getSelection();
51: if (selection.isEmpty()) {
52: return;
53: }
54: taskList.cancelEditing();
55: // get the index of the selected item which has focus
56: Table table = viewer.getTable();
57: int focusIndex = table.getSelectionIndex();
58: List list = selection.toList();
59: IMarker[] markers = new IMarker[list.size()];
60: list.toArray(markers);
61: IUndoableOperation op = new DeleteMarkersOperation(markers,
62: TaskListMessages.RemoveTask_undoText);
63: execute(op, TaskListMessages.RemoveTask_errorMessage, null,
64: WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
65: // set the selection to be the one which took the place of the one with focus
66: int count = table.getItemCount();
67: if (focusIndex < count) {
68: table.setSelection(focusIndex);
69: } else if (count != 0) {
70: table.setSelection(count - 1);
71: }
72: // update the viewer's selection, since setting the table selection does not notify the viewer
73: viewer.setSelection(viewer.getSelection(), true);
74: }
75: }
|