use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class ImportHandler method execute.
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return false;
}
CommandParameter param;
fLock.lock();
try {
param = fParam;
if (param == null) {
return null;
}
param = param.clone();
} finally {
fLock.unlock();
}
// create default project
IProject project = TmfProjectRegistry.createProject(RemoteFetchLogWizardRemotePage.DEFAULT_REMOTE_PROJECT_NAME, null, null);
if (param.getSession().isLiveTrace()) {
importLiveTrace(new LttngRelaydConnectionInfo(param.getSession().getLiveUrl(), param.getSession().getLivePort(), param.getSession().getName()), project);
return null;
} else if (param.getSession().isStreamedTrace()) {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
String notify = store.getString(NOTIFY_IMPORT_STREAMED_PREF_KEY);
if (!MessageDialogWithToggle.ALWAYS.equals(notify)) {
MessageDialogWithToggle.openInformation(window.getShell(), null, Messages.TraceControl_ImportDialogStreamedTraceNotification, Messages.TraceControl_ImportDialogStreamedTraceNotificationToggle, false, store, NOTIFY_IMPORT_STREAMED_PREF_KEY);
}
// Streamed trace
TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true);
TmfTraceFolder traceFolder = projectElement.getTracesFolder();
ImportTraceWizard wizard = new ImportTraceWizard();
wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(traceFolder));
WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
dialog.open();
return null;
}
// Generate the profile
TraceSessionComponent session = param.getSession();
// $NON-NLS-1$
RemoteImportProfileElement profile = new RemoteImportProfileElement(null, "LTTng Remote Traces");
RemoteSystemProxy proxy = session.getTargetNode().getRemoteSystemProxy();
IRemoteConnection rc = proxy.getRemoteConnection();
String name = rc.getName();
if (!rc.hasService(IRemoteConnectionHostService.class)) {
return null;
}
String scheme = rc.getConnectionType().getScheme();
IRemoteConnectionHostService hostService = checkNotNull(rc.getService(IRemoteConnectionHostService.class));
String address = hostService.getHostname();
String user = hostService.getUsername();
int port = hostService.getPort();
URI remoteUri;
try {
remoteUri = new URI(scheme, user, address, port, null, null, null);
} catch (URISyntaxException e) {
return false;
}
RemoteImportConnectionNodeElement connection = new RemoteImportConnectionNodeElement(profile, name, remoteUri.toString());
String pathString = session.isSnapshotSession() ? session.getSnapshotInfo().getSnapshotPath() : session.getSessionPath();
IPath path = new Path(pathString);
RemoteImportTraceGroupElement group = new RemoteImportTraceGroupElement(connection, path.toString());
group.setRecursive(true);
// $NON-NLS-1$//$NON-NLS-2$
TracePackageElement element = new TracePackageTraceElement(group, "", "");
// $NON-NLS-1$
new TracePackageFilesElement(element, ".*");
String experimentName = path.lastSegment();
if (!experimentName.startsWith(session.getName())) {
experimentName = session.getName();
}
RemoteFetchLogWizard wizard = new RemoteFetchLogWizard(profile, experimentName);
wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
dialog.open();
return null;
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.
the class RemoteFetchLogWizardRemotePage method createElementViewer.
@Override
protected void createElementViewer(Composite compositeParent) {
super.createElementViewer(compositeParent);
CheckboxTreeViewer elementViewer = getElementViewer();
elementViewer.setLabelProvider(new TracePackageLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof TracePackageTraceElement) {
for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
if (files instanceof TracePackageFilesElement) {
return ((TracePackageFilesElement) files).getFileName();
}
}
}
return super.getText(element);
}
@Override
public Image getImage(Object element) {
if (element instanceof TracePackageTraceElement) {
for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
return files.getImage();
}
}
return super.getImage(element);
}
});
elementViewer.setComparator(new ViewerComparator() {
@Override
public int category(Object element) {
if (element instanceof TracePackageTraceElement) {
return 1;
}
return 0;
}
});
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement 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.TracePackageTraceElement 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.TracePackageTraceElement in project tracecompass by tracecompass.
the class RemoteProfilesPreferencePage method newTraceGroup.
private RemoteImportTraceGroupElement newTraceGroup(TracePackageElement parent, TracePackageElement previous) {
RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(null, DEFAULT_ROOT_IMPORT_PATH);
TracePackageTraceElement trace = new TracePackageTraceElement(traceGroup, DEFAULT_IMPORT_NAME, null);
new TracePackageFilesElement(trace, DEFAULT_FILE_PATTERN);
int index = previous == null ? parent.getChildren().length : parent.indexOf(previous) + 1;
parent.addChild(index, traceGroup);
newElementAdded(traceGroup);
return traceGroup;
}
Aggregations