Search in sources :

Example 1 with ITmfProjectModelElement

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

the class SelectTracesWizardPage method doCreateTreeViewer.

private TreeViewer doCreateTreeViewer(Composite parent) {
    fCheckboxTreeViewer = new CheckboxTreeViewer(parent, SWT.BORDER);
    fContentProvider = new TmfNavigatorContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            return getChildren(inputElement);
        }

        @Override
        public synchronized Object[] getChildren(Object parentElement) {
            // We only care about the content of trace folders
            if (parentElement instanceof TmfTraceFolder) {
                Object[] children = super.getChildren(parentElement);
                List<ITmfProjectModelElement> filteredChildren = new ArrayList<>();
                for (Object child : children) {
                    if (child instanceof TmfTraceElement) {
                        TmfTraceElement traceElement = (TmfTraceElement) child;
                        String traceType = traceElement.getTraceType();
                        if (traceType != null && TmfTraceType.getTraceType(traceType) != null) {
                            filteredChildren.add(traceElement);
                        }
                    } else if (child instanceof TmfTraceFolder) {
                        filteredChildren.add((TmfTraceFolder) child);
                    }
                }
                return filteredChildren.toArray();
            }
            return null;
        }

        @Override
        public boolean hasChildren(Object element) {
            Object[] children = getChildren(element);
            return children != null && children.length > 0;
        }
    };
    fCheckboxTreeViewer.setContentProvider(fContentProvider);
    fLabelProvider = new TmfNavigatorLabelProvider();
    fCheckboxTreeViewer.setLabelProvider(fLabelProvider);
    fCheckboxTreeViewer.setComparator(new ViewerComparator());
    final Tree tree = fCheckboxTreeViewer.getTree();
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    tree.setLayoutData(gd);
    tree.setHeaderVisible(true);
    final TreeViewerColumn column = new TreeViewerColumn(fCheckboxTreeViewer, SWT.NONE);
    column.getColumn().setWidth(COLUMN_WIDTH);
    column.getColumn().setText(Messages.SelectTracesWizardPage_TraceColumnHeader);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return fLabelProvider.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            return fLabelProvider.getImage(element);
        }
    });
    // Get the list of traces already part of the experiment
    fPreviousTraces.clear();
    for (ITmfProjectModelElement child : fExperiment.getChildren()) {
        if (child instanceof TmfTraceElement) {
            TmfTraceElement trace = (TmfTraceElement) child;
            String name = trace.getElementPath();
            fPreviousTraces.put(name, trace);
        }
    }
    // Populate the list of traces to choose from
    Set<String> keys = fPreviousTraces.keySet();
    TmfTraceFolder traceFolder = fProject.getTracesFolder();
    fCheckboxTreeViewer.setUseHashlookup(true);
    fCheckboxTreeViewer.setInput(traceFolder);
    // Set the checkbox for the traces already included
    setCheckedAlreadyIncludedTraces(keys, fContentProvider.getElements(fCheckboxTreeViewer.getInput()));
    fCheckboxTreeViewer.addCheckStateListener(event -> {
        Object element = event.getElement();
        setSubtreeChecked(element, event.getChecked());
        maintainCheckIntegrity(element);
    });
    return fCheckboxTreeViewer;
}
Also used : TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TmfNavigatorLabelProvider(org.eclipse.tracecompass.tmf.ui.project.model.TmfNavigatorLabelProvider) Image(org.eclipse.swt.graphics.Image) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ITmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement) TmfNavigatorContentProvider(org.eclipse.tracecompass.tmf.ui.project.model.TmfNavigatorContentProvider) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with ITmfProjectModelElement

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

the class CtfTmfExperimentTrimmingTest method setup.

/**
 * Test setup
 */
@Before
public void setup() {
    WaitUtils.waitForJobs();
    SWTBotTreeItem tracesFolder = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
    tracesFolder.contextMenu().menu("Open As Experiment...", "Generic Experiment").click();
    SWTBotUtils.activateEditor(fBot, "Experiment");
    SWTBotTreeItem project = SWTBotUtils.selectProject(fBot, PROJECT_NAME);
    SWTBotTreeItem experimentItem = SWTBotUtils.getTraceProjectItem(fBot, project, "Experiments", "Experiment");
    experimentItem.select();
    TmfTraceManager traceManager = TmfTraceManager.getInstance();
    ITmfTrace trace = traceManager.getActiveTrace();
    assertTrue(String.valueOf(trace), trace instanceof TmfExperiment);
    TmfExperiment experiment = (TmfExperiment) trace;
    assertNotNull(experiment);
    ITmfProjectModelElement elem = TmfProjectRegistry.findElement(experiment.getResource(), true);
    assertTrue(elem instanceof TmfExperimentElement);
    fOriginalExperiment = experiment;
    TmfTimeRange traceCutRange = getTraceCutRange(experiment);
    assertNotNull(traceCutRange);
    fRequestedTraceCutRange = traceCutRange;
    ITmfTimestamp requestedTraceCutEnd = traceCutRange.getEndTime();
    ITmfTimestamp requestedTraceCutStart = traceCutRange.getStartTime();
    assertTrue(experiment.getTimeRange().contains(traceCutRange));
    TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, requestedTraceCutStart, requestedTraceCutEnd, experiment));
    experimentItem.contextMenu("Export Time Selection as New Trace...").click();
    SWTBotShell shell = fBot.shell("Export trace section to...").activate();
    SWTBot dialogBot = shell.bot();
    assertEquals("Experiment", dialogBot.text().getText());
    dialogBot.text().setText("Experiment-trimmed");
    dialogBot.button("OK").click();
    SWTBotEditor newExperiment = fBot.editorByTitle("Experiment-trimmed");
    newExperiment.setFocus();
    fNewExperiment = traceManager.getActiveTrace();
    assertNotNull("No active trace", fNewExperiment);
    assertEquals("Incorrect active trace", "Experiment-trimmed", fNewExperiment.getName());
    WaitUtils.waitForJobs();
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) ITmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement) TmfSelectionRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal) SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Before(org.junit.Before)

Example 3 with ITmfProjectModelElement

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

the class ProjectModelTestData method deleteProject.

/**
 * Deletes a project
 *
 * @param project
 *            Project to delete
 */
public static void deleteProject(TmfProjectElement project) {
    /* Delete experiments */
    TmfExperimentFolder experimentsFolder = project.getExperimentsFolder();
    if (experimentsFolder != null) {
        ITmfProjectModelElement[] experiments = experimentsFolder.getChildren().toArray(new ITmfProjectModelElement[0]);
        for (ITmfProjectModelElement element : experiments) {
            if (element instanceof TmfExperimentElement) {
                TmfExperimentElement experiment = (TmfExperimentElement) element;
                IResource resource = experiment.getResource();
                /* Close the experiment if open */
                experiment.closeEditors();
                IPath path = resource.getLocation();
                if (path != null) {
                    /* Delete supplementary files */
                    experiment.deleteSupplementaryFolder();
                }
                /* Finally, delete the experiment */
                try {
                    resource.delete(true, null);
                } catch (CoreException e) {
                    Activator.getDefault().logError("Error deleting experiment element", e);
                }
            }
        }
    }
    /* Delete traces */
    TmfTraceFolder tracesFolder = project.getTracesFolder();
    if (tracesFolder != null) {
        ITmfProjectModelElement[] traces = tracesFolder.getChildren().toArray(new ITmfProjectModelElement[0]);
        for (ITmfProjectModelElement element : traces) {
            if (element instanceof TmfTraceElement) {
                TmfTraceElement trace = (TmfTraceElement) element;
                IResource resource = trace.getResource();
                /* Close the trace if open */
                trace.closeEditors();
                IPath path = resource.getLocation();
                if (path != null) {
                    /* Delete supplementary files */
                    trace.deleteSupplementaryFolder();
                }
                /* Finally, delete the trace */
                try {
                    resource.delete(true, new NullProgressMonitor());
                } catch (CoreException e) {
                    Activator.getDefault().logError("Error deleting trace element", e);
                }
            }
        }
    }
    /* Delete the project itself */
    try {
        project.getResource().delete(true, null);
    } catch (CoreException e) {
        Activator.getDefault().logError("Error deleting project", e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement) TmfExperimentFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) IResource(org.eclipse.core.resources.IResource)

Example 4 with ITmfProjectModelElement

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

the class ProjectModelTestData method addExperiment.

/**
 * Adds a new experiment to the project
 *
 * @param projectElement
 *            The project to add to
 * @param experimentName
 *            Name of the experiment
 * @return The newly created experiment
 */
public static TmfExperimentElement addExperiment(TmfProjectElement projectElement, String experimentName) {
    TmfExperimentFolder experimentsFolder = projectElement.getExperimentsFolder();
    if (experimentsFolder != null) {
        IFolder experimentFolder = experimentsFolder.getResource();
        final IFolder folder = experimentFolder.getFolder(experimentName);
        WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

            @Override
            public void execute(IProgressMonitor monitor) throws CoreException {
                monitor.beginTask("", 1000);
                folder.create(false, true, monitor);
                monitor.done();
            }
        };
        try {
            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(operation);
        } catch (InterruptedException | InvocationTargetException | RuntimeException exception) {
            exception.printStackTrace();
        }
        experimentsFolder.refresh();
        for (ITmfProjectModelElement el : experimentsFolder.getChildren()) {
            if (el.getName().equals(experimentName) && (el instanceof TmfExperimentElement)) {
                return (TmfExperimentElement) el;
            }
        }
    }
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement) TmfExperimentFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) InvocationTargetException(java.lang.reflect.InvocationTargetException) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with ITmfProjectModelElement

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

the class TraceImportOperationTest method validateImport.

private static void validateImport(String sourcePath, TmfTraceFolder destFolder, boolean isLinked) {
    Map<String, ITmfProjectModelElement> map = new HashMap<>();
    destFolder.getChildren().forEach(element -> map.put(element.getName(), element));
    File source = new File(sourcePath);
    File[] files = source.listFiles();
    for (File file : files) {
        ITmfProjectModelElement element = map.get(file.getName());
        if (element == null) {
            continue;
        }
        if (file.isDirectory()) {
            assertTrue(file.toString(), element instanceof TmfTraceFolder);
            validateImport(file.getAbsolutePath(), (TmfTraceFolder) element, isLinked);
        } else {
            assertTrue(file.toString(), element instanceof TmfTraceElement);
            TmfTraceElement traceElement = (TmfTraceElement) element;
            assertNotNull(file.toString(), traceElement.getTraceType());
            assertEquals(file.toString(), isLinked, traceElement.getResource().isLinked());
        }
    }
}
Also used : ITmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement) HashMap(java.util.HashMap) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) File(java.io.File)

Aggregations

ITmfProjectModelElement (org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement)16 TmfTraceFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder)8 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)7 IResource (org.eclipse.core.resources.IResource)5 CoreException (org.eclipse.core.runtime.CoreException)5 File (java.io.File)4 IPath (org.eclipse.core.runtime.IPath)4 IFile (org.eclipse.core.resources.IFile)3 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TmfAnalysisElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement)2 TmfAnalysisOutputElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisOutputElement)2 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)2 TmfExperimentFolder (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder)2 WaitTimeoutException (org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1