1   /**
2    * QJ-Pro
3    * Copyright (c) 2004, http://qjpro.sourceforge.net
4    *
5    * This program is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License as published by the
7    * Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful, but WITHOUT
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13   * details.
14   *
15   * You should have received a copy of the GNU General Public License along with
16   * this program; if not, write to the Free Software Foundation, Inc.,
17   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18   */
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.jdt.core.IJavaElement;
29  import org.eclipse.jdt.core.IJavaProject;
30  import org.eclipse.jdt.core.JavaModelException;
31  import org.eclipse.jface.action.IAction;
32  import org.eclipse.ui.IEditorActionDelegate;
33  import org.eclipse.ui.IEditorInput;
34  import org.eclipse.ui.IEditorPart;
35  import org.eclipse.ui.actions.ActionDelegate;
36  
37  /**
38   * This class implements the 'Inspect project' action which can
39   * be invoked in the QStudio main menu.
40   */
41  public class InspectProjectAction extends ActionDelegate
42    implements IEditorActionDelegate {
43    /** The editor target. */
44    private IEditorPart editor;
45  
46    /**
47     * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
48     */
49    public void setActiveEditor(IAction action, IEditorPart targetEditor) {
50      editor = targetEditor;
51    }
52  
53    /**
54     * @see org.eclipse.ui.actions.ActionDelegate#run(org.eclipse.jface.action.IAction)
55     */
56    public void run(IAction action) {
57      final IJavaProject ideProject = getJavaElement().getJavaProject();
58      final Vector files = new Vector();
59      final Project qstudioProject =
60        EclipseEnvironment.toQSJavaProject(ideProject);
61  
62      try {
63        EclipseEnvironment.getJavaFilesFromProject(ideProject, files);
64      } catch (JavaModelException e) {
65        new DebugWriter().writeException(e, this);
66      }
67  
68      //    if ( OS.isWindows() ) {
69      //      ExternalAnalyzer analyzer = new ExternalAnalyzer(project, files);
70      //      analyzer.s  etObservationView(observationView);
71      //      analyzer.runAnalyzerThread();
72      //    } else {
73      new EclipseAnalyzer(qstudioProject, files);
74  
75      //}
76    }
77  
78    private IJavaElement getJavaElement() {
79      final IEditorInput input = editor.getEditorInput();
80      final IJavaElement je = (IJavaElement) input.getAdapter(IJavaElement.class);
81  
82      return (je);
83    }
84  }
85