tmf: Introduce the core concept of event aspects
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / events / columns / TmfEventTableColumn.java
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
13 package org.eclipse.tracecompass.tmf.ui.viewers.events.columns;
14
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.aspect.ITmfEventAspect;
20
21 /**
22 * A column in the
23 * {@link org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable}. In
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
28 * {@link org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable#TmfEventsTable(org.eclipse.swt.widgets.Composite, int, java.util.Collection)}
29 *
30 * @author Alexandre Montplaisir
31 * @noextend This class should not be extended directly. You should instead
32 * implement an {@link ITmfEventAspect}.
33 * @since 3.1
34 */
35 @NonNullByDefault
36 public class TmfEventTableColumn {
37
38 // ------------------------------------------------------------------------
39 // Fields
40 // ------------------------------------------------------------------------
41
42 private final ITmfEventAspect fAspect;
43
44 // ------------------------------------------------------------------------
45 // Constructors
46 // ------------------------------------------------------------------------
47
48 /**
49 * Constructor
50 *
51 * @param aspect
52 * The {@link ITmfEventAspect} to be used to populate this
53 * column.
54 */
55 public TmfEventTableColumn(ITmfEventAspect aspect) {
56 fAspect = aspect;
57 }
58
59 // ------------------------------------------------------------------------
60 // Getters
61 // ------------------------------------------------------------------------
62
63 /**
64 * Get this column's header name, a.k.a. title
65 *
66 * @return The column's title
67 */
68 public String getHeaderName() {
69 return fAspect.getName();
70 }
71
72 /**
73 * Get the tooltip text for the column header
74 *
75 * @return The header's tooltip
76 */
77 public @Nullable String getHeaderTooltip() {
78 return fAspect.getHelpText();
79 }
80
81 /**
82 * Get the string that should be displayed in this column's cell for a given
83 * trace event. Basically, this defines "what to print in this column for
84 * this event".
85 *
86 * @param event
87 * The trace event whose element we want to display
88 * @return The string to display in the column for this event
89 */
90 public String getItemString(ITmfEvent event) {
91 /* resolve() is NonNull. toString() is not, but should never return null */
92 @SuppressWarnings("null")
93 @NonNull String ret = fAspect.resolve(event).toString();
94 return ret;
95 }
96
97 /**
98 * Return the FILTER_ID used by the filters to search this column.
99 *
100 * @return The filter ID for this column, or 'null' to not provide a filter
101 * ID (which will mean this column will probably not be
102 * searchable/filterable.)
103 */
104 public @Nullable String getFilterFieldId() {
105 return fAspect.getFilterId();
106 }
107
108 // ------------------------------------------------------------------------
109 // hashCode/equals (so that equivalent columns can be merged together)
110 // ------------------------------------------------------------------------
111
112 @Override
113 public int hashCode() {
114 final int prime = 31;
115 int result = 1;
116 result = prime * result + fAspect.hashCode();
117 return result;
118 }
119
120 @Override
121 public boolean equals(@Nullable Object obj) {
122 if (this == obj) {
123 return true;
124 }
125 if (obj == null) {
126 return false;
127 }
128 if (!(obj instanceof TmfEventTableColumn)) {
129 return false;
130 }
131 TmfEventTableColumn other = (TmfEventTableColumn) obj;
132 if (!fAspect.equals(other.fAspect)) {
133 /* Aspects can also define how they can be "equal" to one another */
134 return false;
135 }
136 return true;
137 }
138 }
This page took 0.034177 seconds and 5 git commands to generate.