use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.
the class RemoteImportProfilesWriter method exportTraceGroup.
private static void exportTraceGroup(Node nodeNode, RemoteImportTraceGroupElement traceGroup) {
Element traceGroupElement = nodeNode.getOwnerDocument().createElement(RemoteImportProfileConstants.TRACE_GROUP_ELEMENT);
traceGroupElement.setAttribute(RemoteImportProfileConstants.TRACE_GROUP_ROOT_ATTRIB, traceGroup.getRootImportPath());
traceGroupElement.setAttribute(RemoteImportProfileConstants.TRACE_GROUP_RECURSIVE_ATTRIB, Boolean.toString(traceGroup.isRecursive()));
for (TracePackageElement trace : traceGroup.getChildren()) {
if (trace instanceof TracePackageTraceElement) {
exportTrace(traceGroupElement, (TracePackageTraceElement) trace);
}
}
nodeNode.appendChild(traceGroupElement);
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.
the class RemoteImportProfilesWriter method writeProfilesToXML.
/**
* Write the profiles to XML format.
*
* @param profiles
* the profile elements to write to XML
*
* @return the generated XML
* @throws ParserConfigurationException
* when an error occurs when parsing
* @throws TransformerException
* when an error occurs when transforming the XML
*/
public static String writeProfilesToXML(TracePackageElement[] profiles) throws ParserConfigurationException, TransformerException {
Document doc = XmlUtils.newSafeDocumentBuilderFactory().newDocumentBuilder().newDocument();
Element profilesElement = doc.createElement(RemoteImportProfileConstants.PROFILES_ELEMENT);
doc.appendChild(profilesElement);
Element versionElement = doc.createElement(RemoteImportProfileConstants.VERSION_ELEMENT);
versionElement.setTextContent(RemoteImportProfileConstants.VERSION);
profilesElement.appendChild(versionElement);
for (TracePackageElement profile : profiles) {
if (profile instanceof RemoteImportProfileElement) {
exportProfile(profilesElement, (RemoteImportProfileElement) profile);
}
}
Transformer transformer = XmlUtils.newSecureTransformer();
// $NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", // $NON-NLS-1$ //$NON-NLS-2$
"4");
DOMSource source = new DOMSource(doc);
StringWriter buffer = new StringWriter();
StreamResult result = new StreamResult(buffer);
transformer.transform(source, result);
String content = buffer.getBuffer().toString();
return content;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.
the class RemoteImportTracesOperation method doRun.
// ------------------------------------------------------------------------
// Helper methods
// ------------------------------------------------------------------------
private void doRun(IProgressMonitor monitor) throws ExecutionException, CoreException, IOException, InterruptedException {
IFolder destinationFolder = fDestination.getResource();
if (!destinationFolder.exists()) {
// $NON-NLS-1$//$NON-NLS-2$
throw new ExecutionException(RemoteMessages.RemoteImportTracesOperation_ImportDialogInvalidTracingProject + " (" + destinationFolder + ")");
}
SubMonitor subMonitor = SubMonitor.convert(monitor, fTraceElements.length * 4);
subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, fTraceElements.length * 4);
for (Object packageElement : fTraceElements) {
if (!(packageElement instanceof TracePackageTraceElement)) {
continue;
}
TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
TracePackageElement parentElement = traceElement.getParent();
while (parentElement != null) {
if (parentElement instanceof RemoteImportTraceGroupElement) {
break;
}
parentElement = parentElement.getParent();
}
if (parentElement == null) {
continue;
}
RemoteImportTraceGroupElement traceGroup = (RemoteImportTraceGroupElement) parentElement;
String rootPath = traceGroup.getRootImportPath();
// Create folder with node name in destination folder
RemoteImportConnectionNodeElement nodeElement = (RemoteImportConnectionNodeElement) traceGroup.getParent();
String nodeName = nodeElement.getName();
IFolder nodeFolder = destinationFolder.getFolder(nodeName);
TracePackageElement[] children = traceElement.getChildren();
SubMonitor childMonitor = subMonitor.newChild(1);
TraceUtils.createFolder(nodeFolder, childMonitor);
for (TracePackageElement element : children) {
ModalContext.checkCanceled(monitor);
if (element instanceof RemoteImportTraceFilesElement) {
RemoteImportTraceFilesElement traceFilesElement = (RemoteImportTraceFilesElement) element;
IFileStore remoteFile = traceFilesElement.getRemoteFile();
// Preserve folder structure
IPath sessionParentPath = TmfTraceCoreUtils.newSafePath(rootPath).removeLastSegments(1);
IPath traceParentPath = TmfTraceCoreUtils.newSafePath(remoteFile.getParent().toURI().getPath());
IPath relativeTracePath = Path.EMPTY;
if (sessionParentPath.isPrefixOf(traceParentPath)) {
relativeTracePath = traceParentPath.makeRelativeTo(sessionParentPath);
}
String[] segments = relativeTracePath.segments();
for (int i = 0; i < segments.length; i++) {
String segment = TmfTraceCoreUtils.validateName(TmfTraceCoreUtils.safePathToString(segments[i]));
if (i == 0) {
relativeTracePath = new Path(segment);
} else {
relativeTracePath = relativeTracePath.append(segment);
}
}
IFolder traceFolder = nodeFolder.getFolder(new Path(relativeTracePath.toOSString()));
childMonitor = subMonitor.newChild(1);
TraceUtils.createFolder(traceFolder, childMonitor);
childMonitor.done();
// Import trace
IResource traceRes = null;
IFileInfo info = remoteFile.fetchInfo();
if (info.isDirectory()) {
traceRes = downloadDirectoryTrace(remoteFile, traceFolder, subMonitor.newChild(1));
} else {
traceRes = downloadFileTrace(remoteFile, traceFolder, subMonitor.newChild(1));
}
String traceName = traceElement.getText();
if (traceRes == null || !traceRes.exists()) {
continue;
}
// Select trace type
TraceTypeHelper traceTypeHelper = null;
String traceTypeStr = traceElement.getTraceType();
if (traceTypeStr != null) {
traceTypeHelper = TmfTraceType.getTraceType(traceTypeStr);
}
// no specific trace type found
if (traceTypeHelper == null) {
try {
// Try to auto-detect the trace typ
childMonitor = subMonitor.newChild(1);
childMonitor.setTaskName(NLS.bind(RemoteMessages.RemoteImportTracesOperation_DetectingTraceType, traceName));
childMonitor.done();
traceTypeHelper = TmfTraceTypeUIUtils.selectTraceType(traceRes.getLocation().toOSString(), null, null);
} catch (TmfTraceImportException e) {
// Could not figure out the type
}
}
if (traceTypeHelper != null) {
TmfTraceTypeUIUtils.setTraceType(traceRes, traceTypeHelper);
fImportedResources.add(traceRes);
}
// Set source location
URI uri = remoteFile.toURI();
String sourceLocation = URIUtil.toUnencodedString(uri);
traceRes.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
}
}
}
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement in project tracecompass by tracecompass.
the class RemoteProfilesPreferencePage method createGlobalActions.
private void createGlobalActions() {
fDeleteAction = new Action(RemoteMessages.RemoteProfilesPreferencePage_DeleteAction) {
@Override
public void run() {
final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
if (selection.size() == 0) {
return;
}
for (Object item : selection.toList()) {
removeElement(item);
}
}
};
fDeleteAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
fDeleteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_DELETE);
fDeleteAction.setAccelerator(SWT.DEL);
fCutAction = new Action(RemoteMessages.RemoteProfilesPreferencePage_CutAction) {
@Override
public void run() {
final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
if (selection.size() != 1) {
return;
}
setClipboardContents(selection);
Object item = selection.getFirstElement();
removeElement(item);
}
};
fCutAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
fCutAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_CUT);
fCutAction.setAccelerator(SWT.CTRL | 'X');
fCopyAction = new Action(RemoteMessages.RemoteProfilesPreferencePage_CopyAction) {
@Override
public void run() {
final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
if (selection.size() != 1) {
return;
}
setClipboardContents(new StructuredSelection(copyElement(null, (TracePackageElement) selection.getFirstElement())));
}
};
fCopyAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
fCopyAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY);
fCopyAction.setAccelerator(SWT.CTRL | 'C');
fPasteAction = new Action(RemoteMessages.RemoteProfilesPreferencePage_PasteAction) {
@Override
public void run() {
final IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
if (selection.size() > 1) {
return;
}
if (!validatePaste(selection.getFirstElement())) {
return;
}
IStructuredSelection data = getClipboardContents();
data = getClipboardContents();
if (data == null) {
return;
}
for (Object object : data.toArray()) {
if (object instanceof RemoteImportProfileElement) {
TracePackageElement element = copyElement(null, (TracePackageElement) object);
TracePackageElement target = (TracePackageElement) selection.getFirstElement();
if (target == null) {
fProfiles.add((RemoteImportProfileElement) element);
} else {
int index = fProfiles.indexOf(target);
fProfiles.add(index + 1, (RemoteImportProfileElement) element);
}
Object[] expanded = fTreeViewer.getExpandedElements();
fTreeViewer.refresh();
fTreeViewer.setExpandedElements(expanded);
fTreeViewer.expandToLevel(element, AbstractTreeViewer.ALL_LEVELS);
fTreeViewer.setSelection(new StructuredSelection(element));
validate();
} else if (object instanceof TracePackageElement && selection.getFirstElement() instanceof TracePackageElement) {
TracePackageElement element = copyElement(null, (TracePackageElement) object);
TracePackageElement target = (TracePackageElement) selection.getFirstElement();
if (target.getClass().equals(element.getClass())) {
int index = target.getParent().indexOf(target);
target.getParent().addChild(index + 1, element);
fTreeViewer.refresh(target.getParent());
} else {
target.addChild(0, element);
fTreeViewer.refresh(target);
}
fTreeViewer.expandToLevel(element, AbstractTreeViewer.ALL_LEVELS);
fTreeViewer.setSelection(new StructuredSelection(element));
validate();
}
}
}
};
fPasteAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
fPasteAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_PASTE);
fPasteAction.setAccelerator(SWT.CTRL | 'V');
fTreeViewer.getTree().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
fDeleteAction.run();
}
if ((e.stateMask & SWT.CTRL) == SWT.CTRL) {
if (e.keyCode == 'x') {
fCutAction.run();
} else if (e.keyCode == 'c') {
fCopyAction.run();
} else if (e.keyCode == 'v') {
fPasteAction.run();
}
}
}
});
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement 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;
}
Aggregations