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 org.eclipse.core.resources.IFile;
13: import org.eclipse.core.resources.IMarker;
14: import org.eclipse.core.resources.IResource;
15: import org.eclipse.jface.util.OpenStrategy;
16: import org.eclipse.jface.viewers.IStructuredSelection;
17: import org.eclipse.ui.IWorkbenchPage;
18: import org.eclipse.ui.PartInitException;
19: import org.eclipse.ui.PlatformUI;
20: import org.eclipse.ui.ide.IDE;
21: import org.eclipse.ui.internal.ide.DialogUtil;
22: import org.eclipse.ui.internal.views.tasklist.TaskListMessages;
23:
24: /**
25: * This action opens an editor for the resource
26: * associated with the selected marker, and
27: * jumps to the marker's location in the editor.
28: */
29: class GotoTaskAction extends TaskAction {
30:
31: /**
32: * Creates the action.
33: *
34: * @param tasklist the task list
35: * @param id the id
36: */
37: public GotoTaskAction(TaskList tasklist, String id) {
38: super (tasklist, id);
39: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
40: ITaskListHelpContextIds.GOTO_TASK_ACTION);
41: }
42:
43: /**
44: * Performs this action. This action works only for single selection.
45: */
46: public void run() {
47: IStructuredSelection selection = (IStructuredSelection) getTaskList()
48: .getSelection();
49: Object o = selection.getFirstElement();
50: if (!(o instanceof IMarker)) {
51: return;
52: }
53: IMarker marker = (IMarker) o;
54: IResource resource = marker.getResource();
55: if (marker.exists() && resource instanceof IFile) {
56: IWorkbenchPage page = getTaskList().getSite().getPage();
57: try {
58: IDE.openEditor(page, marker, OpenStrategy
59: .activateOnOpen());
60: } catch (PartInitException e) {
61: DialogUtil.openError(page.getWorkbenchWindow()
62: .getShell(),
63: TaskListMessages.GotoTask_errorMessage, e
64: .getMessage(), e);
65: }
66: }
67: }
68: }
|