| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation; |
| 2 | |
| 3 | import org.apache.log4j.Logger; |
| 4 | import org.eclipse.jface.action.IAction; |
| 5 | import org.eclipse.jface.dialogs.MessageDialog; |
| 6 | import org.eclipse.jface.viewers.ISelection; |
| 7 | import org.eclipse.ui.IWorkbenchPage; |
| 8 | import org.eclipse.ui.IWorkbenchWindow; |
| 9 | import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
| 10 | import org.eclipse.ui.PartInitException; |
| 11 | |
| 12 | import de.uka.ipd.sdq.sensorframework.visualisation.editor.ConfigEditorInput; |
| 13 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.utils.RConnection; |
| 14 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.views.TimeSeriesHtmlReportView; |
| 15 | |
| 16 | /** |
| 17 | * Our sample action implements workbench action delegate. |
| 18 | * The action proxy will be created by the workbench and |
| 19 | * shown in the UI. When the user tries to use the action, |
| 20 | * this delegate will be created and execution will be |
| 21 | * delegated to it. |
| 22 | * @see IWorkbenchWindowActionDelegate |
| 23 | */ |
| 24 | public class OpenRReportAction implements IWorkbenchWindowActionDelegate { |
| 25 | /** The logger used by this class. */ |
| 26 | private static Logger logger = |
| 27 | Logger.getLogger(RConnection.class.getName()); |
| 28 | |
| 29 | /** The parent window. Used to display message boxes. */ |
| 30 | private IWorkbenchWindow parentWorkbenchWindow; |
| 31 | |
| 32 | /** Identifier of the factory responsible for creating data adapters. */ |
| 33 | private String adapterFactoryID; |
| 34 | |
| 35 | /**Initializes a new report. |
| 36 | * @param adapterFactoryID The identifier for the factory that is |
| 37 | * responsible for creating data adapters. |
| 38 | */ |
| 39 | public OpenRReportAction(final String adapterFactoryID) { |
| 40 | this.adapterFactoryID = adapterFactoryID; |
| 41 | } |
| 42 | |
| 43 | /** {@inheritDoc} |
| 44 | */ |
| 45 | public void run(final IAction action) { |
| 46 | /* |
| 47 | * The action has been activated. The argument of the |
| 48 | * method represents the 'real' action sitting |
| 49 | * in the workbench UI. |
| 50 | * @see IWorkbenchWindowActionDelegate#run |
| 51 | */ |
| 52 | IWorkbenchPage page = RVisualisationPlugin.getDefault().getWorkbench() |
| 53 | .getActiveWorkbenchWindow().getActivePage(); |
| 54 | |
| 55 | try { |
| 56 | page.openEditor(new ConfigEditorInput(adapterFactoryID), |
| 57 | TimeSeriesHtmlReportView.RREPORTVIEW_ID); |
| 58 | } catch (PartInitException e) { |
| 59 | logger.error("Could not generate R report for the ID " |
| 60 | + TimeSeriesHtmlReportView.RREPORTVIEW_ID + " and data " |
| 61 | + "adapter factory " |
| 62 | + "with ID " + adapterFactoryID + ".", e); |
| 63 | MessageDialog.openError(parentWorkbenchWindow.getShell(), "Could " |
| 64 | + "not generate R report", |
| 65 | "The R report for the ID " |
| 66 | + TimeSeriesHtmlReportView.RREPORTVIEW_ID |
| 67 | + " and data adapter factory " + "with ID " |
| 68 | + adapterFactoryID + "could not be generated. Details were" |
| 69 | + " written to the logfile."); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** {@inheritDoc} |
| 74 | */ |
| 75 | public void selectionChanged(final IAction action, |
| 76 | final ISelection selection) { |
| 77 | /* |
| 78 | * Selection in the workbench has been changed. We |
| 79 | * can change the state of the 'real' action here |
| 80 | * if we want, but this can only happen after |
| 81 | * the delegate has been created. |
| 82 | * @see IWorkbenchWindowActionDelegate#selectionChanged |
| 83 | */ |
| 84 | |
| 85 | // Nothing to do |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * We can use this method to dispose of any system |
| 90 | * resources we previously allocated. |
| 91 | * @see IWorkbenchWindowActionDelegate#dispose |
| 92 | * {@inheritDoc} |
| 93 | */ |
| 94 | public void dispose() { |
| 95 | } |
| 96 | |
| 97 | /** {@inheritDoc} |
| 98 | */ |
| 99 | public void init(final IWorkbenchWindow parentWindow) { |
| 100 | /* |
| 101 | * We will cache window object in order to |
| 102 | * be able to provide parent shell for the message dialog. |
| 103 | * @see IWorkbenchWindowActionDelegate#init |
| 104 | */ |
| 105 | parentWorkbenchWindow = parentWindow; |
| 106 | } |
| 107 | } |