58ba56d8caa6ab473975d0926ff93bc9f7a531c8
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / filter / model / TmfFilterAspectNode.java
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
13 package org.eclipse.tracecompass.tmf.core.filter.model;
14
15 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
16 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfEventFieldAspect;
17
18 /**
19 * Base class for filter nodes which use event aspects
20 *
21 * @author Patrick Tasse
22 */
23 public 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$
29 /** field attribute name */
30 public static final String FIELD_ATTR = "field"; //$NON-NLS-1$
31 /** special case trace type id for base aspects */
32 public static final String BASE_ASPECT_ID = "BASE.ASPECT.ID"; //$NON-NLS-1$
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
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
75 */
76 public void setTraceTypeId(String traceTypeId) {
77 fTraceTypeId = traceTypeId;
78 }
79
80 /**
81 * @param explicit
82 * true if the string representation should explicitly include
83 * the trace type id that can differentiate it from other aspects
84 * with the same name
85 *
86 * @return The string representation of the event aspect
87 */
88 public String getAspectLabel(boolean explicit) {
89 if (fEventAspect == null) {
90 return ""; //$NON-NLS-1$
91 }
92 StringBuilder sb = new StringBuilder(fEventAspect.getName());
93 if (explicit) {
94 sb.append('[');
95 sb.append(fTraceTypeId);
96 sb.append(']');
97 }
98 if (fEventAspect instanceof TmfEventFieldAspect) {
99 String field = ((TmfEventFieldAspect) fEventAspect).getFieldPath();
100 if (field != null && !field.isEmpty()) {
101 if (field.charAt(0) != '/') {
102 sb.append('/');
103 }
104 sb.append(field);
105 }
106 }
107 return sb.toString();
108 }
109
110 @Override
111 public ITmfFilterTreeNode clone() {
112 TmfFilterAspectNode clone = (TmfFilterAspectNode) super.clone();
113 clone.setEventAspect(fEventAspect);
114 clone.setTraceTypeId(fTraceTypeId);
115 return clone;
116 }
117 }
This page took 0.039126 seconds and 4 git commands to generate.