KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > views > dependencies > OpenDependenciesAction


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.views.dependencies;
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.core.plugin.PluginRegistry;
22 import org.eclipse.ui.IWorkbenchWindow;
23 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
24
25 public class OpenDependenciesAction implements IWorkbenchWindowActionDelegate {
26     private ISelection fSelection;
27     /*
28      * @see IActionDelegate#run(IAction)
29      */

30     public void run(IAction action) {
31         if (fSelection instanceof IStructuredSelection) {
32             IStructuredSelection ssel = (IStructuredSelection) fSelection;
33             openDependencies(ssel.getFirstElement());
34         }
35     }
36
37     private void openDependencies(Object JavaDoc el) {
38         if (el instanceof IFile) {
39             el = ((IFile)el).getProject();
40         }
41         if (el instanceof IJavaProject) {
42             el = ((IJavaProject)el).getProject();
43         }
44         if (el instanceof IProject) {
45             el = PluginRegistry.findModel((IProject) el);
46         }
47         if (el instanceof IPluginObject) {
48             el = ((IPluginObject)el).getModel();
49         }
50         if (el instanceof IPluginModelBase) {
51             new OpenPluginDependenciesAction((IPluginModelBase)el).run();
52         }
53     }
54
55     /*
56      * @see IWorkbenchWindowActionDelegate#dispose()
57      */

58     public void dispose() {
59     }
60
61     /*
62      * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
63      */

64     public void init(IWorkbenchWindow window) {
65     }
66
67     /*
68      * @see IActionDelegate#selectionChanged(IAction, ISelection)
69      */

70     public void selectionChanged(IAction action, ISelection selection) {
71         fSelection = selection;
72     }
73 }
74
Popular Tags