package org.eclipse.linuxtools.btf.core.trace;
+import org.eclipse.jdt.annotation.NonNull;
+
/**
* Column names
*
*/
NOTES("Notes"); //$NON-NLS-1$
- private final String fField;
+ private final @NonNull String fField;
- private BtfColumnNames(String field) {
+ private BtfColumnNames(@NonNull String field) {
fField = field;
}
@Override
- public String toString() {
+ public @NonNull String toString() {
return fField;
}
}
org.eclipse.ui.ide,
org.eclipse.linuxtools.btf.core
Export-Package: org.eclipse.linuxtools.btf.ui
+Import-Package: com.google.common.collect
package org.eclipse.linuxtools.btf.ui;
-import org.eclipse.linuxtools.btf.core.event.BtfEvent;
+import java.util.Collection;
+
import org.eclipse.linuxtools.btf.core.trace.BtfColumnNames;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
-import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
-import org.eclipse.swt.SWT;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableFieldColumn;
import org.eclipse.swt.widgets.Composite;
+import com.google.common.collect.ImmutableList;
+
/**
* BTF event viewer
*
*/
public class BtfEventViewer extends TmfEventsTable {
- private static final TmfEventField NULL_NOTE_FIELD =
- new TmfEventField(BtfColumnNames.NOTES.toString(), null, null);
-
- private static final String[] COLUMN_NAMES = new String[] {
- BtfColumnNames.TIMESTAMP.toString(),
- BtfColumnNames.SOURCE.toString(),
- BtfColumnNames.SOURCE_INSTANCE.toString(),
- BtfColumnNames.EVENT_TYPE.toString(),
- BtfColumnNames.TARGET.toString(),
- BtfColumnNames.TARGET_INSTANCE.toString(),
- BtfColumnNames.EVENT.toString(),
- BtfColumnNames.NOTES.toString()
- };
-
- private static final ColumnData[] COLUMN_DATA = new ColumnData[] {
- new ColumnData(COLUMN_NAMES[0], 150, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[1], 120, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[2], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[3], 120, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[4], 90, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[5], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[6], 110, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[7], 100, SWT.LEFT),
- };
+ // ------------------------------------------------------------------------
+ // Column definition
+ // ------------------------------------------------------------------------
+
+ private static final Collection<TmfEventTableColumn> BTF_COLUMNS = ImmutableList.of(
+ TmfEventTableColumn.BaseColumns.TIMESTAMP,
+ new BtfSourceColumn(),
+ new BtfSourceInstanceColumn(),
+ TmfEventTableColumn.BaseColumns.EVENT_TYPE,
+ new BtfTargetColumn(),
+ new BtfTargetInstanceColumn(),
+ new BtfEventColumn(),
+ new BtfNotesColumn()
+ );
+
+ /**
+ * The "source" column, whose value comes from {@link ITmfEvent#getSource()}
+ */
+ private static class BtfSourceColumn extends TmfEventTableColumn {
+
+ public BtfSourceColumn() {
+ super(BtfColumnNames.SOURCE.toString(), null);
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ String ret = event.getSource();
+ return (ret == null ? EMPTY_STRING : ret);
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return ITmfEvent.EVENT_FIELD_SOURCE;
+ }
+ }
+
+ /**
+ * The "source instance" column, whose value comes from the field of the
+ * same name.
+ */
+ private static class BtfSourceInstanceColumn extends TmfEventTableFieldColumn {
+ public BtfSourceInstanceColumn() {
+ super(BtfColumnNames.SOURCE_INSTANCE.toString());
+ }
+ }
+
+ /**
+ * The "target" column, taking its value from
+ * {@link ITmfEvent#getReference()}.
+ */
+ private static class BtfTargetColumn extends TmfEventTableColumn {
+
+ public BtfTargetColumn() {
+ super(BtfColumnNames.TARGET.toString());
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ String ret = event.getReference();
+ return (ret == null ? EMPTY_STRING : ret);
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return ITmfEvent.EVENT_FIELD_REFERENCE;
+ }
+ }
+
+ /**
+ * The "target instance" column, whose value comes from the field of the
+ * same name.
+ */
+ private static class BtfTargetInstanceColumn extends TmfEventTableFieldColumn {
+ public BtfTargetInstanceColumn() {
+ super(BtfColumnNames.TARGET_INSTANCE.toString());
+ }
+ }
+
+ /**
+ * The "event" column, whose value comes from the field of the same name.
+ */
+ private static class BtfEventColumn extends TmfEventTableFieldColumn {
+ public BtfEventColumn() {
+ super(BtfColumnNames.EVENT.toString());
+ }
+ }
+
+ /**
+ * The "notes" column, whose value comes from the field of the same name, if
+ * present.
+ */
+ private static class BtfNotesColumn extends TmfEventTableFieldColumn {
+ public BtfNotesColumn() {
+ super(BtfColumnNames.NOTES.toString());
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
/**
* Basic constructor, will use default column data.
* The size of the event table cache
*/
public BtfEventViewer(Composite parent, int cacheSize) {
- super(parent, cacheSize, COLUMN_DATA);
- fTable.getColumns()[0].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TIMESTAMP);
- fTable.getColumns()[1].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_SOURCE);
- fTable.getColumns()[3].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TYPE);
- fTable.getColumns()[4].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_REFERENCE);
- }
-
- @Override
- public String[] getItemStrings(ITmfEvent event) {
- if (!(event instanceof BtfEvent)) {
- return EMPTY_STRING_ARRAY;
- }
- final BtfEvent btfEvent = (BtfEvent) event;
- final ITmfEventField content = btfEvent.getContent();
- final ITmfEventField notesField = content.getField(BtfColumnNames.NOTES.toString());
-
- return new String[] {
- event.getTimestamp().toString(),
- event.getSource(),
- content.getField(BtfColumnNames.SOURCE_INSTANCE.toString()).toString(),
- btfEvent.getType().getName(),
- event.getReference(),
- content.getField(BtfColumnNames.TARGET_INSTANCE.toString()).toString(),
- content.getField(BtfColumnNames.EVENT.toString()).toString(),
- ((notesField != null) ? notesField : NULL_NOTE_FIELD).toString()
- };
+ super(parent, cacheSize, BTF_COLUMNS);
}
-}
+}
\ No newline at end of file
about.html,\
plugin.xml
src.includes = about.html
+additional.bundles = org.eclipse.jdt.annotation
+jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
package org.eclipse.linuxtools.internal.gdbtrace.core.event;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
public class GdbTraceEventContent extends TmfEventField {
/** Trace Frame field name */
- public static final String TRACE_FRAME = "Trace Frame"; //$NON-NLS-1$
+ public static final @NonNull String TRACE_FRAME = "Trace Frame"; //$NON-NLS-1$
/** Tracepoint field name */
- public static final String TRACEPOINT = "Tracepoint"; //$NON-NLS-1$
+ public static final @NonNull String TRACEPOINT = "Tracepoint"; //$NON-NLS-1$
// Tracepoint number
private int fTracepointNumber = 0;
.internal.gdbtrace.ui.views.project.dialogs;x-internal:=true,org.ecli
pse.linuxtools.internal.gdbtrace.ui.views.project.handlers;x-internal
:=true
-Import-Package: org.eclipse.cdt.core
+Import-Package: com.google.common.collect,
+ org.eclipse.cdt.core
plugin.xml,\
plugin.properties
src.includes = about.html
+additional.bundles = org.eclipse.jdt.annotation
+jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
package org.eclipse.linuxtools.internal.gdbtrace.ui.views.events;
+import java.util.Collection;
+
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
-import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableFieldColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableItem;
+import com.google.common.collect.ImmutableList;
+
/**
* GDB Events Table
* @author Patrick Tasse
- *
*/
public class GdbEventsTable extends TmfEventsTable {
- private static final String TRACE_FRAME_COLUMN = GdbTraceEventContent.TRACE_FRAME;
- private static final String TRACEPOINT_COLUMN = GdbTraceEventContent.TRACEPOINT;
- private static final String FILE_COLUMN = "File"; //$NON-NLS-1$
- private static final String CONTENT_COLUMN = "Content"; //$NON-NLS-1$
- private static final ColumnData[] COLUMN_DATA = new ColumnData[] {
- new ColumnData(TRACE_FRAME_COLUMN, 100, SWT.RIGHT),
- new ColumnData(TRACEPOINT_COLUMN, 100, SWT.RIGHT),
- new ColumnData(FILE_COLUMN, 100, SWT.LEFT),
- new ColumnData(CONTENT_COLUMN, 100, SWT.LEFT)
- };
+ // ------------------------------------------------------------------------
+ // Column definition
+ // ------------------------------------------------------------------------
+
+ private static final Collection<TmfEventTableColumn> GDB_COLUMNS = ImmutableList.of(
+ new GdbTraceFrameColumn(),
+ new GdbTracepointColumn(),
+ new GdbFileColumn()
+ );
+
+ private static class GdbTraceFrameColumn extends TmfEventTableFieldColumn {
+ public GdbTraceFrameColumn() {
+ super(GdbTraceEventContent.TRACE_FRAME);
+ }
+ }
+
+ private static class GdbTracepointColumn extends TmfEventTableFieldColumn {
+ public GdbTracepointColumn() {
+ super(GdbTraceEventContent.TRACEPOINT);
+ }
+ }
+
+ private static class GdbFileColumn extends TmfEventTableColumn {
+
+ public GdbFileColumn() {
+ super("File"); //$NON-NLS-1$
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ String ret = event.getReference();
+ return (ret == null ? EMPTY_STRING : ret);
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return ITmfEvent.EVENT_FIELD_REFERENCE;
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Fields
+ // ------------------------------------------------------------------------
private GdbTrace fSelectedTrace = null;
private long fSelectedFrame = 0;
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
/**
* Constructor
- * @param parent the parent
- * @param cacheSize the cache size
+ *
+ * @param parent
+ * the parent
+ * @param cacheSize
+ * the cache size
*/
public GdbEventsTable(Composite parent, int cacheSize) {
- super(parent, cacheSize, COLUMN_DATA);
- // Set search field ids for event filter
- fTable.getColumns()[2].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_REFERENCE);
- fTable.getColumns()[3].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_CONTENT);
+ super(parent, cacheSize, GDB_COLUMNS);
+ // Set the alignment of the first two columns
+ fTable.getColumns()[0].setAlignment(SWT.RIGHT);
+ fTable.getColumns()[1].setAlignment(SWT.RIGHT);
// Synchronize currently selected frame in GDB with table selection
addSelectionChangedListener(new ISelectionChangedListener() {
}
}
- @Override
- public String[] getItemStrings(ITmfEvent event) {
- if (event == null) {
- return EMPTY_STRING_ARRAY;
- }
- // FIXME Unchecked cast. Null check should be replaced with instanceof
- // GdbTraceEvent check, and its getContent() should be overriden.
- GdbTraceEventContent content = (GdbTraceEventContent) event.getContent();
- return new String[] {
- String.valueOf(content.getFrameNumber()),
- String.valueOf(content.getTracepointNumber()),
- event.getReference(),
- content.toString()
- };
- }
-
@Override
@TmfSignalHandler
public void currentTimeUpdated(final TmfTimeSynchSignal signal) {
org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow;x-friends:="org.eclipse.linuxtools.lttng2.kernel.ui.swtbot.tests",
org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.cpuusage;x-friends:="org.eclipse.linuxtools.lttng2.kernel.ui.swtbot.tests",
org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;x-friends:="org.eclipse.linuxtools.lttng2.kernel.ui.swtbot.tests"
+Import-Package: com.google.common.collect
package org.eclipse.linuxtools.internal.lttng2.kernel.ui.viewers.events;
+import java.util.Collection;
+
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
-import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
-import org.eclipse.swt.SWT;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
import org.eclipse.swt.widgets.Composite;
+import com.google.common.collect.ImmutableList;
+
/**
* Events table specific for LTTng 2.0 kernel traces
*/
public class LTTng2EventsTable extends TmfEventsTable {
// ------------------------------------------------------------------------
- // Table data
+ // Column definition
// ------------------------------------------------------------------------
- // Table column names
- static private final String TIMESTAMP_COLUMN = Messages.EventsTable_timestampColumn;
- static private final String CHANNEL_COLUMN = Messages.EventsTable_channelColumn;
- static private final String TYPE_COLUMN = Messages.EventsTable_typeColumn;
- static private final String CONTENT_COLUMN = Messages.EventsTable_contentColumn;
- static private final String[] COLUMN_NAMES = new String[] {
- TIMESTAMP_COLUMN,
- CHANNEL_COLUMN,
- TYPE_COLUMN,
- CONTENT_COLUMN
- };
+ @SuppressWarnings("null")
+ private static final @NonNull String CHANNEL_HEADER = Messages.EventsTable_channelColumn;
+
+ private static final Collection<TmfEventTableColumn> LTTNG_COLUMNS =
+ ImmutableList.<TmfEventTableColumn> of(
+ TmfEventTableColumn.BaseColumns.TIMESTAMP,
+ new LttngChannelColumn(),
+ TmfEventTableColumn.BaseColumns.EVENT_TYPE,
+ TmfEventTableColumn.BaseColumns.CONTENTS);
+
+ private static class LttngChannelColumn extends TmfEventTableColumn {
- static private final ColumnData[] COLUMN_DATA = new ColumnData[] {
- new ColumnData(COLUMN_NAMES[0], 150, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[1], 120, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[2], 200, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[3], 100, SWT.LEFT)
- };
+ public LttngChannelColumn() {
+ super(CHANNEL_HEADER);
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ String ret = event.getReference();
+ return (ret == null ? EMPTY_STRING : ret);
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return ITmfEvent.EVENT_FIELD_REFERENCE;
+ }
+ }
// ------------------------------------------------------------------------
// Constructor
* The size of the rows cache
*/
public LTTng2EventsTable(Composite parent, int cacheSize) {
- super(parent, cacheSize, COLUMN_DATA);
- fTable.getColumns()[0].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TIMESTAMP);
- fTable.getColumns()[1].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_REFERENCE);
- fTable.getColumns()[2].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TYPE);
- fTable.getColumns()[3].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_CONTENT);
- }
-
- @Override
- public String[] getItemStrings(ITmfEvent event) {
- if (event == null) {
- return EMPTY_STRING_ARRAY;
- }
- return new String[] {
- event.getTimestamp().toString(),
- event.getReference(),
- event.getType().getName(),
- event.getContent().toString()
- };
+ super(parent, cacheSize, LTTNG_COLUMNS);
}
}
package org.eclipse.linuxtools.tmf.core.event;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
/**
* Pre-defined event timestamp attribute (for searching &filtering purposes)
*/
- public static final String EVENT_FIELD_TIMESTAMP = ":timestamp:"; //$NON-NLS-1$
+ public static final @NonNull String EVENT_FIELD_TIMESTAMP = ":timestamp:"; //$NON-NLS-1$
/**
* Pre-defined event source attribute (for searching &filtering purposes)
*/
- public static final String EVENT_FIELD_SOURCE = ":source:"; //$NON-NLS-1$
+ public static final @NonNull String EVENT_FIELD_SOURCE = ":source:"; //$NON-NLS-1$
/**
* Pre-defined event type attribute (for searching &filtering purposes)
*/
- public static final String EVENT_FIELD_TYPE = ":type:"; //$NON-NLS-1$
+ public static final @NonNull String EVENT_FIELD_TYPE = ":type:"; //$NON-NLS-1$
/**
* Pre-defined event content attribute (for searching &filtering purposes)
*/
- public static final String EVENT_FIELD_CONTENT = ":content:"; //$NON-NLS-1$
+ public static final @NonNull String EVENT_FIELD_CONTENT = ":content:"; //$NON-NLS-1$
/**
* Pre-defined event reference attribute (for searching &filtering purposes)
*/
- public static final String EVENT_FIELD_REFERENCE = ":reference:"; //$NON-NLS-1$
+ public static final @NonNull String EVENT_FIELD_REFERENCE = ":reference:"; //$NON-NLS-1$
// ------------------------------------------------------------------------
// Getters
// Other operations
// ------------------------------------------------------------------------
+ /**
+ * Get the contents of an event table cell for this event's row.
+ *
+ * @param index
+ * The ID/index of the field to display. This corresponds to the
+ * index in the event content.
+ * @return The String to display in the cell
+ * @since 3.1
+ */
+ public String getEventString(int index) {
+ if (fData != null) {
+ processData();
+ }
+ if (index < 0 || index >= fColumnData.length) {
+ return ""; //$NON-NLS-1$
+ }
+
+ return fColumnData[index].getValue().toString();
+ }
+
/**
* Get the contents of the row in the events table corresponding to this
* event. The order of the elements corresponds to the order of the columns.
*
* @return The event row entries
+ * @deprecated This should not be used, since this isn't related to the
+ * order of columns in the view anymore. You should use
+ * {@link #getEventString(int)}
*/
+ @Deprecated
public String[] getEventStrings() {
if (fData != null) {
processData();
org.eclipse.linuxtools.tmf.pcap.ui,
org.eclipse.linuxtools.tmf.pcap.ui.editor,
org.eclipse.linuxtools.tmf.pcap.ui.stream
+Import-Package: com.google.common.collect
*
* Contributors:
* Vincent Perot - Initial API and implementation
+ * Alexandre Montplaisir - Update to new TmfEventTableColumn API
*******************************************************************************/
package org.eclipse.linuxtools.tmf.pcap.ui.editor;
+import java.util.Collection;
+
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.pcap.core.event.PcapEvent;
import org.eclipse.linuxtools.tmf.pcap.core.protocol.TmfProtocol;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
-import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
-import org.eclipse.swt.SWT;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
import org.eclipse.swt.widgets.Composite;
+import com.google.common.collect.ImmutableList;
+
/**
* Default event table for pcap traces.
*
// Table data
// ------------------------------------------------------------------------
- // Table column names
- private static final String[] COLUMN_NAMES = new String[] {
- Messages.PcapEventsTable_Timestamp,
- Messages.PcapEventsTable_Source,
- Messages.PcapEventsTable_Destination,
- Messages.PcapEventsTable_Reference,
- Messages.PcapEventsTable_Protocol,
- Messages.PcapEventsTable_Content
- };
-
- private static final ColumnData[] COLUMN_DATA = new ColumnData[] {
- new ColumnData(COLUMN_NAMES[0], 150, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[1], 120, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[2], 200, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[3], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[4], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[5], 100, SWT.LEFT)
- };
+ @SuppressWarnings("null")
+ private static final @NonNull Collection<TmfEventTableColumn> PCAP_COLUMNS = ImmutableList.of(
+ TmfEventTableColumn.BaseColumns.TIMESTAMP,
+ new PcapSourceColumn(),
+ new PcapDestinationColumn(),
+ TmfEventTableColumn.BaseColumns.REFERENCE,
+ new PcapProtocolColumn(),
+ TmfEventTableColumn.BaseColumns.CONTENTS
+ );
+
+ /**
+ * The "packet source" column for pcap events
+ */
+ private static class PcapSourceColumn extends TmfEventTableColumn {
+
+ public PcapSourceColumn() {
+ super(getString(Messages.PcapEventsTable_Source));
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ if (!(event instanceof PcapEvent)) {
+ return EMPTY_STRING;
+ }
+ PcapEvent pcapEvent = (PcapEvent) event;
+ TmfProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
+
+ return getString(pcapEvent.getSourceEndpoint(protocol));
+ }
+
+ @Override
+ public @Nullable String getFilterFieldId() {
+ return PcapEvent.EVENT_FIELD_PACKET_SOURCE;
+ }
+ }
+
+ /**
+ * The "packet destination" column for pcap events
+ */
+ private static class PcapDestinationColumn extends TmfEventTableColumn {
+
+ public PcapDestinationColumn() {
+ super(getString(Messages.PcapEventsTable_Destination));
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ if (!(event instanceof PcapEvent)) {
+ return EMPTY_STRING;
+ }
+ PcapEvent pcapEvent = (PcapEvent) event;
+ TmfProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
+ return getString(pcapEvent.getDestinationEndpoint(protocol));
+ }
+
+ @Override
+ public @Nullable String getFilterFieldId() {
+ return PcapEvent.EVENT_FIELD_PACKET_DESTINATION;
+ }
+ }
+
+ /**
+ * The "packet protocol" column for pcap events
+ */
+ private static class PcapProtocolColumn extends TmfEventTableColumn {
+
+ public PcapProtocolColumn() {
+ super(getString(Messages.PcapEventsTable_Protocol));
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ if (!(event instanceof PcapEvent)) {
+ return EMPTY_STRING;
+ }
+ PcapEvent pcapEvent = (PcapEvent) event;
+ TmfProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
+
+ @SuppressWarnings("null")
+ @NonNull String proto = protocol.getShortName().toUpperCase();
+ return proto;
+ }
+
+ @Override
+ public @Nullable String getFilterFieldId() {
+ return PcapEvent.EVENT_FIELD_PACKET_PROTOCOL;
+ }
+ }
+
+ /**
+ * Little convenience method to work around the incompatibilities between
+ * null annotations and NLS files...
+ */
+ private static String getString(@Nullable String str) {
+ return (str == null ? EMPTY_STRING : str);
+ }
// ------------------------------------------------------------------------
// Constructor
* The size of the rows cache
*/
public PcapEventsTable(Composite parent, int cacheSize) {
- super(parent, cacheSize, COLUMN_DATA);
- fTable.getColumns()[0].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TIMESTAMP);
- fTable.getColumns()[1].setData(Key.FIELD_ID, PcapEvent.EVENT_FIELD_PACKET_SOURCE);
- fTable.getColumns()[2].setData(Key.FIELD_ID, PcapEvent.EVENT_FIELD_PACKET_DESTINATION);
- fTable.getColumns()[3].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_REFERENCE);
- fTable.getColumns()[4].setData(Key.FIELD_ID, PcapEvent.EVENT_FIELD_PACKET_PROTOCOL);
- fTable.getColumns()[5].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_CONTENT);
- }
-
- @Override
- public String[] getItemStrings(@Nullable ITmfEvent event) {
-
- if (event == null || !(event instanceof PcapEvent)) {
- return EMPTY_STRING_ARRAY;
- }
-
- PcapEvent pcapEvent = (PcapEvent) event;
- TmfProtocol protocol = pcapEvent.getMostEncapsulatedProtocol();
-
- return new String[] {
- pcapEvent.getTimestamp().toString(),
- pcapEvent.getSourceEndpoint(protocol),
- pcapEvent.getDestinationEndpoint(protocol),
- pcapEvent.getReference(),
- protocol.getShortName().toUpperCase(),
- pcapEvent.getContent().toString()
- };
+ super(parent, cacheSize, PCAP_COLUMNS);
}
}
org.eclipse.ui.ide
Export-Package: org.eclipse.linuxtools.tmf.ui.tests
Bundle-Activator: org.eclipse.linuxtools.tmf.ui.tests.TmfUITestPlugin
+Import-Package: com.google.common.collect
package org.eclipse.linuxtools.tmf.ui.tests.experiment.type;
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import java.util.Collection;
+
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
-import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
-import org.eclipse.swt.SWT;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
import org.eclipse.swt.widgets.Composite;
+import com.google.common.collect.ImmutableList;
+
/**
* Event table stub for experiment type unit tests
*
// Table data
// ------------------------------------------------------------------------
- // Table column names
- private static final String[] COLUMN_NAMES = new String[] {
- Messages.TmfEventsTable_TimestampColumnHeader,
- Messages.TmfEventsTable_SourceColumnHeader,
- Messages.TmfEventsTable_TypeColumnHeader,
- Messages.TmfEventsTable_ReferenceColumnHeader,
- "Trace",
- Messages.TmfEventsTable_ContentColumnHeader
- };
+ private static final Collection<TmfEventTableColumn> EXPERIMENT_COLUMNS =
+ ImmutableList.<TmfEventTableColumn> of(new SourceTraceColumn());
+
+ private static class SourceTraceColumn extends TmfEventTableColumn {
+
+ public SourceTraceColumn() {
+ super("Trace");
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ String ret = event.getTrace().getName();
+ return (ret == null ? EMPTY_STRING : ret);
+ }
- private static final ColumnData[] COLUMN_DATA = new ColumnData[] {
- new ColumnData(COLUMN_NAMES[0], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[1], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[2], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[3], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[4], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[5], 100, SWT.LEFT)
- };
+ @Override
+ public String getFilterFieldId() {
+ return null;
+ }
+ }
// ------------------------------------------------------------------------
// Constructor
* The size of the rows cache
*/
public TmfEventsTableExperimentStub(Composite parent, int cacheSize) {
- super(parent, cacheSize, COLUMN_DATA);
- }
-
- @Override
- public String[] getItemStrings(ITmfEvent event) {
- if (event == null) {
- return EMPTY_STRING_ARRAY;
- }
- return new String[] {
- event.getTimestamp().toString(),
- event.getSource(),
- event.getType().getName(),
- event.getReference(),
- event.getTrace().getName(),
- event.getContent().toString()
- };
+ super(parent, cacheSize, EXPERIMENT_COLUMNS);
}
}
org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace;x-friends:="org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests,org.eclipse.linuxtools.tmf.ui,org.eclipse.linuxtools.lttng2.control.ui",
org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg;x-internal:=true,
org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns;x-internal:=true,
org.eclipse.linuxtools.tmf.ui,
org.eclipse.linuxtools.tmf.ui.analysis,
org.eclipse.linuxtools.tmf.ui.editors,
org.eclipse.linuxtools.tmf.ui.properties,
org.eclipse.linuxtools.tmf.ui.viewers,
org.eclipse.linuxtools.tmf.ui.viewers.events,
+ org.eclipse.linuxtools.tmf.ui.viewers.events.columns,
org.eclipse.linuxtools.tmf.ui.viewers.events.text,
org.eclipse.linuxtools.tmf.ui.viewers.statistics,
org.eclipse.linuxtools.tmf.ui.viewers.statistics.model,
*
* Contributors:
* Patrick Tasse - Initial API and implementation
+ * Alexandre Montplaisir - Update for TmfEventTableColumn
*******************************************************************************/
package org.eclipse.linuxtools.internal.tmf.ui.parsers.custom;
-import java.util.LinkedList;
+import java.util.Collection;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomEvent;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTraceDefinition;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
-import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
-import org.eclipse.swt.SWT;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
import org.eclipse.swt.widgets.Composite;
+import com.google.common.collect.ImmutableList;
+
/**
* Events table for custom text parsers.
*
*/
public class CustomEventsTable extends TmfEventsTable {
- private final CustomTraceDefinition fDefinition;
+ /**
+ * Column for custom events, which uses an integer ID to represent each
+ * column.
+ */
+ private static final class CustomEventTableColumn extends TmfEventTableColumn {
+
+ private final int fIndex;
+
+ /**
+ * Constructor
+ *
+ * @param name
+ * The name (title) of this column
+ * @param idx
+ * The index of this column, which should be the index of the
+ * field in the event's content to display.
+ */
+ public CustomEventTableColumn(@NonNull String name, int idx) {
+ super(name);
+ fIndex = idx;
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ if (event instanceof CustomEvent) {
+ String ret = ((CustomEvent) event).getEventString(fIndex);
+ return (ret == null ? EMPTY_STRING : ret);
+ }
+ return EMPTY_STRING;
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return getHeaderName();
+ }
+ }
/**
* Constructor.
* How many events to keep in cache
*/
public CustomEventsTable(CustomTraceDefinition definition, Composite parent, int cacheSize) {
- super(parent, cacheSize, new ColumnData[0]);
- fDefinition = definition;
- createColumnHeaders();
- }
-
- /**
- * Create the table's headers.
- */
- protected void createColumnHeaders() {
- if (fDefinition == null) {
- return;
- }
- List<ColumnData> columnData = new LinkedList<>();
- for (OutputColumn outputColumn : fDefinition.outputs) {
- ColumnData column = new ColumnData(outputColumn.name, 0, SWT.LEFT);
- columnData.add(column);
- }
- setColumnHeaders(columnData.toArray(new ColumnData[0]));
+ super(parent, cacheSize, generateColumns(definition));
}
- @Override
- public String[] getItemStrings(ITmfEvent event) {
- if (event instanceof CustomEvent) {
- return ((CustomEvent) event).getEventStrings();
+ private static Collection<CustomEventTableColumn> generateColumns(CustomTraceDefinition definition) {
+ ImmutableList.Builder<CustomEventTableColumn> builder = new ImmutableList.Builder<>();
+ List<OutputColumn> outputs = definition.outputs;
+ for (int i = 0; i < outputs.size(); i++) {
+ String name = outputs.get(i).name;
+ if (name != null) {
+ builder.add(new CustomEventTableColumn(name, i));
+ }
}
- return EMPTY_STRING_ARRAY;
+ return builder.build();
}
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
+
+/**
+ * Column for the event contents (fields)
+ *
+ * @author Alexandre Montplaisir
+ */
+public final class TmfContentsColumn extends TmfEventTableColumn {
+
+ @SuppressWarnings("null")
+ private static final @NonNull String HEADER = Messages.TmfEventsTable_ContentColumnHeader;
+
+ /**
+ * Constructor
+ */
+ public TmfContentsColumn() {
+ super(HEADER);
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ String ret = event.getContent().toString();
+ return (ret == null ? EMPTY_STRING : ret);
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return ITmfEvent.EVENT_FIELD_CONTENT;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
+
+/**
+ * Column for the event reference
+ *
+ * TODO Remove me, replace with trace-type-specific columns
+ */
+public final class TmfReferenceColumn extends TmfEventTableColumn {
+
+ @SuppressWarnings("null")
+ private static final @NonNull String HEADER = Messages.TmfEventsTable_ReferenceColumnHeader;
+
+ /**
+ * Constructor
+ */
+ public TmfReferenceColumn() {
+ super(HEADER);
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ String ref = event.getReference();
+ return (ref == null ? EMPTY_STRING : ref);
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return ITmfEvent.EVENT_FIELD_REFERENCE;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
+
+/**
+ * Column for the event source
+ *
+ * TODO Remove me, replace with trace-type-specific columns
+ */
+public final class TmfSourceColumn extends TmfEventTableColumn {
+
+ @SuppressWarnings("null")
+ private static final @NonNull String HEADER = Messages.TmfEventsTable_SourceColumnHeader;
+
+ /**
+ * Constructor
+ */
+ public TmfSourceColumn() {
+ super(HEADER);
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ String source = event.getSource();
+ return (source == null ? EMPTY_STRING : source);
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return ITmfEvent.EVENT_FIELD_SOURCE;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
+
+/**
+ * Column for the timestamps
+ */
+public final class TmfTimestampColumn extends TmfEventTableColumn {
+
+ @SuppressWarnings("null")
+ private static final @NonNull String HEADER = Messages.TmfEventsTable_TimestampColumnHeader;
+
+ /**
+ * Constructor
+ */
+ public TmfTimestampColumn() {
+ super(HEADER);
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ String ret = event.getTimestamp().toString();
+ return (ret == null ? EMPTY_STRING : ret);
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return ITmfEvent.EVENT_FIELD_TIMESTAMP;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
+
+/**
+ * Column for the event type
+ */
+public final class TmfTypeColumn extends TmfEventTableColumn {
+
+ @SuppressWarnings("null")
+ private static final @NonNull String HEADER = Messages.TmfEventsTable_TypeColumnHeader;
+
+ /**
+ * Constructor
+ */
+ public TmfTypeColumn() {
+ super(HEADER);
+ }
+
+ @Override
+ public String getItemString(ITmfEvent event) {
+ ITmfEventType type = event.getType();
+ if (type == null) {
+ return EMPTY_STRING;
+ }
+ String typeName = type.getName();
+ return (typeName == null ? EMPTY_STRING : typeName);
+ }
+
+ @Override
+ public String getFilterFieldId() {
+ return ITmfEvent.EVENT_FIELD_TYPE;
+ }
+}
\ No newline at end of file
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Francois Chouinard - Initial API and implementation
- * Patrick Tasse - Factored out from events view
- * Francois Chouinard - Replaced Table by TmfVirtualTable
- * Patrick Tasse - Filter implementation (inspired by www.eclipse.org/mat)
+ * Francois Chouinard - Initial API and implementation, replaced Table by TmfVirtualTable
+ * Patrick Tasse - Factored out from events view,
+ * Filter implementation (inspired by www.eclipse.org/mat)
* Ansgar Radermacher - Support navigation to model URIs (Bug 396956)
* Bernd Hufmann - Updated call site and model URI implementation
+ * Alexandre Montplaisir - Update to new column API
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.viewers.events;
import java.io.FileNotFoundException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsCache.CachedEvent;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableFieldColumn;
import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting;
import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager;
import org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener;
import org.eclipse.linuxtools.tmf.ui.views.filter.FilterManager;
import org.eclipse.linuxtools.tmf.ui.widgets.rawviewer.TmfRawEventViewer;
-import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData;
import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.TmfVirtualTable;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import com.google.common.base.Joiner;
import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
/**
*
* This is a view that will list events that are read from a trace.
*
- * @version 1.0
* @author Francois Chouinard
* @author Patrick Tasse
* @since 2.0
*/
protected static final @NonNull String[] EMPTY_STRING_ARRAY = new String[0];
+ /**
+ * Empty string
+ * @since 3.1
+ */
+ protected static final @NonNull String EMPTY_STRING = ""; //$NON-NLS-1$
+
private static final Image BOOKMARK_IMAGE = Activator.getDefault().getImageFromPath(
"icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
private static final Image SEARCH_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
private static final String FILTER_HINT = Messages.TmfEventsTable_FilterHint;
private static final int MAX_CACHE_SIZE = 1000;
+ /**
+ * Default set of columns to use for trace types that do not specify
+ * anything
+ */
+ private static final Collection<TmfEventTableColumn> DEFAULT_COLUMNS = ImmutableList.of(
+ TmfEventTableColumn.BaseColumns.TIMESTAMP,
+ TmfEventTableColumn.BaseColumns.SOURCE,
+ TmfEventTableColumn.BaseColumns.EVENT_TYPE,
+ TmfEventTableColumn.BaseColumns.REFERENCE,
+ TmfEventTableColumn.BaseColumns.CONTENTS
+ );
+
/**
* The events table search/filter keys
*
private Color fGreenColor;
private Font fBoldFont;
- // Table column names
- private static final String[] COLUMN_NAMES = new String[] { Messages.TmfEventsTable_TimestampColumnHeader,
- Messages.TmfEventsTable_SourceColumnHeader, Messages.TmfEventsTable_TypeColumnHeader,
- Messages.TmfEventsTable_ReferenceColumnHeader, Messages.TmfEventsTable_ContentColumnHeader };
-
- private static final ColumnData[] COLUMN_DATA = new ColumnData[] { new ColumnData(COLUMN_NAMES[0], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[1], 100, SWT.LEFT), new ColumnData(COLUMN_NAMES[2], 100, SWT.LEFT),
- new ColumnData(COLUMN_NAMES[3], 100, SWT.LEFT), new ColumnData(COLUMN_NAMES[4], 100, SWT.LEFT) };
+ private final List<TmfEventTableColumn> fColumns = new LinkedList<>();
// Event cache
private final TmfEventsCache fCache;
// ------------------------------------------------------------------------
/**
- * Basic constructor, will use default column data.
+ * Basic constructor, using the default set of columns
*
* @param parent
* The parent composite UI object
* The size of the event table cache
*/
public TmfEventsTable(final Composite parent, final int cacheSize) {
- this(parent, cacheSize, COLUMN_DATA);
+ this(parent, cacheSize, DEFAULT_COLUMNS);
}
/**
- * Advanced constructor, where we also define which column data to use.
+ * Legacy constructor, using ColumnData to define columns
*
* @param parent
* The parent composite UI object
* @param cacheSize
* The size of the event table cache
* @param columnData
- * The column data to use for this table
+ * Unused
+ * @deprecated Deprecated constructor, use
+ * {@link #TmfEventsTable(Composite, int, Collection)}
+ */
+ @Deprecated
+ public TmfEventsTable(final Composite parent, int cacheSize,
+ final org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData[] columnData) {
+ /*
+ * We'll do a "best-effort" to keep trace types still using this API to
+ * keep working, by defining a TmfEventTableFieldColumn for each
+ * ColumnData they passed.
+ */
+ this(parent, cacheSize, convertFromColumnData(columnData));
+ }
+
+ @Deprecated
+ private static Collection<TmfEventTableColumn> convertFromColumnData(
+ org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData[] columnData) {
+
+ ImmutableList.Builder<TmfEventTableColumn> builder = new ImmutableList.Builder<>();
+ for (org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData col : columnData) {
+ String header = col.header;
+ if (header != null) {
+ builder.add(new TmfEventTableFieldColumn(header));
+ }
+ }
+ return builder.build();
+ }
+
+ /**
+ * Standard constructor, where we define which columns to use.
+ *
+ * @param parent
+ * The parent composite UI object
+ * @param cacheSize
+ * The size of the event table cache
+ * @param columns
+ * The columns to use in this table.
+ * <p>
+ * The iteration order of this collection will correspond to the
+ * initial ordering of this series of columns in the table.
+ * </p>
+ * @since 3.1
*/
- public TmfEventsTable(final Composite parent, int cacheSize, final ColumnData[] columnData) {
+ public TmfEventsTable(final Composite parent, int cacheSize,
+ Collection<? extends TmfEventTableColumn> columns) {
super("TmfEventsTable"); //$NON-NLS-1$
fComposite = new Composite(parent, SWT.NONE);
fTable.setHeaderVisible(true);
fTable.setLinesVisible(true);
- // Set the columns
- setColumnHeaders(columnData);
-
- // Set the default column field ids if this is not a subclass
- if (Arrays.equals(columnData, COLUMN_DATA)) {
- fTable.getColumns()[0].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TIMESTAMP);
- fTable.getColumns()[1].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_SOURCE);
- fTable.getColumns()[2].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TYPE);
- fTable.getColumns()[3].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_REFERENCE);
- fTable.getColumns()[4].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_CONTENT);
+ // Setup the columns
+ if (columns != null) {
+ fColumns.addAll(columns);
}
+ // Create the UI columns in the table
+ fTable.createColumns(fColumns);
+
// Set the frozen row for header row
fTable.setFrozenRowCount(1);
createPopupMenu();
}
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
/**
* Create a pop-up menu.
*/
/**
* @param columnData
- *
- * FIXME: Add support for column selection
+ * columnData
+ * @deprecated The column headers are now set at the constructor, this
+ * shouldn't be called anymore.
*/
- protected void setColumnHeaders(final ColumnData[] columnData) {
- fTable.setColumnHeaders(columnData);
+ @Deprecated
+ protected void setColumnHeaders(final org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData [] columnData) {
+ /* No-op */
}
/**
* Which rank this event has in the trace/experiment
*/
protected void setItemData(final TableItem item, final ITmfEvent event, final long rank) {
- item.setText(getItemStrings(event));
+ item.setText(getItemStrings(fColumns, event));
item.setData(event);
item.setData(Key.TIMESTAMP, new TmfTimestamp(event.getTimestamp()));
item.setData(Key.RANK, rank);
}
/**
- * Get the contents of the row in the events table corresponding to an
- * event. The order of the elements corresponds to the order of the columns.
+ * Get the array of item strings (e.g., what to display in each cell of the
+ * table row) corresponding to the columns and trace event passed in
+ * parameter. The order of the Strings in the returned array will correspond
+ * to the iteration order of 'columns'.
*
- * TODO Use column IDs, not indexes, so that the column order can be
- * re-arranged.
+ * <p>
+ * To ensure consistent results, make sure only call this within a scope
+ * synchronized on 'columns'! If the order of 'columns' changes right after
+ * this method is called, the returned value won't be ordered correctly
+ * anymore.
+ */
+ private static String[] getItemStrings(List<TmfEventTableColumn> columns, ITmfEvent event) {
+ if (event == null) {
+ return EMPTY_STRING_ARRAY;
+ }
+ synchronized (columns) {
+ List<String> itemStrings = new ArrayList<>(columns.size());
+ for (TmfEventTableColumn column : columns) {
+ itemStrings.add(column.getItemString(event));
+ }
+ return itemStrings.toArray(new String[0]);
+ }
+ }
+
+ /**
+ * Get the contents of the row in the events table corresponding to an
+ * event. The order of the elements corresponds to the current order of the
+ * columns.
*
* @param event
* The event printed in this row
* @since 3.0
*/
public String[] getItemStrings(ITmfEvent event) {
- if (event == null) {
- return EMPTY_STRING_ARRAY;
- }
- return new String[] {
- event.getTimestamp().toString(),
- event.getSource(),
- event.getType().getName(),
- event.getReference(),
- event.getContent().toString()
- };
+ return getItemStrings(fColumns, event);
}
/**
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.viewers.events.columns;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns.TmfContentsColumn;
+import org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns.TmfReferenceColumn;
+import org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns.TmfSourceColumn;
+import org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns.TmfTimestampColumn;
+import org.eclipse.linuxtools.internal.tmf.ui.viewers.events.columns.TmfTypeColumn;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+
+/**
+ * A column in the
+ * {@link org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable}. In
+ * addition to ones provided by default, trace types can extend this class to
+ * create additional columns specific to their events.
+ *
+ * Those additional columns can then be passed to the constructor
+ * {@link org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable#TmfEventsTable(org.eclipse.swt.widgets.Composite, int, java.util.Collection)}
+ *
+ * @author Alexandre Montplaisir
+ * @since 3.1
+ */
+@NonNullByDefault
+public abstract class TmfEventTableColumn {
+
+ // ------------------------------------------------------------------------
+ // Class attributes
+ // ------------------------------------------------------------------------
+
+ /**
+ * The base set of columns, which can apply to any trace type.
+ */
+ public static interface BaseColumns {
+
+ /** Column showing the event timestamp */
+ TmfEventTableColumn TIMESTAMP = new TmfTimestampColumn();
+
+ /** Column showing the event's source */
+ TmfEventTableColumn SOURCE = new TmfSourceColumn();
+
+ /** Column showing the event type */
+ TmfEventTableColumn EVENT_TYPE = new TmfTypeColumn();
+
+ /** Column showing the event reference */
+ TmfEventTableColumn REFERENCE = new TmfReferenceColumn();
+
+ /** Column showing the aggregated event contents (fields) */
+ TmfEventTableColumn CONTENTS = new TmfContentsColumn();
+ }
+
+ /**
+ * Static definition of an empty string. Return this instead of returning
+ * 'null'!
+ */
+ protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Fields
+ // ------------------------------------------------------------------------
+
+ private final String fHeaderName;
+ private final @Nullable String fHeaderTooltip;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor with no tooltip.
+ *
+ * @param headerName
+ * The name (title) of this column. Should ideally be short.
+ */
+ public TmfEventTableColumn(String headerName) {
+ fHeaderName = headerName;
+ fHeaderTooltip = null;
+ }
+
+ /**
+ * Constructor with a tooltip.
+ *
+ * @param headerName
+ * The name (title) of this column. Should ideally be short.
+ * @param headerTooltip
+ * The tooltip text for the column header. Use 'null' for no
+ * tooltip.
+ */
+ public TmfEventTableColumn(String headerName, @Nullable String headerTooltip) {
+ fHeaderName = headerName;
+ fHeaderTooltip = headerTooltip;
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get this column's header name, a.k.a. title
+ *
+ * @return The column's title
+ */
+ public String getHeaderName() {
+ return fHeaderName;
+ }
+
+ /**
+ * Get the tooltip text for the column header
+ *
+ * @return The header's tooltip
+ */
+ public @Nullable String getHeaderTooltip() {
+ return fHeaderTooltip;
+ }
+
+ // ------------------------------------------------------------------------
+ // Abstract methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get the string that should be displayed in this column's cell for a given
+ * trace event. Basically, this defines "what to print in this column for
+ * this event".
+ * <p>
+ * Note to implementers:
+ * <p>
+ * This method takes an {@link ITmfEvent}, because any type of event could
+ * potentially be present in the table at the time. Do not assume that you
+ * will only receive events of your trace type. You'd probably want to
+ * return an empty string for event that don't match your expected class
+ * type here.
+ *
+ * @param event
+ * The trace event whose element we want to display
+ * @return The string to display in the column for this event
+ */
+ public abstract String getItemString(ITmfEvent event);
+
+ /**
+ * Return the FILTER_ID used by the filters to search this column.
+ *
+ * @return The filter ID for this column, or 'null' to not provide a filter
+ * ID (which will mean this column will probably not be
+ * searchable/filterable.)
+ */
+ public abstract @Nullable String getFilterFieldId();
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Montplaisir - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.viewers.events.columns;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+
+/**
+ * Event table column that will print the value of a given event field, and
+ * whose column name is also the same as that field.
+ *
+ * @author Alexandre Montplaisir
+ * @since 3.1
+ */
+@NonNullByDefault
+public class TmfEventTableFieldColumn extends TmfEventTableColumn {
+
+ private final String fFieldName;
+
+ /**
+ * Basic constructor, which uses the same name for the field name and the
+ * column header.
+ *
+ * @param headerAndFieldName
+ * The string that is both the title of the column AND the field
+ * name to look for.
+ */
+ public TmfEventTableFieldColumn(String headerAndFieldName) {
+ super(headerAndFieldName);
+ fFieldName = headerAndFieldName;
+ }
+
+ /**
+ * Advanced constructor, which can define different field name and header.
+ * You can also define a tooltip, optionally.
+ *
+ * @param headerName
+ * The header (title) of the column
+ * @param fieldName
+ * The field name to look for in the event content to populate
+ * this column.
+ * @param headerTooltip
+ * The tooltip text for the column header. Use 'null' for no
+ * tooltip.
+ */
+ public TmfEventTableFieldColumn(String headerName, String fieldName,
+ @Nullable String headerTooltip) {
+ super(headerName, headerTooltip);
+ fFieldName = fieldName;
+ }
+
+ @Override
+ public final String getItemString(ITmfEvent event) {
+ ITmfEventField field = event.getContent().getField(fFieldName);
+ if (field == null) {
+ return EMPTY_STRING;
+ }
+ String val = field.getFormattedValue();
+ return (val == null ? EMPTY_STRING : val);
+ }
+
+ @Override
+ public @NonNull String getFilterFieldId() {
+ return fFieldName;
+ }
+
+ // ------------------------------------------------------------------------
+ // hashCode/equals (so that equivalent columns can be merged together)
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + fFieldName.hashCode();
+ result = prime * result + getHeaderName().hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(@Nullable Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof TmfEventTableFieldColumn)) {
+ return false;
+ }
+ TmfEventTableFieldColumn other = (TmfEventTableFieldColumn) obj;
+ if (!fFieldName.equals(other.fFieldName)) {
+ return false;
+ }
+ if (!getHeaderName().equals(other.getHeaderName())) {
+ return false;
+ }
+ return true;
+ }
+
+}
*
* @author Alexandre Montplaisir
* @since 3.0
+ * @deprecated Users of this class should instead use
+ * {@link TmfEventsTable#TmfEventsTable(Composite, int, java.util.Collection)}
+ * , by passing
+ * {@link org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn}
+ * or
+ * {@link org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableFieldColumn}
+ * .
*/
+@Deprecated
public class TmfTextEventTable extends TmfEventsTable {
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
-
/**
* Constructor
*
******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable;
+
/**
* ColumnData
- * @author Matthew Khouzam
- * @version 1.0
*
+ * @author Matthew Khouzam
+ * @deprecated Use {@link org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn} instead.
*/
+@Deprecated
public class ColumnData {
/**
* The title of the column
package org.eclipse.linuxtools.tmf.ui.widgets.virtualtable;
+import java.util.List;
+
import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable.Key;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.custom.TableEditor;
/**
* Method setColumnHeaders.
- * @param columnData ColumnData[] the columndata array.
+ *
+ * @param columnData
+ * ColumnData[] the columndata array.
*/
+ @Deprecated
public void setColumnHeaders(ColumnData columnData[]) {
- for (int i = 0; i < columnData.length; i++) {
- TableColumn column = new TableColumn(fTable, columnData[i].alignment, i);
- column.setText(columnData[i].header);
+ /* No-op */
+ }
+
+ /**
+ * Method setColumnHeaders.
+ *
+ * @param columns
+ * The configuration elements of every column, in the order they
+ * should be initially in the table.
+ * @since 3.1
+ */
+ public void createColumns(List<TmfEventTableColumn> columns) {
+ for (TmfEventTableColumn column : columns) {
+
+ /* Set the column's header and properties */
+ TableColumn tableCol = new TableColumn(fTable, SWT.LEFT);
+ tableCol.setText(column.getHeaderName());
+
+ /* Set the column's tooltip, if any */
+ String tooltip = column.getHeaderTooltip();
+ if (tooltip != null) {
+ tableCol.setToolTipText(tooltip);
+ }
+
+ /* Set the column's Field ID (for filtering) */
+ tableCol.setData(Key.FIELD_ID, column.getFilterFieldId());
+
/*
* In Linux the table does not receive a control resized event when
* a table column resize causes the horizontal scroll bar to become
* visible or invisible, so a resize listener must be added to every
* table column to properly update the number of fully visible rows.
*/
- column.addControlListener(fResizeListener);
- if (columnData[i].width > 0) {
- column.setWidth(columnData[i].width);
- } else {
- column.pack();
- }
+ tableCol.addControlListener(fResizeListener);
+ tableCol.pack();
}
}