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 | 19 | \r |
d37aaa7f FC |
20 | /**\r |
21 | * Filter node for an event\r | |
22 | * \r | |
23 | * @version 1.0\r | |
24 | * @author Patrick Tasse\r | |
25 | */\r | |
46ab8ce3 FC |
26 | public class TmfFilterEventTypeNode extends TmfFilterTreeNode {\r |
27 | \r | |
28 | public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$\r | |
29 | public static final String TYPE_ATTR = "type"; //$NON-NLS-1$\r | |
30 | public static final String NAME_ATTR = "name"; //$NON-NLS-1$\r | |
31 | \r | |
32 | private String fType;\r | |
33 | private String fName;\r | |
34 | \r | |
35 | public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) {\r | |
36 | super(parent);\r | |
37 | }\r | |
38 | \r | |
39 | @Override\r | |
40 | public String getNodeName() {\r | |
41 | return NODE_NAME;\r | |
42 | }\r | |
43 | \r | |
44 | public String getEventType() {\r | |
45 | return fType;\r | |
46 | }\r | |
47 | \r | |
48 | public void setEventType(String type) {\r | |
49 | this.fType = type;\r | |
50 | }\r | |
51 | \r | |
52 | public String getName() {\r | |
53 | return fName;\r | |
54 | }\r | |
55 | \r | |
56 | public void setName(String name) {\r | |
57 | this.fName = name;\r | |
58 | }\r | |
59 | \r | |
4bf17f4a | 60 | @Override\r |
a96d4804 | 61 | public boolean matches(ITmfEvent event) {\r |
4bf17f4a | 62 | boolean match = false;\r |
63 | if (fType.contains(":")) { //$NON-NLS-1$\r | |
64 | // special case for custom parsers\r | |
65 | if (fType.startsWith(event.getClass().getCanonicalName())) {\r | |
4c564a2d | 66 | if (fType.endsWith(event.getType().getName())) {\r |
4bf17f4a | 67 | match = true;\r |
68 | }\r | |
69 | }\r | |
70 | } else {\r | |
71 | if (event.getClass().getCanonicalName().equals(fType)) {\r | |
72 | match = true;\r | |
73 | }\r | |
74 | }\r | |
75 | if (match) {\r | |
76 | // There should be at most one child\r | |
77 | for (ITmfFilterTreeNode node : getChildren()) {\r | |
78 | if (! node.matches(event)) {\r | |
79 | return false;\r | |
80 | }\r | |
81 | }\r | |
82 | return true;\r | |
83 | }\r | |
84 | return false;\r | |
85 | }\r | |
46ab8ce3 FC |
86 | \r |
87 | @Override\r | |
88 | public List<String> getValidChildren() {\r | |
89 | if (getChildrenCount() == 0) {\r | |
90 | return super.getValidChildren();\r | |
91 | } else {\r | |
92 | return new ArrayList<String>(0); // only one child allowed\r | |
93 | }\r | |
94 | }\r | |
95 | \r | |
96 | @Override\r | |
97 | public String toString() {\r | |
98 | StringBuffer buf = new StringBuffer();\r | |
99 | buf.append("EventType is " + fName); //$NON-NLS-1$\r | |
100 | if (getChildrenCount() > 0) {\r | |
101 | buf.append(" and "); //$NON-NLS-1$\r | |
102 | }\r | |
103 | if (getChildrenCount() > 1) {\r | |
104 | buf.append("( "); //$NON-NLS-1$\r | |
105 | }\r | |
106 | for (int i = 0; i < getChildrenCount(); i++) {\r | |
107 | ITmfFilterTreeNode node = getChildren()[i];\r | |
108 | buf.append(node.toString());\r | |
109 | if (i < getChildrenCount() - 1) {\r | |
110 | buf.append(" and "); //$NON-NLS-1$\r | |
111 | }\r | |
112 | }\r | |
113 | if (getChildrenCount() > 1) {\r | |
114 | buf.append(" )"); //$NON-NLS-1$\r | |
115 | }\r | |
116 | return buf.toString();\r | |
117 | }\r | |
118 | }\r |