From 112352770f1fa04cd48d54c52b39482cce69f49f Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Mon, 25 Jan 2010 13:10:36 +0000
Subject: [PATCH] SE-191 GenericTableRow stuff improved: Render cells if they
 are links.

SVN: 14425
---
 .../renderer/AbstractPropertyColRenderer.java |  5 ++
 .../framework/AbstractColumnDefinition.java   | 11 +++
 .../framework/IColumnDefinitionUI.java        |  5 ++
 .../GenericTableRowColumnDefinition.java      |  2 +-
 .../specific/GridCustomColumnDefinition.java  |  5 ++
 .../ui/data/DataSetReporterGrid.java          |  5 ++
 .../ui/grid/ColumnDefsAndConfigs.java         |  5 ++
 .../ui/grid/GenericTableBrowserGrid.java      | 15 +++-
 .../GenericTableRowColumnDefinitionUI.java    | 27 +++++-
 .../web/client/dto/GenericTableResultSet.java |  4 +-
 .../basic/dto/GenericTableColumnHeader.java   | 43 +++++++--
 .../shared/basic/dto/GenericTableRow.java     | 18 +++-
 .../SerializableComparableIDDecorator.java    | 89 +++++++++++++++++++
 13 files changed, 218 insertions(+), 16 deletions(-)
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SerializableComparableIDDecorator.java

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java
index ad5e214d2c5..952329acd61 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/model/renderer/AbstractPropertyColRenderer.java
@@ -76,6 +76,11 @@ public abstract class AbstractPropertyColRenderer<T extends IEntityPropertiesHol
         return colDef.getComparableValue(rowModel);
     }
 
+    public boolean isLink()
+    {
+        return false;
+    }
+
     /**
      * @return given <var>value</var> rendered depending on property type
      */
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 b49dd3eae7d..a1f037a7e2b 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
@@ -79,6 +79,17 @@ public abstract class AbstractColumnDefinition<T> implements IColumnDefinitionUI
         return false;
     }
 
+    public boolean isLink()
+    {
+        return false;
+    }
+
+    public String getIdentifier()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
     public String tryToGetProperty(String key)
     {
         return null;
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/IColumnDefinitionUI.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/IColumnDefinitionUI.java
index 857c42d30ca..6dafeff5a77 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/IColumnDefinitionUI.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/framework/IColumnDefinitionUI.java
@@ -19,4 +19,9 @@ public interface IColumnDefinitionUI<T> extends IColumnDefinition<T>
      * Returns <code>true</code> if the values of the column are numerically.
      */
     boolean isNumeric();
+    
+    /**
+     * Returns <code>true</code> if the column cell should be rendered as a link.
+     */
+    boolean isLink();
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GenericTableRowColumnDefinition.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GenericTableRowColumnDefinition.java
index ad1ea74b0bb..a03aee67f68 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GenericTableRowColumnDefinition.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GenericTableRowColumnDefinition.java
@@ -27,7 +27,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ISerializableComparable
  */
 public class GenericTableRowColumnDefinition implements IColumnDefinition<GenericTableRow>
 {
-    private GenericTableColumnHeader header;
+    protected GenericTableColumnHeader header;
 
     private String title;
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GridCustomColumnDefinition.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GridCustomColumnDefinition.java
index 376d87ddb46..97ede91094c 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GridCustomColumnDefinition.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/GridCustomColumnDefinition.java
@@ -51,6 +51,11 @@ public class GridCustomColumnDefinition<T> implements IColumnDefinitionUI<T>
         return false;
     }
 
+    public boolean isLink()
+    {
+        return false;
+    }
+
     public Comparable<?> getComparableValue(GridRowModel<T> rowModel)
     {
         return getPrimitiveValue(rowModel).getComparableValue();
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetReporterGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetReporterGrid.java
index 29e29ae16b6..53814e169e8 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetReporterGrid.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/data/DataSetReporterGrid.java
@@ -98,6 +98,11 @@ public class DataSetReporterGrid extends
             return isHidden;
         }
 
+        public boolean isLink()
+        {
+            return false;
+        }
+
         // GWT only
         @SuppressWarnings("unused")
         private DatasetReportColumnUI()
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/ColumnDefsAndConfigs.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/ColumnDefsAndConfigs.java
index 63c1e93c3fd..d1a6357dfcd 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/ColumnDefsAndConfigs.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/ColumnDefsAndConfigs.java
@@ -26,6 +26,7 @@ import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
 import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
 
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.BaseEntityModel;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.LinkRenderer;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.IColumnDefinitionUI;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IColumnDefinition;
 
@@ -83,6 +84,10 @@ public class ColumnDefsAndConfigs<T>
         {
             columnConfig.setAlignment(HorizontalAlignment.RIGHT);
         }
+        if (column.isLink())
+        {
+            columnConfig.setRenderer(LinkRenderer.createLinkRenderer());
+        }
         columnConfig.setWidth(column.getWidth());
         columnConfig.setHidden(column.isHidden());
         return columnConfig;
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableBrowserGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableBrowserGrid.java
index 305efda124b..50d7017c644 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableBrowserGrid.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableBrowserGrid.java
@@ -40,7 +40,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableColumnHeade
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow;
 
 /**
- * 
+ * Implementation of a table browser grid for {@link GenericTableRow} data.
  *
  * @author Franz-Josef Elmer
  */
@@ -50,7 +50,18 @@ public abstract class GenericTableBrowserGrid
     private static final String BROWSER_ID_PATTERN = "[a-z0-9_]*";
     
     private List<GenericTableColumnHeader> headers;
-    
+
+    /**
+     * Creates an instane for specified view context, browserID, gridID, and display type ID
+     * generator. The browser ID is also used to create dictionary keys for message providing in
+     * according to the following schema:
+     * 
+     * <pre>
+     *    &lt;browser ID&gt;_&lt;column code&gt;
+     * </pre>
+     * 
+     * @param browserId Only lower-case letter, digits, and '_' are allowed as browser ID.
+     */
     protected GenericTableBrowserGrid(IViewContext<ICommonClientServiceAsync> viewContext,
             String browserId, String gridId, boolean showHeader, boolean refreshAutomatically,
             IDisplayTypeIDGenerator displayTypeIDGenerator)
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableRowColumnDefinitionUI.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableRowColumnDefinitionUI.java
index 31a468a4c46..9c8891cdbbe 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableRowColumnDefinitionUI.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/grid/GenericTableRowColumnDefinitionUI.java
@@ -18,17 +18,32 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid;
 
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.IColumnDefinitionUI;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.GenericTableRowColumnDefinition;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableColumnHeader;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow;
 
+/**
+ * UI extension of {@link GenericTableRowColumnDefinition}.
+ * 
+ *
+ * @author Franz-Josef Elmer
+ */
 public class GenericTableRowColumnDefinitionUI extends GenericTableRowColumnDefinition implements
         IColumnDefinitionUI<GenericTableRow>
 {
+    private int width;
+
     public GenericTableRowColumnDefinitionUI(GenericTableColumnHeader header, String title)
     {
-        super(header, title);
+        this(header, title, 100);
     }
 
+    public GenericTableRowColumnDefinitionUI(GenericTableColumnHeader header, String title, int width)
+    {
+        super(header, title);
+        this.width = width;
+    }
+    
     // GWT only
     @SuppressWarnings("unused")
     private GenericTableRowColumnDefinitionUI()
@@ -38,7 +53,7 @@ public class GenericTableRowColumnDefinitionUI extends GenericTableRowColumnDefi
 
     public int getWidth()
     {
-        return 100;
+        return width;
     }
 
     public boolean isHidden()
@@ -48,7 +63,13 @@ public class GenericTableRowColumnDefinitionUI extends GenericTableRowColumnDefi
 
     public boolean isNumeric()
     {
-        return false;
+        DataTypeCode type = header.getType();
+        return type == DataTypeCode.INTEGER || type == DataTypeCode.REAL;
+    }
+
+    public boolean isLink()
+    {
+        return header.isLinkable();
     }
     
 }
\ No newline at end of file
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/GenericTableResultSet.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/GenericTableResultSet.java
index 7f0cf0680ac..16f66e37322 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/GenericTableResultSet.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/GenericTableResultSet.java
@@ -20,12 +20,14 @@ import java.util.List;
 
 import com.google.gwt.user.client.rpc.IsSerializable;
 
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.GenericTableRowColumnDefinition;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableColumnHeader;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow;
 
 /**
+ * Class for the {@link ResultSet} of {@link GenericTableRow}. It also contains the
+ * {@link GenericTableRowColumnDefinition}s.
  * 
- *
  * @author Franz-Josef Elmer
  */
 public class GenericTableResultSet implements IsSerializable
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableColumnHeader.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableColumnHeader.java
index b3007c1bac8..ef1cac1ba73 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableColumnHeader.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableColumnHeader.java
@@ -20,8 +20,17 @@ import java.io.Serializable;
 
 import com.google.gwt.user.client.rpc.IsSerializable;
 
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider;
+
 /**
- * 
+ * Definition of a column header for {@link GenericTableRow} data. 
+ * A column had has
+ * <ul><li>an index (needed to access a cell in a {@link GenericTableRow} object),
+ * <li>a code which has to be unique among all other headers,
+ * <li>a data type
+ * </ul>
+ * The header title is optional. If not specified the code will be the title. Usually it will be
+ * set in the client code by using a translation mechanism (like {@link IMessageProvider}).
  *
  * @author Franz-Josef Elmer
  */
@@ -29,26 +38,41 @@ public class GenericTableColumnHeader implements Serializable, IsSerializable
 {
     private static final long serialVersionUID = ServiceVersionHolder.VERSION;
     
-    public static GenericTableColumnHeader untitledStringHeader(int identifier, String code)
+    /**
+     * Creates a header without a title.
+     */
+    public static GenericTableColumnHeader untitledStringHeader(int index, String code)
     {
         GenericTableColumnHeader header = new GenericTableColumnHeader();
-        header.setIndex(identifier);
+        header.setIndex(index);
         header.setCode(code);
         header.setType(DataTypeCode.VARCHAR);
         return header;
     }
 
+    /**
+     * Creates a header without a title and <code>linkable</code> flag set <code>true</code>..
+     */
+    public static GenericTableColumnHeader untitledLinkableStringHeader(int index, String code)
+    {
+        GenericTableColumnHeader header = untitledStringHeader(index, code);
+        header.setLinkable(true);
+        return header;
+    }
+    
     private String title;
     
     private int index;
     
     private String code;
     
+    private boolean linkable;
+    
     private DataTypeCode type;
 
     public String getTitle()
     {
-        return title;
+        return title == null ? code : title;
     }
 
     public void setTitle(String title)
@@ -85,6 +109,15 @@ public class GenericTableColumnHeader implements Serializable, IsSerializable
     {
         this.type = type;
     }
-    
+
+    public void setLinkable(boolean linkable)
+    {
+        this.linkable = linkable;
+    }
+
+    public boolean isLinkable()
+    {
+        return linkable;
+    }
     
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableRow.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableRow.java
index 16c4699e6eb..227bdf73942 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableRow.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/GenericTableRow.java
@@ -20,8 +20,10 @@ import java.io.Serializable;
 
 import com.google.gwt.user.client.rpc.IsSerializable;
 
+import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GenericTableResultSet;
+
 /**
- * 
+ * The values of a row of a {@link GenericTableResultSet}.
  *
  * @author Franz-Josef Elmer
  */
@@ -31,14 +33,22 @@ public class GenericTableRow implements Serializable, IsSerializable
     
     private ISerializableComparable[] cells;
     
+    /**
+     * Creates an instance for specified cells.
+     */
     public GenericTableRow(ISerializableComparable... cells)
     {
         this.cells = cells;
     }
-    
-    public ISerializableComparable tryToGetValue(int columnID)
+
+    /**
+     * Returns the value of cell with specified index.
+     * 
+     * @return <code>null</code> if cell value is <code>null</code>.
+     */
+    public ISerializableComparable tryToGetValue(int index)
     {
-        return cells[columnID]; 
+        return cells[index]; 
     }
 
     // GWT only
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SerializableComparableIDDecorator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SerializableComparableIDDecorator.java
new file mode 100644
index 00000000000..03b01767b05
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/SerializableComparableIDDecorator.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2010 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
+
+import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
+
+/**
+ * Decorator of {@link ISerializableComparable} with a {@link TechId}.
+ *
+ * @author Franz-Josef Elmer
+ */
+public class SerializableComparableIDDecorator implements ISerializableComparable
+{
+    private static final long serialVersionUID = ServiceVersionHolder.VERSION;
+    
+    private ISerializableComparable serializableComparable;
+    private Long id;
+    
+    public SerializableComparableIDDecorator(ISerializableComparable serializableComparable, Long idOrNull)
+    {
+        assert serializableComparable != null : "Unspecified ISerializableComparable";
+        this.serializableComparable = serializableComparable;
+        this.id = idOrNull;
+    }
+    
+    public Long getID()
+    {
+        return id;
+    }
+    
+    public int compareTo(ISerializableComparable o)
+    {
+        if (o instanceof SerializableComparableIDDecorator)
+        {
+            SerializableComparableIDDecorator decorator = (SerializableComparableIDDecorator) o;
+            return serializableComparable.compareTo(decorator.serializableComparable);
+        }
+        return serializableComparable.compareTo(o);
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if (obj instanceof SerializableComparableIDDecorator == false)
+        {
+            return false;
+        }
+        SerializableComparableIDDecorator decorator = (SerializableComparableIDDecorator) obj;
+        return serializableComparable.equals(decorator.serializableComparable);
+   }
+    
+    @Override
+    public int hashCode()
+    {
+        return serializableComparable.hashCode();
+    }
+    
+    @Override
+    public String toString()
+    {
+        return serializableComparable.toString();
+    }
+    
+    // ---------------------------
+
+    // GWT only
+    @SuppressWarnings("unused")
+    private SerializableComparableIDDecorator()
+    {
+    }
+}
-- 
GitLab