From 37aa07dc828748ea66ba12469ba782d36cd4cd78 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Mon, 3 May 2010 16:02:43 +0000
Subject: [PATCH] [LMS-1504] introduced links to Project in
 sample/experiment/dataset viewers; added Project column in data set browser

SVN: 15733
---
 .../ui/PropertyValueRenderers.java            | 53 +++++++++++++++++++
 .../data/CommonExternalDataColDefKind.java    | 25 ++++++---
 .../dataset/DataSetPropertiesPanel.java       |  5 ++
 .../experiment/ExperimentPropertiesPanel.java |  4 ++
 .../sample/GenericSampleViewer.java           |  4 ++
 5 files changed, 83 insertions(+), 8 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java
index 2f31b44ab7c..40c01c7b3e2 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/PropertyValueRenderers.java
@@ -16,6 +16,7 @@
 
 package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui;
 
+import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.user.client.ui.FlowPanel;
 import com.google.gwt.user.client.ui.InlineHTML;
@@ -29,12 +30,14 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.L
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.renderer.PersonRenderer;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.framework.LinkExtractor;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityDetailsTabClickListener;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityDetailsTabHelper;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property.AbstractPropertyValueRenderer;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property.AbstractSimplePropertyValueRenderer;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property.IPropertyValueRenderer;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.ExternalHyperlink;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.MultilineHTML;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.WidgetUtils;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolder;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IInvalidationProvider;
@@ -50,6 +53,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Invalidation;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType;
@@ -68,6 +72,15 @@ public final class PropertyValueRenderers
         // Can not be instantiated
     }
 
+    /**
+     * Creates a {@link IPropertyValueRenderer} implementation for rendering {@link Project}.
+     */
+    public final static IPropertyValueRenderer<Project> createProjectPropertyValueRenderer(
+            final IViewContext<?> viewContext)
+    {
+        return new ProjectPropertyValueRenderer(viewContext);
+    }
+
     /**
      * Creates a {@link IPropertyValueRenderer} implementation for rendering {@link Sample}.
      */
@@ -441,6 +454,46 @@ public final class PropertyValueRenderers
 
     }
 
+    /**
+     * Renderer for {@link Project}.
+     * 
+     * @author Piotr Buczek
+     */
+    public static class ProjectPropertyValueRenderer extends AbstractPropertyValueRenderer<Project>
+    {
+
+        private final IViewContext<?> viewContext;
+
+        public ProjectPropertyValueRenderer(final IViewContext<?> viewContext)
+        {
+            super(viewContext);
+            this.viewContext = viewContext;
+        }
+
+        //
+        // AbstractPropertyValueRenderer
+        //
+        public Widget getAsWidget(final Project project)
+        {
+            final String displayText = project.getIdentifier();
+            final ClickHandler listener = new ClickHandler()
+                {
+                    public void onClick(ClickEvent event)
+                    {
+                        OpenEntityDetailsTabHelper.open(viewContext, project, WidgetUtils
+                                .ifSpecialKeyPressed(event.getNativeEvent()));
+                    }
+                };
+            String href = LinkExtractor.tryExtract(project);
+            final Widget link =
+                    LinkRenderer.getLinkWidget(displayText, listener, false, href != null ? "#"
+                            + href : null);
+
+            return link;
+        }
+
+    }
+
     /**
      * Renderer for {@link Sample}.
      * 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/data/CommonExternalDataColDefKind.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/data/CommonExternalDataColDefKind.java
index 1fbd84809bc..0cae6413a3c 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/data/CommonExternalDataColDefKind.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/columns/specific/data/CommonExternalDataColDefKind.java
@@ -94,10 +94,6 @@ public enum CommonExternalDataColDefKind implements IColumnDefinitionKind<Extern
             public String tryGetValue(ExternalData entity)
             {
                 final Experiment exp = entity.getExperiment();
-                if (exp == null)
-                {
-                    return null;
-                }
                 return exp.getCode();
             }
 
@@ -115,10 +111,6 @@ public enum CommonExternalDataColDefKind implements IColumnDefinitionKind<Extern
             public String tryGetValue(ExternalData entity)
             {
                 final Experiment exp = entity.getExperiment();
-                if (exp == null)
-                {
-                    return null;
-                }
                 return exp.getIdentifier();
             }
 
@@ -143,6 +135,23 @@ public enum CommonExternalDataColDefKind implements IColumnDefinitionKind<Extern
             }
         }),
 
+    PROJECT(new AbstractColumnDefinitionKind<ExternalData>(Dict.PROJECT)
+        {
+            @Override
+            public String tryGetValue(ExternalData entity)
+            {
+                final Experiment exp = entity.getExperiment();
+                return exp.getProject().getCode();
+            }
+
+            @Override
+            public String tryGetLink(ExternalData entity)
+            {
+                final Experiment exp = entity.getExperiment();
+                return LinkExtractor.tryExtract(exp.getProject());
+            }
+        }),
+
     REGISTRATION_DATE(new AbstractColumnDefinitionKind<ExternalData>(Dict.REGISTRATION_DATE, 200,
             false)
         {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/DataSetPropertiesPanel.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/DataSetPropertiesPanel.java
index 72c33c77613..c18814fae09 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/DataSetPropertiesPanel.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/dataset/DataSetPropertiesPanel.java
@@ -43,6 +43,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Invalidation;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialValueEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermValueEntityProperty;
@@ -81,6 +82,8 @@ public class DataSetPropertiesPanel extends ContentPanel
                 .createDataSetTypePropertyValueRenderer(viewContext));
         propertyGrid.registerPropertyValueRenderer(Invalidation.class, PropertyValueRenderers
                 .createInvalidationPropertyValueRenderer(viewContext));
+        propertyGrid.registerPropertyValueRenderer(Project.class, PropertyValueRenderers
+                .createProjectPropertyValueRenderer(viewContext));
         final IPropertyValueRenderer<IEntityProperty> propertyRenderer =
                 PropertyValueRenderers.createEntityPropertyPropertyValueRenderer(viewContext);
         propertyGrid.registerPropertyValueRenderer(EntityProperty.class, propertyRenderer);
@@ -132,6 +135,8 @@ public class DataSetPropertiesPanel extends ContentPanel
         properties.put(messageProvider.getMessage(Dict.REGISTRATOR), dataset.getRegistrator());
         properties.put(messageProvider.getMessage(Dict.REGISTRATION_DATE), dataset
                 .getRegistrationDate());
+        properties.put(messageProvider.getMessage(Dict.PROJECT), dataset.getExperiment()
+                .getProject());
         properties.put(messageProvider.getMessage(Dict.EXPERIMENT), dataset.getExperiment());
         if (sample != null)
         {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ExperimentPropertiesPanel.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ExperimentPropertiesPanel.java
index 8073a807ad7..39b93b89cbf 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ExperimentPropertiesPanel.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ExperimentPropertiesPanel.java
@@ -48,6 +48,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Invalidation;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialValueEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermValueEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind.ObjectKind;
@@ -100,6 +101,8 @@ public class ExperimentPropertiesPanel extends ContentPanel
                 .createExperimentTypePropertyValueRenderer(messageProvider));
         propertyGrid.registerPropertyValueRenderer(Invalidation.class, PropertyValueRenderers
                 .createInvalidationPropertyValueRenderer(messageProvider));
+        propertyGrid.registerPropertyValueRenderer(Project.class, PropertyValueRenderers
+                .createProjectPropertyValueRenderer(viewContext));
         final IPropertyValueRenderer<IEntityProperty> renderer =
                 PropertyValueRenderers.createEntityPropertyPropertyValueRenderer(viewContext);
         propertyGrid.registerPropertyValueRenderer(EntityProperty.class, renderer);
@@ -128,6 +131,7 @@ public class ExperimentPropertiesPanel extends ContentPanel
         {
             properties.put(messageProvider.getMessage(Dict.INVALIDATION), invalidation);
         }
+        properties.put(messageProvider.getMessage(Dict.PROJECT), experiment.getProject());
         final List<IEntityProperty> experimentProperties = experiment.getProperties();
         Collections.sort(experimentProperties);
         List<PropertyType> types = EntityPropertyUtils.extractTypes(experimentProperties);
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java
index 9fafec6be7d..f9e47e168b9 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewer.java
@@ -67,6 +67,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Invalidation;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialValueEntityProperty;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived;
@@ -256,6 +257,7 @@ abstract public class GenericSampleViewer extends AbstractViewer<Sample> impleme
         Experiment experiment = sample.getExperiment();
         if (experiment != null)
         {
+            properties.put(messageProvider.getMessage(Dict.PROJECT), experiment.getProject());
             properties.put(messageProvider.getMessage(Dict.EXPERIMENT), experiment);
         }
 
@@ -316,6 +318,8 @@ abstract public class GenericSampleViewer extends AbstractViewer<Sample> impleme
                 .createSamplePropertyValueRenderer(viewContext, true));
         propertyGrid.registerPropertyValueRenderer(Invalidation.class, PropertyValueRenderers
                 .createInvalidationPropertyValueRenderer(viewContext));
+        propertyGrid.registerPropertyValueRenderer(Project.class, PropertyValueRenderers
+                .createProjectPropertyValueRenderer(viewContext));
         final IPropertyValueRenderer<IEntityProperty> propertyValueRenderer =
                 PropertyValueRenderers.createEntityPropertyPropertyValueRenderer(viewContext);
         propertyGrid.registerPropertyValueRenderer(EntityProperty.class, propertyValueRenderer);
-- 
GitLab