Commit | Line | Data |
---|---|---|
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 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.internal.tmf.pcap.ui.editor; |
b6eb4dce | 15 | |
baafe54c AM |
16 | import java.util.Collection; |
17 | ||
18 | import org.eclipse.jdt.annotation.NonNull; | |
b6eb4dce | 19 | import org.eclipse.jdt.annotation.Nullable; |
2bdf0193 AM |
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; | |
9447c7ee | 23 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; |
2bdf0193 AM |
24 | import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.ITmfEventTableColumns; |
25 | import org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn; | |
b6eb4dce | 26 | |
baafe54c AM |
27 | import com.google.common.collect.ImmutableList; |
28 | ||
b6eb4dce VP |
29 | /** |
30 | * Default event table for pcap traces. | |
31 | * | |
32 | * @author Vincent Perot | |
33 | */ | |
99d7adc6 | 34 | public class PcapEventTableColumns implements ITmfEventTableColumns { |
b6eb4dce VP |
35 | |
36 | // ------------------------------------------------------------------------ | |
37 | // Table data | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
baafe54c AM |
40 | @SuppressWarnings("null") |
41 | private static final @NonNull Collection<TmfEventTableColumn> PCAP_COLUMNS = ImmutableList.of( | |
9447c7ee AM |
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) | |
baafe54c AM |
48 | ); |
49 | ||
50 | /** | |
51 | * The "packet source" column for pcap events | |
52 | */ | |
9447c7ee | 53 | private static class PcapSourceAspect implements ITmfEventAspect { |
baafe54c | 54 | |
9447c7ee AM |
55 | @Override |
56 | public String getName() { | |
57 | return getString(Messages.PcapEventsTable_Source); | |
58 | } | |
59 | ||
60 | @Override | |
61 | public String getHelpText() { | |
62 | return EMPTY_STRING; | |
baafe54c AM |
63 | } |
64 | ||
65 | @Override | |
9447c7ee | 66 | public String resolve(ITmfEvent event) { |
baafe54c AM |
67 | if (!(event instanceof PcapEvent)) { |
68 | return EMPTY_STRING; | |
69 | } | |
70 | PcapEvent pcapEvent = (PcapEvent) event; | |
c88feda9 | 71 | TmfPcapProtocol protocol = pcapEvent.getMostEncapsulatedProtocol(); |
baafe54c AM |
72 | |
73 | return getString(pcapEvent.getSourceEndpoint(protocol)); | |
74 | } | |
75 | ||
76 | @Override | |
9447c7ee | 77 | public @NonNull String getFilterId() { |
baafe54c AM |
78 | return PcapEvent.EVENT_FIELD_PACKET_SOURCE; |
79 | } | |
80 | } | |
81 | ||
82 | /** | |
83 | * The "packet destination" column for pcap events | |
84 | */ | |
9447c7ee | 85 | private static class PcapDestinationAspect implements ITmfEventAspect { |
baafe54c | 86 | |
9447c7ee AM |
87 | @Override |
88 | public String getName() { | |
89 | return getString(Messages.PcapEventsTable_Destination); | |
90 | } | |
91 | ||
92 | @Override | |
93 | public String getHelpText() { | |
94 | return EMPTY_STRING; | |
baafe54c AM |
95 | } |
96 | ||
97 | @Override | |
9447c7ee | 98 | public String resolve(ITmfEvent event) { |
baafe54c AM |
99 | if (!(event instanceof PcapEvent)) { |
100 | return EMPTY_STRING; | |
101 | } | |
102 | PcapEvent pcapEvent = (PcapEvent) event; | |
c88feda9 | 103 | TmfPcapProtocol protocol = pcapEvent.getMostEncapsulatedProtocol(); |
baafe54c AM |
104 | return getString(pcapEvent.getDestinationEndpoint(protocol)); |
105 | } | |
106 | ||
107 | @Override | |
9447c7ee | 108 | public @NonNull String getFilterId() { |
baafe54c AM |
109 | return PcapEvent.EVENT_FIELD_PACKET_DESTINATION; |
110 | } | |
111 | } | |
112 | ||
e1de2fd4 AM |
113 | /** |
114 | * The "packet reference" column for pcap events | |
115 | */ | |
9447c7ee | 116 | private static class PcapReferenceAspect implements ITmfEventAspect { |
e1de2fd4 | 117 | |
9447c7ee AM |
118 | @Override |
119 | public String getName() { | |
120 | return getString(Messages.PcapEventsTable_Reference); | |
121 | } | |
122 | ||
123 | @Override | |
124 | public String getHelpText() { | |
125 | return EMPTY_STRING; | |
e1de2fd4 AM |
126 | } |
127 | ||
128 | @Override | |
9447c7ee | 129 | public String resolve(ITmfEvent event) { |
e1de2fd4 AM |
130 | if (!(event instanceof PcapEvent)) { |
131 | return EMPTY_STRING; | |
132 | } | |
133 | return ((PcapEvent) event).getReference(); | |
134 | } | |
135 | ||
136 | @Override | |
9447c7ee | 137 | public @Nullable String getFilterId() { |
e1de2fd4 AM |
138 | return ITmfEvent.EVENT_FIELD_REFERENCE; |
139 | } | |
140 | } | |
141 | ||
baafe54c AM |
142 | /** |
143 | * The "packet protocol" column for pcap events | |
144 | */ | |
9447c7ee | 145 | private static class PcapProtocolAspect implements ITmfEventAspect { |
baafe54c | 146 | |
9447c7ee AM |
147 | @Override |
148 | public String getName() { | |
149 | return getString(Messages.PcapEventsTable_Protocol); | |
150 | } | |
151 | ||
152 | @Override | |
153 | public String getHelpText() { | |
154 | return EMPTY_STRING; | |
baafe54c AM |
155 | } |
156 | ||
157 | @Override | |
9447c7ee | 158 | public String resolve(ITmfEvent event) { |
baafe54c AM |
159 | if (!(event instanceof PcapEvent)) { |
160 | return EMPTY_STRING; | |
161 | } | |
162 | PcapEvent pcapEvent = (PcapEvent) event; | |
c88feda9 | 163 | TmfPcapProtocol protocol = pcapEvent.getMostEncapsulatedProtocol(); |
baafe54c AM |
164 | |
165 | @SuppressWarnings("null") | |
166 | @NonNull String proto = protocol.getShortName().toUpperCase(); | |
167 | return proto; | |
168 | } | |
169 | ||
170 | @Override | |
9447c7ee | 171 | public @Nullable String getFilterId() { |
baafe54c AM |
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) { | |
99d7adc6 | 181 | return (str == null ? "" : str); //$NON-NLS-1$ |
baafe54c | 182 | } |
b6eb4dce VP |
183 | |
184 | // ------------------------------------------------------------------------ | |
99d7adc6 | 185 | // ITmfEventTableColumns |
b6eb4dce VP |
186 | // ------------------------------------------------------------------------ |
187 | ||
99d7adc6 AM |
188 | @Override |
189 | public Collection<? extends TmfEventTableColumn> getEventTableColumns() { | |
190 | return PCAP_COLUMNS; | |
b6eb4dce VP |
191 | } |
192 | } |