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