Search in sources :

Example 16 with TracePackageElement

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

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

the class RemoteProfilesPreferencePage method writeProfiles.

private boolean writeProfiles(List<RemoteImportProfileElement> profiles, String path) {
    try {
        String contents = RemoteImportProfilesWriter.writeProfilesToXML(profiles.toArray(new TracePackageElement[0]));
        File file = new File(path);
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            writer.write(contents);
            return true;
        }
    } catch (IOException | ParserConfigurationException | TransformerException e) {
        MessageDialog.openError(getShell(), RemoteMessages.RemoteProfilesPreferencePage_ErrorWritingProfile, e.getMessage());
    }
    return false;
}
Also used : FileWriter(java.io.FileWriter) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException) BufferedWriter(java.io.BufferedWriter)

Example 18 with TracePackageElement

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

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

the class RemoteProfilesPreferencePage method readProfiles.

private static List<RemoteImportProfileElement> readProfiles(String path, IProgressMonitor monitor) {
    final ExtractRemoteProfilesOperation op = new ExtractRemoteProfilesOperation(path);
    op.run(monitor);
    List<RemoteImportProfileElement> profiles = new ArrayList<>();
    if (!op.getStatus().isOK()) {
        return profiles;
    }
    TracePackageElement[] resultElements = op.getResultElements();
    if (resultElements != null) {
        for (TracePackageElement element : resultElements) {
            if (element instanceof RemoteImportProfileElement) {
                profiles.add((RemoteImportProfileElement) element);
            }
        }
    }
    return profiles;
}
Also used : ExtractRemoteProfilesOperation(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.ExtractRemoteProfilesOperation) ArrayList(java.util.ArrayList) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) RemoteImportProfileElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)

Example 20 with TracePackageElement

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

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