analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / filter / model / TmfFilterTraceTypeNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 Ericsson
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.tracecompass.tmf.core.filter.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
19 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
20
21 /**
22 * Filter node for an trace type
23 *
24 * @version 1.0
25 * @author Patrick Tasse
26 */
27 public class TmfFilterTraceTypeNode extends TmfFilterTreeNode {
28
29 /** tracetype node name */
30 public static final String NODE_NAME = "TRACETYPE"; //$NON-NLS-1$
31 /** type attribute name */
32 public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
33 /** name attribute name */
34 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
35
36 private String fTraceTypeId;
37 private Class<? extends ITmfTrace> fTraceClass;
38 private String fName;
39
40 /**
41 * @param parent the parent node
42 */
43 public TmfFilterTraceTypeNode(ITmfFilterTreeNode parent) {
44 super(parent);
45 }
46
47 @Override
48 public String getNodeName() {
49 return NODE_NAME;
50 }
51
52 /**
53 * @return the trace type id
54 */
55 public String getTraceTypeId() {
56 return fTraceTypeId;
57 }
58
59 /**
60 * @param traceTypeId the trace type id
61 */
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;
78 }
79
80 /**
81 * @return the category and trace type name
82 */
83 public String getName() {
84 return fName;
85 }
86
87 /**
88 * @param name the category and trace type name
89 */
90 public void setName(String name) {
91 this.fName = name;
92 }
93
94 @Override
95 public boolean matches(ITmfEvent event) {
96 boolean match = false;
97 ITmfTrace trace = event.getTrace();
98 if (trace.getClass().equals(fTraceClass)) {
99 if (fTraceTypeId != null) {
100 if (fTraceTypeId.equals(trace.getTraceTypeId())) {
101 match = true;
102 }
103 } else {
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
119 @Override
120 public List<String> getValidChildren() {
121 if (getChildrenCount() == 0) {
122 return super.getValidChildren();
123 }
124 return new ArrayList<>(0); // only one child allowed
125 }
126
127 @Override
128 public String toString(boolean explicit) {
129 StringBuffer buf = new StringBuffer();
130 buf.append("TraceType is " + fName); //$NON-NLS-1$
131 if (explicit) {
132 buf.append('[');
133 buf.append(fTraceTypeId);
134 buf.append(']');
135 }
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];
144 buf.append(node.toString(explicit));
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 }
154 }
This page took 0.036043 seconds and 5 git commands to generate.