1 /*******************************************************************************
2 * Copyright (c) 2010, 2015 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 * Alexandre Montplaisir - Update for TmfEventTableColumn
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.tmf
.core
.parsers
.custom
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
18 import java
.util
.List
;
20 import org
.eclipse
.jdt
.annotation
.NonNull
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomEvent
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
27 import com
.google
.common
.collect
.ImmutableList
;
30 * Event aspects for Custom {Text|XML} traces.
32 * Since this definition will be different for every single custom trace, we
33 * cannot define specific {@link ITmfEventAspect} in advance.
35 * Instead, one has to call {@link #generateAspects(CustomTraceDefinition)}
36 * with the CustomTraceDefinition of the the particular trace to display.
38 * @author Alexandre Montplaisir
40 public class CustomEventAspects
{
43 * Aspects for custom events, which use an integer ID to represent each
46 private static final class CustomEventFieldAspect
implements ITmfEventAspect
{
48 private final @NonNull String fName
;
49 private final int fIndex
;
55 * The name of this aspect
57 * The index of this field in the event's content to display
59 public CustomEventFieldAspect(@NonNull String name
, int idx
) {
65 public String
getName() {
70 public String
getHelpText() {
75 public String
resolve(ITmfEvent event
) {
76 if (event
instanceof CustomEvent
) {
77 String ret
= ((CustomEvent
) event
).getEventString(fIndex
);
78 return (ret
== null ? EMPTY_STRING
: ret
);
85 * Build a set of event aspects for a given trace definition
88 * The {@link CustomTraceDefinition} of the trace for which you
90 * @return The set of event aspects for the given trace
92 public static @NonNull Iterable
<ITmfEventAspect
> generateAspects(CustomTraceDefinition definition
) {
93 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
94 List
<OutputColumn
> outputs
= definition
.outputs
;
95 for (int i
= 0; i
< outputs
.size(); i
++) {
96 String name
= outputs
.get(i
).name
;
97 builder
.add(new CustomEventFieldAspect(name
, i
));
99 return checkNotNull(builder
.build());