Search in sources :

Example 6 with TmfFilterOrNode

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

the class FilterViewer method fillContextMenuForNode.

/**
 * Fill the context menu with the valid children of the provided node
 *
 * @param node
 *            The target node
 * @param manager
 *            The menu manager
 */
protected void fillContextMenuForNode(final ITmfFilterTreeNode node, IMenuManager manager) {
    for (final String child : node.getValidChildren()) {
        final Action action = new Action() {

            @Override
            public void run() {
                ITmfFilterTreeNode newNode = null;
                if (TmfFilterNode.NODE_NAME.equals(child)) {
                    // $NON-NLS-1$
                    newNode = new TmfFilterNode(node, "");
                } else if (TmfFilterTraceTypeNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterTraceTypeNode(node);
                } else if (TmfFilterAndNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterAndNode(node);
                } else if (TmfFilterOrNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterOrNode(node);
                } else if (TmfFilterContainsNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterContainsNode(node);
                } else if (TmfFilterEqualsNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterEqualsNode(node);
                } else if (TmfFilterMatchesNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterMatchesNode(node);
                } else if (TmfFilterCompareNode.NODE_NAME.equals(child)) {
                    newNode = new TmfFilterCompareNode(node);
                }
                if (newNode != null) {
                    fViewer.refresh();
                    fViewer.setSelection(new StructuredSelection(newNode), true);
                }
            }
        };
        if (TmfFilterNode.NODE_NAME.equals(child)) {
            // $NON-NLS-1$
            action.setText(Messages.FilterViewer_NewPrefix + " " + child);
        } else {
            action.setText(child);
        }
        manager.add(action);
    }
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) Action(org.eclipse.jface.action.Action) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) 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) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)

Example 7 with TmfFilterOrNode

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

the class TmfFilterHelperTest method testInputFilterOr.

/**
 * Test conversion of an or filter
 */
@Test
public void testInputFilterOr() {
    ITmfEventAspect<@NonNull Object> aspectF1 = TmfBaseAspects.getContentsAspect().forField(FIELD1_NAME);
    ITmfEventAspect<@NonNull Object> aspectF2 = TmfBaseAspects.getContentsAspect().forField(FIELD2_NAME);
    String expected = "\"" + FIELD1_NAME + "\" " + IFilterStrings.MATCHES + " \".*afield.*\" " + IFilterStrings.OR + " \"" + FIELD2_NAME + "\" " + IFilterStrings.MATCHES + " \".*2.*\"";
    TmfFilterMatchesNode matchesFilter1 = new TmfFilterMatchesNode(null);
    matchesFilter1.setEventAspect(aspectF1);
    matchesFilter1.setRegex(".*afield.*");
    TmfFilterMatchesNode matchesFilter2 = new TmfFilterMatchesNode(null);
    matchesFilter2.setEventAspect(aspectF2);
    matchesFilter2.setRegex(".*2.*");
    TmfFilterOrNode orFilter = new TmfFilterOrNode(null);
    orFilter.addChild(matchesFilter1);
    orFilter.addChild(matchesFilter2);
    Predicate<Multimap<String, Object>> predicate = getRegex(orFilter, expected);
    assertTrue(predicate.test(fObjectMap1));
    assertFalse(predicate.test(fObjectMap2));
    assertTrue(predicate.test(fObjectMap3));
    /* Test the negation */
    orFilter.setNot(true);
    predicate = getRegex(orFilter, notRegex(expected));
    assertFalse(predicate.test(fObjectMap1));
    assertTrue(predicate.test(fObjectMap2));
    assertFalse(predicate.test(fObjectMap3));
}
Also used : Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) Test(org.junit.Test)

Example 8 with TmfFilterOrNode

use of org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode 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 TmfFilterOrNode

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

the class FilterExpressionCu method mergeEventFilters.

private ITmfFilterTreeNode mergeEventFilters(@Nullable ITmfFilterTreeNode prevNode, String operator, ITmfFilterTreeNode node) {
    if (prevNode == null) {
        return node;
    }
    TmfFilterTreeNode parentNode;
    if (operator == IFilterStrings.OR) {
        TmfFilterOrNode orNode = new TmfFilterOrNode(null);
        orNode.setNot(getNot());
        parentNode = orNode;
    } else {
        TmfFilterAndNode andNode = new TmfFilterAndNode(null);
        andNode.setNot(getNot());
        parentNode = andNode;
    }
    parentNode.addChild(prevNode);
    parentNode.addChild(node);
    return parentNode;
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTreeNode) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)

Aggregations

TmfFilterOrNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode)9 TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)6 ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)5 TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)5 TmfFilterContainsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode)4 TmfFilterNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode)4 TmfFilterCompareNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode)3 TmfFilterEqualsNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode)3 TmfFilterTraceTypeNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode)3 TmfFilterAspectNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAspectNode)2 TmfFilterRootNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode)2 Test (org.junit.Test)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Multimap (com.google.common.collect.Multimap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Action (org.eclipse.jface.action.Action)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1