use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class RemoteProfilesPreferencePage method newProfile.
private RemoteImportProfileElement newProfile(TracePackageElement previous) {
RemoteImportProfileElement profile = new RemoteImportProfileElement(null, RemoteMessages.RemoteProfilesPreferencePage_DefaultProfileName);
RemoteImportConnectionNodeElement node = new RemoteImportConnectionNodeElement(profile, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeName, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeURI);
RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(node, DEFAULT_ROOT_IMPORT_PATH);
TracePackageTraceElement trace = new TracePackageTraceElement(traceGroup, DEFAULT_IMPORT_NAME, null);
new TracePackageFilesElement(trace, DEFAULT_FILE_PATTERN);
int index = previous == null ? fProfiles.size() : fProfiles.indexOf(previous) + 1;
fProfiles.add(index, profile);
newElementAdded(profile);
return profile;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class RemoteProfilesPreferencePage method createVerticalButtonBar.
private Composite createVerticalButtonBar(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout());
fAddButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_AddButton);
fAddButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
if (selection.isEmpty()) {
newProfile(null);
} else if (selection.getFirstElement() instanceof TracePackageElement) {
TracePackageElement previous = (TracePackageElement) selection.getFirstElement();
if (previous instanceof RemoteImportProfileElement) {
newProfile(previous);
} else if (previous instanceof RemoteImportConnectionNodeElement) {
newConnectionNode(previous.getParent(), previous);
} else if (previous instanceof RemoteImportTraceGroupElement) {
newTraceGroup(previous.getParent(), previous);
} else if (previous instanceof TracePackageTraceElement) {
newTrace(previous.getParent(), previous);
}
}
}
});
fRemoveButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_RemoveButton);
fRemoveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
for (Object item : selection.toList()) {
if (item instanceof RemoteImportProfileElement) {
fProfiles.remove(item);
} else if (item instanceof TracePackageElement) {
TracePackageElement element = (TracePackageElement) item;
element.getParent().removeChild(element);
}
}
fTreeViewer.refresh();
validate();
}
});
new Label(composite, SWT.NONE);
fImportButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_ImportButton);
fImportButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = TmfFileDialogFactory.create(Display.getCurrent().getActiveShell(), SWT.OPEN);
dialog.setText(RemoteMessages.RemoteProfilesPreferencePage_ImportFileDialogTitle);
// $NON-NLS-1$ //$NON-NLS-2$
dialog.setFilterExtensions(new String[] { "*.xml", "*" });
String path = dialog.open();
if (path != null) {
List<RemoteImportProfileElement> profiles = readProfiles(path, new NullProgressMonitor());
fProfiles.addAll(profiles);
fTreeViewer.refresh();
for (RemoteImportProfileElement profile : profiles) {
fTreeViewer.expandToLevel(profile, AbstractTreeViewer.ALL_LEVELS);
}
fTreeViewer.setSelection(new StructuredSelection(profiles));
validate();
}
}
});
fExportButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_ExportButton);
fExportButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = TmfFileDialogFactory.create(Display.getCurrent().getActiveShell(), SWT.SAVE);
dialog.setText(RemoteMessages.RemoteProfilesPreferencePage_ExportFileDialogTitle);
// $NON-NLS-1$ //$NON-NLS-2$
dialog.setFilterExtensions(new String[] { "*.xml", "*" });
String path = dialog.open();
if (path != null) {
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
List<RemoteImportProfileElement> profiles = new ArrayList<>();
for (Object element : selection.toList()) {
if (element instanceof RemoteImportProfileElement) {
profiles.add((RemoteImportProfileElement) element);
}
}
writeProfiles(profiles, path);
}
}
});
new Label(composite, SWT.NONE);
fMoveUpButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_MoveUpButton);
fMoveUpButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
Object element = selection.getFirstElement();
if (element instanceof RemoteImportProfileElement) {
int index = fProfiles.indexOf(element);
if (index > 0) {
RemoteImportProfileElement profile = fProfiles.remove(index);
fProfiles.add(index - 1, profile);
Object[] expanded = fTreeViewer.getExpandedElements();
fTreeViewer.refresh();
fTreeViewer.setExpandedElements(expanded);
enableButtons(selection);
}
} else if (element instanceof TracePackageElement) {
TracePackageElement child = (TracePackageElement) element;
TracePackageElement parentElement = child.getParent();
int index = parentElement.indexOf(child);
if (index > 0) {
parentElement.removeChild(child);
parentElement.addChild(index - 1, child);
Object[] expanded = fTreeViewer.getExpandedElements();
fTreeViewer.refresh(parentElement);
fTreeViewer.setExpandedElements(expanded);
enableButtons(selection);
}
}
}
});
fMoveDownButton = createVerticalButton(composite, RemoteMessages.RemoteProfilesPreferencePage_MoveDownButton);
fMoveDownButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
Object element = selection.getFirstElement();
if (element instanceof RemoteImportProfileElement) {
int index = fProfiles.indexOf(selection.getFirstElement());
if (index >= 0 && index < fProfiles.size() - 1) {
RemoteImportProfileElement profile = fProfiles.remove(index);
fProfiles.add(index + 1, profile);
Object[] expanded = fTreeViewer.getExpandedElements();
fTreeViewer.refresh();
fTreeViewer.setExpandedElements(expanded);
enableButtons(selection);
}
} else if (element instanceof TracePackageElement) {
TracePackageElement child = (TracePackageElement) element;
TracePackageElement parentElement = child.getParent();
int index = parentElement.indexOf(child);
if (index >= 0 && index < parentElement.getChildren().length - 1) {
parentElement.removeChild(child);
parentElement.addChild(index + 1, child);
Object[] expanded = fTreeViewer.getExpandedElements();
fTreeViewer.refresh(parentElement);
fTreeViewer.setExpandedElements(expanded);
enableButtons(selection);
}
}
}
});
return composite;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class ExportTracePackageWizardPage method createElementViewerInput.
@Override
protected Object createElementViewerInput() {
List<TracePackageTraceElement> traceElements = new ArrayList<>();
for (TmfCommonProjectElement projectElement : fSelectedTraces) {
TracePackageTraceElement traceElement;
if (projectElement instanceof TmfExperimentElement) {
TmfExperimentElement experimentElement = (TmfExperimentElement) projectElement;
traceElement = new TracePackageExperimentElement(null, experimentElement);
for (TmfTraceElement expTrace : experimentElement.getTraces()) {
((TracePackageExperimentElement) traceElement).addExpTrace(expTrace.getElementPath());
}
} else {
traceElement = new TracePackageTraceElement(null, projectElement);
}
// Trace files
TracePackageFilesElement filesElement = new TracePackageFilesElement(traceElement, projectElement.getResource());
filesElement.setChecked(true);
// Supplementary files
try {
String supplementaryFolder = projectElement.getResource().getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER);
TracePackageSupplFilesElement suppFilesElement = new TracePackageSupplFilesElement(null);
IResource[] supplementaryResources = projectElement.getSupplementaryResources();
for (IResource res : supplementaryResources) {
String name = supplementaryFolder == null ? res.getName() : res.getLocation().makeRelativeTo(new Path(supplementaryFolder)).toString();
new TracePackageSupplFileElement(res, name, suppFilesElement);
}
if (supplementaryFolder != null) {
// If the supplementary folder path is in a shadow project,
// the resources must be taken from the parent project.
IFolder projectSupplementaryFolder = projectElement.getProject().getSupplementaryFolder();
IPath path = new Path(supplementaryFolder).append(TmfCommonConstants.TRACE_PROPERTIES_FOLDER);
IFolder propertiesFolder = projectSupplementaryFolder.getFolder(path.makeRelativeTo(projectSupplementaryFolder.getLocation()));
if (propertiesFolder.exists()) {
for (IResource res : propertiesFolder.members()) {
String name = res.getLocation().makeRelativeTo(new Path(supplementaryFolder)).toString();
new TracePackageSupplFileElement(res, name, suppFilesElement);
}
}
}
if (suppFilesElement.getChildren().length > 0) {
traceElement.addChild(suppFilesElement);
}
} catch (CoreException e) {
// Should not happen
// $NON-NLS-1$
Activator.getDefault().logError("Error finding supplementary files", e);
}
// Bookmarks
IFile bookmarksFile = projectElement.getBookmarksFile();
if (bookmarksFile != null && bookmarksFile.exists()) {
IMarker[] findMarkers;
try {
findMarkers = bookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO);
if (findMarkers.length > 0) {
new TracePackageBookmarkElement(traceElement, null);
}
} catch (CoreException e) {
// Should not happen since we just checked bookmarksFile.exists() but log it just in case
// $NON-NLS-1$
Activator.getDefault().logError("Error finding bookmarks", e);
}
}
traceElements.add(traceElement);
}
return traceElements.toArray(new TracePackageTraceElement[] {});
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class ExportTracePackageWizardPage method finish.
/**
* Finish the wizard page
*
* @return true on success
*/
public boolean finish() {
if (!checkForOverwrite()) {
return false;
}
saveWidgetValues();
TracePackageTraceElement[] traceExportElements = (TracePackageTraceElement[]) getElementViewer().getInput();
boolean useCompression = fCompressContentsCheckbox.getSelection();
boolean useTar = fTargzFormatButton.getSelection();
String fileName = getFilePathValue();
final TracePackageExportOperation exporter = new TracePackageExportOperation(traceExportElements, useCompression, useTar, fileName);
try {
getContainer().run(true, true, exporter::run);
IStatus status = exporter.getStatus();
if (status.getSeverity() == IStatus.ERROR) {
handleErrorStatus(status);
}
} catch (InvocationTargetException e) {
handleError(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return exporter.getStatus().getSeverity() == IStatus.OK;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class ImportTracePackageWizardPage method checkForConflict.
private boolean checkForConflict() {
TracePackageElement[] packageElements = (TracePackageElement[]) getElementViewer().getInput();
List<TracePackageExperimentElement> experimentElements = new ArrayList<>();
List<TracePackageTraceElement> traceElements = new ArrayList<>();
Map<TracePackageExperimentElement, List<TracePackageTraceElement>> experimentTracesMap = new HashMap<>();
// List of experiment to rename
List<TracePackageExperimentElement> experimentToRename = new ArrayList<>();
// Conflict traces that are not in an experiment
List<TracePackageTraceElement> unhandledTraces = new ArrayList<>();
// Process package element to separate experiments and traces
for (TracePackageElement packageElement : packageElements) {
TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
if (AbstractTracePackageOperation.isFilesChecked(traceElement)) {
if (traceElement instanceof TracePackageExperimentElement) {
TracePackageExperimentElement experimentElement = (TracePackageExperimentElement) traceElement;
experimentElements.add(experimentElement);
if (experimentExists(experimentElement)) {
experimentToRename.add(experimentElement);
}
} else {
traceElements.add(traceElement);
}
}
}
for (TracePackageTraceElement traceElement : traceElements) {
processTrace(experimentElements, traceElement, experimentTracesMap, unhandledTraces);
}
boolean result = true;
if (!experimentTracesMap.isEmpty() || !experimentToRename.isEmpty()) {
result &= handleExperimentConflict(experimentTracesMap, experimentToRename);
}
if (!unhandledTraces.isEmpty()) {
result &= handleTracesConflict(unhandledTraces);
}
return result;
}
Aggregations