01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 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.pde.internal.ui.editor.feature;
11:
12: import org.eclipse.core.resources.IFile;
13: import org.eclipse.core.resources.IProject;
14: import org.eclipse.core.resources.IResource;
15: import org.eclipse.jface.viewers.ISelectionProvider;
16: import org.eclipse.jface.viewers.IStructuredSelection;
17: import org.eclipse.pde.core.plugin.IPluginBase;
18: import org.eclipse.pde.core.plugin.IPluginModelBase;
19: import org.eclipse.pde.internal.core.feature.FeatureChild;
20: import org.eclipse.pde.internal.core.feature.FeaturePlugin;
21: import org.eclipse.pde.internal.core.ifeature.IFeature;
22: import org.eclipse.pde.internal.core.ifeature.IFeatureChild;
23: import org.eclipse.pde.internal.core.ifeature.IFeatureData;
24: import org.eclipse.pde.internal.ui.PDEPlugin;
25: import org.eclipse.pde.internal.ui.PDEUIMessages;
26: import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
27: import org.eclipse.ui.IWorkbenchPage;
28: import org.eclipse.ui.PartInitException;
29: import org.eclipse.ui.actions.SelectionProviderAction;
30: import org.eclipse.ui.ide.IDE;
31:
32: public class OpenReferenceAction extends SelectionProviderAction {
33: public OpenReferenceAction(ISelectionProvider provider) {
34: super (provider, PDEUIMessages.Actions_open_label);
35: }
36:
37: public void run() {
38: IStructuredSelection sel = (IStructuredSelection) getSelection();
39: Object obj = sel.getFirstElement();
40:
41: if (obj instanceof FeaturePlugin) {
42: IPluginBase base = ((FeaturePlugin) obj).getPluginBase();
43: if (base != null)
44: ManifestEditor.openPluginEditor((IPluginModelBase) base
45: .getModel());
46: } else if (obj instanceof IFeatureData) {
47: IFeatureData data = (IFeatureData) obj;
48: String id = data.getId();
49: IResource resource = data.getModel()
50: .getUnderlyingResource();
51: if (resource != null) {
52: IProject project = resource.getProject();
53: IFile file = project.getFile(id);
54: if (file != null && file.exists()) {
55: IWorkbenchPage page = PDEPlugin.getActivePage();
56: try {
57: IDE.openEditor(page, file, true);
58: } catch (PartInitException e) {
59: }
60: }
61: }
62: } else if (obj instanceof IFeatureChild) {
63: IFeatureChild included = (IFeatureChild) obj;
64: IFeature feature = ((FeatureChild) included)
65: .getReferencedFeature();
66: FeatureEditor.openFeatureEditor(feature);
67: }
68: }
69:
70: public void selectionChanged(IStructuredSelection selection) {
71: setEnabled(!selection.isEmpty());
72: }
73: }
|