From 0064a9baaaab987ac37cd026e8b043f73b30bfec Mon Sep 17 00:00:00 2001
From: gpawel <gpawel>
Date: Thu, 19 May 2011 09:11:19 +0000
Subject: [PATCH] [LMS-2221] show tooltips when well do not have it's dataset,
 auto-width for tooltips

SVN: 21385
---
 .../detailviewers/dto/WellData.java           |  4 +++
 .../heatmaps/HeatmapPresenter.java            |  4 +++
 .../detailviewers/heatmaps/PlateLayouter.java | 34 +++++++++++++++++--
 .../heatmaps/WellTooltipGenerator.java        |  5 ++-
 4 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/dto/WellData.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/dto/WellData.java
index 1201df9529a..42729d5e19d 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/dto/WellData.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/dto/WellData.java
@@ -109,4 +109,8 @@ public class WellData
         return fullyLoaded;
     }
 
+    public void setFullyLoaded(boolean fullyLoaded)
+    {
+        this.fullyLoaded = fullyLoaded;
+    }
 }
\ No newline at end of file
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/HeatmapPresenter.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/HeatmapPresenter.java
index 3c0717ecab4..e8cfbf7c8b5 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/HeatmapPresenter.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/HeatmapPresenter.java
@@ -276,6 +276,10 @@ class HeatmapPresenter
                         };
             viewContext.getService().getWellFeatureVectorValues(datasetCode, datastoreCode,
                     location, callback);
+        } else
+        {
+            wellData.setFullyLoaded(true);
+            refreshTooltipAction.execute();
         }
     }
 
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/PlateLayouter.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/PlateLayouter.java
index 0d09c150e00..ab5325172a3 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/PlateLayouter.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/PlateLayouter.java
@@ -34,6 +34,7 @@ import com.extjs.gxt.ui.client.widget.form.SimpleComboValue;
 import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
 import com.extjs.gxt.ui.client.widget.layout.RowLayout;
 import com.extjs.gxt.ui.client.widget.layout.TableLayout;
+import com.extjs.gxt.ui.client.widget.tips.ToolTip;
 import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig;
 import com.google.gwt.user.client.ui.Widget;
 
@@ -152,8 +153,6 @@ public class PlateLayouter
                     config.setMouseOffset(new int[]
                         { 0, 0 });
                     config.setAnchor(anchor);
-                    // WORKAROUND width isn't properly updated - we set fixed value
-                    config.setMinWidth(300);
                     config.setDismissDelay(10000); // 10s to hide
                     GWTUtils.setToolTip(wellComponent, config);
                 }
@@ -419,7 +418,36 @@ public class PlateLayouter
 
     private static Component createBox()
     {
-        return new Text("");
+        return new Text("")
+            {
+                @Override
+                // WORKAROUND to have an auto-width feature in ToolTips. See:
+                // http://www.sencha.com/forum/archive/index.php/t-124754.html?s=656b4337e47b9419755bf0a6bc7409e9
+                public void setToolTip(ToolTipConfig config)
+                {
+                    if (config != null)
+                    {
+                        if (toolTip == null)
+                        {
+                            toolTip = new ToolTip(this, config)
+                                {
+                                    @Override
+                                    public void update(ToolTipConfig tooTipConfig)
+                                    {
+                                        super.update(tooTipConfig);
+                                        if (isRendered() && isAttached())
+                                        {
+                                            hide();
+                                            doAutoWidth();
+                                            show();
+                                        }
+                                    }
+                                };
+                        }
+                    }
+                    super.setToolTip(config);
+                }
+            };
     }
 
     // ---------
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/WellTooltipGenerator.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/WellTooltipGenerator.java
index 3860ef76e6e..3b7e0fbbe69 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/WellTooltipGenerator.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/heatmaps/WellTooltipGenerator.java
@@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.plugin.screening.client.web.client.application.
 import java.util.Collections;
 import java.util.List;
 
+import ch.systemsx.cisd.common.shared.basic.utils.StringUtils;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.IRealNumberRenderer;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
@@ -36,6 +37,8 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.WellMetadata;
  */
 class WellTooltipGenerator implements HeatmapPresenter.IWellTooltipGenerator
 {
+    private static final String UNKNOWN_WELL_LABEL = "No well information available.";
+
     private static final String NEWLINE = "\n";
 
     private static final int MAX_DESCRIBED_FEATURES = 20;
@@ -97,7 +100,7 @@ class WellTooltipGenerator implements HeatmapPresenter.IWellTooltipGenerator
                 tooltip += "...";
             }
         }
-        return tooltip;
+        return StringUtils.isBlank(tooltip) ? UNKNOWN_WELL_LABEL : tooltip;
     }
 
     private int getNumberOfLoadedFeatures(WellData wellData)
-- 
GitLab