ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / events / columns / TmfEventTableFieldColumn.java
CommitLineData
baafe54c
AM
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 * Alexandre Montplaisir - Initial API and implementation
11 ******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.ui.viewers.events.columns;
14
15import org.eclipse.jdt.annotation.NonNull;
16import org.eclipse.jdt.annotation.NonNullByDefault;
17import org.eclipse.jdt.annotation.Nullable;
18import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
19import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
20
21/**
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.
24 *
25 * @author Alexandre Montplaisir
26 * @since 3.1
27 */
28@NonNullByDefault
29public class TmfEventTableFieldColumn extends TmfEventTableColumn {
30
31 private final String fFieldName;
32
33 /**
34 * Basic constructor, which uses the same name for the field name and the
35 * column header.
36 *
37 * @param headerAndFieldName
38 * The string that is both the title of the column AND the field
39 * name to look for.
40 */
41 public TmfEventTableFieldColumn(String headerAndFieldName) {
42 super(headerAndFieldName);
43 fFieldName = headerAndFieldName;
44 }
45
46 /**
47 * Advanced constructor, which can define different field name and header.
48 * You can also define a tooltip, optionally.
49 *
50 * @param headerName
51 * The header (title) of the column
52 * @param fieldName
53 * The field name to look for in the event content to populate
54 * this column.
55 * @param headerTooltip
56 * The tooltip text for the column header. Use 'null' for no
57 * tooltip.
58 */
59 public TmfEventTableFieldColumn(String headerName, String fieldName,
60 @Nullable String headerTooltip) {
61 super(headerName, headerTooltip);
62 fFieldName = fieldName;
63 }
64
65 @Override
66 public final String getItemString(ITmfEvent event) {
67 ITmfEventField field = event.getContent().getField(fFieldName);
68 if (field == null) {
69 return EMPTY_STRING;
70 }
71 String val = field.getFormattedValue();
72 return (val == null ? EMPTY_STRING : val);
73 }
74
75 @Override
76 public @NonNull String getFilterFieldId() {
77 return fFieldName;
78 }
79
80 // ------------------------------------------------------------------------
81 // hashCode/equals (so that equivalent columns can be merged together)
82 // ------------------------------------------------------------------------
83
84 @Override
85 public int hashCode() {
86 final int prime = 31;
87 int result = 1;
88 result = prime * result + fFieldName.hashCode();
89 result = prime * result + getHeaderName().hashCode();
90 return result;
91 }
92
93 @Override
94 public boolean equals(@Nullable Object obj) {
95 if (this == obj) {
96 return true;
97 }
98 if (obj == null) {
99 return false;
100 }
101 if (!(obj instanceof TmfEventTableFieldColumn)) {
102 return false;
103 }
104 TmfEventTableFieldColumn other = (TmfEventTableFieldColumn) obj;
105 if (!fFieldName.equals(other.fFieldName)) {
106 return false;
107 }
108 if (!getHeaderName().equals(other.getHeaderName())) {
109 return false;
110 }
111 return true;
112 }
113
114}
This page took 0.029488 seconds and 5 git commands to generate.