analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / parsers / custom / CustomEventAspects.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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 * Alexandre Montplaisir - Update for TmfEventTableColumn
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.internal.tmf.core.parsers.custom;
15
16 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17
18 import java.util.List;
19
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;
26
27 import com.google.common.collect.ImmutableList;
28
29 /**
30 * Event aspects for Custom {Text|XML} traces.
31 *
32 * Since this definition will be different for every single custom trace, we
33 * cannot define specific {@link ITmfEventAspect} in advance.
34 *
35 * Instead, one has to call {@link #generateAspects(CustomTraceDefinition)}
36 * with the CustomTraceDefinition of the the particular trace to display.
37 *
38 * @author Alexandre Montplaisir
39 */
40 public class CustomEventAspects {
41
42 /**
43 * Aspects for custom events, which use an integer ID to represent each
44 * field.
45 */
46 private static final class CustomEventFieldAspect implements ITmfEventAspect {
47
48 private final @NonNull String fName;
49 private final int fIndex;
50
51 /**
52 * Constructor
53 *
54 * @param name
55 * The name of this aspect
56 * @param idx
57 * The index of this field in the event's content to display
58 */
59 public CustomEventFieldAspect(@NonNull String name, int idx) {
60 fName = name;
61 fIndex = idx;
62 }
63
64 @Override
65 public String getName() {
66 return fName;
67 }
68
69 @Override
70 public String getHelpText() {
71 return EMPTY_STRING;
72 }
73
74 @Override
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);
79 }
80 return EMPTY_STRING;
81 }
82 }
83
84 /**
85 * Build a set of event aspects for a given trace definition
86 *
87 * @param definition
88 * The {@link CustomTraceDefinition} of the trace for which you
89 * want the aspects
90 * @return The set of event aspects for the given trace
91 */
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 if (name != null) {
98 builder.add(new CustomEventFieldAspect(name, i));
99 }
100 }
101 return checkNotNull(builder.build());
102 }
103 }
This page took 0.049724 seconds and 5 git commands to generate.