tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.pcap.ui / src / org / eclipse / linuxtools / internal / tmf / pcap / ui / editor / PcapEventTableColumns.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.internal.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.internal.tmf.pcap.core.event.PcapEvent;
21 import org.eclipse.linuxtools.internal.tmf.pcap.core.protocol.TmfPcapProtocol;
22 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
23 import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.ITmfEventTableColumns;
24 import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
25
26 import com.google.common.collect.ImmutableList;
27
28 /**
29 * Default event table for pcap traces.
30 *
31 * @author Vincent Perot
32 */
33 public class PcapEventTableColumns implements ITmfEventTableColumns {
34
35 // ------------------------------------------------------------------------
36 // Table data
37 // ------------------------------------------------------------------------
38
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;
64 TmfPcapProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
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;
90 TmfPcapProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
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;
115 TmfPcapProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
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) {
133 return (str == null ? "" : str); //$NON-NLS-1$
134 }
135
136 // ------------------------------------------------------------------------
137 // ITmfEventTableColumns
138 // ------------------------------------------------------------------------
139
140 @Override
141 public Collection<? extends TmfEventTableColumn> getEventTableColumns() {
142 return PCAP_COLUMNS;
143 }
144 }
This page took 0.046024 seconds and 5 git commands to generate.