Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
2b0005f0 | 2 | * Copyright (c) 2010, 2015 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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.filter.model; |
be222f56 PT |
14 | |
15 | import java.util.ArrayList; | |
16 | import java.util.List; | |
17 | ||
2bdf0193 | 18 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
2b0005f0 | 19 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
be222f56 PT |
20 | |
21 | /** | |
2b0005f0 | 22 | * Filter node for an trace type |
be222f56 PT |
23 | * |
24 | * @version 1.0 | |
25 | * @author Patrick Tasse | |
26 | */ | |
2b0005f0 | 27 | public class TmfFilterTraceTypeNode extends TmfFilterTreeNode { |
be222f56 | 28 | |
ec34bf48 | 29 | /** tracetype node name */ |
2b0005f0 | 30 | public static final String NODE_NAME = "TRACETYPE"; //$NON-NLS-1$ |
ec34bf48 | 31 | /** type attribute name */ |
d5efe032 | 32 | public static final String TYPE_ATTR = "type"; //$NON-NLS-1$ |
ec34bf48 | 33 | /** name attribute name */ |
d5efe032 | 34 | public static final String NAME_ATTR = "name"; //$NON-NLS-1$ |
be222f56 | 35 | |
2b0005f0 PT |
36 | private String fTraceTypeId; |
37 | private Class<? extends ITmfTrace> fTraceClass; | |
d5efe032 | 38 | private String fName; |
be222f56 | 39 | |
d5efe032 AF |
40 | /** |
41 | * @param parent the parent node | |
42 | */ | |
2b0005f0 | 43 | public TmfFilterTraceTypeNode(ITmfFilterTreeNode parent) { |
d5efe032 AF |
44 | super(parent); |
45 | } | |
be222f56 | 46 | |
d5efe032 AF |
47 | @Override |
48 | public String getNodeName() { | |
49 | return NODE_NAME; | |
50 | } | |
be222f56 | 51 | |
d5efe032 | 52 | /** |
2b0005f0 | 53 | * @return the trace type id |
d5efe032 | 54 | */ |
2b0005f0 PT |
55 | public String getTraceTypeId() { |
56 | return fTraceTypeId; | |
d5efe032 | 57 | } |
be222f56 | 58 | |
d5efe032 | 59 | /** |
2b0005f0 | 60 | * @param traceTypeId the trace type id |
d5efe032 | 61 | */ |
2b0005f0 PT |
62 | public void setTraceTypeId(String traceTypeId) { |
63 | this.fTraceTypeId = traceTypeId; | |
64 | } | |
65 | ||
66 | /** | |
67 | * @return the trace class | |
68 | */ | |
69 | public Class<? extends ITmfTrace> getTraceClass() { | |
70 | return fTraceClass; | |
71 | } | |
72 | ||
73 | /** | |
74 | * @param traceClass the trace class | |
75 | */ | |
76 | public void setTraceClass(Class<? extends ITmfTrace> traceClass) { | |
77 | this.fTraceClass = traceClass; | |
d5efe032 | 78 | } |
be222f56 | 79 | |
d5efe032 | 80 | /** |
4b3b667b | 81 | * @return the category and trace type name |
d5efe032 AF |
82 | */ |
83 | public String getName() { | |
84 | return fName; | |
85 | } | |
be222f56 | 86 | |
d5efe032 | 87 | /** |
4b3b667b | 88 | * @param name the category and trace type name |
d5efe032 AF |
89 | */ |
90 | public void setName(String name) { | |
91 | this.fName = name; | |
92 | } | |
be222f56 PT |
93 | |
94 | @Override | |
95 | public boolean matches(ITmfEvent event) { | |
96 | boolean match = false; | |
2b0005f0 PT |
97 | ITmfTrace trace = event.getTrace(); |
98 | if (trace.getClass().equals(fTraceClass)) { | |
99 | if (fTraceTypeId != null) { | |
100 | if (fTraceTypeId.equals(trace.getTraceTypeId())) { | |
be222f56 PT |
101 | match = true; |
102 | } | |
2b0005f0 | 103 | } else { |
be222f56 PT |
104 | match = true; |
105 | } | |
106 | } | |
107 | if (match) { | |
108 | // There should be at most one child | |
109 | for (ITmfFilterTreeNode node : getChildren()) { | |
110 | if (! node.matches(event)) { | |
111 | return false; | |
112 | } | |
113 | } | |
114 | return true; | |
115 | } | |
116 | return false; | |
117 | } | |
118 | ||
d5efe032 AF |
119 | @Override |
120 | public List<String> getValidChildren() { | |
121 | if (getChildrenCount() == 0) { | |
122 | return super.getValidChildren(); | |
123 | } | |
a4524c1b | 124 | return new ArrayList<>(0); // only one child allowed |
d5efe032 | 125 | } |
be222f56 | 126 | |
d5efe032 | 127 | @Override |
e883975e | 128 | public String toString(boolean explicit) { |
d5efe032 | 129 | StringBuffer buf = new StringBuffer(); |
2b0005f0 | 130 | buf.append("TraceType is " + fName); //$NON-NLS-1$ |
e883975e PT |
131 | if (explicit) { |
132 | buf.append('['); | |
133 | buf.append(fTraceTypeId); | |
134 | buf.append(']'); | |
135 | } | |
d5efe032 AF |
136 | if (getChildrenCount() > 0) { |
137 | buf.append(" and "); //$NON-NLS-1$ | |
138 | } | |
139 | if (getChildrenCount() > 1) { | |
140 | buf.append("( "); //$NON-NLS-1$ | |
141 | } | |
142 | for (int i = 0; i < getChildrenCount(); i++) { | |
143 | ITmfFilterTreeNode node = getChildren()[i]; | |
e883975e | 144 | buf.append(node.toString(explicit)); |
d5efe032 AF |
145 | if (i < getChildrenCount() - 1) { |
146 | buf.append(" and "); //$NON-NLS-1$ | |
147 | } | |
148 | } | |
149 | if (getChildrenCount() > 1) { | |
150 | buf.append(" )"); //$NON-NLS-1$ | |
151 | } | |
152 | return buf.toString(); | |
153 | } | |
be222f56 | 154 | } |