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 * Alexandre Montplaisir - Initial API and implementation
11 ******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
22 * Event table column that will print the value of a given event field, and
23 * whose column name is also the same as that field.
25 * @author Alexandre Montplaisir
29 public class TmfEventTableFieldColumn
extends TmfEventTableColumn
{
31 private final String fFieldName
;
34 * Basic constructor, which uses the same name for the field name and the
37 * @param headerAndFieldName
38 * The string that is both the title of the column AND the field
41 public TmfEventTableFieldColumn(String headerAndFieldName
) {
42 super(headerAndFieldName
);
43 fFieldName
= headerAndFieldName
;
47 * Advanced constructor, which can define different field name and header.
48 * You can also define a tooltip, optionally.
51 * The header (title) of the column
53 * The field name to look for in the event content to populate
55 * @param headerTooltip
56 * The tooltip text for the column header. Use 'null' for no
59 public TmfEventTableFieldColumn(String headerName
, String fieldName
,
60 @Nullable String headerTooltip
) {
61 super(headerName
, headerTooltip
);
62 fFieldName
= fieldName
;
66 public final String
getItemString(ITmfEvent event
) {
67 ITmfEventField field
= event
.getContent().getField(fFieldName
);
71 String val
= field
.getFormattedValue();
72 return (val
== null ? EMPTY_STRING
: val
);
76 public @NonNull String
getFilterFieldId() {
80 // ------------------------------------------------------------------------
81 // hashCode/equals (so that equivalent columns can be merged together)
82 // ------------------------------------------------------------------------
85 public int hashCode() {
88 result
= prime
* result
+ fFieldName
.hashCode();
89 result
= prime
* result
+ getHeaderName().hashCode();
94 public boolean equals(@Nullable Object obj
) {
101 if (!(obj
instanceof TmfEventTableFieldColumn
)) {
104 TmfEventTableFieldColumn other
= (TmfEventTableFieldColumn
) obj
;
105 if (!fFieldName
.equals(other
.fFieldName
)) {
108 if (!getHeaderName().equals(other
.getHeaderName())) {