use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class NewTmfViewAction method run.
@Override
public void run() {
ITmfTrace pinnedTrace = fPinnedTrace;
if (fNewInstance) {
if (pinnedTrace == null) {
return;
}
/* We need to wait for the trace to be opened before opening the view */
IFile file = TmfTraceManager.getInstance().getTraceContext(pinnedTrace).getEditorFile();
Object element = new TmfEditorLinkHelper().findSelection(new FileEditorInput(file)).getFirstElement();
if (element instanceof TmfCommonProjectElement) {
OpenProjectElementJob openJob = new OpenProjectElementJob((TmfCommonProjectElement) element, file);
openJob.schedule();
Thread waitThread = new Thread() {
@Override
public void run() {
while (!TmfTraceManager.getInstance().getOpenedTraces().contains(openJob.getTrace())) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
Display.getDefault().asyncExec(() -> {
IViewPart view = TmfViewFactory.newView(fViewId, true);
if (view instanceof ITmfPinnable) {
((ITmfPinnable) view).setPinned(openJob.getTrace());
}
});
}
};
waitThread.start();
}
return;
}
IViewPart view = TmfViewFactory.newView(fViewId, true);
if (pinnedTrace != null && view instanceof ITmfPinnable) {
((ITmfPinnable) view).setPinned(pinnedTrace);
}
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class TrimTraceDialog method validateNewTraceName.
private void validateNewTraceName() {
String newTraceName = fNewElementName.getText();
TmfCommonProjectElement element = fElement;
IWorkspace workspace = element.getResource().getWorkspace();
IStatus nameStatus = workspace.validateName(newTraceName, IResource.FOLDER);
if ("".equals(newTraceName)) {
// $NON-NLS-1$
updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null));
return;
}
if (!nameStatus.isOK()) {
updateStatus(nameStatus);
return;
}
IContainer parentFolder = element.getResource().getParent();
if (parentFolder.findMember(newTraceName) != null) {
updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null));
return;
}
TmfTraceFolder tracesFolderElement = element.getProject().getTracesFolder();
if (tracesFolderElement != null) {
IFolder tracesFolder = tracesFolderElement.getResource();
IPath traceDestinationPath = new Path(newTraceName);
if (tracesFolder.getFolder(traceDestinationPath).exists()) {
updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null));
return;
}
}
// $NON-NLS-1$
updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, ""));
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class TracePackageImportOperation method importSupplFiles.
private IStatus importSupplFiles(TracePackageTraceElement packageElement, IProgressMonitor monitor) {
List<Pair<String, String>> fileNameAndLabelPairs = new ArrayList<>();
Map<String, String> suppFilesRename = new HashMap<>();
for (TracePackageElement element : packageElement.getChildren()) {
if (element instanceof TracePackageSupplFilesElement) {
for (TracePackageElement child : element.getChildren()) {
if (child.isChecked()) {
TracePackageSupplFileElement supplFile = (TracePackageSupplFileElement) child;
if (packageElement instanceof TracePackageExperimentElement) {
String oldExpName = getOldExpName(supplFile);
if (!packageElement.getImportName().equals(oldExpName)) {
suppFilesRename.put(supplFile.getText(), supplFile.getText().replace(oldExpName, packageElement.getImportName()));
}
}
fileNameAndLabelPairs.add(new Pair<>(checkNotNull(supplFile.getText()), checkNotNull(new Path(supplFile.getText()).lastSegment())));
}
}
}
}
if (!fileNameAndLabelPairs.isEmpty()) {
TmfCommonProjectElement projectElement = getMatchingProjectElement(packageElement);
if (projectElement != null) {
ArchiveFile archiveFile = getSpecifiedArchiveFile();
projectElement.refreshSupplementaryFolder();
IPath destinationContainerPath;
if (packageElement instanceof TracePackageExperimentElement) {
destinationContainerPath = projectElement.getProject().getSupplementaryFolder().getFullPath();
} else {
// Project/Traces/A/B -> A/B
final TmfTraceFolder tracesFolder = fTmfTraceFolder.getProject().getTracesFolder();
if (tracesFolder == null) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation);
}
IPath traceFolderRelativePath = fTmfTraceFolder.getPath().makeRelativeTo(tracesFolder.getPath());
// Project/.tracing/A/B/
IFolder traceSupplementaryFolder = fTmfTraceFolder.getTraceSupplementaryFolder(traceFolderRelativePath.toString());
destinationContainerPath = traceSupplementaryFolder.getFullPath();
}
// Remove the .tracing segment at the beginning so that a file
// in folder .tracing/A/B/ imports to destinationContainerPath/A/B/
Path baseSourcePath = new Path(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER_NAME);
return importFiles(archiveFile, fileNameAndLabelPairs, destinationContainerPath, baseSourcePath, suppFilesRename, monitor);
}
}
return Status.OK_STATUS;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class TracePackageExportOperation method exportTraceFiles.
private void exportTraceFiles(IProgressMonitor monitor, Node traceNode, TracePackageFilesElement element) throws CoreException {
Document doc = traceNode.getOwnerDocument();
TmfCommonProjectElement traceElement = ((TracePackageTraceElement) element.getParent()).getTraceElement();
IResource resource = traceElement.getResource();
final TmfProjectModelElement tracesFolder = traceElement.getProject().getTracesFolder();
if (tracesFolder == null) {
return;
}
IPath traceFolderPath = tracesFolder.getPath();
// project/Traces/A/B/Kernel -> A/B/Kernel
IPath relativeToExportFolder = resource.getFullPath().makeRelativeTo(traceFolderPath);
// project/.traceExport/A/B
IFolder folder = fExportFolder.getFolder(relativeToExportFolder.removeLastSegments(1));
TraceUtils.createFolder(folder, SubMonitor.convert(monitor));
createExportResource(folder, resource);
Element fileElement = doc.createElement(ITracePackageConstants.TRACE_FILE_ELEMENT);
fileElement.setAttribute(ITracePackageConstants.TRACE_FILE_NAME_ATTRIB, relativeToExportFolder.toString());
traceNode.appendChild(fileElement);
// Always export the top-most folder containing the trace or the
// trace itself
IResource exportedResource = fExportFolder.findMember(relativeToExportFolder.segment(0));
fResources.add(exportedResource);
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class TracePackageExportOperation method exportCommon.
private Node exportCommon(IProgressMonitor monitor, Node tmfNode, TracePackageTraceElement tracePackageElement, String elementString) throws InterruptedException, CoreException {
TmfCommonProjectElement commonElement = tracePackageElement.getTraceElement();
Element commonXmlElement = tmfNode.getOwnerDocument().createElement(elementString);
commonXmlElement.setAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB, commonElement.getResource().getName());
commonXmlElement.setAttribute(ITracePackageConstants.TRACE_TYPE_ATTRIB, commonElement.getTraceType());
Node commonNode = tmfNode.appendChild(commonXmlElement);
for (TracePackageElement element : tracePackageElement.getChildren()) {
ModalContext.checkCanceled(monitor);
if (!element.isChecked()) {
continue;
}
if (element instanceof TracePackageSupplFilesElement) {
exportSupplementaryFiles(monitor, commonNode, commonElement, (TracePackageSupplFilesElement) element);
} else if (element instanceof TracePackageBookmarkElement) {
exportBookmarks(monitor, commonNode, (TracePackageBookmarkElement) element);
} else if (element instanceof TracePackageFilesElement && commonElement instanceof TmfTraceElement) {
exportTraceFiles(monitor, commonNode, (TracePackageFilesElement) element);
}
monitor.worked(1);
}
return commonNode;
}
Aggregations