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