Search in sources :

Example 11 with TracePackageTraceElement

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

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

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

the class RemoteProfilesPreferencePage method newConnectionNode.

private RemoteImportConnectionNodeElement newConnectionNode(TracePackageElement parent, TracePackageElement previous) {
    RemoteImportConnectionNodeElement node = new RemoteImportConnectionNodeElement(null, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeName, RemoteMessages.RemoteProfilesPreferencePage_DefaultConnectionNodeURI);
    RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(node, DEFAULT_ROOT_IMPORT_PATH);
    TracePackageTraceElement trace = new TracePackageTraceElement(traceGroup, DEFAULT_IMPORT_NAME, null);
    new TracePackageFilesElement(trace, DEFAULT_FILE_PATTERN);
    int index = previous == null ? parent.getChildren().length : parent.indexOf(previous) + 1;
    parent.addChild(index, node);
    newElementAdded(node);
    return node;
}
Also used : RemoteImportConnectionNodeElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) RemoteImportTraceGroupElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement)

Example 14 with TracePackageTraceElement

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

the class RemoteProfilesPreferencePage method copyElement.

private TracePackageElement copyElement(TracePackageElement parent, TracePackageElement element) {
    TracePackageElement copy = null;
    if (element instanceof RemoteImportProfileElement) {
        RemoteImportProfileElement source = (RemoteImportProfileElement) element;
        copy = new RemoteImportProfileElement(parent, source.getProfileName());
    } else if (element instanceof RemoteImportConnectionNodeElement) {
        RemoteImportConnectionNodeElement source = (RemoteImportConnectionNodeElement) element;
        copy = new RemoteImportConnectionNodeElement(parent, source.getName(), source.getURI());
    } else if (element instanceof RemoteImportTraceGroupElement) {
        RemoteImportTraceGroupElement source = (RemoteImportTraceGroupElement) element;
        copy = new RemoteImportTraceGroupElement(parent, source.getRootImportPath());
        ((RemoteImportTraceGroupElement) copy).setRecursive(source.isRecursive());
    } else if (element instanceof TracePackageTraceElement) {
        TracePackageTraceElement source = (TracePackageTraceElement) element;
        copy = new TracePackageTraceElement(parent, source.getImportName(), source.getTraceType());
    } else if (element instanceof TracePackageFilesElement) {
        TracePackageFilesElement source = (TracePackageFilesElement) element;
        copy = new TracePackageFilesElement(parent, source.getFileName());
    }
    for (TracePackageElement child : element.getChildren()) {
        copyElement(copy, child);
    }
    return copy;
}
Also used : RemoteImportConnectionNodeElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement) 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) RemoteImportTraceGroupElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement) RemoteImportProfileElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)

Example 15 with TracePackageTraceElement

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

the class RemoteProfilesPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    composite.setLayoutData(gd);
    GridLayout gl = new GridLayout(2, false);
    composite.setLayout(gl);
    PatternFilter patternFilter = new PatternFilter() {

        // show all children of matching profiles or profiles with matching connection node
        @Override
        protected boolean isLeafMatch(Viewer viewer, Object element) {
            TreeViewer treeViewer = (TreeViewer) viewer;
            TracePackageContentProvider contentProvider = (TracePackageContentProvider) treeViewer.getContentProvider();
            Object parentElement = element;
            while (!(parentElement instanceof RemoteImportProfileElement)) {
                parentElement = contentProvider.getParent(parentElement);
                if (parentElement instanceof TracePackageTraceElement) {
                    // don't show children of trace element
                    return false;
                }
            }
            RemoteImportProfileElement profile = (RemoteImportProfileElement) parentElement;
            if (super.isLeafMatch(viewer, profile)) {
                return true;
            }
            for (Object child : contentProvider.getChildren(profile)) {
                if ((child instanceof RemoteImportConnectionNodeElement) && (super.isLeafMatch(viewer, child))) {
                    return true;
                }
            }
            return false;
        }
    };
    final FilteredTree filteredTree = new FilteredTree(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.heightHint = 0;
    filteredTree.setLayoutData(gd);
    final TreeViewer treeViewer = filteredTree.getViewer();
    fTreeViewer = treeViewer;
    treeViewer.setContentProvider(new TracePackageContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof ArrayList) {
                return ((ArrayList<?>) inputElement).toArray();
            }
            return super.getElements(inputElement);
        }

        @Override
        public boolean hasChildren(Object element) {
            if (element instanceof TracePackageTraceElement) {
                return false;
            }
            return super.hasChildren(element);
        }
    });
    treeViewer.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof TracePackageTraceElement) {
                for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
                    if (files instanceof TracePackageFilesElement) {
                        return ((TracePackageFilesElement) files).getFileName();
                    }
                }
            } else if (element instanceof TracePackageElement) {
                return ((TracePackageElement) element).getText();
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof TracePackageTraceElement) {
                for (TracePackageElement files : ((TracePackageTraceElement) element).getChildren()) {
                    return files.getImage();
                }
            } else if (element instanceof TracePackageElement) {
                return ((TracePackageElement) element).getImage();
            }
            return super.getImage(element);
        }
    });
    treeViewer.addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        TracePackageElement element = (TracePackageElement) (selection.size() == 1 ? selection.getFirstElement() : null);
        fDetailsPanel.refreshDetailsPanel(element);
        enableButtons(selection);
        fSelectedProfileName = null;
        while (element != null) {
            if (element instanceof RemoteImportProfileElement) {
                fSelectedProfileName = ((RemoteImportProfileElement) element).getProfileName();
            }
            element = element.getParent();
        }
    });
    createGlobalActions();
    createContextMenu();
    fProfiles = readProfiles(PROFILE_FILE_PATH, new NullProgressMonitor());
    treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    treeViewer.setInput(fProfiles);
    treeViewer.expandAll();
    Composite buttonBar = createVerticalButtonBar(composite);
    gd = new GridData(SWT.CENTER, SWT.BEGINNING, false, false);
    gd.verticalIndent = filteredTree.getFilterControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y + gl.verticalSpacing;
    buttonBar.setLayoutData(gd);
    enableButtons((IStructuredSelection) treeViewer.getSelection());
    Composite details = new Composite(composite, SWT.NONE);
    gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
    details.setLayoutData(gd);
    gl = new GridLayout(2, false);
    gl.marginWidth = 0;
    details.setLayout(gl);
    Label label = new Label(details, SWT.NONE);
    label.setText(RemoteMessages.RemoteProfilesPreferencePage_DetailsPanelLabel);
    gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1);
    label.setLayoutData(gd);
    fDetailsPanel = new DetailsPanel(details);
    validate();
    for (RemoteImportProfileElement profile : fProfiles) {
        if (profile.getProfileName().equals(fSelectedProfileName)) {
            fTreeViewer.setSelection(new StructuredSelection(profile));
        }
    }
    Dialog.applyDialogFont(composite);
    return composite;
}
Also used : RemoteImportConnectionNodeElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TreeViewer(org.eclipse.jface.viewers.TreeViewer) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TreeViewer(org.eclipse.jface.viewers.TreeViewer) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) RemoteImportProfileElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TracePackageContentProvider(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageContentProvider) GridData(org.eclipse.swt.layout.GridData) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Aggregations

TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)32 TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)23 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)22 RemoteImportConnectionNodeElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement)9 RemoteImportTraceGroupElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement)9 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)9 ArrayList (java.util.ArrayList)8 RemoteImportProfileElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)8 Element (org.w3c.dom.Element)7 IPath (org.eclipse.core.runtime.IPath)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 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)6 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)6 Path (org.eclipse.core.runtime.Path)4 Node (org.w3c.dom.Node)4 URI (java.net.URI)3 HashMap (java.util.HashMap)3