Search in sources :

Example 6 with TmfFilterNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode in project tracecompass by tracecompass.

the class TmfFilterXMLWriter method buildXMLTree.

/**
 * The Tree to XML parser
 *
 * @param document The XML document
 * @param treenode The node to write
 * @param parentElement The XML element of the parent
 */
public static void buildXMLTree(final Document document, final ITmfFilterTreeNode treenode, Element parentElement) {
    Element element = document.createElement(treenode.getNodeName());
    if (treenode instanceof ITmfFilterWithNot && ((ITmfFilterWithNot) treenode).isNot()) {
        element.setAttribute(ITmfFilterWithNot.NOT_ATTRIBUTE, Boolean.TRUE.toString());
    }
    if (treenode instanceof ITmfFilterWithValue) {
        ITmfFilterWithValue node = (ITmfFilterWithValue) treenode;
        element.setAttribute(ITmfFilterWithValue.VALUE_ATTRIBUTE, node.getValue());
    }
    if (treenode instanceof TmfFilterNode) {
        TmfFilterNode node = (TmfFilterNode) treenode;
        element.setAttribute(TmfFilterNode.NAME_ATTR, node.getFilterName());
    } else if (treenode instanceof TmfFilterTraceTypeNode) {
        TmfFilterTraceTypeNode node = (TmfFilterTraceTypeNode) treenode;
        element.setAttribute(TmfFilterTraceTypeNode.TYPE_ATTR, node.getTraceTypeId());
        element.setAttribute(TmfFilterTraceTypeNode.NAME_ATTR, node.getName());
    } else if (treenode instanceof TmfFilterContainsNode) {
        TmfFilterContainsNode node = (TmfFilterContainsNode) treenode;
        setAspectAttributes(element, node);
        element.setAttribute(TmfFilterContainsNode.IGNORECASE_ATTR, Boolean.toString(node.isIgnoreCase()));
    } else if (treenode instanceof TmfFilterEqualsNode) {
        TmfFilterEqualsNode node = (TmfFilterEqualsNode) treenode;
        setAspectAttributes(element, node);
        element.setAttribute(TmfFilterEqualsNode.IGNORECASE_ATTR, Boolean.toString(node.isIgnoreCase()));
    } else if (treenode instanceof TmfFilterMatchesNode) {
        TmfFilterMatchesNode node = (TmfFilterMatchesNode) treenode;
        setAspectAttributes(element, node);
        element.setAttribute(TmfFilterMatchesNode.REGEX_ATTR, node.getRegex());
    } else if (treenode instanceof TmfFilterCompareNode) {
        TmfFilterCompareNode node = (TmfFilterCompareNode) treenode;
        setAspectAttributes(element, node);
        element.setAttribute(TmfFilterCompareNode.RESULT_ATTR, Integer.toString(node.getResult()));
        element.setAttribute(TmfFilterCompareNode.TYPE_ATTR, node.getType().toString());
    }
    parentElement.appendChild(element);
    for (int i = 0; i < treenode.getChildrenCount(); i++) {
        buildXMLTree(document, treenode.getChild(i), element);
    }
}
Also used : TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) Element(org.w3c.dom.Element) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterTraceTypeNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode) ITmfFilterWithValue(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithValue) ITmfFilterWithNot(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithNot) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)

Example 7 with TmfFilterNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode in project tracecompass by tracecompass.

the class TmfEventsTableHeader method addNewFilter.

private void addNewFilter(ITmfFilter filter) {
    CLabel label = new CLabel(this, SWT.SHADOW_OUT);
    label.setBackground(fLabelBackground);
    String text;
    if (filter instanceof TmfFilterNode) {
        text = ((TmfFilterNode) filter).getFilterName();
        label.setData(TOOLTIP_KEY, filter.toString());
    } else {
        text = filter.toString();
    }
    if (fCollapsed) {
        label.setToolTipText(text);
        label.setTopMargin(0);
        label.setBottomMargin(0);
        label.setRightMargin(COLLAPSED_RIGHT_MARGIN);
    } else {
        label.setImage(DELETE);
        label.setText(text);
        label.setToolTipText((String) label.getData(TOOLTIP_KEY));
    }
    label.setData(filter);
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            Rectangle bounds;
            if (fCollapsed) {
                bounds = new Rectangle(0, 0, 2 * COLLAPSED_IMAGE_MARGIN + DELETE_SMALL.getBounds().width, label.getBounds().height);
            } else {
                bounds = DELETE.getBounds();
                bounds.x += label.getLeftMargin();
                bounds.y = (label.getSize().y - bounds.height) / 2;
            }
            if (bounds.contains(e.x, e.y)) {
                fListener.filterRemoved((ITmfFilter) label.getData());
            } else {
                fListener.filterSelected((ITmfFilter) label.getData());
                getParent().layout(true, true);
            }
        }
    });
    label.addPaintListener(e -> {
        if (fCollapsed) {
            e.gc.drawImage(DELETE_SMALL, COLLAPSED_IMAGE_MARGIN, COLLAPSED_IMAGE_MARGIN);
        }
    });
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) MouseEvent(org.eclipse.swt.events.MouseEvent) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode)

Example 8 with TmfFilterNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode in project tracecompass by tracecompass.

the class StreamListView method createPartControl.

@Override
public void createPartControl(@Nullable Composite parent) {
    // Initialize
    final Map<TmfPcapProtocol, Table> tables = new HashMap<>();
    fTableMap = tables;
    fCurrentTrace = TmfTraceManager.getInstance().getActiveTrace();
    fCurrentStream = null;
    // Add a tab folder
    fTabFolder = new CTabFolder(parent, SWT.NONE);
    fTabFolder.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(@Nullable SelectionEvent e) {
            if (e == null) {
                return;
            }
            TmfPcapProtocol protocol = (TmfPcapProtocol) e.item.getData(KEY_PROTOCOL);
            final Table table = tables.get(protocol);
            if (table != null) {
                table.deselectAll();
            }
            fCurrentStream = null;
        }
    });
    // Add items and tables for each protocol
    for (TmfPcapProtocol protocol : TmfPcapProtocol.values()) {
        if (protocol.supportsStream()) {
            CTabItem item = new CTabItem(fTabFolder, SWT.NONE);
            item.setText(protocol.getName());
            item.setData(KEY_PROTOCOL, protocol);
            Table table = new Table(fTabFolder, SWT.NONE);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            // Add columns to table
            for (int i = 0; i < COLUMN_NAMES.length || i < COLUMN_SIZES.length; i++) {
                TableColumn column = new TableColumn(table, SWT.NONE);
                column.setText(COLUMN_NAMES[i]);
                column.setWidth(COLUMN_SIZES[i]);
            }
            item.setControl(table);
            table.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(@Nullable SelectionEvent e) {
                    if (e == null) {
                        return;
                    }
                    fCurrentStream = (TmfPacketStream) e.item.getData(KEY_STREAM);
                }
            });
            tables.put(protocol, table);
            // Add right click menu
            Menu menu = new Menu(table);
            MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
            menuItem.setText(Messages.StreamListView_FollowStream);
            menuItem.addListener(SWT.Selection, (@Nullable Event event) -> {
                TmfSignal signal = new TmfPacketStreamSelectedSignal(this, 0, fCurrentStream);
                TmfSignalManager.dispatchSignal(signal);
            });
            menuItem = new MenuItem(menu, SWT.PUSH);
            menuItem.setText(Messages.StreamListView_Clear);
            menuItem.addListener(SWT.Selection, (@Nullable Event event) -> {
                TmfSignal signal = new TmfPacketStreamSelectedSignal(this, 0, null);
                TmfSignalManager.dispatchSignal(signal);
            });
            menuItem = new MenuItem(menu, SWT.PUSH);
            menuItem.setText(Messages.StreamListView_ExtractAsFilter);
            menuItem.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(@Nullable Event event) {
                    // Generate filter.
                    ITmfFilterTreeNode filter = generateFilter();
                    // Update view and XML
                    updateFilters(filter);
                }

                private void updateFilters(@Nullable ITmfFilterTreeNode filter) {
                    if (filter == null) {
                        return;
                    }
                    // Update XML
                    List<ITmfFilterTreeNode> filters = Lists.newArrayList(FilterManager.getSavedFilters());
                    boolean newFilter = true;
                    for (ITmfFilterTreeNode savedFilter : filters) {
                        // Use toString(explicit) equality because equals() is not implemented
                        if (savedFilter.toString(true).equals(filter.toString(true))) {
                            newFilter = false;
                            break;
                        }
                    }
                    if (newFilter) {
                        filters.add(filter);
                        FilterManager.setSavedFilters(filters.toArray(new ITmfFilterTreeNode[filters.size()]));
                    }
                    // Update Filter View
                    try {
                        final IWorkbench wb = PlatformUI.getWorkbench();
                        final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
                        IViewPart view = activePage.showView(FilterView.ID);
                        FilterView filterView = (FilterView) view;
                        filterView.addFilter(filter);
                    } catch (final PartInitException e) {
                        // $NON-NLS-1$
                        TraceUtils.displayErrorMsg(Messages.StreamListView_ExtractAsFilter, "Error opening view " + FilterView.ID + e.getMessage());
                        // $NON-NLS-1$
                        Activator.logError("Error opening view " + FilterView.ID, e);
                        return;
                    }
                }

                @Nullable
                private ITmfFilterTreeNode generateFilter() {
                    TmfPacketStream stream = fCurrentStream;
                    if (stream == null) {
                        return null;
                    }
                    // First stage - root
                    String name = Messages.StreamListView_FilterName_Stream + ' ' + stream.getProtocol().getShortName() + ' ' + stream.getFirstEndpoint() + " <--> " + // $NON-NLS-1$
                    stream.getSecondEndpoint();
                    TmfFilterNode root = new TmfFilterNode(name);
                    // Second stage - and
                    TmfFilterAndNode and = new TmfFilterAndNode(root);
                    // Third stage - protocol + or
                    TmfFilterContainsNode protocolFilter = new TmfFilterContainsNode(and);
                    protocolFilter.setEventAspect(TmfBaseAspects.getContentsAspect().forField(stream.getProtocol().getName()));
                    protocolFilter.setTraceTypeId(TmfFilterAspectNode.BASE_ASPECT_ID);
                    protocolFilter.setValue(EMPTY_STRING);
                    TmfFilterOrNode or = new TmfFilterOrNode(and);
                    // Fourth stage - and
                    TmfFilterAndNode andA = new TmfFilterAndNode(or);
                    TmfFilterAndNode andB = new TmfFilterAndNode(or);
                    // Fourth stage - endpoints
                    TmfFilterContainsNode endpointAAndA = new TmfFilterContainsNode(andA);
                    endpointAAndA.setEventAspect(PcapSourceAspect.INSTANCE);
                    endpointAAndA.setTraceTypeId(PcapTrace.TRACE_TYPE_ID);
                    endpointAAndA.setValue(stream.getFirstEndpoint());
                    TmfFilterContainsNode endpointBAndA = new TmfFilterContainsNode(andA);
                    endpointBAndA.setEventAspect(PcapDestinationAspect.INSTANCE);
                    endpointBAndA.setTraceTypeId(PcapTrace.TRACE_TYPE_ID);
                    endpointBAndA.setValue(stream.getSecondEndpoint());
                    TmfFilterContainsNode endpointAAndB = new TmfFilterContainsNode(andB);
                    endpointAAndB.setEventAspect(PcapSourceAspect.INSTANCE);
                    endpointAAndB.setTraceTypeId(PcapTrace.TRACE_TYPE_ID);
                    endpointAAndB.setValue(stream.getSecondEndpoint());
                    TmfFilterContainsNode endpointBAndB = new TmfFilterContainsNode(andB);
                    endpointBAndB.setEventAspect(PcapDestinationAspect.INSTANCE);
                    endpointBAndB.setTraceTypeId(PcapTrace.TRACE_TYPE_ID);
                    endpointBAndB.setValue(stream.getFirstEndpoint());
                    return root;
                }
            });
            table.setMenu(menu);
        }
    }
    // Ask the analysis for data.
    queryAnalysis();
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) IViewPart(org.eclipse.ui.IViewPart) CTabFolder(org.eclipse.swt.custom.CTabFolder) Listener(org.eclipse.swt.widgets.Listener) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) HashMap(java.util.HashMap) TmfPacketStream(org.eclipse.tracecompass.internal.tmf.pcap.core.event.TmfPacketStream) CTabItem(org.eclipse.swt.custom.CTabItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) FilterView(org.eclipse.tracecompass.tmf.ui.views.filter.FilterView) TmfSignal(org.eclipse.tracecompass.tmf.core.signal.TmfSignal) Table(org.eclipse.swt.widgets.Table) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfPcapProtocol(org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) TableColumn(org.eclipse.swt.widgets.TableColumn) IWorkbench(org.eclipse.ui.IWorkbench) TmfPacketStreamSelectedSignal(org.eclipse.tracecompass.internal.tmf.pcap.core.signal.TmfPacketStreamSelectedSignal) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 9 with TmfFilterNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode in project tracecompass by tracecompass.

the class TmfEventTableDataProvider method extractFilter.

@Nullable
private static ITmfFilter extractFilter(Map<String, Object> fetchParameters) {
    Object filtersObject = fetchParameters.get(TABLE_FILTERS_KEY);
    if (filtersObject instanceof ITmfFilterModel) {
        ITmfFilterModel filters = (ITmfFilterModel) filtersObject;
        Map<Long, String> filterMap = filters.getTableFilter();
        List<String> presetFilter = filters.getPresetFilter();
        if ((filterMap == null || filterMap.isEmpty()) && (presetFilter == null || presetFilter.isEmpty())) {
            return null;
        }
        TmfFilterRootNode rootFilter = new TmfFilterRootNode();
        if (filterMap != null && !filterMap.isEmpty()) {
            for (Entry<Long, String> filterEntry : filterMap.entrySet()) {
                TmfFilterMatchesNode filterNode = new TmfFilterMatchesNode(null);
                ITmfEventAspect<?> aspect = fAspectToIdMap.inverse().get(filterEntry.getKey());
                if (aspect == null) {
                    return null;
                }
                filterNode.setEventAspect(aspect);
                filterNode.setRegex(filterEntry.getValue());
                rootFilter.addChild(filterNode);
            }
        }
        if (presetFilter != null && !presetFilter.isEmpty()) {
            ITmfFilterTreeNode[] savedFilters = FilterManager.getSavedFilters();
            for (ITmfFilterTreeNode filterNode : savedFilters) {
                if (filterNode instanceof TmfFilterNode) {
                    for (String presetFilterName : presetFilter) {
                        if (((TmfFilterNode) filterNode).getFilterName().equals(presetFilterName)) {
                            rootFilter.addChild(filterNode);
                        }
                    }
                }
            }
        }
        return rootFilter;
    }
    return null;
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) ITmfFilterModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.ITmfFilterModel) AtomicLong(java.util.concurrent.atomic.AtomicLong) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

TmfFilterNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode)9 ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)5 TmfFilterContainsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode)5 TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)5 TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)4 TmfFilterCompareNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)4 TmfFilterEqualsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode)4 TmfFilterOrNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode)4 TmfFilterTraceTypeNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode)4 HashMap (java.util.HashMap)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Action (org.eclipse.jface.action.Action)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1