Merge master in TmfTraceModel
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.filter.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
19
20
21 public class TmfFilterNode extends TmfFilterTreeNode {
22
23 public static final String NODE_NAME = "FILTER"; //$NON-NLS-1$
24 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
25
26 String fFilterName;
27
28 public TmfFilterNode(String filterName) {
29 super(null);
30 fFilterName = filterName;
31 }
32
33 public TmfFilterNode(ITmfFilterTreeNode parent, String filterName) {
34 super(parent);
35 fFilterName = filterName;
36 }
37
38 public String getFilterName() {
39 return fFilterName;
40 }
41
42 public void setFilterName(String filterName) {
43 fFilterName = filterName;
44 }
45
46 @Override
47 public String getNodeName() {
48 return NODE_NAME;
49 }
50
51 @Override
52 public boolean matches(ITmfEvent event) {
53 // There should be at most one child
54 for (ITmfFilterTreeNode node : getChildren()) {
55 if (node.matches(event)) {
56 return true;
57 }
58 }
59 return false;
60 }
61
62 @Override
63 public List<String> getValidChildren() {
64 if (getChildrenCount() == 0) {
65 return super.getValidChildren();
66 }
67 return new ArrayList<String>(0); // only one child allowed
68 }
69
70 @Override
71 public String toString() {
72 StringBuffer buf = new StringBuffer();
73 if (getChildrenCount() > 1) {
74 buf.append("( "); //$NON-NLS-1$
75 }
76 for (int i = 0; i < getChildrenCount(); i++) {
77 ITmfFilterTreeNode node = getChildren()[i];
78 buf.append(node.toString());
79 if (i < (getChildrenCount() - 1)) {
80 buf.append(" and "); //$NON-NLS-1$
81 }
82 }
83 if (getChildrenCount() > 1) {
84 buf.append(" )"); //$NON-NLS-1$
85 }
86 return buf.toString();
87 }
88 }
This page took 0.032679 seconds and 5 git commands to generate.