1 /*******************************************************************************
2 * Copyright (c) 2010, 2014 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
.linuxtools
.internal
.tmf
.ui
.parsers
.custom
;
16 import java
.util
.Collection
;
17 import java
.util
.List
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
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
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.columns
.ITmfEventTableColumns
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
28 import com
.google
.common
.collect
.ImmutableList
;
31 * Event table column definition for Custom {Text|XML} traces.
33 * Since this definition will be different for every single custom trace, this
34 * does not work the same as with {@link ITmfEventTableColumns}.
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)}
42 * @author Alexandre Montplaisir
44 public class CustomEventTableColumns
{
47 * Column for custom events, which uses an integer ID to represent each
50 private static final class CustomEventTableColumn
extends TmfEventTableColumn
{
52 private final int fIndex
;
58 * The name (title) of this column
60 * The index of this column, which should be the index of the
61 * field in the event's content to display.
63 public CustomEventTableColumn(@NonNull String name
, int idx
) {
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
);
78 public String
getFilterFieldId() {
79 return getHeaderName();
84 * Get the event table columns for a given trace definition
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.
89 public static Collection
<CustomEventTableColumn
> generateColumns(CustomTraceDefinition definition
) {
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
;
95 builder
.add(new CustomEventTableColumn(name
, i
));
98 return builder
.build();