KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > ActionRevealMarker


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.markers.internal;
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jface.viewers.ISelectionProvider;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IWorkbenchPart;
21 import org.eclipse.ui.ide.IDE;
22 import org.eclipse.ui.ide.ResourceUtil;
23
24 /**
25  * ActionRevealMarker is the action for opening the editor on
26  * a marker.
27  *
28  */

29 public class ActionRevealMarker extends MarkerSelectionProviderAction {
30
31     protected IWorkbenchPart part;
32
33     /**
34      * Create a new instance of the receiver.
35      * @param part
36      * @param provider
37      */

38     public ActionRevealMarker(IWorkbenchPart part, ISelectionProvider provider) {
39         super(provider, Util.EMPTY_STRING);
40         this.part = part;
41     }
42
43     /*
44      * (non-Javadoc)
45      *
46      * @see org.eclipse.jface.action.Action#run()
47      */

48     public void run() {
49         
50         IEditorPart editor = part.getSite().getPage().getActiveEditor();
51         if (editor == null) {
52             return;
53         }
54         IFile file = ResourceUtil.getFile(editor.getEditorInput());
55         if (file != null) {
56             IMarker marker = getSelectedMarker();
57             if (marker.getResource().equals(file)) {
58                 try {
59                     IDE.openEditor(part.getSite().getPage(),
60                             marker, false);
61                 } catch (CoreException e) {
62                 }
63             }
64         }
65     }
66
67     /* (non-Javadoc)
68      * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
69      */

70     public void selectionChanged(IStructuredSelection selection) {
71         setEnabled(Util.isSingleConcreteSelection(selection));
72     }
73 }
74
Popular Tags