tmf: Add TmfEventTableColumn class
[deliverable/tracecompass.git] / org.eclipse.linuxtools.btf.ui / src / org / eclipse / linuxtools / btf / ui / BtfEventViewer.java
1 /*******************************************************************************
2 * Copyright (c) 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 * Matthew Khouzam - Initial API and implementation
11 * Alexandre Montplaisir - Updated to new Event Table API
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.btf.ui;
15
16 import java.util.Collection;
17
18 import org.eclipse.linuxtools.btf.core.trace.BtfColumnNames;
19 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
20 import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
21 import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
22 import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableFieldColumn;
23 import org.eclipse.swt.widgets.Composite;
24
25 import com.google.common.collect.ImmutableList;
26
27 /**
28 * BTF event viewer
29 *
30 * @author Matthew Khouzam
31 */
32 public class BtfEventViewer extends TmfEventsTable {
33
34 // ------------------------------------------------------------------------
35 // Column definition
36 // ------------------------------------------------------------------------
37
38 private static final Collection<TmfEventTableColumn> BTF_COLUMNS = ImmutableList.of(
39 TmfEventTableColumn.BaseColumns.TIMESTAMP,
40 new BtfSourceColumn(),
41 new BtfSourceInstanceColumn(),
42 TmfEventTableColumn.BaseColumns.EVENT_TYPE,
43 new BtfTargetColumn(),
44 new BtfTargetInstanceColumn(),
45 new BtfEventColumn(),
46 new BtfNotesColumn()
47 );
48
49 /**
50 * The "source" column, whose value comes from {@link ITmfEvent#getSource()}
51 */
52 private static class BtfSourceColumn extends TmfEventTableColumn {
53
54 public BtfSourceColumn() {
55 super(BtfColumnNames.SOURCE.toString(), null);
56 }
57
58 @Override
59 public String getItemString(ITmfEvent event) {
60 String ret = event.getSource();
61 return (ret == null ? EMPTY_STRING : ret);
62 }
63
64 @Override
65 public String getFilterFieldId() {
66 return ITmfEvent.EVENT_FIELD_SOURCE;
67 }
68 }
69
70 /**
71 * The "source instance" column, whose value comes from the field of the
72 * same name.
73 */
74 private static class BtfSourceInstanceColumn extends TmfEventTableFieldColumn {
75 public BtfSourceInstanceColumn() {
76 super(BtfColumnNames.SOURCE_INSTANCE.toString());
77 }
78 }
79
80 /**
81 * The "target" column, taking its value from
82 * {@link ITmfEvent#getReference()}.
83 */
84 private static class BtfTargetColumn extends TmfEventTableColumn {
85
86 public BtfTargetColumn() {
87 super(BtfColumnNames.TARGET.toString());
88 }
89
90 @Override
91 public String getItemString(ITmfEvent event) {
92 String ret = event.getReference();
93 return (ret == null ? EMPTY_STRING : ret);
94 }
95
96 @Override
97 public String getFilterFieldId() {
98 return ITmfEvent.EVENT_FIELD_REFERENCE;
99 }
100 }
101
102 /**
103 * The "target instance" column, whose value comes from the field of the
104 * same name.
105 */
106 private static class BtfTargetInstanceColumn extends TmfEventTableFieldColumn {
107 public BtfTargetInstanceColumn() {
108 super(BtfColumnNames.TARGET_INSTANCE.toString());
109 }
110 }
111
112 /**
113 * The "event" column, whose value comes from the field of the same name.
114 */
115 private static class BtfEventColumn extends TmfEventTableFieldColumn {
116 public BtfEventColumn() {
117 super(BtfColumnNames.EVENT.toString());
118 }
119 }
120
121 /**
122 * The "notes" column, whose value comes from the field of the same name, if
123 * present.
124 */
125 private static class BtfNotesColumn extends TmfEventTableFieldColumn {
126 public BtfNotesColumn() {
127 super(BtfColumnNames.NOTES.toString());
128 }
129 }
130
131 // ------------------------------------------------------------------------
132 // Constructor
133 // ------------------------------------------------------------------------
134
135 /**
136 * Basic constructor, will use default column data.
137 *
138 * @param parent
139 * The parent composite UI object
140 * @param cacheSize
141 * The size of the event table cache
142 */
143 public BtfEventViewer(Composite parent, int cacheSize) {
144 super(parent, cacheSize, BTF_COLUMNS);
145 }
146 }
This page took 0.032978 seconds and 5 git commands to generate.