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