Search in sources :

Example 1 with TracePackageBookmarkElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement 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[] {});
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) ArrayList(java.util.ArrayList) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) CoreException(org.eclipse.core.runtime.CoreException) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with TracePackageBookmarkElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement in project tracecompass by tracecompass.

the class ManifestReader method loadTracesFomNodeList.

private static void loadTracesFomNodeList(List<TracePackageElement> packageElements, NodeList traceElements) {
    for (int i = 0; i < traceElements.getLength(); i++) {
        Node traceNode = traceElements.item(i);
        if (traceNode.getNodeType() == Node.ELEMENT_NODE) {
            Element traceElement = (Element) traceNode;
            String traceName = traceElement.getAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB);
            String traceType = traceElement.getAttribute(ITracePackageConstants.TRACE_TYPE_ATTRIB);
            TracePackageElement element;
            if (traceNode.getNodeName().equals(ITracePackageConstants.EXPERIMENT_ELEMENT)) {
                element = new TracePackageExperimentElement(null, traceName, traceType);
                // $NON-NLS-1$
                new TracePackageFilesElement(element, "");
                NodeList expTraces = traceElement.getElementsByTagName(ITracePackageConstants.EXP_TRACE_ELEMENT);
                for (int j = 0; j < expTraces.getLength(); j++) {
                    Node expTraceNode = expTraces.item(j);
                    if (expTraceNode.getNodeType() == Node.ELEMENT_NODE) {
                        Element expTraceElement = (Element) expTraceNode;
                        String expTrace = expTraceElement.getAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB);
                        ((TracePackageExperimentElement) element).addExpTrace(expTrace);
                    }
                }
            } else {
                element = new TracePackageTraceElement(null, traceName, traceType);
                NodeList fileElements = traceElement.getElementsByTagName(ITracePackageConstants.TRACE_FILE_ELEMENT);
                for (int j = 0; j < fileElements.getLength(); j++) {
                    Node fileNode = fileElements.item(j);
                    if (fileNode.getNodeType() == Node.ELEMENT_NODE) {
                        Element fileElement = (Element) fileNode;
                        String fileName = fileElement.getAttribute(ITracePackageConstants.TRACE_FILE_NAME_ATTRIB);
                        new TracePackageFilesElement(element, fileName);
                    }
                }
            }
            // Supplementary files
            NodeList suppFilesElements = traceElement.getElementsByTagName(ITracePackageConstants.SUPPLEMENTARY_FILE_ELEMENT);
            if (suppFilesElements.getLength() > 0) {
                TracePackageSupplFilesElement supplFilesElement = new TracePackageSupplFilesElement(element);
                for (int j = 0; j < suppFilesElements.getLength(); j++) {
                    Node suppFileNode = suppFilesElements.item(j);
                    if (suppFileNode.getNodeType() == Node.ELEMENT_NODE) {
                        Element suppFileElement = (Element) suppFileNode;
                        String fileName = suppFileElement.getAttribute(ITracePackageConstants.SUPPLEMENTARY_FILE_NAME_ATTRIB);
                        new TracePackageSupplFileElement(fileName, supplFilesElement);
                    }
                }
            }
            // bookmarks
            List<Map<String, String>> bookmarkAttribs = new ArrayList<>();
            NodeList bookmarksElements = traceElement.getElementsByTagName(ITracePackageConstants.BOOKMARKS_ELEMENT);
            for (int j = 0; j < bookmarksElements.getLength(); j++) {
                Node bookmarksNode = bookmarksElements.item(j);
                if (bookmarksNode.getNodeType() == Node.ELEMENT_NODE) {
                    NodeList bookmarkElements = traceElement.getElementsByTagName(ITracePackageConstants.BOOKMARK_ELEMENT);
                    for (int k = 0; k < bookmarkElements.getLength(); k++) {
                        Node bookmarkNode = bookmarkElements.item(k);
                        if (bookmarkNode.getNodeType() == Node.ELEMENT_NODE) {
                            Element bookmarkElement = (Element) bookmarkNode;
                            NamedNodeMap attributesMap = bookmarkElement.getAttributes();
                            Map<String, String> attribs = new HashMap<>();
                            for (int l = 0; l < attributesMap.getLength(); l++) {
                                Node item = attributesMap.item(l);
                                attribs.put(item.getNodeName(), item.getNodeValue());
                            }
                            bookmarkAttribs.add(attribs);
                        }
                    }
                }
            }
            if (!bookmarkAttribs.isEmpty()) {
                new TracePackageBookmarkElement(element, bookmarkAttribs);
            }
            packageElements.add(element);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) HashMap(java.util.HashMap) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) Node(org.w3c.dom.Node) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) Element(org.w3c.dom.Element) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) HashMap(java.util.HashMap) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)

Example 3 with TracePackageBookmarkElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement in project tracecompass by tracecompass.

the class TracePackageExportOperation method exportBookmarks.

private static void exportBookmarks(IProgressMonitor monitor, Node commonNode, TracePackageBookmarkElement element) throws CoreException, InterruptedException {
    Document doc = commonNode.getOwnerDocument();
    IFile bookmarksFile = ((TracePackageTraceElement) element.getParent()).getTraceElement().getBookmarksFile();
    if (bookmarksFile != null && bookmarksFile.exists()) {
        IMarker[] findMarkers = bookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO);
        if (findMarkers.length > 0) {
            Element bookmarksXmlElement = doc.createElement(ITracePackageConstants.BOOKMARKS_ELEMENT);
            Node bookmarksNode = commonNode.appendChild(bookmarksXmlElement);
            for (IMarker marker : findMarkers) {
                ModalContext.checkCanceled(monitor);
                Element singleBookmarkXmlElement = doc.createElement(ITracePackageConstants.BOOKMARK_ELEMENT);
                for (String key : marker.getAttributes().keySet()) {
                    singleBookmarkXmlElement.setAttribute(key, marker.getAttribute(key).toString());
                }
                bookmarksNode.appendChild(singleBookmarkXmlElement);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectModelElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) Element(org.w3c.dom.Element) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) Node(org.w3c.dom.Node) IMarker(org.eclipse.core.resources.IMarker) Document(org.w3c.dom.Document)

Example 4 with TracePackageBookmarkElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement 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);
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) IMarker(org.eclipse.core.resources.IMarker) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with TracePackageBookmarkElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement 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;
}
Also used : TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectModelElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) Element(org.w3c.dom.Element) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) Node(org.w3c.dom.Node) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)

Aggregations

TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)5 TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)4 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)4 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)4 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)4 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)4 TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)4 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)4 IFile (org.eclipse.core.resources.IFile)3 IMarker (org.eclipse.core.resources.IMarker)3 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)3 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)3 Element (org.w3c.dom.Element)3 Node (org.w3c.dom.Node)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CoreException (org.eclipse.core.runtime.CoreException)2 TmfProjectModelElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectModelElement)2 IFolder (org.eclipse.core.resources.IFolder)1