Search in sources :

Example 6 with TmfCommonProjectElement

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

the class RcpCliParser method findElements.

/**
 * Find in the workspace the trace elements that corresponds to the traces
 * to open.
 *
 * @param tracePaths
 *            The path of the trace to open
 * @return The existing trace elements or <code>null</code> if the trace
 *         does not exist in the workspace
 */
private static Collection<TmfCommonProjectElement> findElements(List<Path> tracePaths) {
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(0);
    List<TmfCommonProjectElement> wanted = new ArrayList<>();
    for (IProject project : projects) {
        TmfProjectElement pElement = TmfProjectRegistry.getProject(project);
        if (pElement != null) {
            List<TmfCommonProjectElement> tElements = new ArrayList<>();
            TmfTraceFolder tracesFolder = pElement.getTracesFolder();
            if (tracesFolder != null) {
                tElements.addAll(tracesFolder.getTraces());
            }
            for (TmfCommonProjectElement tElement : tElements) {
                // If this element is for the same trace, return it
                Path elementPath = new Path(tElement.getLocation().getPath());
                if (tracePaths.contains(elementPath)) {
                    wanted.add(tElement);
                    tracePaths.remove(elementPath);
                }
            }
        }
    }
    return wanted;
}
Also used : Path(org.eclipse.core.runtime.Path) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) ArrayList(java.util.ArrayList) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) IProject(org.eclipse.core.resources.IProject)

Example 7 with TmfCommonProjectElement

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

the class ProjectModelOutputTest method testListOutputs.

/**
 * Test the getAvailableOutputs() method
 */
@Test
public void testListOutputs() {
    TmfAnalysisElement analysis = getTestAnalysisUi();
    TmfCommonProjectElement traceElement = analysis.getParent().getParent();
    /* To get the list of outputs the trace needs to be opened */
    analysis.activateParentTrace();
    try {
        ProjectModelTestData.delayUntilTraceOpened(traceElement);
    } catch (WaitTimeoutException e) {
        fail("The analysis parent did not open in a reasonable time");
    }
    /* Make sure the output list is not empty */
    WaitUtils.waitUntil(new ConditionTraceChildrenElements(analysis, 1));
    List<TmfAnalysisOutputElement> outputList = analysis.getAvailableOutputs();
    assertFalse(outputList.isEmpty());
    boolean found = false;
    for (ITmfProjectModelElement element : outputList) {
        if (element instanceof TmfAnalysisOutputElement) {
            TmfAnalysisOutputElement outputElement = (TmfAnalysisOutputElement) element;
            if (outputElement.getName().equals("Test Analysis View")) {
                found = true;
            }
        }
    }
    assertTrue(found);
    traceElement.closeEditors();
}
Also used : TmfAnalysisOutputElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisOutputElement) ITmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement) TmfAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) WaitTimeoutException(org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException) Test(org.junit.Test)

Example 8 with TmfCommonProjectElement

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

the class ProjectModelOutputTest method testOpenView.

/**
 * Test the outputAnalysis method for a view
 */
@Test
public void testOpenView() {
    TmfAnalysisElement analysis = getTestAnalysisUi();
    TmfCommonProjectElement traceElement = analysis.getParent().getParent();
    analysis.activateParentTrace();
    try {
        ProjectModelTestData.delayUntilTraceOpened(traceElement);
    } catch (WaitTimeoutException e) {
        fail("The analysis parent did not open in a reasonable time");
    }
    WaitUtils.waitUntil(new ConditionTraceChildrenElements(analysis, 1));
    List<TmfAnalysisOutputElement> outputList = analysis.getAvailableOutputs();
    assertFalse(outputList.isEmpty());
    final IWorkbench wb = PlatformUI.getWorkbench();
    final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
    IViewPart view = activePage.findView(TestAnalysisUi.VIEW_ID);
    if (view != null) {
        activePage.hideView(view);
    }
    TmfAnalysisOutputElement outputElement = null;
    for (ITmfProjectModelElement element : outputList) {
        if (element instanceof TmfAnalysisOutputElement) {
            TmfAnalysisOutputElement el = (TmfAnalysisOutputElement) element;
            if (el.getName().equals("Test Analysis View")) {
                outputElement = el;
            }
        }
    }
    assertNotNull(outputElement);
    outputElement.outputAnalysis();
    WaitUtils.waitUntil(workbenchPage -> workbenchPage.findView(TestAnalysisUi.VIEW_ID) != null, activePage, "Test Analysis View did not open");
    traceElement.closeEditors();
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IViewPart(org.eclipse.ui.IViewPart) TmfAnalysisOutputElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisOutputElement) ITmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement) TmfAnalysisElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) WaitTimeoutException(org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException) Test(org.junit.Test)

Example 9 with TmfCommonProjectElement

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

the class DeleteTraceSupplementaryFilesHandler 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;
    }
    // Get the selection
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (!(selection instanceof IStructuredSelection)) {
        return null;
    }
    final Multimap<TmfCommonProjectElement, IResource> resourceMap = TreeMultimap.create(ELEMENT_COMPARATOR, RESOURCE_COMPARATOR);
    final Iterator<Object> iterator = ((IStructuredSelection) selection).iterator();
    while (iterator.hasNext()) {
        Object element = iterator.next();
        if (element instanceof TmfTraceElement) {
            TmfTraceElement trace = (TmfTraceElement) element;
            // If trace is under an experiment, use the original trace from the traces folder
            trace = trace.getElementUnderTraceFolder();
            for (IResource resource : trace.getSupplementaryResources()) {
                resourceMap.put(trace, resource);
            }
        } else if (element instanceof TmfExperimentElement) {
            TmfExperimentElement experiment = (TmfExperimentElement) element;
            for (IResource resource : experiment.getSupplementaryResources()) {
                resourceMap.put(experiment, resource);
            }
            for (TmfTraceElement trace : experiment.getTraces()) {
                // If trace is under an experiment, use the original trace from the traces folder
                trace = trace.getElementUnderTraceFolder();
                for (IResource resource : trace.getSupplementaryResources()) {
                    resourceMap.put(trace, resource);
                }
            }
        }
    }
    boolean confirm = Activator.getDefault().getPreferenceStore().getBoolean(ITmfUIPreferences.CONFIRM_DELETION_SUPPLEMENTARY_FILES);
    if (confirm) {
        final SelectSupplementaryResourcesDialog dialog = new SelectSupplementaryResourcesDialog(window.getShell(), resourceMap);
        if (dialog.open() != Window.OK) {
            return null;
        }
        // Only keep selected resource in the map
        resourceMap.values().retainAll(Arrays.asList(dialog.getResources()));
    }
    // Close editors for traces that have supplementary resources to delete
    resourceMap.keys().forEach(TmfCommonProjectElement::closeEditors);
    TmfWorkspaceModifyOperation operation = new TmfWorkspaceModifyOperation() {

        @Override
        public void execute(IProgressMonitor monitor) throws CoreException {
            Set<IProject> projectsToRefresh = new HashSet<>();
            // Initial work is number of resources to delete plus number of traces
            SubMonitor subMonitor = SubMonitor.convert(monitor, resourceMap.size() + resourceMap.keySet().size());
            for (Entry<TmfCommonProjectElement, Collection<IResource>> entry : resourceMap.asMap().entrySet()) {
                TmfCommonProjectElement trace = entry.getKey();
                Collection<IResource> resources = entry.getValue();
                subMonitor.split(resources.size());
                subMonitor.setTaskName(NLS.bind(Messages.DeleteSupplementaryFiles_DeletionTask, trace.getElementPath()));
                trace.deleteSupplementaryResources(resources.toArray(new IResource[0]));
                projectsToRefresh.add(trace.getProject().getResource());
            }
            // Redistribute work remaining from number of traces to number of projects
            subMonitor.setWorkRemaining(projectsToRefresh.size());
            // Refresh projects
            for (IProject project : projectsToRefresh) {
                subMonitor.setTaskName(NLS.bind(Messages.DeleteSupplementaryFiles_ProjectRefreshTask, project.getName()));
                try {
                    project.refreshLocal(IResource.DEPTH_INFINITE, subMonitor.split(1));
                } catch (CoreException e) {
                    // $NON-NLS-1$
                    Activator.getDefault().logError("Error refreshing project " + project, e);
                }
            }
        }
    };
    try {
        PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (InvocationTargetException e) {
        TraceUtils.displayErrorMsg(e.toString(), e.getTargetException().toString());
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) SelectSupplementaryResourcesDialog(org.eclipse.tracecompass.internal.tmf.ui.project.dialogs.SelectSupplementaryResourcesDialog) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) SubMonitor(org.eclipse.core.runtime.SubMonitor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ISelection(org.eclipse.jface.viewers.ISelection) Collection(java.util.Collection) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) TmfWorkspaceModifyOperation(org.eclipse.tracecompass.internal.tmf.ui.project.operations.TmfWorkspaceModifyOperation) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 10 with TmfCommonProjectElement

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

the class TrimTraceHandler method execute.

@Override
@Nullable
public Object execute(@Nullable ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    Object firstElement = ((IStructuredSelection) selection).getFirstElement();
    final TmfCommonProjectElement traceElem = (firstElement instanceof TmfTraceElement) ? ((TmfTraceElement) firstElement).getElementUnderTraceFolder() : (TmfCommonProjectElement) firstElement;
    ITmfTrace trace = traceElem.getTrace();
    if (trace == null || !isValid(trace)) {
        /* That trace is not currently opened */
        return null;
    }
    /* Retrieve the current time range */
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    TmfTraceManager tm = TmfTraceManager.getInstance();
    TmfTimeRange timeRange = tm.getTraceContext(trace).getSelectionRange();
    if (Objects.equals(timeRange.getStartTime(), timeRange.getEndTime())) {
        MessageDialog.openError(shell, Messages.TrimTraces_InvalidTimeRange_DialogTitle, Messages.TrimTraces_InvalidTimeRange_DialogText);
        return null;
    }
    /* Ensure the time range is in the right direction */
    final TmfTimeRange tr = ((timeRange.getStartTime().compareTo(timeRange.getEndTime()) > 0) ? new TmfTimeRange(timeRange.getEndTime(), timeRange.getStartTime()) : timeRange);
    /*
         * Pop a dialog asking the user to select a parent directory for the new
         * trace.
         */
    TrimTraceDialog dialog = new TrimTraceDialog(shell, traceElem);
    if (dialog.open() != Window.OK) {
        return null;
    }
    Object result = dialog.getFirstResult();
    if (result == null) {
        /* Dialog was cancelled, take no further action. */
        return null;
    }
    /* Verify that the selected path is valid and writeable */
    final Path destinationPath = checkNotNull(Paths.get(result.toString()));
    if (destinationPath.toFile().exists()) {
        MessageDialog.openError(shell, Messages.TrimTraces_InvalidDirectory_DialogTitle, Messages.TrimTraces_InvalidDirectory_DialogText);
        return null;
    }
    TraceToTrim toTrim = TraceToTrim.create(traceElem, destinationPath);
    if (toTrim == null) {
        return null;
    }
    try {
        toTrim.createDir();
    } catch (IOException e) {
        /* Should not happen since we have checked permissions, etc. */
        throw new ExecutionException(e.getMessage(), e);
    }
    TmfWorkspaceModifyOperation trimOperation = new TmfWorkspaceModifyOperation() {

        @Override
        public void execute(@Nullable IProgressMonitor monitor) throws CoreException {
            SubMonitor mon = SubMonitor.convert(monitor, 2);
            toTrim.trim(tr, mon);
            /*
                 * Import the new trace into the current project, at the
                 * top-level.
                 */
            TmfProjectElement currentProjectElement = traceElem.getProject();
            TmfTraceFolder traceFolder = currentProjectElement.getTracesFolder();
            toTrim.importTrace(mon);
            if (mon.isCanceled()) {
                return;
            }
            if (traceFolder != null) {
                Display.getDefault().asyncExec(toTrim::open);
            } else {
                // $NON-NLS-1$
                Activator.getDefault().logWarning("Trace folder does not exist: " + toTrim.fDestinationPath);
            }
        }
    };
    try {
        PlatformUI.getWorkbench().getProgressService().run(true, true, trimOperation);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (InvocationTargetException e) {
        TraceUtils.displayErrorMsg(Messages.TrimTraceHandler_failMsg, e.getMessage(), e);
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) SubMonitor(org.eclipse.core.runtime.SubMonitor) TmfProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) IOException(java.io.IOException) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) InvocationTargetException(java.lang.reflect.InvocationTargetException) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Shell(org.eclipse.swt.widgets.Shell) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) TrimTraceDialog(org.eclipse.tracecompass.tmf.ui.project.wizards.TrimTraceDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) ISelection(org.eclipse.jface.viewers.ISelection) TmfWorkspaceModifyOperation(org.eclipse.tracecompass.internal.tmf.ui.project.operations.TmfWorkspaceModifyOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) 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