Search in sources :

Example 1 with TracePackageExperimentElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement 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 TracePackageExperimentElement

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

the class ImportTracePackageWizardPage method checkForConflict.

private boolean checkForConflict() {
    TracePackageElement[] packageElements = (TracePackageElement[]) getElementViewer().getInput();
    List<TracePackageExperimentElement> experimentElements = new ArrayList<>();
    List<TracePackageTraceElement> traceElements = new ArrayList<>();
    Map<TracePackageExperimentElement, List<TracePackageTraceElement>> experimentTracesMap = new HashMap<>();
    // List of experiment to rename
    List<TracePackageExperimentElement> experimentToRename = new ArrayList<>();
    // Conflict traces that are not in an experiment
    List<TracePackageTraceElement> unhandledTraces = new ArrayList<>();
    // Process package element to separate experiments and traces
    for (TracePackageElement packageElement : packageElements) {
        TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
        if (AbstractTracePackageOperation.isFilesChecked(traceElement)) {
            if (traceElement instanceof TracePackageExperimentElement) {
                TracePackageExperimentElement experimentElement = (TracePackageExperimentElement) traceElement;
                experimentElements.add(experimentElement);
                if (experimentExists(experimentElement)) {
                    experimentToRename.add(experimentElement);
                }
            } else {
                traceElements.add(traceElement);
            }
        }
    }
    for (TracePackageTraceElement traceElement : traceElements) {
        processTrace(experimentElements, traceElement, experimentTracesMap, unhandledTraces);
    }
    boolean result = true;
    if (!experimentTracesMap.isEmpty() || !experimentToRename.isEmpty()) {
        result &= handleExperimentConflict(experimentTracesMap, experimentToRename);
    }
    if (!unhandledTraces.isEmpty()) {
        result &= handleTracesConflict(unhandledTraces);
    }
    return result;
}
Also used : TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) ArrayList(java.util.ArrayList) List(java.util.List) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Example 3 with TracePackageExperimentElement

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

the class ImportTracePackageWizardPage method handleExperimentConflict.

private boolean handleExperimentConflict(Map<TracePackageExperimentElement, List<TracePackageTraceElement>> experimentTracesMap, List<TracePackageExperimentElement> experimentToRename) {
    if (!experimentToRename.isEmpty() && experimentTracesMap.isEmpty()) {
        for (TracePackageExperimentElement experimentElement : experimentToRename) {
            int returnCode = promptForExperimentRename(experimentElement);
            // constant for that.
            if (returnCode < 0) {
                return false;
            }
            final String[] response = new String[] { IDialogConstants.NO_LABEL, IDialogConstants.YES_LABEL };
            if (response[returnCode].equals(IDialogConstants.NO_LABEL)) {
                uncheckExperimentElement(experimentElement, Collections.emptyList());
            } else if (response[returnCode].equals(IDialogConstants.YES_LABEL)) {
                changeExperimentName(experimentElement);
            }
        }
    } else {
        for (Entry<TracePackageExperimentElement, List<TracePackageTraceElement>> experimentEntry : experimentTracesMap.entrySet()) {
            int returnCode = promptForExperimentOverwrite(experimentEntry, experimentToRename);
            // constant for that.
            if (returnCode < 0) {
                return false;
            }
            final String[] response = new String[] { IDialogConstants.NO_LABEL, IDialogConstants.YES_LABEL };
            if (response[returnCode].equals(IDialogConstants.NO_LABEL)) {
                uncheckExperimentElement(experimentEntry.getKey(), experimentEntry.getValue());
            }
        }
    }
    return true;
}
Also used : TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with TracePackageExperimentElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement 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 5 with TracePackageExperimentElement

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

the class TracePackageImportOperation method getMatchingProjectElement.

/**
 * Return the matching TmfTraceElement for a given trace element.
 */
private TmfCommonProjectElement getMatchingProjectElement(TracePackageTraceElement tracePackageElement) {
    if (tracePackageElement instanceof TracePackageExperimentElement) {
        for (TmfExperimentElement experiment : fTmfExperimentFolder.getExperiments()) {
            if (experiment.getName().equals(tracePackageElement.getImportName())) {
                return experiment;
            }
        }
    } else {
        IPath tracePath = fTmfTraceFolder.getPath().append(tracePackageElement.getDestinationElementPath());
        List<TmfTraceElement> traces = fTmfTraceFolder.getTraces();
        for (TmfTraceElement t : traces) {
            if (t.getPath().equals(tracePath)) {
                return t;
            }
        }
    }
    return null;
}
Also used : 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) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)

Aggregations

TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)10 ArrayList (java.util.ArrayList)7 TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)7 TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)6 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)5 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)5 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)5 TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)4 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)4 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)4 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)4 HashMap (java.util.HashMap)3 IPath (org.eclipse.core.runtime.IPath)3 Element (org.w3c.dom.Element)3 Node (org.w3c.dom.Node)3 List (java.util.List)2 IFolder (org.eclipse.core.resources.IFolder)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Path (org.eclipse.core.runtime.Path)2