Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2010, 2014 Ericsson |
be222f56 PT |
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 | |
baafe54c | 11 | * Alexandre Montplaisir - Update for TmfEventTableColumn |
be222f56 PT |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.internal.tmf.ui.parsers.custom; |
be222f56 | 15 | |
baafe54c | 16 | import java.util.Collection; |
be222f56 PT |
17 | import java.util.List; |
18 | ||
baafe54c | 19 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 | 20 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
9447c7ee | 21 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; |
2bdf0193 AM |
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; | |
25 | import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable; | |
26 | import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.ITmfEventTableColumns; | |
27 | import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn; | |
be222f56 | 28 | |
baafe54c AM |
29 | import com.google.common.collect.ImmutableList; |
30 | ||
a0a88f65 | 31 | /** |
99d7adc6 | 32 | * Event table column definition for Custom {Text|XML} traces. |
a0a88f65 | 33 | * |
99d7adc6 AM |
34 | * Since this definition will be different for every single custom trace, this |
35 | * does not work the same as with {@link ITmfEventTableColumns}. | |
36 | * | |
37 | * Instead, one has to call {@link #generateColumns(CustomTraceDefinition)} with | |
38 | * the CustomTraceDefinition of the the particular trace to display. Then the | |
39 | * returned collection can be passed to the constructor | |
40 | * {@link TmfEventsTable#TmfEventsTable(org.eclipse.swt.widgets.Composite, int, Collection)} | |
41 | * as usual. | |
42 | * | |
43 | * @author Alexandre Montplaisir | |
a0a88f65 | 44 | */ |
99d7adc6 | 45 | public class CustomEventTableColumns { |
be222f56 | 46 | |
baafe54c AM |
47 | /** |
48 | * Column for custom events, which uses an integer ID to represent each | |
49 | * column. | |
50 | */ | |
9447c7ee | 51 | private static final class CustomEventFieldAspect implements ITmfEventAspect { |
baafe54c | 52 | |
9447c7ee | 53 | private final @NonNull String fName; |
baafe54c AM |
54 | private final int fIndex; |
55 | ||
56 | /** | |
57 | * Constructor | |
58 | * | |
59 | * @param name | |
9447c7ee | 60 | * The name (title) of this aspect |
baafe54c | 61 | * @param idx |
9447c7ee AM |
62 | * The "index" of this aspect, which should be the index of |
63 | * the field in the event's content to display. | |
baafe54c | 64 | */ |
9447c7ee AM |
65 | public CustomEventFieldAspect(@NonNull String name, int idx) { |
66 | fName = name; | |
baafe54c AM |
67 | fIndex = idx; |
68 | } | |
69 | ||
70 | @Override | |
9447c7ee AM |
71 | public String getName() { |
72 | return fName; | |
73 | } | |
74 | ||
75 | @Override | |
76 | public String getHelpText() { | |
77 | return EMPTY_STRING; | |
78 | } | |
79 | ||
80 | @Override | |
81 | public String resolve(ITmfEvent event) { | |
baafe54c AM |
82 | if (event instanceof CustomEvent) { |
83 | String ret = ((CustomEvent) event).getEventString(fIndex); | |
84 | return (ret == null ? EMPTY_STRING : ret); | |
85 | } | |
86 | return EMPTY_STRING; | |
87 | } | |
88 | ||
89 | @Override | |
9447c7ee AM |
90 | public String getFilterId() { |
91 | return fName; | |
baafe54c AM |
92 | } |
93 | } | |
be222f56 | 94 | |
a0a88f65 | 95 | /** |
99d7adc6 | 96 | * Get the event table columns for a given trace definition |
a0a88f65 | 97 | * |
99d7adc6 AM |
98 | * @param definition The {@link CustomTraceDefinition} of the trace for which you want the columns |
99 | * @return The set of columns for the given trace. | |
a0a88f65 | 100 | */ |
9447c7ee AM |
101 | public static Collection<TmfEventTableColumn> generateColumns(CustomTraceDefinition definition) { |
102 | ImmutableList.Builder<TmfEventTableColumn> builder = new ImmutableList.Builder<>(); | |
baafe54c AM |
103 | List<OutputColumn> outputs = definition.outputs; |
104 | for (int i = 0; i < outputs.size(); i++) { | |
105 | String name = outputs.get(i).name; | |
106 | if (name != null) { | |
9447c7ee | 107 | builder.add(new TmfEventTableColumn(new CustomEventFieldAspect(name, i))); |
baafe54c | 108 | } |
be222f56 | 109 | } |
baafe54c | 110 | return builder.build(); |
be222f56 PT |
111 | } |
112 | } |