tmf: Add TmfEventTableColumn class
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.pcap.ui / src / org / eclipse / linuxtools / tmf / pcap / ui / editor / PcapEventsTable.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 * Vincent Perot - Initial API and implementation
11 * Alexandre Montplaisir - Update to new TmfEventTableColumn API
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.pcap.ui.editor;
15
16 import java.util.Collection;
17
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
21 import org.eclipse.linuxtools.tmf.pcap.core.event.PcapEvent;
22 import org.eclipse.linuxtools.tmf.pcap.core.protocol.TmfProtocol;
23 import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
24 import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
25 import org.eclipse.swt.widgets.Composite;
26
27 import com.google.common.collect.ImmutableList;
28
29 /**
30 * Default event table for pcap traces.
31 *
32 * @author Vincent Perot
33 */
34 public class PcapEventsTable extends TmfEventsTable {
35
36 // ------------------------------------------------------------------------
37 // Table data
38 // ------------------------------------------------------------------------
39
40 @SuppressWarnings("null")
41 private static final @NonNull Collection<TmfEventTableColumn> PCAP_COLUMNS = ImmutableList.of(
42 TmfEventTableColumn.BaseColumns.TIMESTAMP,
43 new PcapSourceColumn(),
44 new PcapDestinationColumn(),
45 TmfEventTableColumn.BaseColumns.REFERENCE,
46 new PcapProtocolColumn(),
47 TmfEventTableColumn.BaseColumns.CONTENTS
48 );
49
50 /**
51 * The "packet source" column for pcap events
52 */
53 private static class PcapSourceColumn extends TmfEventTableColumn {
54
55 public PcapSourceColumn() {
56 super(getString(Messages.PcapEventsTable_Source));
57 }
58
59 @Override
60 public String getItemString(ITmfEvent event) {
61 if (!(event instanceof PcapEvent)) {
62 return EMPTY_STRING;
63 }
64 PcapEvent pcapEvent = (PcapEvent) event;
65 TmfProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
66
67 return getString(pcapEvent.getSourceEndpoint(protocol));
68 }
69
70 @Override
71 public @Nullable String getFilterFieldId() {
72 return PcapEvent.EVENT_FIELD_PACKET_SOURCE;
73 }
74 }
75
76 /**
77 * The "packet destination" column for pcap events
78 */
79 private static class PcapDestinationColumn extends TmfEventTableColumn {
80
81 public PcapDestinationColumn() {
82 super(getString(Messages.PcapEventsTable_Destination));
83 }
84
85 @Override
86 public String getItemString(ITmfEvent event) {
87 if (!(event instanceof PcapEvent)) {
88 return EMPTY_STRING;
89 }
90 PcapEvent pcapEvent = (PcapEvent) event;
91 TmfProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
92 return getString(pcapEvent.getDestinationEndpoint(protocol));
93 }
94
95 @Override
96 public @Nullable String getFilterFieldId() {
97 return PcapEvent.EVENT_FIELD_PACKET_DESTINATION;
98 }
99 }
100
101 /**
102 * The "packet protocol" column for pcap events
103 */
104 private static class PcapProtocolColumn extends TmfEventTableColumn {
105
106 public PcapProtocolColumn() {
107 super(getString(Messages.PcapEventsTable_Protocol));
108 }
109
110 @Override
111 public String getItemString(ITmfEvent event) {
112 if (!(event instanceof PcapEvent)) {
113 return EMPTY_STRING;
114 }
115 PcapEvent pcapEvent = (PcapEvent) event;
116 TmfProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
117
118 @SuppressWarnings("null")
119 @NonNull String proto = protocol.getShortName().toUpperCase();
120 return proto;
121 }
122
123 @Override
124 public @Nullable String getFilterFieldId() {
125 return PcapEvent.EVENT_FIELD_PACKET_PROTOCOL;
126 }
127 }
128
129 /**
130 * Little convenience method to work around the incompatibilities between
131 * null annotations and NLS files...
132 */
133 private static String getString(@Nullable String str) {
134 return (str == null ? EMPTY_STRING : str);
135 }
136
137 // ------------------------------------------------------------------------
138 // Constructor
139 // ------------------------------------------------------------------------
140
141 /**
142 * Constructor
143 *
144 * @param parent
145 * The parent composite
146 * @param cacheSize
147 * The size of the rows cache
148 */
149 public PcapEventsTable(Composite parent, int cacheSize) {
150 super(parent, cacheSize, PCAP_COLUMNS);
151 }
152 }
This page took 0.038803 seconds and 5 git commands to generate.