1
19 package com.qasystems.qstudio.java.integration.eclipse.actions;
20
21 import com.qasystems.debug.DebugWriter;
22 import com.qasystems.qstudio.java.gui.ComplianceView;
23 import com.qasystems.qstudio.java.gui.ProjectMember;
24 import com.qasystems.qstudio.java.integration.eclipse.EclipseEnvironment;
25 import com.qasystems.qstudio.java.integration.eclipse.EclipseProjectMember;
26
27 import org.eclipse.jdt.core.IJavaElement;
28 import org.eclipse.jface.action.IAction;
29 import org.eclipse.jface.viewers.ISelectionProvider;
30 import org.eclipse.jface.viewers.StructuredSelection;
31 import org.eclipse.ui.IEditorActionDelegate;
32 import org.eclipse.ui.IEditorPart;
33 import org.eclipse.ui.IObjectActionDelegate;
34 import org.eclipse.ui.IWorkbenchPage;
35 import org.eclipse.ui.IWorkbenchPart;
36 import org.eclipse.ui.IWorkbenchPartSite;
37 import org.eclipse.ui.actions.ActionDelegate;
38
39 public class ComplianceViewAction extends ActionDelegate
40 implements IObjectActionDelegate, IEditorActionDelegate {
41 private IEditorPart editor;
42 private IWorkbenchPart part;
43 private IWorkbenchPage page;
44
45
51 public void setActivePart(IAction iAction, IWorkbenchPart iWorkbenchPart) {
52 part = iWorkbenchPart;
53 page = part.getSite().getPage();
54 editor = null;
55 }
56
57
60 public void setActiveEditor(IAction action, IEditorPart targetEditor) {
61 editor = targetEditor;
62 part = null;
63 page = null;
64 }
65
66
69 public void run(final IAction action) {
70 try {
71 IJavaElement element = null;
72
73 if (part != null) {
74 final IWorkbenchPartSite site = part.getSite();
75 final ISelectionProvider provider = site.getSelectionProvider();
76 final StructuredSelection selection =
77 (StructuredSelection) provider.getSelection();
78 final Object object = selection.getFirstElement();
79
80 if (object instanceof IJavaElement) {
81 element = (IJavaElement) object;
82 }
83 } else if (editor != null) {
84 element = EclipseEnvironment.getJavaElement(editor);
85 } else {
86 element = null;
87 }
88
89 openComplianceView(element);
90 } catch (Exception e) {
91 e.printStackTrace();
92 }
93 }
94
95 private void openComplianceView(IJavaElement element) {
96 if (element != null) {
97 try {
98 final ProjectMember member = new EclipseProjectMember(element);
99
100 new ComplianceView(member).openComplianceView();
101 } catch (Exception e) {
102 new DebugWriter().writeException(e, this);
103 }
104 }
105 }
106 }
107