Search in sources :

Example 11 with TracePackageElement

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

the class ImportTracePackageWizardPage method finish.

/**
 * Finish the wizard page
 *
 * @return true on success
 */
public boolean finish() {
    if (!checkForConflict()) {
        return false;
    }
    saveWidgetValues();
    Object input = getElementViewer().getInput();
    TracePackageElement[] traceElements = (TracePackageElement[]) input;
    final TracePackageImportOperation importOperation = new TracePackageImportOperation(fValidatedFilePath, traceElements, fTmfTraceFolder);
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                importOperation.run(monitor);
            }
        });
        IStatus status = importOperation.getStatus();
        if (status.getSeverity() == IStatus.ERROR) {
            handleErrorStatus(status);
        }
    } catch (InvocationTargetException e) {
        handleError(Messages.ImportTracePackageWizardPage_ErrorOperation, e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    return importOperation.getStatus().getSeverity() == IStatus.OK;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 12 with TracePackageElement

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

the class ImportTracePackageWizardPage method createElementViewerInput.

@Override
protected Object createElementViewerInput() {
    final AbstractTracePackageOperation op = createExtractManifestOperation(getFilePathValue());
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.ImportTracePackageWizardPage_ReadingPackage, 10);
                op.run(monitor);
                monitor.done();
            }
        });
        IStatus status = op.getStatus();
        if (status.getSeverity() == IStatus.ERROR) {
            handleErrorStatus(status);
        }
    } catch (InvocationTargetException e1) {
        handleError(Messages.TracePackageExtractManifestOperation_ErrorReadingManifest, e1);
    } catch (InterruptedException e1) {
    // Canceled
    }
    TracePackageElement[] resultElements = op.getResultElements();
    if (resultElements == null || resultElements.length == 0) {
        return null;
    }
    return resultElements;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) AbstractTracePackageOperation(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageOperation) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 13 with TracePackageElement

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

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

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement 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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) 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) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) Document(org.w3c.dom.Document) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)41 TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)26 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)20 ArrayList (java.util.ArrayList)12 Element (org.w3c.dom.Element)11 RemoteImportProfileElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)9 IStatus (org.eclipse.core.runtime.IStatus)8 RemoteImportConnectionNodeElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement)8 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)8 IPath (org.eclipse.core.runtime.IPath)7 Status (org.eclipse.core.runtime.Status)6 RemoteImportTraceGroupElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement)6 TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)6 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)6 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)6 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)6 HashMap (java.util.HashMap)5 Path (org.eclipse.core.runtime.Path)5 Document (org.w3c.dom.Document)5 IFileStore (org.eclipse.core.filesystem.IFileStore)4