af90427a495317ce28d46d2e7188edb091232ce7
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / internal / tmf / ui / parsers / custom / CustomEventTableColumns.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.linuxtools.internal.tmf.ui.parsers.custom;
15
16 import java.util.Collection;
17 import java.util.List;
18
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;
27
28 import com.google.common.collect.ImmutableList;
29
30 /**
31 * Event table column definition for Custom {Text|XML} traces.
32 *
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
43 */
44 public class CustomEventTableColumns {
45
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 }
82
83 /**
84 * Get the event table columns for a given trace definition
85 *
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.
88 */
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;
94 if (name != null) {
95 builder.add(new CustomEventTableColumn(name, i));
96 }
97 }
98 return builder.build();
99 }
100 }
This page took 0.032152 seconds and 4 git commands to generate.