Search in sources :

Example 26 with TracePackageElement

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

the class TracePackageExportOperation method run.

/**
 * Run the operation. The status (result) of the operation can be obtained
 * with {@link #getStatus}
 *
 * @param progressMonitor
 *            the progress monitor to use to display progress and receive
 *            requests for cancellation
 */
@Override
public void run(IProgressMonitor progressMonitor) {
    try {
        int totalWork = getNbCheckedElements(fTraceExportElements) * 2;
        progressMonitor.beginTask(Messages.TracePackageExportOperation_GeneratingPackage, totalWork);
        fExportFolder = createExportFolder(progressMonitor);
        Document doc = XmlUtils.newSafeDocumentBuilderFactory().newDocumentBuilder().newDocument();
        Element createElement = doc.createElement(ITracePackageConstants.TMF_EXPORT_ELEMENT);
        Node tmfNode = doc.appendChild(createElement);
        List<TracePackageExperimentElement> experimentPackageElements = new ArrayList<>();
        for (TracePackageTraceElement tracePackageElement : fTraceExportElements) {
            if (!isFilesChecked(tracePackageElement)) {
                continue;
            }
            if (tracePackageElement instanceof TracePackageExperimentElement) {
                experimentPackageElements.add((TracePackageExperimentElement) tracePackageElement);
            } else {
                exportTrace(progressMonitor, tmfNode, tracePackageElement);
            }
        }
        for (TracePackageExperimentElement experimentPackageElement : experimentPackageElements) {
            exportExperiment(progressMonitor, tmfNode, experimentPackageElement);
        }
        Transformer transformer = XmlUtils.newSecureTransformer();
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        // $NON-NLS-1$ //$NON-NLS-2$
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        DOMSource source = new DOMSource(doc);
        StringWriter buffer = new StringWriter();
        StreamResult result = new StreamResult(buffer);
        transformer.transform(source, result);
        String content = buffer.getBuffer().toString();
        ModalContext.checkCanceled(progressMonitor);
        exportManifest(content);
        setStatus(exportToArchive(progressMonitor, totalWork));
        fExportFolder.delete(true, SubMonitor.convert(progressMonitor));
        progressMonitor.done();
    } catch (InterruptedException e) {
        setStatus(Status.CANCEL_STATUS);
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) 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) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) StringWriter(java.io.StringWriter) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Example 27 with TracePackageElement

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

Example 28 with TracePackageElement

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

the class TracePackageImportOperation method deleteExistingTraces.

private IStatus deleteExistingTraces(IProgressMonitor progressMonitor) {
    for (TracePackageElement packageElement : fImportTraceElements) {
        TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
        if (!isFilesChecked(traceElement)) {
            continue;
        }
        TmfCommonProjectElement projectElement = getMatchingProjectElement(traceElement);
        try {
            if (projectElement instanceof TmfExperimentElement) {
                Display.getDefault().syncExec(() -> projectElement.closeEditors());
                projectElement.deleteSupplementaryFolder();
                projectElement.getResource().delete(true, SubMonitor.convert(progressMonitor));
            } else if (projectElement instanceof TmfTraceElement) {
                ((TmfTraceElement) projectElement).delete(SubMonitor.convert(progressMonitor), true);
            }
        } catch (CoreException e) {
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e);
        }
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)

Example 29 with TracePackageElement

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

the class ExportTracePackageWizardPage method createElementViewer.

@Override
protected void createElementViewer(Composite parent) {
    super.createElementViewer(parent);
    CheckboxTreeViewer elementViewer = getElementViewer();
    elementViewer.getTree().setHeaderVisible(true);
    // Content column
    TreeViewerColumn column = new TreeViewerColumn(elementViewer, SWT.NONE);
    column.getColumn().setWidth(CONTENT_COL_WIDTH);
    column.getColumn().setText(Messages.ExportTracePackageWizardPage_ContentColumnName);
    column.setLabelProvider(new TracePackageLabelProvider());
    // Size column
    column = new TreeViewerColumn(elementViewer, SWT.NONE);
    column.getColumn().setWidth(SIZE_COL_WIDTH);
    column.getColumn().setText(Messages.ExportTracePackageWizardPage_SizeColumnName);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TracePackageElement tracePackageElement = (TracePackageElement) element;
            long size = tracePackageElement.getSize(false);
            if (size == 0) {
                return null;
            }
            int level = 0;
            TracePackageElement curElement = tracePackageElement.getParent();
            while (curElement != null) {
                curElement = curElement.getParent();
                ++level;
            }
            return indent(getHumanReadable(size), level);
        }

        private String indent(String humanReadable, int level) {
            StringBuilder s = new StringBuilder(humanReadable);
            for (int i = 0; i < level; ++i) {
                // $NON-NLS-1$
                final String indentStr = "  ";
                s.insert(0, indentStr);
            }
            return s.toString();
        }
    });
    elementViewer.setInput(createElementViewerInput());
    elementViewer.expandToLevel(2);
    setAllChecked(elementViewer, false, true);
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageLabelProvider(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageLabelProvider) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn)

Example 30 with TracePackageElement

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

the class ExportTracePackageWizardPage method updateApproximateSelectedSize.

@Override
protected void updateApproximateSelectedSize() {
    long checkedSize = 0;
    TracePackageElement[] tracePackageElements = (TracePackageElement[]) getElementViewer().getInput();
    for (TracePackageElement element : tracePackageElements) {
        checkedSize += element.getSize(true);
    }
    checkedSize = Math.max(0, checkedSize);
    fApproximateSizeLabel.setText(MessageFormat.format(Messages.ExportTracePackageWizardPage_ApproximateSizeLbl, getHumanReadable(checkedSize)));
}
Also used : TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)

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