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.views.dependencies;
11:
12: import org.eclipse.core.resources.IFile;
13: import org.eclipse.core.resources.IProject;
14: import org.eclipse.jdt.core.IJavaProject;
15: import org.eclipse.jface.action.IAction;
16: import org.eclipse.jface.viewers.ISelection;
17: import org.eclipse.jface.viewers.IStructuredSelection;
18: import org.eclipse.pde.core.plugin.IPluginModelBase;
19: import org.eclipse.pde.core.plugin.IPluginObject;
20: import org.eclipse.pde.core.plugin.PluginRegistry;
21: import org.eclipse.ui.IWorkbenchWindow;
22: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
23:
24: public class OpenDependenciesAction implements
25: IWorkbenchWindowActionDelegate {
26: private ISelection fSelection;
27:
28: /*
29: * @see IActionDelegate#run(IAction)
30: */
31: public void run(IAction action) {
32: if (fSelection instanceof IStructuredSelection) {
33: IStructuredSelection ssel = (IStructuredSelection) fSelection;
34: openDependencies(ssel.getFirstElement());
35: }
36: }
37:
38: private void openDependencies(Object el) {
39: if (el instanceof IFile) {
40: el = ((IFile) el).getProject();
41: }
42: if (el instanceof IJavaProject) {
43: el = ((IJavaProject) el).getProject();
44: }
45: if (el instanceof IProject) {
46: el = PluginRegistry.findModel((IProject) el);
47: }
48: if (el instanceof IPluginObject) {
49: el = ((IPluginObject) el).getModel();
50: }
51: if (el instanceof IPluginModelBase) {
52: new OpenPluginDependenciesAction((IPluginModelBase) el)
53: .run();
54: }
55: }
56:
57: /*
58: * @see IWorkbenchWindowActionDelegate#dispose()
59: */
60: public void dispose() {
61: }
62:
63: /*
64: * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
65: */
66: public void init(IWorkbenchWindow window) {
67: }
68:
69: /*
70: * @see IActionDelegate#selectionChanged(IAction, ISelection)
71: */
72: public void selectionChanged(IAction action, ISelection selection) {
73: fSelection = selection;
74: }
75: }
|