Search in sources :

Example 1 with LamiAnalysisReport

use of org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisReport in project tracecompass by tracecompass.

the class LamiReportView method createPartControl.

// ------------------------------------------------------------------------
// ViewPart
// ------------------------------------------------------------------------
@Override
public void createPartControl(@Nullable Composite parent) {
    LamiAnalysisReport report = fReport;
    if (report == null || parent == null) {
        return;
    }
    setPartName(report.getName());
    fTabFolder = new CTabFolder(parent, SWT.NONE);
    fTabFolder.setSimple(false);
    for (LamiResultTable table : report.getTables()) {
        String name = table.getTableClass().getTableTitle();
        CTabItem tabItem = new CTabItem(fTabFolder, SWT.NULL);
        tabItem.setText(name);
        SashForm sf = new SashForm(fTabFolder, SWT.NONE);
        fTabPages.add(new LamiReportViewTabPage(sf, table));
        tabItem.setControl(sf);
    }
    /* Add toolbar buttons */
    Action toggleTableAction = new ToggleTableAction();
    toggleTableAction.setText(Messages.LamiReportView_ActivateTableAction_ButtonName);
    toggleTableAction.setToolTipText(Messages.LamiReportView_ActivateTableAction_ButtonTooltip);
    // $NON-NLS-1$
    toggleTableAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath("icons/table.gif"));
    IActionBars actionBars = getViewSite().getActionBars();
    IToolBarManager toolbarMgr = actionBars.getToolBarManager();
    toolbarMgr.add(toggleTableAction);
    fNewChartAction.setText(Messages.LamiReportView_NewCustomChart);
    fClearCustomViewsAction.setText(Messages.LamiReportView_ClearAllCustomViews);
    IMenuManager menuMgr = actionBars.getMenuManager();
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener((@Nullable IMenuManager manager) -> {
        if (manager != null) {
            populateMenu(manager);
        }
    });
    populateMenu(menuMgr);
    /* Select the first tab initially */
    CTabFolder tf = checkNotNull(fTabFolder);
    if (tf.getItemCount() > 0) {
        tf.setSelection(0);
    }
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ExportToTsvAction(org.eclipse.tracecompass.internal.tmf.ui.commands.ExportToTsvAction) CTabFolder(org.eclipse.swt.custom.CTabFolder) CTabItem(org.eclipse.swt.custom.CTabItem) SashForm(org.eclipse.swt.custom.SashForm) IToolBarManager(org.eclipse.jface.action.IToolBarManager) LamiResultTable(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiResultTable) LamiAnalysisReport(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisReport) IMenuManager(org.eclipse.jface.action.IMenuManager) IActionBars(org.eclipse.ui.IActionBars) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with LamiAnalysisReport

use of org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisReport in project tracecompass by tracecompass.

the class RunAnalysisHandler method execute.

@Override
@Nullable
public Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
    /* Types should have been checked by the plugin.xml already */
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    Object element = ((IStructuredSelection) selection).getFirstElement();
    final TmfOnDemandAnalysisElement analysisElem = (TmfOnDemandAnalysisElement) element;
    TmfCommonProjectElement traceElem = analysisElem.getParent().getParent();
    ITmfTrace trace = traceElem.getTrace();
    if (trace == null) {
        /* That trace is not currently opened */
        return null;
    }
    /* Retrieve and initialize the analysis module, aka read the script's metadata */
    IOnDemandAnalysis ondemandAnalysis = analysisElem.getAnalysis();
    if (!(ondemandAnalysis instanceof LamiAnalysis)) {
        return null;
    }
    LamiAnalysis analysis = (LamiAnalysis) ondemandAnalysis;
    /* Retrieve the current time range, will be used as parameters to the analysis */
    TmfTraceManager tm = TmfTraceManager.getInstance();
    TmfTimeRange timeRange = tm.getCurrentTraceContext().getSelectionRange();
    if (timeRange.getStartTime().equals(timeRange.getEndTime())) {
        timeRange = null;
    }
    /* Job below needs a final reference... */
    final TmfTimeRange tr = timeRange;
    /* Pop the dialog to ask for extra parameters */
    String baseCommand = analysis.getFullCommandAsString(trace, tr);
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    ParameterDialog dialog = new ParameterDialog(shell, Messages.ParameterDialog_ExternalParameters, Messages.ParameterDialog_ExternalParametersDescription, baseCommand, null);
    if (dialog.open() != Window.OK) {
        /* User clicked Cancel, don't run */
        return null;
    }
    String extraParams = nullToEmptyString(dialog.getValue());
    /* Execute the analysis and produce the reports */
    Job job = new Job(Messages.LamiAnalysis_MainTaskName) {

        @Override
        @Nullable
        protected IStatus run(@Nullable IProgressMonitor monitor) {
            IProgressMonitor mon = (monitor == null ? new NullProgressMonitor() : monitor);
            try {
                List<LamiResultTable> results = analysis.execute(trace, tr, extraParams, mon);
                String reportName = analysis.getName() + ' ' + Messages.ParameterDialog_ReportNameSuffix;
                LamiAnalysisReport report = new LamiAnalysisReport(reportName, results);
                registerNewReport(analysisElem, report);
                /* Automatically open the report for convenience */
                Display.getDefault().syncExec(() -> {
                    try {
                        LamiReportViewFactory.createNewView(report);
                    } catch (PartInitException e) {
                    }
                });
                return Status.OK_STATUS;
            } catch (CoreException e) {
                /*
                     * The analysis execution did not complete normally, we will
                     * report it to the user.
                     */
                IStatus status = e.getStatus();
                /* Don't display a dialog if it was simply cancelled by the user */
                if (status.matches(IStatus.CANCEL)) {
                    return status;
                }
                String dialogTitle;
                String dialogMessage;
                if (status.matches(IStatus.ERROR)) {
                    dialogTitle = Messages.ErrorDialog_Error;
                    dialogMessage = Messages.ErrorDialog_ErrorMessage;
                } else {
                    dialogTitle = Messages.ErrorDialog_Info;
                    dialogMessage = Messages.ErrorDialog_InfoMessage;
                }
                Display.getDefault().asyncExec(() -> {
                    ErrorDialog.openError(shell, dialogTitle, dialogMessage, status);
                });
                /*
                     * We showed our own error message, no need for the Job to
                     * show another one.
                     */
                return Status.OK_STATUS;
            }
        }
    };
    job.schedule();
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) TmfOnDemandAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) LamiAnalysis(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis) NonNullUtils.nullToEmptyString(org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) LamiResultTable(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiResultTable) ISelection(org.eclipse.jface.viewers.ISelection) IOnDemandAnalysis(org.eclipse.tracecompass.tmf.core.analysis.ondemand.IOnDemandAnalysis) LamiAnalysisReport(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisReport) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) Nullable(org.eclipse.jdt.annotation.Nullable) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

Nullable (org.eclipse.jdt.annotation.Nullable)2 LamiAnalysisReport (org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysisReport)2 LamiResultTable (org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiResultTable)2 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 IToolBarManager (org.eclipse.jface.action.IToolBarManager)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 SashForm (org.eclipse.swt.custom.SashForm)1 Shell (org.eclipse.swt.widgets.Shell)1 NonNullUtils.nullToEmptyString (org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString)1 LamiAnalysis (org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis)1