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