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