KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > view > OpenDependenciesAction


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 package org.eclipse.pde.internal.ui.view;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.jdt.core.IJavaProject;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.pde.core.plugin.IPluginModelBase;
20 import org.eclipse.pde.core.plugin.IPluginObject;
21 import org.eclipse.pde.internal.core.PDECore;
22 import org.eclipse.pde.internal.ui.IPDEUIConstants;
23 import org.eclipse.pde.internal.ui.PDEPlugin;
24 import org.eclipse.ui.IViewPart;
25 import org.eclipse.ui.IWorkbenchPage;
26 import org.eclipse.ui.IWorkbenchWindow;
27 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
28 import org.eclipse.ui.PartInitException;
29
30 public class OpenDependenciesAction implements IWorkbenchWindowActionDelegate {
31     private ISelection fSelection;
32     /*
33      * @see IActionDelegate#run(IAction)
34      */

35     public void run(IAction action) {
36         if (fSelection instanceof IStructuredSelection) {
37             IStructuredSelection ssel = (IStructuredSelection) fSelection;
38             openDependencies(ssel.getFirstElement());
39         }
40     }
41
42     private void openDependencies(Object JavaDoc el) {
43         if (el instanceof IFile) {
44             el = ((IFile)el).getProject();
45         }
46         if (el instanceof IJavaProject) {
47             el = ((IJavaProject)el).getProject();
48         }
49         if (el instanceof IProject) {
50             el = PDECore.getDefault().getModelManager().findModel((IProject) el);
51         }
52         if (el instanceof IPluginObject) {
53             el = ((IPluginObject)el).getModel();
54         }
55         if (el instanceof IPluginModelBase) {
56             openDependencies((IPluginModelBase)el);
57         }
58     }
59     
60     public static void openDependencies(IPluginModelBase model) {
61         IWorkbenchPage page = PDEPlugin.getActivePage();
62         try {
63             IViewPart view = page.showView(IPDEUIConstants.DEPENDENCIES_VIEW_ID);
64             ((DependenciesView)view).openTo(model);
65         }
66         catch (PartInitException e) {
67             PDEPlugin.logException(e);
68         }
69     }
70
71     /*
72      * @see IWorkbenchWindowActionDelegate#dispose()
73      */

74     public void dispose() {
75     }
76
77     /*
78      * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
79      */

80     public void init(IWorkbenchWindow window) {
81     }
82
83     /*
84      * @see IActionDelegate#selectionChanged(IAction, ISelection)
85      */

86     public void selectionChanged(IAction action, ISelection selection) {
87         fSelection = selection;
88     }
89 }
90
Popular Tags