KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > tasklist > GotoTaskAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.tasklist;
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.jface.util.OpenStrategy;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.ui.IWorkbenchPage;
20 import org.eclipse.ui.PartInitException;
21 import org.eclipse.ui.PlatformUI;
22 import org.eclipse.ui.ide.IDE;
23 import org.eclipse.ui.internal.ide.DialogUtil;
24 import org.eclipse.ui.internal.views.tasklist.TaskListMessages;
25
26 /**
27  * This action opens an editor for the resource
28  * associated with the selected marker, and
29  * jumps to the marker's location in the editor.
30  */

31 class GotoTaskAction extends TaskAction {
32
33     /**
34      * Creates the action.
35      *
36      * @param tasklist the task list
37      * @param id the id
38      */

39     public GotoTaskAction(TaskList tasklist, String JavaDoc id) {
40         super(tasklist, id);
41         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
42                 ITaskListHelpContextIds.GOTO_TASK_ACTION);
43     }
44
45     /**
46      * Performs this action. This action works only for single selection.
47      */

48     public void run() {
49         IStructuredSelection selection = (IStructuredSelection) getTaskList()
50                 .getSelection();
51         Object JavaDoc o = selection.getFirstElement();
52         if (!(o instanceof IMarker)) {
53             return;
54         }
55         IMarker marker = (IMarker) o;
56         IResource resource = marker.getResource();
57         if (marker.exists() && resource instanceof IFile) {
58             IWorkbenchPage page = getTaskList().getSite().getPage();
59             try {
60                 IDE.openEditor(page, marker, OpenStrategy.activateOnOpen());
61             } catch (PartInitException e) {
62                 DialogUtil.openError(page.getWorkbenchWindow().getShell(),
63                         TaskListMessages.GotoTask_errorMessage,
64                         e.getMessage(), e);
65             }
66         }
67     }
68 }
69
Popular Tags