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;
}
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();
}
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);
}
}
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;
}
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());
}
}
}
Aggregations