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