Fix for Bug337914
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / filter / model / TmfFilterEventTypeNode.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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.linuxtools.tmf.filter.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.tmf.event.TmfEvent;
19
20
21 public class TmfFilterEventTypeNode extends TmfFilterTreeNode {
22
23 public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$
24 public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
25 public static final String NAME_ATTR = "name"; //$NON-NLS-1$
26
27 private String fType;
28 private String fName;
29
30 public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) {
31 super(parent);
32 }
33
34 @Override
35 public String getNodeName() {
36 return NODE_NAME;
37 }
38
39 public String getEventType() {
40 return fType;
41 }
42
43 public void setEventType(String type) {
44 this.fType = type;
45 }
46
47 public String getName() {
48 return fName;
49 }
50
51 public void setName(String name) {
52 this.fName = name;
53 }
54
55 @Override
56 public boolean matches(TmfEvent event) {
57 if (event.getType().getTypeId().equals(fName)) {
58 // There should be at most one child
59 for (ITmfFilterTreeNode node : getChildren()) {
60 if (! node.matches(event)) {
61 return false;
62 }
63 }
64 return true;
65 }
66 return false;
67 }
68
69 @Override
70 public List<String> getValidChildren() {
71 if (getChildrenCount() == 0) {
72 return super.getValidChildren();
73 } else {
74 return new ArrayList<String>(0); // only one child allowed
75 }
76 }
77
78 @Override
79 public String toString() {
80 StringBuffer buf = new StringBuffer();
81 buf.append("EventType is " + fName); //$NON-NLS-1$
82 if (getChildrenCount() > 0) {
83 buf.append(" and "); //$NON-NLS-1$
84 }
85 if (getChildrenCount() > 1) {
86 buf.append("( "); //$NON-NLS-1$
87 }
88 for (int i = 0; i < getChildrenCount(); i++) {
89 ITmfFilterTreeNode node = getChildren()[i];
90 buf.append(node.toString());
91 if (i < getChildrenCount() - 1) {
92 buf.append(" and "); //$NON-NLS-1$
93 }
94 }
95 if (getChildrenCount() > 1) {
96 buf.append(" )"); //$NON-NLS-1$
97 }
98 return buf.toString();
99 }
100 }
This page took 0.032389 seconds and 5 git commands to generate.