ctf: make Declarations have some NonNull annotations
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.pcap.ui / src / org / eclipse / tracecompass / 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.tracecompass.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.tracecompass.internal.tmf.pcap.core.event.PcapEvent;
21 import org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol;
22 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
23 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
24 import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.ITmfEventTableColumns;
25 import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn;
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 PcapEventTableColumns implements ITmfEventTableColumns {
35
36 // ------------------------------------------------------------------------
37 // Table data
38 // ------------------------------------------------------------------------
39
40 @SuppressWarnings("null")
41 private static final @NonNull Collection<TmfEventTableColumn> PCAP_COLUMNS = ImmutableList.of(
42 new TmfEventTableColumn(ITmfEventAspect.BaseAspects.TIMESTAMP),
43 new TmfEventTableColumn(new PcapSourceAspect()),
44 new TmfEventTableColumn(new PcapDestinationAspect()),
45 new TmfEventTableColumn(new PcapReferenceAspect()),
46 new TmfEventTableColumn(new PcapProtocolAspect()),
47 new TmfEventTableColumn(ITmfEventAspect.BaseAspects.CONTENTS)
48 );
49
50 /**
51 * The "packet source" column for pcap events
52 */
53 private static class PcapSourceAspect implements ITmfEventAspect {
54
55 @Override
56 public String getName() {
57 return getString(Messages.PcapEventsTable_Source);
58 }
59
60 @Override
61 public String getHelpText() {
62 return EMPTY_STRING;
63 }
64
65 @Override
66 public String resolve(ITmfEvent event) {
67 if (!(event instanceof PcapEvent)) {
68 return EMPTY_STRING;
69 }
70 PcapEvent pcapEvent = (PcapEvent) event;
71 TmfPcapProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
72
73 return getString(pcapEvent.getSourceEndpoint(protocol));
74 }
75
76 @Override
77 public @NonNull String getFilterId() {
78 return PcapEvent.EVENT_FIELD_PACKET_SOURCE;
79 }
80 }
81
82 /**
83 * The "packet destination" column for pcap events
84 */
85 private static class PcapDestinationAspect implements ITmfEventAspect {
86
87 @Override
88 public String getName() {
89 return getString(Messages.PcapEventsTable_Destination);
90 }
91
92 @Override
93 public String getHelpText() {
94 return EMPTY_STRING;
95 }
96
97 @Override
98 public String resolve(ITmfEvent event) {
99 if (!(event instanceof PcapEvent)) {
100 return EMPTY_STRING;
101 }
102 PcapEvent pcapEvent = (PcapEvent) event;
103 TmfPcapProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
104 return getString(pcapEvent.getDestinationEndpoint(protocol));
105 }
106
107 @Override
108 public @NonNull String getFilterId() {
109 return PcapEvent.EVENT_FIELD_PACKET_DESTINATION;
110 }
111 }
112
113 /**
114 * The "packet reference" column for pcap events
115 */
116 private static class PcapReferenceAspect implements ITmfEventAspect {
117
118 @Override
119 public String getName() {
120 return getString(Messages.PcapEventsTable_Reference);
121 }
122
123 @Override
124 public String getHelpText() {
125 return EMPTY_STRING;
126 }
127
128 @Override
129 public String resolve(ITmfEvent event) {
130 if (!(event instanceof PcapEvent)) {
131 return EMPTY_STRING;
132 }
133 return ((PcapEvent) event).getReference();
134 }
135
136 @Override
137 public @Nullable String getFilterId() {
138 return ITmfEvent.EVENT_FIELD_REFERENCE;
139 }
140 }
141
142 /**
143 * The "packet protocol" column for pcap events
144 */
145 private static class PcapProtocolAspect implements ITmfEventAspect {
146
147 @Override
148 public String getName() {
149 return getString(Messages.PcapEventsTable_Protocol);
150 }
151
152 @Override
153 public String getHelpText() {
154 return EMPTY_STRING;
155 }
156
157 @Override
158 public String resolve(ITmfEvent event) {
159 if (!(event instanceof PcapEvent)) {
160 return EMPTY_STRING;
161 }
162 PcapEvent pcapEvent = (PcapEvent) event;
163 TmfPcapProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
164
165 @SuppressWarnings("null")
166 @NonNull String proto = protocol.getShortName().toUpperCase();
167 return proto;
168 }
169
170 @Override
171 public @Nullable String getFilterId() {
172 return PcapEvent.EVENT_FIELD_PACKET_PROTOCOL;
173 }
174 }
175
176 /**
177 * Little convenience method to work around the incompatibilities between
178 * null annotations and NLS files...
179 */
180 private static String getString(@Nullable String str) {
181 return (str == null ? "" : str); //$NON-NLS-1$
182 }
183
184 // ------------------------------------------------------------------------
185 // ITmfEventTableColumns
186 // ------------------------------------------------------------------------
187
188 @Override
189 public Collection<? extends TmfEventTableColumn> getEventTableColumns() {
190 return PCAP_COLUMNS;
191 }
192 }
This page took 0.038538 seconds and 5 git commands to generate.