KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > OpenReferenceAction


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