Commit | Line | Data |
---|---|---|
46ab8ce3 FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
3 | * \r | |
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 | |
8 | * \r | |
9 | * Contributors:\r | |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
6c13869b | 13 | package org.eclipse.linuxtools.tmf.core.filter.model;\r |
46ab8ce3 FC |
14 | \r |
15 | import java.util.ArrayList;\r | |
16 | import java.util.List;\r | |
17 | \r | |
a96d4804 | 18 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r |
46ab8ce3 FC |
19 | \r |
20 | \r | |
21 | public class TmfFilterNode extends TmfFilterTreeNode {\r | |
22 | \r | |
23 | public static final String NODE_NAME = "FILTER"; //$NON-NLS-1$\r | |
24 | public static final String NAME_ATTR = "name"; //$NON-NLS-1$\r | |
25 | \r | |
26 | String fFilterName;\r | |
27 | \r | |
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 | |
66 | } else {\r | |
67 | return new ArrayList<String>(0); // only one child allowed\r | |
68 | }\r | |
69 | }\r | |
70 | \r | |
71 | @Override\r | |
72 | public String toString() {\r | |
73 | StringBuffer buf = new StringBuffer();\r | |
74 | if (getChildrenCount() > 1) {\r | |
75 | buf.append("( "); //$NON-NLS-1$\r | |
76 | }\r | |
77 | for (int i = 0; i < getChildrenCount(); i++) {\r | |
78 | ITmfFilterTreeNode node = getChildren()[i];\r | |
79 | buf.append(node.toString());\r | |
80 | if (i < getChildrenCount() - 1) {\r | |
81 | buf.append(" and "); //$NON-NLS-1$\r | |
82 | }\r | |
83 | }\r | |
84 | if (getChildrenCount() > 1) {\r | |
85 | buf.append(" )"); //$NON-NLS-1$\r | |
86 | }\r | |
87 | return buf.toString();\r | |
88 | }\r | |
89 | }\r |