tmf: Add generics to ITmfEventAspect
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / events / columns / TmfEventTableColumn.java
CommitLineData
baafe54c 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2014, 2015 Ericsson
baafe54c
AM
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
2bdf0193 13package org.eclipse.tracecompass.tmf.ui.viewers.events.columns;
baafe54c
AM
14
15import org.eclipse.jdt.annotation.NonNullByDefault;
16import org.eclipse.jdt.annotation.Nullable;
2a28075c 17import org.eclipse.tracecompass.common.core.NonNullUtils;
2bdf0193 18import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
9447c7ee 19import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
baafe54c
AM
20
21/**
22 * A column in the
2bdf0193 23 * {@link org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable}. In
baafe54c
AM
24 * addition to ones provided by default, trace types can extend this class to
25 * create additional columns specific to their events.
26 *
27 * Those additional columns can then be passed to the constructor
2bdf0193 28 * {@link org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable#TmfEventsTable(org.eclipse.swt.widgets.Composite, int, java.util.Collection)}
baafe54c
AM
29 *
30 * @author Alexandre Montplaisir
9447c7ee
AM
31 * @noextend This class should not be extended directly. You should instead
32 * implement an {@link ITmfEventAspect}.
baafe54c
AM
33 */
34@NonNullByDefault
9447c7ee 35public class TmfEventTableColumn {
baafe54c
AM
36
37 // ------------------------------------------------------------------------
38 // Fields
39 // ------------------------------------------------------------------------
40
ec48d248 41 private final ITmfEventAspect<?> fAspect;
baafe54c
AM
42
43 // ------------------------------------------------------------------------
44 // Constructors
45 // ------------------------------------------------------------------------
46
47 /**
9447c7ee 48 * Constructor
baafe54c 49 *
9447c7ee
AM
50 * @param aspect
51 * The {@link ITmfEventAspect} to be used to populate this
52 * column.
baafe54c 53 */
ec48d248 54 public TmfEventTableColumn(ITmfEventAspect<?> aspect) {
9447c7ee 55 fAspect = aspect;
baafe54c
AM
56 }
57
58 // ------------------------------------------------------------------------
59 // Getters
60 // ------------------------------------------------------------------------
61
62 /**
63 * Get this column's header name, a.k.a. title
64 *
65 * @return The column's title
66 */
67 public String getHeaderName() {
9447c7ee 68 return fAspect.getName();
baafe54c
AM
69 }
70
71 /**
72 * Get the tooltip text for the column header
73 *
74 * @return The header's tooltip
75 */
76 public @Nullable String getHeaderTooltip() {
9447c7ee 77 return fAspect.getHelpText();
baafe54c
AM
78 }
79
baafe54c
AM
80 /**
81 * Get the string that should be displayed in this column's cell for a given
82 * trace event. Basically, this defines "what to print in this column for
83 * this event".
baafe54c
AM
84 *
85 * @param event
86 * The trace event whose element we want to display
87 * @return The string to display in the column for this event
88 */
9447c7ee 89 public String getItemString(ITmfEvent event) {
2a28075c 90 return NonNullUtils.nullToEmptyString(fAspect.resolve(event));
9447c7ee 91 }
baafe54c
AM
92
93 /**
c409f16b 94 * Get the event aspect assigned to this column
baafe54c 95 *
c409f16b 96 * @return The event aspect
baafe54c 97 */
ec48d248 98 public ITmfEventAspect<?> getEventAspect() {
c409f16b 99 return fAspect;
9447c7ee
AM
100 }
101
102 // ------------------------------------------------------------------------
103 // hashCode/equals (so that equivalent columns can be merged together)
104 // ------------------------------------------------------------------------
105
106 @Override
107 public int hashCode() {
108 final int prime = 31;
109 int result = 1;
110 result = prime * result + fAspect.hashCode();
111 return result;
112 }
113
114 @Override
115 public boolean equals(@Nullable Object obj) {
116 if (this == obj) {
117 return true;
118 }
119 if (obj == null) {
120 return false;
121 }
122 if (!(obj instanceof TmfEventTableColumn)) {
123 return false;
124 }
125 TmfEventTableColumn other = (TmfEventTableColumn) obj;
126 if (!fAspect.equals(other.fAspect)) {
127 /* Aspects can also define how they can be "equal" to one another */
128 return false;
129 }
130 return true;
131 }
baafe54c 132}
This page took 0.074103 seconds and 5 git commands to generate.