1
19 package com.qasystems.qstudio.java.integration.eclipse.actions;
20
21 import com.qasystems.debug.DebugWriter;
22 import com.qasystems.qstudio.java.gui.Project;
23 import com.qasystems.qstudio.java.integration.eclipse.EclipseAnalyzer;
24 import com.qasystems.qstudio.java.integration.eclipse.EclipseEnvironment;
25
26 import java.util.Vector;
27
28 import org.eclipse.core.resources.IFile;
29 import org.eclipse.core.resources.IResource;
30 import org.eclipse.core.runtime.CoreException;
31 import org.eclipse.jdt.core.ICompilationUnit;
32 import org.eclipse.jdt.core.IJavaProject;
33 import org.eclipse.jdt.core.IPackageFragment;
34 import org.eclipse.jdt.core.JavaCore;
35 import org.eclipse.jface.action.IAction;
36 import org.eclipse.jface.viewers.ISelection;
37 import org.eclipse.jface.viewers.ISelectionProvider;
38 import org.eclipse.jface.viewers.StructuredSelection;
39 import org.eclipse.ui.IObjectActionDelegate;
40 import org.eclipse.ui.IWorkbenchPage;
41 import org.eclipse.ui.IWorkbenchPart;
42 import org.eclipse.ui.IWorkbenchPartSite;
43 import org.eclipse.ui.actions.ActionDelegate;
44
45
49 public class InspectAction extends ActionDelegate
50 implements IObjectActionDelegate {
51
52 private IWorkbenchPage page;
53
54
55 private IWorkbenchPart part;
56
57
63 public void setActivePart(IAction iAction, IWorkbenchPart iWorkbenchPart) {
64 part = iWorkbenchPart;
65 page = part.getSite().getPage();
66 }
67
68
71 public void selectionChanged(IAction action, ISelection selection) {
72 }
73
74
77 public void run(final IAction action) {
78 final IWorkbenchPartSite site = part.getSite();
79 final ISelectionProvider provider = site.getSelectionProvider();
80 final StructuredSelection selection =
81 (StructuredSelection) provider.getSelection();
82 final Vector files = new Vector();
83
84 retrieveJavaMembers(selection, files);
85
86 if (files.size() > 0) {
87 final IFile file = (IFile) files.get(0);
88 final Project project =
89 EclipseEnvironment.toQSJavaProject(
90 JavaCore.create(file).getJavaProject()
91 );
92
93 new EclipseAnalyzer(project, files);
99
100 }
102 }
103
104 private void retrieveJavaMembers(
105 final StructuredSelection selection, Vector files
106 ) {
107 final Object[] items = selection.toArray();
108
109 try {
110 for (int i = 0; i < items.length; i++) {
111 if (items[i] instanceof IResource) {
112 EclipseEnvironment.getJavaFilesFromResource(
113 (IResource) items[i], files
114 );
115 } else if (items[i] instanceof ICompilationUnit) {
116 EclipseEnvironment.getJavaFilesFromCompilationUnit(
117 (ICompilationUnit) items[i], files
118 );
119 } else if (items[i] instanceof IPackageFragment) {
120 EclipseEnvironment.getJavaFilesFromPackage(
121 (IPackageFragment) items[i], files
122 );
123 } else if (items[i] instanceof IJavaProject) {
124 EclipseEnvironment.getJavaFilesFromProject(
125 (IJavaProject) items[i], files
126 );
127 }
128 }
129 } catch (CoreException e) {
130 new DebugWriter().writeException(e, this);
131 }
132 }
133 }
134