From 43e5f8f1e797cb6c8ed12a263204fefcc45e6a80 Mon Sep 17 00:00:00 2001
From: izabel <izabel>
Date: Tue, 27 Oct 2009 12:31:06 +0000
Subject: [PATCH] add abundance renderer

SVN: 13084
---
 .../renderer/RealPropertyColRenderer.java     | 17 ++-----
 .../renderer/RealNumberRenderer.java          | 45 +++++++++++++++++++
 .../SampleAbundanceBrowserGrid.java           |  5 ++-
 3 files changed, 52 insertions(+), 15 deletions(-)
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/RealNumberRenderer.java

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/RealPropertyColRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/RealPropertyColRenderer.java
index 3d6d009d219..f463655ff5f 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/RealPropertyColRenderer.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/RealPropertyColRenderer.java
@@ -16,8 +16,7 @@
 
 package ch.systemsx.cisd.openbis.generic.client.web.client.application.model.renderer;
 
-import com.google.gwt.i18n.client.NumberFormat;
-
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.RealNumberRenderer;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.EntityPropertyColDef;
 import ch.systemsx.cisd.openbis.generic.shared.basic.GridRowModel;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityPropertiesHolder;
@@ -27,14 +26,10 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityPropertiesHolder
  * 
  * @author Izabela Adamczyk
  */
-class RealPropertyColRenderer<T extends IEntityPropertiesHolder> extends
+public class RealPropertyColRenderer<T extends IEntityPropertiesHolder> extends
         AbstractPropertyColRenderer<T>
 {
 
-    private static final int MAX_DIGITAL_FORMAT_LENGTH = 10;
-    private static final String SCIENTIFIC_FORMAT = "0.0000E00";
-    private static final String DIGITAL_FORMAT = "0.0000";
-
     public RealPropertyColRenderer(EntityPropertyColDef<T> colDef)
     {
         super(colDef);
@@ -44,13 +39,7 @@ class RealPropertyColRenderer<T extends IEntityPropertiesHolder> extends
     protected String renderValue(GridRowModel<T> entity)
     {
         String value = colDef.getValue(entity);
-        double doubleValue = Double.parseDouble(value);
-        String formattedValue = NumberFormat.getFormat(DIGITAL_FORMAT).format(doubleValue);
-        if (formattedValue.length() > MAX_DIGITAL_FORMAT_LENGTH)
-        {
-            formattedValue = NumberFormat.getFormat(SCIENTIFIC_FORMAT).format(doubleValue);
-        }
-        return formattedValue;
+        return RealNumberRenderer.render(value);
     }
 
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/RealNumberRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/RealNumberRenderer.java
new file mode 100644
index 00000000000..f2d1c6eeac4
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/renderer/RealNumberRenderer.java
@@ -0,0 +1,45 @@
+package ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer;
+
+import com.extjs.gxt.ui.client.store.ListStore;
+import com.extjs.gxt.ui.client.widget.grid.ColumnData;
+import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
+import com.google.gwt.i18n.client.NumberFormat;
+
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.BaseEntityModel;
+
+/**
+ * Renderer of {@link Double} value.
+ * 
+ * @author Izabela Adamczyk
+ */
+public final class RealNumberRenderer implements GridCellRenderer<BaseEntityModel<?>>
+{
+    private static final int MAX_DIGITAL_FORMAT_LENGTH = 10;
+
+    private static final String SCIENTIFIC_FORMAT = "0.0000E00";
+
+    private static final String DIGITAL_FORMAT = "0.0000";
+
+    public String render(BaseEntityModel<?> model, String property, ColumnData config,
+            int rowIndex, int colIndex, ListStore<BaseEntityModel<?>> store)
+    {
+        String value = String.valueOf(model.get(property));
+        if (value == null)
+        {
+            return "";
+        }
+        return render(value);
+    }
+
+    public static String render(String value)
+    {
+        double doubleValue = Double.parseDouble(value);
+        String formattedValue = NumberFormat.getFormat(DIGITAL_FORMAT).format(doubleValue);
+        if (formattedValue.length() > MAX_DIGITAL_FORMAT_LENGTH)
+        {
+            formattedValue = NumberFormat.getFormat(SCIENTIFIC_FORMAT).format(doubleValue);
+        }
+        return formattedValue;
+    }
+
+}
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/SampleAbundanceBrowserGrid.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/SampleAbundanceBrowserGrid.java
index b2d85d14d69..e87a5f2a789 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/SampleAbundanceBrowserGrid.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/SampleAbundanceBrowserGrid.java
@@ -35,6 +35,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.Base
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.plugin.IClientPlugin;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.plugin.IClientPluginFactory;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.LinkRenderer;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.RealNumberRenderer;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.IColumnDefinitionKind;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.AbstractEntityBrowserGrid;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.ColumnDefsAndConfigs;
@@ -169,7 +170,7 @@ public class SampleAbundanceBrowserGrid
     }
 
     // property types used in the previous refresh operation or null if it has not occurred yet
-    private List<PropertyType> previousPropertyTypes;
+    private final List<PropertyType> previousPropertyTypes;
 
     // provides property types which will be used to build property columns in the grid and
     // criteria to filter samples
@@ -334,6 +335,8 @@ public class SampleAbundanceBrowserGrid
                 SampleAbundanceModelFactory.createColumnsSchema(viewContext, propertyTypes);
         schema.setGridCellRendererFor(SampleAbundanceColDefKind.CODE.id(), LinkRenderer
                 .createLinkRenderer());
+        schema.setGridCellRendererFor(SampleAbundanceColDefKind.ABUNDANCE.id(),
+                new RealNumberRenderer());
         return schema;
     }
 
-- 
GitLab