tmf: Add TmfEventTableColumn class
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 29 Jul 2014 22:07:17 +0000 (18:07 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 12 Aug 2014 21:19:02 +0000 (17:19 -0400)
Introduce the concept of "event table column" objects. This
object will contain:
- The initial column configuration (previously in "ColumnData")
- The getItemString() "functor" defining how to populate the cell
  in this column for a given event.
- The "field ID" to allow searching/filtering to keep working as
  before. Eventually, the filtering mechanism could be reworked
  to just use getItemString() directly.

The base framework now defines 5 columns, that are available for
all trace types (whose getter methods are currently in ITmfEvent):
- Timestamp
- Source*
- Event Type
- Reference*
- Contents (fields)

(* = could eventually be removed, subject to future discussion)

Every trace type can now specify which columns it wants to display,
which may or may not include the default-provided ones.

This is the first step towards decoupling the trace type, event table,
and column order and number. This will eventually allow displaying all
the possible trace type columns in an experiment of heterogeneous traces.

Change-Id: I4ffdb0564114a92a58a271a7a99d3ca43fa57e31
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/30468
Tested-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
29 files changed:
org.eclipse.linuxtools.btf.core/src/org/eclipse/linuxtools/btf/core/trace/BtfColumnNames.java
org.eclipse.linuxtools.btf.ui/META-INF/MANIFEST.MF
org.eclipse.linuxtools.btf.ui/src/org/eclipse/linuxtools/btf/ui/BtfEventViewer.java
org.eclipse.linuxtools.gdbtrace.core/build.properties
org.eclipse.linuxtools.gdbtrace.core/src/org/eclipse/linuxtools/internal/gdbtrace/core/event/GdbTraceEventContent.java
org.eclipse.linuxtools.gdbtrace.ui/META-INF/MANIFEST.MF
org.eclipse.linuxtools.gdbtrace.ui/build.properties
org.eclipse.linuxtools.gdbtrace.ui/src/org/eclipse/linuxtools/internal/gdbtrace/ui/views/events/GdbEventsTable.java
org.eclipse.linuxtools.lttng2.kernel.ui/META-INF/MANIFEST.MF
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/viewers/events/LTTng2EventsTable.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/ITmfEvent.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomEvent.java
org.eclipse.linuxtools.tmf.pcap.ui/META-INF/MANIFEST.MF
org.eclipse.linuxtools.tmf.pcap.ui/src/org/eclipse/linuxtools/tmf/pcap/ui/editor/PcapEventsTable.java
org.eclipse.linuxtools.tmf.ui.tests/META-INF/MANIFEST.MF
org.eclipse.linuxtools.tmf.ui.tests/widgetStubs/org/eclipse/linuxtools/tmf/ui/tests/experiment/type/TmfEventsTableExperimentStub.java
org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomEventsTable.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfContentsColumn.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfReferenceColumn.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfSourceColumn.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfTimestampColumn.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfTypeColumn.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/columns/TmfEventTableColumn.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/columns/TmfEventTableFieldColumn.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/text/TmfTextEventTable.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/ColumnData.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/widgets/virtualtable/TmfVirtualTable.java

index 7b1eb6d57aa12e36115c5ed1ebdbdbd214aa321f..9b4f43fe76f2b32fdaa7560da67ef6cad98edd42 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.linuxtools.btf.core.trace;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * Column names
  *
@@ -52,14 +54,14 @@ public enum BtfColumnNames {
      */
     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;
     }
 }
index d35b4d5b61a4bfb344df09d6e8ed2201669b2e6f..766f4bcf4c0d7a63f6881027fe364d04a8d259e0 100644 (file)
@@ -17,3 +17,4 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.ui.ide,
  org.eclipse.linuxtools.btf.core
 Export-Package: org.eclipse.linuxtools.btf.ui
+Import-Package: com.google.common.collect
index 4af3bee6bd2316d38a3ea489dff16af815560bac..143082776be02107b50a27caa4d98a7a0ef9fdea 100644 (file)
 
 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
  *
@@ -30,30 +31,106 @@ import org.eclipse.swt.widgets.Composite;
  */
 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.
@@ -64,31 +141,6 @@ public class BtfEventViewer extends TmfEventsTable {
      *            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
index a64eddee16063af5e92b36a64e9803e047e44e3c..fddf99c6350871ddd4cba1d19747cebf28cb7ba9 100644 (file)
@@ -18,3 +18,5 @@ bin.includes = META-INF/,\
                about.html,\
                plugin.xml
 src.includes = about.html
+additional.bundles = org.eclipse.jdt.annotation
+jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
index 13b5505186464df55319fd55e747d1b2666dedee..99d7f33e40127d4269db707a42a967f65ad10cba 100644 (file)
@@ -13,6 +13,7 @@
 
 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;
 
@@ -23,9 +24,9 @@ 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;
index 1bb671850a51675b95a99a09ca88807dedbc818e..0550a7a30b3799a813d519c9e6e088bf675055d0 100644 (file)
@@ -24,4 +24,5 @@ Export-Package: org.eclipse.linuxtools.internal.gdbtrace.ui;x-friends:
  .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
index d4c250f32008f767e0e5b7b4393acee8354532c1..42bfedd20e8c4541c642eaa2a0d9f5ee70ccd715 100644 (file)
@@ -19,3 +19,5 @@ bin.includes = META-INF/,\
                plugin.xml,\
                plugin.properties
 src.includes = about.html
+additional.bundles = org.eclipse.jdt.annotation
+jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
index 8f8acdcfc3f958229823eb976891af8e2a4b1207..7b47ec23c20844403bb4b9f207283feeca2fcd08 100644 (file)
@@ -12,6 +12,8 @@
 
 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;
@@ -28,42 +30,84 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
 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() {
@@ -103,22 +147,6 @@ public class GdbEventsTable extends TmfEventsTable {
         }
     }
 
-    @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) {
index e74f843b1dd90b0e1af95235357e54dd183dd021..d08246edc913ae3f5ef3b18466d6207c61bf2847 100644 (file)
@@ -23,3 +23,4 @@ Export-Package: org.eclipse.linuxtools.internal.lttng2.kernel.ui;x-friends:="org
  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
index b6cb3e57935ed4a4e66f8215002def1fb225dc9e..f9efdf98d6e6306376457d83eeaf9f2678e2ac1e 100644 (file)
 
 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
@@ -59,23 +72,6 @@ public class LTTng2EventsTable extends TmfEventsTable {
      *            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);
     }
 }
index e6e4ebfd92360198266b31f50e27794bc7cf583b..807552e565023a5a1978a89ecc8a4be0a6f16650 100644 (file)
@@ -13,6 +13,7 @@
 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;
 
@@ -47,27 +48,27 @@ public interface ITmfEvent extends IAdaptable {
     /**
      * 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
index 10ecebe7acc8820679064f23a5d2a0f8dc9ebf2d..3fde3dfd063a502a96d17a38588f19e080ee5b9b 100644 (file)
@@ -178,12 +178,36 @@ public class CustomEvent extends TmfEvent {
     // 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();
index 38069ea533919d1510bdd227bb1cddfc5a2094c6..8233c1bcf1fd8c3f5c64559858e7f3b9a4db3ad5 100644 (file)
@@ -19,3 +19,4 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.pcap.ui;x-internal:=true,
  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
index 06d9fa1f4a2601bea31e8ac6643595ca908dd5c7..4ac42dd62310c48cd563c21dd14eecc6097717cd 100644 (file)
@@ -8,19 +8,24 @@
  *
  * 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.
  *
@@ -32,24 +37,102 @@ public class PcapEventsTable extends TmfEventsTable {
     // 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
@@ -64,32 +147,6 @@ public class PcapEventsTable extends TmfEventsTable {
      *            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);
     }
 }
index a735ad801593f18859f3ad82c9bfdd60c039831c..3ca181c5bf177a40aca8867217425d58cf9bfd2b 100644 (file)
@@ -18,3 +18,4 @@ Require-Bundle: org.junit;bundle-version="4.0.0",
  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
index 6485d3775b7d378d10239d98a17bb4f4728a6df5..4d615d56af6aa4791b24561405cb234a830d382d 100644 (file)
 
 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
  *
@@ -30,24 +32,26 @@ public class TmfEventsTableExperimentStub extends TmfEventsTable {
     // 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
@@ -62,21 +66,6 @@ public class TmfEventsTableExperimentStub extends TmfEventsTable {
      *            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);
     }
 }
index 7ce0cd4c5feac997e5bb859c810f75040666364b..e6c805b34fab54e494fe908da2f71310273d4767 100644 (file)
@@ -32,6 +32,7 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.l
  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,
@@ -40,6 +41,7 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.l
  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,
index 6875715a66cc2eb264c69497f3a9cb378c9de12f..51ec206a83bee677708d4371c2f3a93b56fc85f7 100644 (file)
@@ -8,22 +8,25 @@
  *
  * 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.
  *
@@ -31,7 +34,42 @@ import org.eclipse.swt.widgets.Composite;
  */
 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.
@@ -44,31 +82,18 @@ public class CustomEventsTable extends TmfEventsTable {
      *            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();
     }
 }
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfContentsColumn.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfContentsColumn.java
new file mode 100644 (file)
index 0000000..ee26dcd
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfReferenceColumn.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfReferenceColumn.java
new file mode 100644 (file)
index 0000000..645c4e6
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfSourceColumn.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfSourceColumn.java
new file mode 100644 (file)
index 0000000..b2064e9
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfTimestampColumn.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfTimestampColumn.java
new file mode 100644 (file)
index 0000000..d7fb6bc
--- /dev/null
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfTypeColumn.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/viewers/events/columns/TmfTypeColumn.java
new file mode 100644 (file)
index 0000000..7209a36
--- /dev/null
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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
index 9d9c1103ada0705d6cf2df1c954042d0cf997ef3..d54dc4a45a97a02ec905feb30ecea59dfc7222f4 100644 (file)
@@ -7,21 +7,21 @@
  * 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;
@@ -101,12 +101,13 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 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;
@@ -149,6 +150,7 @@ import org.eclipse.ui.themes.ColorUtil;
 
 import com.google.common.base.Joiner;
 import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Multimap;
 
 /**
@@ -156,7 +158,6 @@ 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
@@ -169,6 +170,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
      */
     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$
@@ -183,6 +190,18 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
     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
      *
@@ -278,14 +297,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
     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;
@@ -301,7 +313,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
     // ------------------------------------------------------------------------
 
     /**
-     * Basic constructor, will use default column data.
+     * Basic constructor, using the default set of columns
      *
      * @param parent
      *            The parent composite UI object
@@ -309,20 +321,63 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
      *            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);
@@ -347,18 +402,14 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
         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);
 
@@ -589,6 +640,10 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
         createPopupMenu();
     }
 
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
     /**
      * Create a pop-up menu.
      */
@@ -994,11 +1049,13 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
 
     /**
      * @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 */
     }
 
     /**
@@ -1012,7 +1069,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
      *            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);
@@ -1859,11 +1916,34 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
     }
 
     /**
-     * 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
@@ -1871,16 +1951,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
      * @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);
     }
 
     /**
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/columns/TmfEventTableColumn.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/columns/TmfEventTableColumn.java
new file mode 100644 (file)
index 0000000..6069620
--- /dev/null
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * 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();
+}
diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/columns/TmfEventTableFieldColumn.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/columns/TmfEventTableFieldColumn.java
new file mode 100644 (file)
index 0000000..fbbaed7
--- /dev/null
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * 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;
+    }
+
+}
index aad2806a01fdcf417808a37915da9937a81d6468..4238413fb43392cb69789c8baffe497bbb969058 100644 (file)
@@ -26,11 +26,17 @@ import org.eclipse.swt.widgets.Composite;
  *
  * @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
      *
index ffccde7c3a6617eee923a0559c81ea3aeaf95fc8..bf18d4c1dfde9b4782a9cac80d561e85fcc1101b 100644 (file)
  ******************************************************************************/
 
 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
index 7971433598173954c887b0854c971d6b31a6dad1..94800631e9183209f9d6f067868880fb34084eac 100644 (file)
 
 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;
@@ -893,24 +897,47 @@ public class TmfVirtualTable extends Composite {
 
     /**
      * 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();
         }
     }
 
This page took 0.063063 seconds and 5 git commands to generate.