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.markers.internal;
11:
12: import org.eclipse.core.resources.IFile;
13: import org.eclipse.core.resources.IMarker;
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.jface.viewers.ISelectionProvider;
16: import org.eclipse.jface.viewers.IStructuredSelection;
17: import org.eclipse.ui.IEditorPart;
18: import org.eclipse.ui.IWorkbenchPart;
19: import org.eclipse.ui.ide.IDE;
20: import org.eclipse.ui.ide.ResourceUtil;
21:
22: /**
23: * ActionRevealMarker is the action for opening the editor on
24: * a marker.
25: *
26: */
27: public class ActionRevealMarker extends MarkerSelectionProviderAction {
28:
29: protected IWorkbenchPart part;
30:
31: /**
32: * Create a new instance of the receiver.
33: * @param part
34: * @param provider
35: */
36: public ActionRevealMarker(IWorkbenchPart part,
37: ISelectionProvider provider) {
38: super (provider, Util.EMPTY_STRING);
39: this .part = part;
40: }
41:
42: /*
43: * (non-Javadoc)
44: *
45: * @see org.eclipse.jface.action.Action#run()
46: */
47: public void run() {
48:
49: IEditorPart editor = part.getSite().getPage().getActiveEditor();
50: if (editor == null) {
51: return;
52: }
53: IFile file = ResourceUtil.getFile(editor.getEditorInput());
54: if (file != null) {
55: IMarker marker = getSelectedMarker();
56: if (marker.getResource().equals(file)) {
57: try {
58: IDE.openEditor(part.getSite().getPage(), marker,
59: false);
60: } catch (CoreException e) {
61: }
62: }
63: }
64: }
65:
66: /* (non-Javadoc)
67: * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
68: */
69: public void selectionChanged(IStructuredSelection selection) {
70: setEnabled(Util.isSingleConcreteSelection(selection));
71: }
72: }
|