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.JavaModelException;
30  import org.eclipse.jface.action.IAction;
31  import org.eclipse.ui.IEditorActionDelegate;
32  import org.eclipse.ui.IEditorInput;
33  import org.eclipse.ui.IEditorPart;
34  import org.eclipse.ui.actions.ActionDelegate;
35  
36  /**
37   * Inspect the current file active in the editor.
38   */
39  public class InspectFileAction extends ActionDelegate
40    implements IEditorActionDelegate {
41    /** The editor target. */
42    private IEditorPart editor;
43  
44    /**
45     * Create a new EditorPopupAction object.
46     */
47    public InspectFileAction() {
48      super();
49    }
50  
51    /**
52     * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
53     */
54    public void setActiveEditor(IAction action, IEditorPart targetEditor) {
55      editor = targetEditor;
56    }
57  
58    /**
59     * @see org.eclipse.ui.actions.ActionDelegate#run(org.eclipse.jface.action.IAction)
60     */
61    public void run(IAction action) {
62      if (editor.isDirty() && editor.isSaveAsAllowed()) {
63        editor.doSave(null);
64      }
65  
66      final IJavaElement javaElement = getJavaElement();
67      final Vector files = new Vector();
68      final Project qstudioProject =
69        EclipseEnvironment.toQSJavaProject(javaElement.getJavaProject());
70  
71      try {
72        EclipseEnvironment.getJavaFileFromJavaElement(javaElement, files);
73      } catch (JavaModelException e) {
74        new DebugWriter().writeException(e, this);
75      }
76  
77      //    if ( OS.isWindows() ) {
78      //      ExternalAnalyzer analyzer = new ExternalAnalyzer(project, files);
79      //      analyzer.setObservationView(observationView);
80      //      analyzer.runAnalyzerThread();
81      //    } else {
82      new EclipseAnalyzer(qstudioProject, files);
83  
84      //}
85    }
86  
87    private IJavaElement getJavaElement() {
88      final IEditorInput input = editor.getEditorInput();
89      final IJavaElement je = (IJavaElement) input.getAdapter(IJavaElement.class);
90  
91      return (je);
92    }
93  }
94