Search in sources :

Example 21 with TmfCommonProjectElement

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

the class RcpCliParser method workspaceLoading.

@Override
public IStatus workspaceLoading(CliCommandLine commandLine, IProgressMonitor monitor) {
    if (commandLine.hasOption(OPTION_COMMAND_LINE_OPEN_SHORT)) {
        IProject defaultProject = createDefaultProject();
        IStatus returnStatus = Status.OK_STATUS;
        List<Path> allTracePaths = replaceHomeDir(commandLine.getOptionValues(OPTION_COMMAND_LINE_OPEN_SHORT));
        List<Path> tracePaths = new ArrayList<>();
        // Remove paths that do not exist
        for (Path tracePath : allTracePaths) {
            if (!tracePath.toFile().exists()) {
                returnStatus = addStatus(returnStatus, new Status(IStatus.ERROR, TracingRcpPlugin.PLUGIN_ID, NLS.bind(Messages.CliParser_TraceDoesNotExist, tracePath)));
            } else {
                tracePaths.add(tracePath);
            }
        }
        Collection<TmfCommonProjectElement> existingTraceElement = findElements(tracePaths);
        if (monitor.isCanceled()) {
            return Status.CANCEL_STATUS;
        }
        WaitAllTracesOpened service = openTraceIfNecessary(defaultProject, tracePaths, existingTraceElement, monitor);
        returnStatus = addStatus(returnStatus, service.waitForCompletion(monitor));
        service.dispose();
        return returnStatus;
    }
    return Status.OK_STATUS;
}
Also used : Path(org.eclipse.core.runtime.Path) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) IProject(org.eclipse.core.resources.IProject)

Example 22 with TmfCommonProjectElement

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

the class SelectTraceTypeHandler method execute.

// ------------------------------------------------------------------------
// Execution
// ------------------------------------------------------------------------
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // Check if we are closing down
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return null;
    }
    List<IStatus> statuses = new ArrayList<>();
    Set<TmfProjectElement> projects = new HashSet<>();
    boolean ok = true;
    for (Object element : fSelection.toList()) {
        TmfCommonProjectElement trace = (TmfCommonProjectElement) element;
        if (trace instanceof TmfTraceElement) {
            trace = ((TmfTraceElement) trace).getElementUnderTraceFolder();
        }
        IResource resource = trace.getResource();
        if (resource != null) {
            try {
                // Set the trace type for this resource
                String traceType = event.getParameter(TYPE_PARAMETER);
                String previousTraceType = trace.getTraceType();
                IStatus status = propagateProperties(trace, traceType);
                ok &= status.isOK();
                if (status.isOK()) {
                    if ((previousTraceType != null) && (!traceType.equals(previousTraceType))) {
                        // Close the trace if open
                        trace.closeEditors();
                        // Delete all supplementary resources
                        trace.deleteSupplementaryResources();
                    }
                } else {
                    statuses.add(status);
                }
                projects.add(trace.getProject());
            } catch (CoreException e) {
                Activator.getDefault().logError(Messages.SelectTraceTypeHandler_ErrorSelectingTrace + trace.getName(), e);
            }
        }
        trace.getProject();
    }
    for (TmfProjectElement project : projects) {
        project.refresh();
    }
    if (!ok) {
        final Shell shell = window.getShell();
        MultiStatus info = new MultiStatus(Activator.PLUGIN_ID, 1, Messages.SelectTraceTypeHandler_TraceFailedValidation, null);
        if (statuses.size() > 1) {
            info = new MultiStatus(Activator.PLUGIN_ID, 1, Messages.SelectTraceTypeHandler_TracesFailedValidation, null);
        }
        for (IStatus status : statuses) {
            info.add(status);
        }
        ErrorDialog.openError(shell, Messages.SelectTraceTypeHandler_Title, Messages.SelectTraceTypeHandler_InvalidTraceType, info);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IStatus(org.eclipse.core.runtime.IStatus) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) ArrayList(java.util.ArrayList) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) MultiStatus(org.eclipse.core.runtime.MultiStatus) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 23 with TmfCommonProjectElement

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

the class TrimTraceHandler method isEnabled.

@Override
public boolean isEnabled() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        return false;
    }
    @SuppressWarnings("null") IHandlerService service = workbench.getService(IHandlerService.class);
    // we need the current state, and the map, but the command and the
    // trigger are
    // not necessary for getCurrentSelection
    ExecutionEvent executionEvent = new ExecutionEvent(null, Collections.emptyMap(), null, service.getCurrentState());
    final Object element = HandlerUtil.getCurrentSelection(executionEvent);
    if (!(element instanceof TreeSelection)) {
        return false;
    }
    /*
         * plugin.xml should have done type/count verification already
         */
    Object firstElement = ((TreeSelection) element).getFirstElement();
    ITmfTrace trace = null;
    if (firstElement instanceof TmfCommonProjectElement) {
        TmfCommonProjectElement traceElem = (TmfCommonProjectElement) firstElement;
        if (traceElem instanceof TmfTraceElement) {
            traceElem = ((TmfTraceElement) traceElem).getElementUnderTraceFolder();
        }
        trace = traceElem.getTrace();
    }
    if (trace == null || !isValid(trace)) {
        return false;
    }
    /* Only enable the action if a time range is currently selected */
    TmfTraceManager tm = TmfTraceManager.getInstance();
    TmfTimeRange selectionRange = tm.getTraceContext(trace).getSelectionRange();
    return !(selectionRange.getStartTime().equals(selectionRange.getEndTime()));
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) IHandlerService(org.eclipse.ui.handlers.IHandlerService) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) TreeSelection(org.eclipse.jface.viewers.TreeSelection) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)

Example 24 with TmfCommonProjectElement

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

TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)24 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)10 CoreException (org.eclipse.core.runtime.CoreException)8 IResource (org.eclipse.core.resources.IResource)7 IPath (org.eclipse.core.runtime.IPath)7 IStatus (org.eclipse.core.runtime.IStatus)7 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)7 ArrayList (java.util.ArrayList)6 Path (org.eclipse.core.runtime.Path)6 TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)6 TmfTraceFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder)6 IFile (org.eclipse.core.resources.IFile)5 IFolder (org.eclipse.core.resources.IFolder)5 TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)5 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)5 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)5 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)5 TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)5 IProject (org.eclipse.core.resources.IProject)4 Status (org.eclipse.core.runtime.Status)4