btf: throw an exception when the trace is deleted.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / filter / model / TmfFilterEventTypeNode.java
CommitLineData
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
13package org.eclipse.linuxtools.tmf.core.filter.model;
14
15import java.util.ArrayList;
16import java.util.List;
17
18import 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")
27public class TmfFilterEventTypeNode extends TmfFilterTreeNode {
28
29 public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$
d5efe032
AF
30 public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
31 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
be222f56 32
d5efe032
AF
33 private String fType;
34 private String fName;
be222f56 35
d5efe032
AF
36 /**
37 * @param parent the parent node
38 */
39 public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) {
40 super(parent);
41 }
be222f56 42
d5efe032
AF
43 @Override
44 public String getNodeName() {
45 return NODE_NAME;
46 }
be222f56 47
d5efe032
AF
48 /**
49 * @return the event type
50 */
51 public String getEventType() {
52 return fType;
53 }
be222f56 54
d5efe032
AF
55 /**
56 * @param type the event type
57 */
58 public void setEventType(String type) {
59 this.fType = type;
60 }
be222f56 61
d5efe032
AF
62 /**
63 * @return TBD
64 */
65 public String getName() {
66 return fName;
67 }
be222f56 68
d5efe032
AF
69 /**
70 * @param name TBD
71 */
72 public void setName(String name) {
73 this.fName = name;
74 }
be222f56
PT
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
d5efe032
AF
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
d5efe032 109 }
be222f56 110
d5efe032
AF
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 }
be222f56 133}
This page took 0.044516 seconds and 5 git commands to generate.