use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class XMLAnalysesManagerPreferencePage method deleteSupplementaryFiles.
/**
* Delete the supplementary files associated with XML analysis files.
*
* @param xmlFiles
* the xml analysis files (with extension)
* @return the list of elements that should be re-opened
*/
private static Collection<TmfCommonProjectElement> deleteSupplementaryFiles(Collection<String> xmlFiles) {
// 1. Look for all traces that have these analyses
// 2. Close them if they are opened, but remember them
// 3. Delete the related supplementary files
Collection<TmfCommonProjectElement> toReopen = new ArrayList<>();
List<IResource> resourceToDelete = new ArrayList<>();
Set<String> ids = Sets.newHashSet();
xmlFiles.forEach(xmlFile -> ids.addAll(XmlUtils.getAnalysisIdsFromFile(xmlFile)));
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(0);
for (IProject project : projects) {
TmfProjectElement pElement = TmfProjectRegistry.getProject(project);
if (pElement != null) {
List<TmfCommonProjectElement> tElements = new ArrayList<>();
TmfTraceFolder tracesFolder = pElement.getTracesFolder();
if (tracesFolder != null) {
tElements.addAll(tracesFolder.getTraces());
}
TmfExperimentFolder experimentsFolder = pElement.getExperimentsFolder();
if (experimentsFolder != null) {
tElements.addAll(experimentsFolder.getExperiments());
}
Set<IEditorReference> editorReferences = getEditorReferences();
for (TmfCommonProjectElement tElement : tElements) {
for (IResource resource : tElement.getSupplementaryResources()) {
for (String id : ids) {
if (resource.getName().startsWith(id)) {
resourceToDelete.add(resource);
}
}
}
IFile file = tElement.getBookmarksFile();
FileEditorInput input = new FileEditorInput(file);
boolean open = Iterables.any(editorReferences, editorReference -> {
try {
return editorReference.getEditorInput().equals(input);
} catch (PartInitException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Activator.logError("Failed to test the " + tElement.getName() + " editor", e);
return false;
}
});
if (open) {
toReopen.add(tElement);
}
tElement.closeEditors();
}
}
}
for (IResource resource : resourceToDelete) {
try {
resource.delete(false, null);
} catch (CoreException e) {
Activator.logError(NLS.bind(Messages.ManageXMLAnalysisDialog_DeleteFileError, resource.getName()));
}
}
return toReopen;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class XMLAnalysesManagerPreferencePage method importAnalysis.
/**
* Import new analysis.
*/
private void importAnalysis() {
FileDialog dialog = TmfFileDialogFactory.create(Display.getCurrent().getActiveShell(), SWT.OPEN | SWT.MULTI);
dialog.setText(Messages.ManageXMLAnalysisDialog_SelectFilesImport);
// $NON-NLS-1$ //$NON-NLS-2$
dialog.setFilterNames(new String[] { Messages.ManageXMLAnalysisDialog_ImportXmlFile + " (" + XML_FILTER_EXTENSION + ")" });
dialog.setFilterExtensions(new String[] { XML_FILTER_EXTENSION });
dialog.open();
String directoryPath = dialog.getFilterPath();
if (!directoryPath.isEmpty()) {
File directory = new File(directoryPath);
String[] files = dialog.getFileNames();
Collection<String> filesToProcess = Lists.newArrayList();
for (String fileName : files) {
File file = new File(directory, fileName);
if (loadXmlFile(file, true)) {
filesToProcess.add(file.getName());
}
}
if (!filesToProcess.isEmpty()) {
fillAnalysesTable();
Collection<TmfCommonProjectElement> elements = deleteSupplementaryFiles(filesToProcess);
XmlAnalysisModuleSource.notifyModuleChange();
refreshProject(elements);
}
}
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement 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.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class TracePackageExportOperation method exportSupplementaryFiles.
private void exportSupplementaryFiles(IProgressMonitor monitor, Node commonNode, TmfCommonProjectElement commonElement, TracePackageSupplFilesElement element) throws InterruptedException, CoreException {
Document doc = commonNode.getOwnerDocument();
if (element.getChildren().length > 0) {
IPath projectPath = commonElement.getProject().getPath();
for (TracePackageElement child : element.getChildren()) {
TracePackageSupplFileElement supplFile = (TracePackageSupplFileElement) child;
ModalContext.checkCanceled(monitor);
IResource res = supplFile.getResource();
// project/.tracing/A/B/statistics.ht -> .tracing/A/B/statistics.ht
IPath relativeToExportFolder = res.getFullPath().makeRelativeTo(projectPath);
// project/.traceExport/.tracing/A/B
IFolder folder = fExportFolder.getFolder(relativeToExportFolder.removeLastSegments(1));
TraceUtils.createFolder(folder, SubMonitor.convert(monitor));
res.refreshLocal(0, SubMonitor.convert(monitor));
createExportResource(folder, res);
Element suppFileElement = doc.createElement(ITracePackageConstants.SUPPLEMENTARY_FILE_ELEMENT);
suppFileElement.setAttribute(ITracePackageConstants.SUPPLEMENTARY_FILE_NAME_ATTRIB, relativeToExportFolder.toString());
commonNode.appendChild(suppFileElement);
}
IFolder suppFilesFolder = fExportFolder.getFolder(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER_NAME);
fResources.add(suppFilesFolder);
}
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement in project tracecompass by tracecompass.
the class TracePackageImportOperation method importBookmarks.
private void importBookmarks(IResource traceRes, TracePackageTraceElement traceElement, IProgressMonitor monitor) {
for (TracePackageElement o : traceElement.getChildren()) {
if (o instanceof TracePackageBookmarkElement && o.isChecked()) {
// Get element
IFile bookmarksFile = null;
TmfCommonProjectElement projectElement = getMatchingProjectElement(traceElement);
if (projectElement != null) {
try {
bookmarksFile = projectElement.createBookmarksFile(monitor);
// Make sure that if a bookmark is double-clicked first
// before opening the trace, it opens the right editor
// Get the editor id from the extension point
String traceEditorId = projectElement.getEditorId();
final String editorId = (traceEditorId != null) ? traceEditorId : TmfEventsEditor.ID;
IDE.setDefaultEditor(bookmarksFile, editorId);
} catch (CoreException e) {
Activator.getDefault().logError(MessageFormat.format(Messages.TracePackageImportOperation_ErrorCreatingBookmarkFile, traceRes.getName()), e);
}
}
if (bookmarksFile == null) {
break;
}
TracePackageBookmarkElement bookmarkElement = (TracePackageBookmarkElement) o;
List<Map<String, String>> bookmarks = bookmarkElement.getBookmarks();
for (Map<String, String> attrs : bookmarks) {
IMarker createMarker = null;
try {
createMarker = bookmarksFile.createMarker(IMarker.BOOKMARK);
} catch (CoreException e) {
Activator.getDefault().logError(MessageFormat.format(Messages.TracePackageImportOperation_ErrorCreatingBookmark, traceRes.getName()), e);
}
if (createMarker != null && createMarker.exists()) {
try {
for (Entry<String, String> entry : attrs.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key.equals(IMarker.LOCATION)) {
try {
/* try location as an integer for backward compatibility */
createMarker.setAttribute(IMarker.LOCATION, Integer.parseInt(value));
} catch (NumberFormatException e) {
createMarker.setAttribute(IMarker.LOCATION, value);
}
} else {
createMarker.setAttribute(key, value);
}
}
} catch (CoreException e) {
Activator.getDefault().logError(MessageFormat.format(Messages.TracePackageImportOperation_ErrorCreatingBookmark, traceRes.getName()), e);
}
}
}
}
}
monitor.worked(1);
}
Aggregations