01: /*******************************************************************************
02: * Copyright (c) 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: * Chris Aniszczyk <zx@us.ibm.com> - initial API and implementation
10: * Marcelo Paternostro <marcelop@ca.ibm.com> - bug 201105
11: *******************************************************************************/package org.eclipse.pde.internal.runtime.spy;
12:
13: import org.eclipse.core.resources.IResource;
14: import org.eclipse.jdt.core.IJavaProject;
15: import org.eclipse.jdt.core.IType;
16: import org.eclipse.jdt.core.JavaCore;
17: import org.eclipse.jdt.core.JavaModelException;
18: import org.eclipse.jdt.ui.JavaUI;
19: import org.eclipse.pde.core.plugin.IPluginModelBase;
20: import org.eclipse.pde.core.plugin.PluginRegistry;
21: import org.eclipse.pde.internal.core.PDECore;
22: import org.eclipse.pde.internal.core.SearchablePluginsManager;
23: import org.eclipse.ui.PartInitException;
24:
25: public class SpyIDEUtil {
26: public static void openClass(String pluginId, String clazz) {
27: IPluginModelBase model = PluginRegistry.findModel(pluginId);
28: IResource resource = model != null ? model
29: .getUnderlyingResource() : null;
30: IJavaProject project;
31: if (resource != null) { // project is open in workspace
32: project = JavaCore.create(resource.getProject());
33: } else {
34: SearchablePluginsManager manager = PDECore.getDefault()
35: .getSearchablePluginsManager();
36: project = manager.getProxyProject();
37: manager.addToJavaSearch(new IPluginModelBase[] { model });
38: }
39: if (project != null)
40: openInEditor(project, clazz);
41: }
42:
43: public static void openInEditor(IJavaProject project, String clazz) {
44: try {
45: IType type = project.findType(clazz);
46: JavaUI.openInEditor(type, false, true);
47: } catch (JavaModelException e1) {
48: e1.printStackTrace();
49: } catch (PartInitException e1) {
50: e1.printStackTrace();
51: }
52: }
53:
54: }
|