1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Vincent Perot - Initial API and implementation
11 * Alexandre Montplaisir - Update to new TmfEventTableColumn API
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.tmf
.pcap
.ui
.editor
;
16 import java
.util
.Collection
;
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
;
26 import com
.google
.common
.collect
.ImmutableList
;
29 * Default event table for pcap traces.
31 * @author Vincent Perot
33 public class PcapEventTableColumns
implements ITmfEventTableColumns
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
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
50 * The "packet source" column for pcap events
52 private static class PcapSourceColumn
extends TmfEventTableColumn
{
54 public PcapSourceColumn() {
55 super(getString(Messages
.PcapEventsTable_Source
));
59 public String
getItemString(ITmfEvent event
) {
60 if (!(event
instanceof PcapEvent
)) {
63 PcapEvent pcapEvent
= (PcapEvent
) event
;
64 TmfPcapProtocol protocol
= pcapEvent
.getMostEncapsulatedProtocol();
66 return getString(pcapEvent
.getSourceEndpoint(protocol
));
70 public @Nullable String
getFilterFieldId() {
71 return PcapEvent
.EVENT_FIELD_PACKET_SOURCE
;
76 * The "packet destination" column for pcap events
78 private static class PcapDestinationColumn
extends TmfEventTableColumn
{
80 public PcapDestinationColumn() {
81 super(getString(Messages
.PcapEventsTable_Destination
));
85 public String
getItemString(ITmfEvent event
) {
86 if (!(event
instanceof PcapEvent
)) {
89 PcapEvent pcapEvent
= (PcapEvent
) event
;
90 TmfPcapProtocol protocol
= pcapEvent
.getMostEncapsulatedProtocol();
91 return getString(pcapEvent
.getDestinationEndpoint(protocol
));
95 public @Nullable String
getFilterFieldId() {
96 return PcapEvent
.EVENT_FIELD_PACKET_DESTINATION
;
101 * The "packet protocol" column for pcap events
103 private static class PcapProtocolColumn
extends TmfEventTableColumn
{
105 public PcapProtocolColumn() {
106 super(getString(Messages
.PcapEventsTable_Protocol
));
110 public String
getItemString(ITmfEvent event
) {
111 if (!(event
instanceof PcapEvent
)) {
114 PcapEvent pcapEvent
= (PcapEvent
) event
;
115 TmfPcapProtocol protocol
= pcapEvent
.getMostEncapsulatedProtocol();
117 @SuppressWarnings("null")
118 @NonNull String proto
= protocol
.getShortName().toUpperCase();
123 public @Nullable String
getFilterFieldId() {
124 return PcapEvent
.EVENT_FIELD_PACKET_PROTOCOL
;
129 * Little convenience method to work around the incompatibilities between
130 * null annotations and NLS files...
132 private static String
getString(@Nullable String str
) {
133 return (str
== null ?
"" : str
); //$NON-NLS-1$
136 // ------------------------------------------------------------------------
137 // ITmfEventTableColumns
138 // ------------------------------------------------------------------------
141 public Collection
<?
extends TmfEventTableColumn
> getEventTableColumns() {