tmf.swtbot: Test event highlighting

Change-Id: I4494069d84175c72ed88ed5e66f2af254578e1ea
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/128940
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: CI Bot
(cherry picked from commit c2af083923248224acb003fa620e2981c27ed8d0)
Reviewed-on: https://git.eclipse.org/r/129130
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/views/TimeGraphViewStub.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/views/TimeGraphViewStub.java
index 82de041..cfa722f 100644
--- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/views/TimeGraphViewStub.java
+++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/views/TimeGraphViewStub.java
@@ -20,6 +20,7 @@
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.swt.graphics.RGBA;
+import org.eclipse.tracecompass.tmf.core.model.timegraph.IFilterProperty;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
@@ -33,6 +34,8 @@
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent;
 
+import com.google.common.collect.Multimap;
+
 /**
  * Time graph stub.
  *
@@ -76,6 +79,8 @@
     private final @NonNull TimeGraphEntry fRow4;
     private StubPresentationProvider fPresentationProvider;
 
+    private String fFilterRegex;
+
     /**
      * Constructor
      */
@@ -142,6 +147,25 @@
     }
 
     @Override
+    protected @NonNull Multimap<@NonNull Integer, @NonNull String> getRegexes() {
+        Multimap<@NonNull Integer, @NonNull String> regexes = super.getRegexes();
+        if (regexes.containsKey(IFilterProperty.BOUND) && (fFilterRegex == null || fFilterRegex.isEmpty())) {
+            regexes.removeAll(IFilterProperty.BOUND);
+        }
+        if (!regexes.containsKey(IFilterProperty.BOUND) && fFilterRegex != null && !fFilterRegex.isEmpty()) {
+            regexes.put(IFilterProperty.BOUND, fFilterRegex);
+        }
+        return regexes;
+    }
+
+    /**
+     * Set the regex to highlight on
+     */
+    public void setFilterRegex(String filterRegex) {
+        fFilterRegex = filterRegex;
+    }
+
+    @Override
     protected void buildEntryList(@NonNull ITmfTrace trace, @NonNull ITmfTrace parentTrace, @NonNull IProgressMonitor monitor) {
         List<@NonNull TimeGraphEntry> entryList = getEntryList(trace);
         if (entryList == null || entryList.isEmpty()) {
@@ -163,7 +187,7 @@
      * Set the presentation provider
      *
      * @param presentaitonProvider
-     *                                 the presentation provider
+     *            the presentation provider
      */
     public void setPresentationProvider(StubPresentationProvider presentaitonProvider) {
         fPresentationProvider = presentaitonProvider;
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/views/TimeGraphViewTest.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/views/TimeGraphViewTest.java
index e514c97..aa3dc3b 100644
--- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/views/TimeGraphViewTest.java
+++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/views/TimeGraphViewTest.java
@@ -225,7 +225,8 @@
         TmfWindowRangeUpdatedSignal signal = new TmfWindowRangeUpdatedSignal(this, smallerRange);
 
         TimeGraphViewStub view = getView();
-        // This is an oddity: the signals may be lost if a view is not initialized, so
+        // This is an oddity: the signals may be lost if a view is not
+        // initialized, so
         // they are send in the condition.
         //
         // NOTE: maybe use a shorter poll delay?
@@ -269,8 +270,8 @@
     }
 
     /**
-     * Clean up after a test, reset the views and reset the states of the timegraph
-     * by pressing reset on all the resets of the legend
+     * Clean up after a test, reset the views and reset the states of the
+     * timegraph by pressing reset on all the resets of the legend
      */
     @After
     public void after() {
@@ -356,8 +357,39 @@
     }
 
     /**
-     * Test the legend operation. Change sliders and reset, do not change colors as
-     * there is not mock of the color picker yet
+     * Test the event styling methods, should put a box around the events.
+     */
+    @Test
+    public void testEventStyling() {
+        SWTWorkbenchBot bot = new SWTWorkbenchBot();
+        resetTimeRange(bot);
+        Rectangle bounds = fBounds;
+        ImageHelper precollapse = ImageHelper.grabImage(bounds);
+        SWTBotTimeGraph tg = new SWTBotTimeGraph(fViewBot.bot());
+        tg.getEntry("Plumber guy").collapse();
+        TimeGraphViewStub view = getView();
+        // take a first saved picture, the original is pre-collapse
+        ImageHelper ref = ImageHelper.waitForNewImage(bounds, precollapse);
+        /*
+         * Regex, not a question
+         */
+        view.setFilterRegex("row?");
+        UIThreadRunnable.syncExec(() -> view.restartZoomThread());
+        // Take another picture/
+        ImageHelper highlighted = ImageHelper.waitForNewImage(bounds, ref);
+        view.setFilterRegex(null);
+        UIThreadRunnable.syncExec(() -> view.restartZoomThread());
+        // take a third picture
+        ImageHelper reset = ImageHelper.waitForNewImage(bounds, highlighted);
+        assertEquals(ref.getHistogram(), reset.getHistogram());
+        ImageHelper delta = highlighted.diff(reset);
+        tg.expandAll();
+        assertTrue("Some highlighting", delta.getHistogram().elementSet().size() > 1);
+    }
+
+    /**
+     * Test the legend operation. Change sliders and reset, do not change colors
+     * as there is not mock of the color picker yet
      *
      * TODO: mock color picker
      */
@@ -406,14 +438,15 @@
     }
 
     /**
-     * Test the legend and export operations. Resize states, take screenshots and
-     * compare, they should be different. then reset the sizes and compare, they
-     * should be the same.
+     * Test the legend and export operations. Resize states, take screenshots
+     * and compare, they should be different. then reset the sizes and compare,
+     * they should be the same.
      *
      * NOTE: This utterly fails in GTK3.
      *
      * @throws IOException
-     *             file not found, someone deleted files while the test is running
+     *             file not found, someone deleted files while the test is
+     *             running
      */
     @Test
     public void testExport() throws IOException {
@@ -455,7 +488,8 @@
         /* Compare with the original, they should be different */
         int refCount = refImage.getHistogram().count(HAIR);
         int skinnyCount = skinnyImage.getHistogram().count(HAIR);
-        assertTrue(String.format("Count of \"\"HAIR\"\" (%s) did not get change despite change of width before: %d after:%d histogram:%s", HAIR, refCount, skinnyCount, Multisets.copyHighestCountFirst(skinnyImage.getHistogram())), skinnyCount < refCount);
+        assertTrue(String.format("Count of \"\"HAIR\"\" (%s) did not get change despite change of width before: %d after:%d histogram:%s", HAIR, refCount, skinnyCount, Multisets.copyHighestCountFirst(skinnyImage.getHistogram())),
+                skinnyCount < refCount);
 
         /* reset all */
         fViewBot.toolbarButton(SHOW_LEGEND).click();
@@ -477,13 +511,12 @@
         assertEquals("Count of \"HAIR\" did not get change despite reset of width", refCount, resetCount);
     }
 
-    private static class PaletteIsPresent extends DefaultCondition  {
+    private static class PaletteIsPresent extends DefaultCondition {
 
         private String fFailureMessage;
         private List<RGB> fRgbs;
         private Rectangle fRect;
 
-
         public PaletteIsPresent(List<RGB> rgbs, Rectangle bounds) {
             fRgbs = rgbs;
             fRect = bounds;
@@ -512,7 +545,6 @@
         }
     }
 
-
     /**
      * Test time graph with color palettes
      */
@@ -530,7 +562,7 @@
                 return paletteBlue;
             }
         }));
-        List<RGB> rgbs = Lists.transform(paletteBlue.get(), a->RGBAUtil.fromInt(a.toInt()).rgb);
+        List<RGB> rgbs = Lists.transform(paletteBlue.get(), a -> RGBAUtil.fromInt(a.toInt()).rgb);
         fViewBot.bot().waitUntil(new PaletteIsPresent(rgbs, bounds));
 
         IPaletteProvider paletteGreen = SequentialPaletteProvider.create(new RGBAColor(0x23, 0xf3, 0x67, 0xff), 5);
@@ -540,7 +572,7 @@
                 return paletteGreen;
             }
         }));
-        rgbs = Lists.transform(paletteGreen.get(), a->RGBAUtil.fromInt(a.toInt()).rgb);
+        rgbs = Lists.transform(paletteGreen.get(), a -> RGBAUtil.fromInt(a.toInt()).rgb);
         fViewBot.bot().waitUntil(new PaletteIsPresent(rgbs, bounds));
 
         IPaletteProvider rotating = new QualitativePaletteProvider.Builder().setAttenuation(0.5f).setBrightness(1.0f).setNbColors(4).build();
@@ -550,7 +582,7 @@
                 return rotating;
             }
         }));
-        rgbs = Lists.transform(rotating.get(), a->RGBAUtil.fromInt(a.toInt()).rgb);
+        rgbs = Lists.transform(rotating.get(), a -> RGBAUtil.fromInt(a.toInt()).rgb);
         fViewBot.bot().waitUntil(new PaletteIsPresent(rgbs, bounds));
     }
 
@@ -572,7 +604,7 @@
         ImageHelper ref = ImageHelper.grabImage(bounds);
 
         timegraph.setFocus();
-        //Press '/' to open the filter dialog
+        // Press '/' to open the filter dialog
         timegraph.pressShortcut(KeyStroke.getInstance('/'));
 
         SWTBotShell dialogShell = viewBot.shell("Time Event Filter").activate();