tmf: Make TmfEventFieldAspect independent of event content
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / filter / model / TmfFilterAspectNode.java
CommitLineData
ec34bf48
PT
1/*******************************************************************************
2 * Copyright (c) 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
13package org.eclipse.tracecompass.tmf.core.filter.model;
14
15import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
40dfafb3 16import org.eclipse.tracecompass.tmf.core.event.aspect.TmfEventFieldAspect;
ec34bf48
PT
17
18/**
19 * Base class for filter nodes which use event aspects
20 *
21 * @author Patrick Tasse
22 */
23public abstract class TmfFilterAspectNode extends TmfFilterTreeNode {
24
25 /** event aspect attribute name */
26 public static final String EVENT_ASPECT_ATTR = "eventaspect"; //$NON-NLS-1$
27 /** trace type id attribute name */
28 public static final String TRACE_TYPE_ID_ATTR = "tracetypeid"; //$NON-NLS-1$
40dfafb3
PT
29 /** field attribute name */
30 public static final String FIELD_ATTR = "field"; //$NON-NLS-1$
ec34bf48
PT
31 /** special case trace type id for base aspects */
32 public static final String BASE_ASPECT_ID = "BASE.ASPECT.ID"; //$NON-NLS-1$
ec34bf48
PT
33
34 /** event aspect */
35 protected ITmfEventAspect fEventAspect;
36
37 private String fTraceTypeId;
38
39 /**
40 * @param parent the parent node
41 */
42 public TmfFilterAspectNode(ITmfFilterTreeNode parent) {
43 super(parent);
44 }
45
46 /**
47 * @return The event aspect of this filter
48 */
49 public ITmfEventAspect getEventAspect() {
50 return fEventAspect;
51 }
52
53 /**
54 * @param aspect
55 * The event aspect to assign to this filter
56 */
57 public void setEventAspect(ITmfEventAspect aspect) {
58 fEventAspect = aspect;
59 }
60
61 /**
62 * @return The trace type id from which the event aspect belongs, or a
63 * special case id
64 * @see #BASE_ASPECT_ID
ec34bf48
PT
65 */
66 public String getTraceTypeId() {
67 return fTraceTypeId;
68 }
69
70 /**
71 * @param traceTypeId
72 * The trace type id from which the event aspect belongs, or a
73 * special case id
74 * @see #BASE_ASPECT_ID
ec34bf48
PT
75 */
76 public void setTraceTypeId(String traceTypeId) {
77 fTraceTypeId = traceTypeId;
78 }
79
40dfafb3
PT
80 /**
81 * @return The string representation of the event aspect
82 */
83 public String getAspectLabel() {
84 if (fEventAspect == null) {
85 return ""; //$NON-NLS-1$
86 }
87 StringBuilder sb = new StringBuilder(fEventAspect.getName());
88 if (fEventAspect instanceof TmfEventFieldAspect) {
89 String field = ((TmfEventFieldAspect) fEventAspect).getFieldPath();
90 if (field != null && !field.isEmpty()) {
91 if (field.charAt(0) != '/') {
92 sb.append('/');
93 }
94 sb.append(field);
95 }
96 }
97 return sb.toString();
98 }
99
ec34bf48
PT
100 @Override
101 public ITmfFilterTreeNode clone() {
102 TmfFilterAspectNode clone = (TmfFilterAspectNode) super.clone();
103 clone.setEventAspect(fEventAspect);
104 clone.setTraceTypeId(fTraceTypeId);
105 return clone;
106 }
107
108 @Override
109 public int hashCode() {
110 final int prime = 31;
111 int result = super.hashCode();
112 result = prime * result + ((fEventAspect == null) ? 0 : fEventAspect.hashCode());
113 result = prime * result + ((fTraceTypeId == null) ? 0 : fTraceTypeId.hashCode());
114 return result;
115 }
116
117 @Override
118 public boolean equals(Object obj) {
119 if (this == obj) {
120 return true;
121 }
122 if (!super.equals(obj)) {
123 return false;
124 }
125 if (getClass() != obj.getClass()) {
126 return false;
127 }
128 TmfFilterAspectNode other = (TmfFilterAspectNode) obj;
129 if (fEventAspect == null) {
130 if (other.fEventAspect != null) {
131 return false;
132 }
133 } else if (!fEventAspect.equals(other.fEventAspect)) {
134 return false;
135 }
136 if (fTraceTypeId == null) {
137 if (other.fTraceTypeId != null) {
138 return false;
139 }
140 } else if (!fTraceTypeId.equals(other.fTraceTypeId)) {
141 return false;
142 }
143 return true;
144 }
145}
This page took 0.030222 seconds and 5 git commands to generate.