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 java
.util
.List
;
18 import org
.eclipse
.jdt
.annotation
.NonNull
;
19 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomEvent
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
26 import com
.google
.common
.collect
.ImmutableList
;
29 * Event aspects for Custom {Text|XML} traces.
31 * Since this definition will be different for every single custom trace, we
32 * cannot define specific {@link ITmfEventAspect} in advance.
34 * Instead, one has to call {@link #generateAspects(CustomTraceDefinition)}
35 * with the CustomTraceDefinition of the the particular trace to display.
37 * @author Alexandre Montplaisir
39 public class CustomEventAspects
{
42 * Aspects for custom events, which use an integer ID to represent each
45 private static final class CustomEventFieldAspect
implements ITmfEventAspect
{
47 private final @NonNull String fName
;
48 private final int fIndex
;
54 * The name of this aspect
56 * The index of this field in the event's content to display
58 public CustomEventFieldAspect(@NonNull String name
, int idx
) {
64 public String
getName() {
69 public String
getHelpText() {
74 public String
resolve(ITmfEvent event
) {
75 if (event
instanceof CustomEvent
) {
76 return NonNullUtils
.nullToEmptyString(((CustomEvent
) event
).getEventString(fIndex
));
83 * Build a set of event aspects for a given trace definition
86 * The {@link CustomTraceDefinition} of the trace for which you
88 * @return The set of event aspects for the given trace
90 public static @NonNull Iterable
<ITmfEventAspect
> generateAspects(CustomTraceDefinition definition
) {
91 ImmutableList
.Builder
<ITmfEventAspect
> builder
= new ImmutableList
.Builder
<>();
92 List
<OutputColumn
> outputs
= definition
.outputs
;
93 for (int i
= 0; i
< outputs
.size(); i
++) {
94 String name
= outputs
.get(i
).name
;
95 builder
.add(new CustomEventFieldAspect(name
, i
));
97 return builder
.build();