use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class TracePackageImportOperation method deleteExistingTraces.
private IStatus deleteExistingTraces(IProgressMonitor progressMonitor) {
for (TracePackageElement packageElement : fImportTraceElements) {
TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
if (!isFilesChecked(traceElement)) {
continue;
}
TmfCommonProjectElement projectElement = getMatchingProjectElement(traceElement);
try {
if (projectElement instanceof TmfExperimentElement) {
Display.getDefault().syncExec(() -> projectElement.closeEditors());
projectElement.deleteSupplementaryFolder();
projectElement.getResource().delete(true, SubMonitor.convert(progressMonitor));
} else if (projectElement instanceof TmfTraceElement) {
((TmfTraceElement) projectElement).delete(SubMonitor.convert(progressMonitor), true);
}
} catch (CoreException e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e);
}
}
return Status.OK_STATUS;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class XMLAnalysesManagerPreferencePage method deleteAnalyses.
/**
* Delete analyses, remove the corresponding files, and close the editors, if
* opened.
*/
private void deleteAnalyses() {
// Get list of files
TableItem[] selection = fAnalysesTable.getSelection();
List<String> filesToDeleteList = Lists.newArrayList();
for (TableItem item : selection) {
filesToDeleteList.add(ELEMENT_SEP + item.getText());
}
final String filesToDelete = Joiner.on(LINE_SEP).join(filesToDeleteList);
boolean confirm = MessageDialog.openQuestion(getShell(), Messages.ManageXMLAnalysisDialog_DeleteFile, Messages.ManageXMLAnalysisDialog_DeleteConfirmation + StringUtils.repeat(LINE_SEP, 2) + filesToDelete);
if (confirm) {
Set<IEditorReference> editorReferences = getEditorReferences();
Collection<String> toDeleteSupFiles = Lists.newArrayList();
Collection<String> toDeleteFiles = Lists.newArrayList();
for (TableItem item : selection) {
String itemTitle = XmlUtils.createXmlFileString(item.getText());
// If opened, close the editor before deleting the file
editorReferences.forEach(editorReference -> {
if (editorReference.getTitle().equals(itemTitle)) {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editorReference.getEditor(false), false);
}
});
// disabled
if (XmlUtils.isAnalysisEnabled(itemTitle)) {
toDeleteSupFiles.add(itemTitle);
}
toDeleteFiles.add(itemTitle);
}
Collection<TmfCommonProjectElement> elements = deleteSupplementaryFiles(toDeleteSupFiles);
XmlUtils.deleteFiles(toDeleteFiles);
fillAnalysesTable();
handleSelection(fAnalysesTable.getSelection());
XmlAnalysisModuleSource.notifyModuleChange();
refreshProject(elements);
}
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class SelectTraceTypeHandler method isEnabled.
// ------------------------------------------------------------------------
// Validation
// ------------------------------------------------------------------------
@Override
public boolean isEnabled() {
// Check if we are closing down
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return false;
}
// Get the selection
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IWorkbenchPart part = page.getActivePart();
if (part == null) {
return false;
}
ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
if (selectionProvider == null) {
return false;
}
ISelection selection = selectionProvider.getSelection();
// Make sure selection contains only traces
fSelection = null;
if (selection instanceof TreeSelection) {
fSelection = (TreeSelection) selection;
Iterator<Object> iterator = fSelection.iterator();
while (iterator.hasNext()) {
Object element = iterator.next();
if (!(element instanceof TmfCommonProjectElement)) {
return false;
}
}
}
// If we get here, either nothing is selected or everything is a trace
return !selection.isEmpty();
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class SelectSupplementaryResourcesDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Group contextGroup = new Group(composite, SWT.SHADOW_NONE);
contextGroup.setText(Messages.SelectSpplementaryResources_ResourcesGroupTitle);
contextGroup.setLayout(new GridLayout(2, false));
contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
fTreeViewer = new CheckboxTreeViewer(contextGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
GridData data = new GridData(GridData.FILL_BOTH);
Tree tree = fTreeViewer.getTree();
tree.setLayoutData(data);
fTreeViewer.setContentProvider(new ITreeContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// Do nothing
}
@Override
public void dispose() {
// Do nothing
}
@Override
public boolean hasChildren(Object element) {
return element instanceof TmfCommonProjectElement;
}
@Override
public Object getParent(Object element) {
if (element instanceof IResource) {
getParentElement((IResource) element);
}
return null;
}
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof Object[]) {
return (Object[]) inputElement;
}
return null;
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof TmfCommonProjectElement) {
return fResourceMap.get((TmfCommonProjectElement) parentElement).toArray();
}
return null;
}
});
fTreeViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof IResource) {
IResource resource = (IResource) element;
TmfCommonProjectElement projectElement = getParentElement(resource);
// remove .tracing/<supplementary folder> segments
IPath suppFolderPath = projectElement.getTraceSupplementaryFolder(projectElement.getElementPath()).getFullPath();
return resource.getFullPath().removeFirstSegments(suppFolderPath.segmentCount()).toString();
} else if (element instanceof TmfCommonProjectElement) {
TmfCommonProjectElement projectElement = (TmfCommonProjectElement) element;
return projectElement.getElementPath();
}
return super.getText(element);
}
@Override
public Image getImage(Object element) {
if (element instanceof IResource) {
return RESOURCE_IMAGE;
} else if (element instanceof TmfTraceElement) {
return TRACE_IMAGE;
} else if (element instanceof TmfExperimentElement) {
return EXPERIMENT_IMAGE;
}
return null;
}
});
fTreeViewer.setInput(fResourceMap.keySet().toArray());
fTreeViewer.expandAll();
setAllChecked(true);
fTreeViewer.addCheckStateListener(event -> {
if (event.getElement() instanceof TmfCommonProjectElement) {
fTreeViewer.setSubtreeChecked(event.getElement(), event.getChecked());
fTreeViewer.setGrayed(event.getElement(), false);
} else if (event.getElement() instanceof IResource) {
TmfCommonProjectElement projectElement = getParentElement((IResource) event.getElement());
int checkedCount = 0;
Collection<IResource> resources = fResourceMap.get(projectElement);
for (IResource resource : resources) {
if (fTreeViewer.getChecked(resource)) {
checkedCount++;
}
}
if (checkedCount == resources.size()) {
fTreeViewer.setChecked(projectElement, true);
fTreeViewer.setGrayed(projectElement, false);
} else if (checkedCount > 0) {
fTreeViewer.setGrayChecked(projectElement, true);
} else {
fTreeViewer.setGrayChecked(projectElement, false);
}
}
});
fTreeViewer.addSelectionChangedListener(event -> updateOKButtonEnablement());
Composite btComp = new Composite(contextGroup, SWT.NONE);
FillLayout layout = new FillLayout(SWT.VERTICAL);
layout.spacing = 4;
btComp.setLayout(layout);
GridData gd = new GridData();
gd.verticalAlignment = SWT.CENTER;
btComp.setLayoutData(gd);
final Button selectAll = new Button(btComp, SWT.PUSH);
selectAll.setText(Messages.Dialog_SelectAll);
selectAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setAllChecked(true);
updateOKButtonEnablement();
}
});
final Button deselectAll = new Button(btComp, SWT.PUSH);
deselectAll.setText(Messages.Dialog_DeselectAll);
deselectAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setAllChecked(false);
updateOKButtonEnablement();
}
});
getShell().setMinimumSize(new Point(300, 150));
return composite;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class RcpCliParser method openTraceIfNecessary.
private static WaitAllTracesOpened openTraceIfNecessary(IProject project, List<Path> tracePaths, Collection<TmfCommonProjectElement> existingTraces, IProgressMonitor monitor) {
WaitAllTracesOpened waitService = new WaitAllTracesOpened(tracePaths, existingTraces);
if (!existingTraces.isEmpty()) {
Display.getDefault().asyncExec(() -> {
for (TmfCommonProjectElement existingTrace : existingTraces) {
if (monitor.isCanceled()) {
return;
}
try {
IStatus status = TmfOpenTraceHelper.openFromElement(existingTrace);
if (!status.isOK() || (status.getCode() != IStatus.OK)) {
waitService.registerStatus(new Path(existingTrace.getLocation().getPath()), status);
}
} catch (Exception e) {
// Some other exception occurred, the trace will likely
// never be opened, catch the exception and send to
// waitService
waitService.registerException(new Path(existingTrace.getLocation().getPath()), e);
}
}
});
}
if (tracePaths.isEmpty()) {
return waitService;
}
TmfTraceFolder destinationFolder = TmfProjectRegistry.getProject(project, true).getTracesFolder();
if (!tracePaths.isEmpty()) {
Display.getDefault().asyncExec(() -> {
for (Path tracePath : tracePaths) {
if (monitor.isCanceled()) {
return;
}
try {
IStatus status = TmfOpenTraceHelper.openTraceFromPath(destinationFolder, tracePath.toOSString(), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
if (!status.isOK() || (status.getCode() != IStatus.OK)) {
waitService.registerStatus(tracePath, status);
}
} catch (CoreException e) {
waitService.registerException(tracePath, e);
}
}
});
}
return waitService;
}
Aggregations