Search in sources :

Example 1 with TmfFilterAndNode

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

the class TmfFilterContentHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    ITmfFilterTreeNode node = null;
    if (localName.equalsIgnoreCase(TmfFilterRootNode.NODE_NAME)) {
        node = new TmfFilterRootNode();
    } else if (localName.equals(TmfFilterNode.NODE_NAME)) {
        node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));
    } else if (localName.equals(TmfFilterTraceTypeNode.NODE_NAME)) {
        node = new TmfFilterTraceTypeNode(null);
        String traceTypeId = atts.getValue(TmfFilterTraceTypeNode.TYPE_ATTR);
        traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
        ((TmfFilterTraceTypeNode) node).setTraceTypeId(traceTypeId);
        TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
        if (helper != null) {
            ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
        }
        ((TmfFilterTraceTypeNode) node).setName(atts.getValue(TmfFilterTraceTypeNode.NAME_ATTR));
    } else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {
        node = new TmfFilterAndNode(null);
    } else if (localName.equals(TmfFilterOrNode.NODE_NAME)) {
        node = new TmfFilterOrNode(null);
    } else if (localName.equals(TmfFilterContainsNode.NODE_NAME)) {
        node = new TmfFilterContainsNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterContainsNode.IGNORECASE_ATTR);
        if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
            ((TmfFilterContainsNode) node).setIgnoreCase(true);
        }
    } else if (localName.equals(TmfFilterEqualsNode.NODE_NAME)) {
        node = new TmfFilterEqualsNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterEqualsNode.IGNORECASE_ATTR);
        if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
            ((TmfFilterEqualsNode) node).setIgnoreCase(true);
        }
    } else if (localName.equals(TmfFilterMatchesNode.NODE_NAME)) {
        node = new TmfFilterMatchesNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        ((TmfFilterMatchesNode) node).setRegex(atts.getValue(TmfFilterMatchesNode.REGEX_ATTR));
    } else if (localName.equals(TmfFilterCompareNode.NODE_NAME)) {
        node = new TmfFilterCompareNode(null);
        createEventAspect((TmfFilterAspectNode) node, atts);
        String value = atts.getValue(TmfFilterCompareNode.TYPE_ATTR);
        if (value != null) {
            ((TmfFilterCompareNode) node).setType(Type.valueOf(value));
        }
        value = atts.getValue(TmfFilterCompareNode.RESULT_ATTR);
        if (value != null) {
            if (value.equals(Integer.toString(-1))) {
                ((TmfFilterCompareNode) node).setResult(-1);
            } else if (value.equals(Integer.toString(1))) {
                ((TmfFilterCompareNode) node).setResult(1);
            } else {
                ((TmfFilterCompareNode) node).setResult(0);
            }
        }
    // Backward compatibility with event type filter node
    } else if (localName.equals(EVENTTYPE_NODE_NAME)) {
        node = new TmfFilterTraceTypeNode(null);
        String label = atts.getValue(NAME_ATTR);
        if (label != null) {
            // Backward compatibility with renamed LTTng Kernel Trace
            if (label.equals(LTTNG_KERNEL_TRACE)) {
                label = LINUX_KERNEL_TRACE;
            }
            String traceTypeId = TmfTraceType.getTraceTypeId(label);
            TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
            if (helper == null) {
                // Backward compatibility with category-less custom trace types
                for (TraceTypeHelper h : TmfTraceType.getTraceTypeHelpers()) {
                    if (h.getName().equals(label)) {
                        label = h.getLabel();
                        helper = h;
                        break;
                    }
                }
            }
            if (helper != null) {
                ((TmfFilterTraceTypeNode) node).setTraceTypeId(helper.getTraceTypeId());
                ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
            }
            ((TmfFilterTraceTypeNode) node).setName(label);
        }
    }
    String value = atts.getValue(ITmfFilterWithNot.NOT_ATTRIBUTE);
    if (node instanceof ITmfFilterWithNot && Boolean.TRUE.toString().equalsIgnoreCase(value)) {
        ((ITmfFilterWithNot) node).setNot(true);
    }
    if (node instanceof ITmfFilterWithValue) {
        ((ITmfFilterWithValue) node).setValue(atts.getValue(ITmfFilterWithValue.VALUE_ATTRIBUTE));
    }
    fFilterTreeStack.addFirst(node);
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterContainsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode) 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) TraceTypeHelper(org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper) TmfFilterOrNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode) TmfFilterAspectNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAspectNode) TmfFilterEqualsNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) TmfFilterCompareNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode) ITmfFilterWithNot(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterWithNot)

Example 2 with TmfFilterAndNode

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

the class FilterTreeLabelProvider method getText.

@Override
public String getText(Object element) {
    StringBuilder label = new StringBuilder();
    if (element instanceof TmfFilterNode) {
        TmfFilterNode node = (TmfFilterNode) element;
        label.append(node.getNodeName()).append(' ').append(node.getFilterName() != null && !node.getFilterName().isEmpty() ? node.getFilterName() : Messages.FilterTreeLabelProvider_FilterNameHint);
    } else if (element instanceof TmfFilterTraceTypeNode) {
        TmfFilterTraceTypeNode node = (TmfFilterTraceTypeNode) element;
        // $NON-NLS-1$
        label.append(node.isNot() ? NOT : EMPTY_STRING).append("WITH ").append(node.getNodeName()).append(' ').append((node.getName() != null ? node.getName() : Messages.FilterTreeLabelProvider_TraceTypeHint));
    } else if (element instanceof TmfFilterAndNode) {
        TmfFilterAndNode node = (TmfFilterAndNode) element;
        label.append((node.isNot() ? NOT : EMPTY_STRING)).append(node.getNodeName());
    } else if (element instanceof TmfFilterOrNode) {
        TmfFilterOrNode node = (TmfFilterOrNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getNodeName());
    } else if (element instanceof TmfFilterContainsNode) {
        TmfFilterContainsNode node = (TmfFilterContainsNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(' ').append(node.getNodeName()).append(node.getValue() != null ? new StringBuilder().append(SPACE_QUOTE).append(node.getValue()).append(QUOTE).toString() : EMPTY_STRING);
    } else if (element instanceof TmfFilterEqualsNode) {
        TmfFilterEqualsNode node = (TmfFilterEqualsNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(' ').append(node.getNodeName()).append(node.getValue() != null ? new StringBuilder().append(SPACE_QUOTE).append(node.getValue()).append(QUOTE).toString() : EMPTY_STRING);
    } else if (element instanceof TmfFilterMatchesNode) {
        TmfFilterMatchesNode node = (TmfFilterMatchesNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(' ').append(node.getNodeName()).append(node.getRegex() != null ? new StringBuilder().append(SPACE_QUOTE).append(node.getRegex()).append(QUOTE).toString() : EMPTY_STRING);
    } else if (element instanceof TmfFilterCompareNode) {
        TmfFilterCompareNode node = (TmfFilterCompareNode) element;
        label.append(node.isNot() ? NOT : EMPTY_STRING).append(node.getEventAspect() != null ? node.getAspectLabel(false) : Messages.FilterTreeLabelProvider_AspectHint).append(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        node.getResult() < 0 ? " <" : (node.getResult() > 0 ? " >" : " =")).append(// $NON-NLS-1$
        node.getType() == Type.ALPHA ? SPACE_QUOTE : node.getType() == Type.TIMESTAMP ? " [" : ' ').append(node.hasValidValue() ? node.getValue() : Messages.FilterTreeLabelProvider_ValueHint).append(node.getType() == Type.ALPHA ? '\"' : node.getType() == Type.TIMESTAMP ? ']' : EMPTY_STRING);
    }
    return label.toString();
}
Also used : 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) 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 3 with TmfFilterAndNode

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

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

the class TmfFilterHelperTest method testInputRegexNot.

/**
 * Test a negative regex on an && regex
 */
@Test
public void testInputRegexNot() {
    String regex = "!(" + FIELD1_NAME + " matches .*afield.* && " + FIELD2_NAME + " present)";
    ITmfFilter filter = getFilter(regex);
    ITmfEventAspect<@NonNull Object> aspectF1 = TmfBaseAspects.getContentsAspect().forField(FIELD1_NAME);
    ITmfEventAspect<@NonNull Object> aspectF2 = TmfBaseAspects.getContentsAspect().forField(FIELD2_NAME);
    // verify the main root node
    assertTrue(filter instanceof TmfFilterRootNode);
    TmfFilterRootNode node = (TmfFilterRootNode) filter;
    assertEquals(1, node.getChildrenCount());
    ITmfFilterTreeNode child = node.getChild(0);
    assertTrue(child instanceof TmfFilterAndNode);
    TmfFilterAndNode andNode = (TmfFilterAndNode) child;
    assertEquals(2, andNode.getChildrenCount());
    // Verify first child, a matches node
    child = andNode.getChild(0);
    assertTrue(child instanceof TmfFilterMatchesNode);
    TmfFilterMatchesNode equalsNode = (TmfFilterMatchesNode) child;
    assertEquals(aspectF1, equalsNode.getEventAspect());
    assertEquals(".*afield.*", equalsNode.getRegex());
    // Verify second child the present node
    child = andNode.getChild(1);
    assertTrue(child instanceof TmfFilterMatchesNode);
    equalsNode = (TmfFilterMatchesNode) child;
    assertEquals(aspectF2, equalsNode.getEventAspect());
    assertEquals(".*", equalsNode.getRegex());
    // Test expected behavior on events
    assertTrue(filter.matches(fEvent1));
    assertTrue(filter.matches(fEvent2));
    assertFalse(filter.matches(fEvent3));
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) Test(org.junit.Test)

Example 5 with TmfFilterAndNode

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

the class TmfFilterHelperTest method testInputFilterAnd.

/**
 * Test conversion of and filters to regex
 */
@Test
public void testInputFilterAnd() {
    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.AND + " \"" + FIELD2_NAME + "\" present";
    TmfFilterMatchesNode matchesFilter1 = new TmfFilterMatchesNode(null);
    matchesFilter1.setEventAspect(aspectF1);
    matchesFilter1.setRegex(".*afield.*");
    TmfFilterMatchesNode matchesFilter2 = new TmfFilterMatchesNode(null);
    matchesFilter2.setEventAspect(aspectF2);
    matchesFilter2.setRegex(".*");
    TmfFilterAndNode andFilter = new TmfFilterAndNode(null);
    andFilter.addChild(matchesFilter1);
    andFilter.addChild(matchesFilter2);
    Predicate<Multimap<String, Object>> predicate = getRegex(andFilter, expected);
    assertFalse(predicate.test(fObjectMap1));
    assertFalse(predicate.test(fObjectMap2));
    assertTrue(predicate.test(fObjectMap3));
    /* Test the negation */
    andFilter.setNot(true);
    predicate = getRegex(andFilter, notRegex(expected));
    assertTrue(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) TmfFilterAndNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode) TmfFilterMatchesNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode) Test(org.junit.Test)

Aggregations

TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)9 ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)6 TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)6 TmfFilterOrNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode)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 TmfFilterRootNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode)3 TmfFilterTraceTypeNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode)3 Test (org.junit.Test)3 ITmfFilter (org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)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