From 02931424d3d34215af3bbca453032b0d0e6f0982 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Tue, 9 Feb 2010 09:44:19 +0000
Subject: [PATCH] LMS-1354 add numeric flag to AbstractColumnDefinition

SVN: 14641
---
 .../renderer/RealPropertyColRenderer.java     |  6 ++
 .../renderer/RealNumberRenderer.java          | 61 +++++++------------
 .../framework/AbstractColumnDefinition.java   |  9 ++-
 .../AbstractColumnDefinitionKind.java         | 18 +++++-
 .../framework/CommonColumnDefinition.java     |  2 +-
 .../framework/EntityPropertyColDef.java       |  2 +-
 .../sample/AbstractParentSampleColDef.java    |  2 +-
 .../server/calculator/RowCalculatorTest.java  |  2 +-
 .../web/server/util/FilterUtilsTest.java      |  2 +-
 9 files changed, 54 insertions(+), 50 deletions(-)

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 cbfe66ff35e..3407f15e98d 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
@@ -47,4 +47,10 @@ public class RealPropertyColRenderer<T extends IEntityPropertiesHolder> extends
         return RealNumberRenderer.render(value, realNumberFormatingParameters);
     }
 
+    @Override
+    public boolean isNumeric()
+    {
+        return true;
+    }
+    
 }
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
index a2c431f3e23..0794c5f85d9 100644
--- 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
@@ -19,49 +19,11 @@ public final class RealNumberRenderer implements GridCellRenderer<BaseEntityMode
 {
     private static final String ZEROS = "00000000000000000000";
     private static final int MAX_PRECISION = ZEROS.length();
-
-    private static final int MAX_DIGITAL_FORMAT_LENGTH = 10;
-
-    private static final double MIN_DIGITAL_FORMAT_VALUE = 0.00005;
-
-    private static final String SCIENTIFIC_FORMAT = "0.0000E0000";
-
-    private static final String DIGITAL_FORMAT = "0.0000";
-
-    private 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);
-        }
-        if (Math.abs(doubleValue) < MIN_DIGITAL_FORMAT_VALUE)
-        {
-            formattedValue += "..."; // show 0.0000...
-        } else
-        {
-            formattedValue += "&nbsp;&nbsp;&nbsp;"; // add ' ' to always have a correct alignment
-        }
-        return MultilineHTML.wrapUpInDivWithTooltip(formattedValue, Double.toString(doubleValue));
-    }
-
-    public Object render(BaseEntityModel<?> model, String property, ColumnData config,
-            int rowIndex, int colIndex, ListStore<BaseEntityModel<?>> store,
-            Grid<BaseEntityModel<?>> grid)
-    {
-        String value = String.valueOf(model.get(property));
-        if (value == null)
-        {
-            return "";
-        }
-        return render(value);
-    }
-
+    
     public static String render(String value,
             RealNumberFormatingParameters realNumberFormatingParameters)
     {
-        if (realNumberFormatingParameters.isFormatingEnabled() == false)
+        if (realNumberFormatingParameters.isFormatingEnabled() == false || value.length() == 0)
         {
             return value;
         }
@@ -76,4 +38,23 @@ public final class RealNumberRenderer implements GridCellRenderer<BaseEntityMode
         return MultilineHTML.wrapUpInDivWithTooltip(formattedValue, value);
     }
 
+    private final RealNumberFormatingParameters realNumberFormatingParameters;
+    
+    public RealNumberRenderer(RealNumberFormatingParameters realNumberFormatingParameters)
+    {
+        this.realNumberFormatingParameters = realNumberFormatingParameters;
+    }
+
+    public Object render(BaseEntityModel<?> model, String property, ColumnData config,
+            int rowIndex, int colIndex, ListStore<BaseEntityModel<?>> store,
+            Grid<BaseEntityModel<?>> grid)
+    {
+        String value = String.valueOf(model.get(property));
+        if (value == null)
+        {
+            return "";
+        }
+        return render(value, realNumberFormatingParameters);
+    }
+    
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractColumnDefinition.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractColumnDefinition.java
index 8c7cb1c65b9..41b66a1ae00 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractColumnDefinition.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractColumnDefinition.java
@@ -31,20 +31,23 @@ public abstract class AbstractColumnDefinition<T> implements IColumnDefinitionUI
 
     private boolean isHidden;
 
+    private boolean numeric;
+
     // GWT only
     protected AbstractColumnDefinition()
     {
-        this(null, 0, false);
+        this(null, 0, false, false);
     }
 
     /**
      * if headerTextOrNull is null, it means that we never want to call {@link #getHeader()} method
      */
-    protected AbstractColumnDefinition(String headerTextOrNull, int width, boolean isHidden)
+    protected AbstractColumnDefinition(String headerTextOrNull, int width, boolean isHidden, boolean numeric)
     {
         this.headerText = headerTextOrNull;
         this.width = width;
         this.isHidden = isHidden;
+        this.numeric = numeric;
     }
 
     public int getWidth()
@@ -76,7 +79,7 @@ public abstract class AbstractColumnDefinition<T> implements IColumnDefinitionUI
 
     public boolean isNumeric()
     {
-        return false;
+        return numeric;
     }
 
     public boolean isLink()
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractColumnDefinitionKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractColumnDefinitionKind.java
index 0d774d1e9e9..512701d1bf5 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractColumnDefinitionKind.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/AbstractColumnDefinitionKind.java
@@ -50,22 +50,31 @@ public abstract class AbstractColumnDefinitionKind<T>
 
     private boolean isHidden;
 
+    private boolean numeric;
+
     public AbstractColumnDefinitionKind(final String headerMsgKey, final int width,
             final boolean isHidden)
+    {
+        this(headerMsgKey, width, isHidden, false);
+    }
+    
+    public AbstractColumnDefinitionKind(final String headerMsgKey, final int width,
+            final boolean isHidden, boolean numeric)
     {
         this.headerMsgKey = headerMsgKey;
         this.width = width;
         this.isHidden = isHidden;
+        this.numeric = numeric;
     }
 
     public AbstractColumnDefinitionKind(final String headerMsgKey, final boolean isHidden)
     {
-        this(headerMsgKey, DEFAULT_COLUMN_WIDTH, isHidden);
+        this(headerMsgKey, DEFAULT_COLUMN_WIDTH, isHidden, false);
     }
 
     public AbstractColumnDefinitionKind(final String headerMsgKey, final int width)
     {
-        this(headerMsgKey, width, false);
+        this(headerMsgKey, width, false, false);
     }
 
     public AbstractColumnDefinitionKind(final String headerMsgKey)
@@ -90,6 +99,11 @@ public abstract class AbstractColumnDefinitionKind<T>
     {
         return headerMsgKey;
     }
+    
+    public boolean isNumeric()
+    {
+        return numeric;
+    }
 
     public Comparable<?> getComparableValue(GridRowModel<T> entity)
     {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/CommonColumnDefinition.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/CommonColumnDefinition.java
index 564e6863b91..cbbb2d34982 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/CommonColumnDefinition.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/CommonColumnDefinition.java
@@ -41,7 +41,7 @@ public class CommonColumnDefinition<T> extends AbstractColumnDefinition<T>
             final String headerText)
     {
         super(headerText, columnDefinitionKind.getDescriptor().getWidth(), columnDefinitionKind
-                .getDescriptor().isHidden());
+                .getDescriptor().isHidden(), columnDefinitionKind.getDescriptor().isNumeric());
         this.columnDefinitionKind = columnDefinitionKind;
     }
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/EntityPropertyColDef.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/EntityPropertyColDef.java
index 4930b32f5e3..b969a8a41f3 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/EntityPropertyColDef.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/EntityPropertyColDef.java
@@ -91,7 +91,7 @@ public class EntityPropertyColDef<T extends IEntityPropertiesHolder> extends
             boolean isInternalNamespace, String propertyTypeLabel, String identifierPrefix,
             PropertyType propertyType)
     {
-        super(propertyTypeLabel, width, isDisplayedByDefault);
+        super(propertyTypeLabel, width, isDisplayedByDefault, false);
         this.isInternalNamespace = isInternalNamespace;
         this.simpleCode = propertyTypeCode;
         this.identifierPrefix = identifierPrefix;
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/sample/AbstractParentSampleColDef.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/sample/AbstractParentSampleColDef.java
index 594e5253040..7caf1293b07 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/sample/AbstractParentSampleColDef.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/sample/AbstractParentSampleColDef.java
@@ -33,7 +33,7 @@ public abstract class AbstractParentSampleColDef extends AbstractColumnDefinitio
 
     AbstractParentSampleColDef(int level, String headerText)
     {
-        super(headerText, AbstractColumnDefinitionKind.DEFAULT_COLUMN_WIDTH, false);
+        super(headerText, AbstractColumnDefinitionKind.DEFAULT_COLUMN_WIDTH, false, false);
         this.level = level;
     }
 
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/RowCalculatorTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/RowCalculatorTest.java
index 8d17595dcf8..e0f22846cd4 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/RowCalculatorTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/RowCalculatorTest.java
@@ -56,7 +56,7 @@ public class RowCalculatorTest extends AssertJUnit
     public void setUp()
     {
         availableColumns = new LinkedHashSet<IColumnDefinition<Data>>();
-        availableColumns.add(new AbstractColumnDefinition<Data>("header", 100, true)
+        availableColumns.add(new AbstractColumnDefinition<Data>("header", 100, true, false)
             {
 
                 public String getIdentifier()
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/FilterUtilsTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/FilterUtilsTest.java
index 3f54c67daa1..7bd2ba4f5a7 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/FilterUtilsTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/server/util/FilterUtilsTest.java
@@ -63,7 +63,7 @@ public class FilterUtilsTest extends AssertJUnit
         filterInfo.setParameters(new LinkedHashSet<ParameterWithValue>(Arrays.asList(parameter)));
         Set<IColumnDefinition<Data>> availableColumns =
                 new LinkedHashSet<IColumnDefinition<Data>>();
-        availableColumns.add(new AbstractColumnDefinition<Data>("header", 100, true)
+        availableColumns.add(new AbstractColumnDefinition<Data>("header", 100, true, false)
             {
 
                 public String getIdentifier()
-- 
GitLab