Search in sources :

Example 1 with TmfOnDemandAnalysisElement

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement in project tracecompass by tracecompass.

the class RunAnalysisHandler method isEnabled.

@Override
public boolean isEnabled() {
    final Object element = HandlerUtils.getSelectedModelElement();
    if (element == null) {
        return false;
    }
    /*
         * plugin.xml should have done type verifications already
         */
    TmfOnDemandAnalysisElement elem = (TmfOnDemandAnalysisElement) element;
    return (elem.getAnalysis() instanceof LamiAnalysis && elem.canRun());
}
Also used : TmfOnDemandAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement) LamiAnalysis(org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis)

Example 2 with TmfOnDemandAnalysisElement

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement in project tracecompass by tracecompass.

the class OpenAction method isEnabled.

@Override
public boolean isEnabled() {
    ISelection selection = selectionProvider.getSelection();
    if (!selection.isEmpty()) {
        IStructuredSelection sSelection = (IStructuredSelection) selection;
        Object firstElement = sSelection.getFirstElement();
        if ((sSelection.size() == 1) && (firstElement instanceof TmfTraceElement || firstElement instanceof TmfExperimentElement || firstElement instanceof TmfOnDemandAnalysisElement || firstElement instanceof TmfAnalysisOutputElement || firstElement instanceof TmfReportElement || firstElement instanceof TmfAnalysisElement)) {
            element = (TmfProjectModelElement) firstElement;
            return true;
        }
    }
    return false;
}
Also used : TmfReportElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfReportElement) TmfAnalysisOutputElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisOutputElement) TmfOnDemandAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)

Example 3 with TmfOnDemandAnalysisElement

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement in project tracecompass by tracecompass.

the class OpenAction method run.

@Override
public void run() {
    try {
        Object service = page.getActivePart().getSite().getService(IHandlerService.class);
        IHandlerService handlerService = (IHandlerService) service;
        boolean executeCommand = (element instanceof TmfTraceElement || element instanceof TmfOnDemandAnalysisElement || element instanceof TmfAnalysisOutputElement || element instanceof TmfReportElement || element instanceof TmfAnalysisElement);
        if (!executeCommand && element instanceof TmfExperimentElement) {
            TmfExperimentElement experiment = (TmfExperimentElement) element;
            executeCommand = (!experiment.getTraces().isEmpty());
        }
        if (executeCommand) {
            handlerService.executeCommand(OPEN_COMMAND_ID, null);
        }
    } catch (ExecutionException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Error opening resource " + element.getName(), e);
    } catch (NotDefinedException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Error opening resource " + element.getName(), e);
    } catch (NotEnabledException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Error opening resource " + element.getName(), e);
    } catch (NotHandledException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Error opening resource " + element.getName(), e);
    }
}
Also used : NotHandledException(org.eclipse.core.commands.NotHandledException) TmfReportElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfReportElement) TmfOnDemandAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) TmfAnalysisOutputElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisOutputElement) IHandlerService(org.eclipse.ui.handlers.IHandlerService) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 4 with TmfOnDemandAnalysisElement

use of org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement 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

TmfOnDemandAnalysisElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfOnDemandAnalysisElement)4 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 LamiAnalysis (org.eclipse.tracecompass.internal.provisional.analysis.lami.core.module.LamiAnalysis)2 TmfAnalysisElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement)2 TmfAnalysisOutputElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisOutputElement)2 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)2 TmfReportElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfReportElement)2 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 NotEnabledException (org.eclipse.core.commands.NotEnabledException)1 NotHandledException (org.eclipse.core.commands.NotHandledException)1 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)1 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 Nullable (org.eclipse.jdt.annotation.Nullable)1 Shell (org.eclipse.swt.widgets.Shell)1