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
.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
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.pcap
.core
.event
.PcapEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.pcap
.core
.protocol
.TmfProtocol
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.TmfEventsTable
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
27 import com
.google
.common
.collect
.ImmutableList
;
30 * Default event table for pcap traces.
32 * @author Vincent Perot
34 public class PcapEventsTable
extends TmfEventsTable
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 @SuppressWarnings("null")
41 private static final @NonNull Collection
<TmfEventTableColumn
> PCAP_COLUMNS
= ImmutableList
.of(
42 TmfEventTableColumn
.BaseColumns
.TIMESTAMP
,
43 new PcapSourceColumn(),
44 new PcapDestinationColumn(),
45 TmfEventTableColumn
.BaseColumns
.REFERENCE
,
46 new PcapProtocolColumn(),
47 TmfEventTableColumn
.BaseColumns
.CONTENTS
51 * The "packet source" column for pcap events
53 private static class PcapSourceColumn
extends TmfEventTableColumn
{
55 public PcapSourceColumn() {
56 super(getString(Messages
.PcapEventsTable_Source
));
60 public String
getItemString(ITmfEvent event
) {
61 if (!(event
instanceof PcapEvent
)) {
64 PcapEvent pcapEvent
= (PcapEvent
) event
;
65 TmfProtocol protocol
= pcapEvent
.getMostEncapsulatedProtocol();
67 return getString(pcapEvent
.getSourceEndpoint(protocol
));
71 public @Nullable String
getFilterFieldId() {
72 return PcapEvent
.EVENT_FIELD_PACKET_SOURCE
;
77 * The "packet destination" column for pcap events
79 private static class PcapDestinationColumn
extends TmfEventTableColumn
{
81 public PcapDestinationColumn() {
82 super(getString(Messages
.PcapEventsTable_Destination
));
86 public String
getItemString(ITmfEvent event
) {
87 if (!(event
instanceof PcapEvent
)) {
90 PcapEvent pcapEvent
= (PcapEvent
) event
;
91 TmfProtocol protocol
= pcapEvent
.getMostEncapsulatedProtocol();
92 return getString(pcapEvent
.getDestinationEndpoint(protocol
));
96 public @Nullable String
getFilterFieldId() {
97 return PcapEvent
.EVENT_FIELD_PACKET_DESTINATION
;
102 * The "packet protocol" column for pcap events
104 private static class PcapProtocolColumn
extends TmfEventTableColumn
{
106 public PcapProtocolColumn() {
107 super(getString(Messages
.PcapEventsTable_Protocol
));
111 public String
getItemString(ITmfEvent event
) {
112 if (!(event
instanceof PcapEvent
)) {
115 PcapEvent pcapEvent
= (PcapEvent
) event
;
116 TmfProtocol protocol
= pcapEvent
.getMostEncapsulatedProtocol();
118 @SuppressWarnings("null")
119 @NonNull String proto
= protocol
.getShortName().toUpperCase();
124 public @Nullable String
getFilterFieldId() {
125 return PcapEvent
.EVENT_FIELD_PACKET_PROTOCOL
;
130 * Little convenience method to work around the incompatibilities between
131 * null annotations and NLS files...
133 private static String
getString(@Nullable String str
) {
134 return (str
== null ? EMPTY_STRING
: str
);
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
145 * The parent composite
147 * The size of the rows cache
149 public PcapEventsTable(Composite parent
, int cacheSize
) {
150 super(parent
, cacheSize
, PCAP_COLUMNS
);