From 171e68a86f54f2daf36d9aa511075dbea9d0948a Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Mon, 13 Jul 2009 11:14:53 +0000
Subject: [PATCH] LMS-1028 ProteinViewer showing properties

SVN: 11730
---
 .../client/web/client/application/Dict.java   |  5 ++
 .../ProteinByExperimentBrowerToolBar.java     |  5 ++
 .../ProteinByExperimentBrowserGrid.java       | 11 ++--
 .../web/client/application/ProteinViewer.java | 57 ++++++++++++++-----
 .../web/public/phosphonetx-dictionary.js      |  4 ++
 .../phosphonetx/server/PhosphoNetXServer.java |  1 +
 .../server/dataaccess/IProteinQueryDAO.java   |  2 +-
 7 files changed, 64 insertions(+), 21 deletions(-)

diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/Dict.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/Dict.java
index e46fd56d9dd..f152a854585 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/Dict.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/Dict.java
@@ -31,5 +31,10 @@ public class Dict
     public static final String PROTEIN_DESCRIPTION = "protein_description";
     public static final String FALSE_DISCOVERY_RATE = "false_discovery_rate";
     public static final String DATA_SET = "data_set";
+    
+    // Protein Viewer
+    public static final String PROTEIN_IN_EXPERIMENT_TAB_LABEL = "protein_in_experiment_tab_label";
+    public static final String EXPERIMENT_LABEL = "experiment_label";
+    
 
 }
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinByExperimentBrowerToolBar.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinByExperimentBrowerToolBar.java
index 235ebabbfc7..215b59c539a 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinByExperimentBrowerToolBar.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinByExperimentBrowerToolBar.java
@@ -119,6 +119,11 @@ class ProteinByExperimentBrowerToolBar extends ToolBar
             });
         add(new AdapterToolItem(fdrComboBox));
     }
+    
+    Experiment getExperimentOrNull()
+    {
+        return experiment;
+    }
 
     void setBrowserGrid(ProteinByExperimentBrowserGrid browserGrid)
     {
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinByExperimentBrowserGrid.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinByExperimentBrowserGrid.java
index 9be37d252a3..bd5591d5c67 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinByExperimentBrowserGrid.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinByExperimentBrowserGrid.java
@@ -56,23 +56,24 @@ class ProteinByExperimentBrowserGrid extends AbstractSimpleBrowserGrid<ProteinIn
 
     private final IViewContext<IPhosphoNetXClientServiceAsync> specificViewContext;
 
+    private final ProteinByExperimentBrowerToolBar toolbar;
+    
     private ListProteinByExperimentCriteria criteria;
     
     static IDisposableComponent create(
             final IViewContext<IPhosphoNetXClientServiceAsync> viewContext)
     {
-        final ProteinByExperimentBrowerToolBar toolbar =
-                new ProteinByExperimentBrowerToolBar(viewContext);
         final ProteinByExperimentBrowserGrid browserGrid =
                 new ProteinByExperimentBrowserGrid(viewContext);
-        toolbar.setBrowserGrid(browserGrid);
-        return browserGrid.asDisposableWithToolbar(toolbar);
+        return browserGrid.asDisposableWithToolbar(browserGrid.toolbar);
     }
     
     private ProteinByExperimentBrowserGrid(final IViewContext<IPhosphoNetXClientServiceAsync> viewContext)
     {
         super(viewContext.getCommonViewContext(), BROWSER_ID, GRID_ID, false);
         specificViewContext = viewContext;
+        toolbar = new ProteinByExperimentBrowerToolBar(viewContext);
+        toolbar.setBrowserGrid(this);
         setDisplayTypeIDGenerator(PhosphoNetXDisplayTypeIDGenerator.PROTEIN_BY_EXPERIMENT_BROWSER_GRID);
         registerLinkClickListenerFor(ProteinColDefKind.DESCRIPTION.id(),
                 new ICellListener<ProteinInfo>()
@@ -80,7 +81,7 @@ class ProteinByExperimentBrowserGrid extends AbstractSimpleBrowserGrid<ProteinIn
                         public void handle(ProteinInfo rowItem)
                         {
                             DispatcherHelper.dispatchNaviEvent(ProteinViewer.createTabItemFactory(
-                                    viewContext, rowItem));
+                                    viewContext, toolbar.getExperimentOrNull(), rowItem));
                         }
                     });
     }
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinViewer.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinViewer.java
index eb4afb12bde..3db1af446b4 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinViewer.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/client/application/ProteinViewer.java
@@ -20,7 +20,11 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
+import com.extjs.gxt.ui.client.Style.LayoutRegion;
+import com.extjs.gxt.ui.client.Style.Scroll;
 import com.extjs.gxt.ui.client.widget.ContentPanel;
+import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
+import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
 
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericConstants;
@@ -30,7 +34,11 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.IDatabaseModificationObserver;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.ITabItem;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.ITabItemFactory;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractViewer;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property.PropertyGrid;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.StringUtils;
+import ch.systemsx.cisd.openbis.generic.client.web.client.dto.Experiment;
+import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolder;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind;
 import ch.systemsx.cisd.openbis.plugin.phosphonetx.client.web.client.IPhosphoNetXClientServiceAsync;
@@ -42,7 +50,9 @@ import ch.systemsx.cisd.openbis.plugin.phosphonetx.shared.basic.dto.ProteinByExp
  *
  * @author Franz-Josef Elmer
  */
-public class ProteinViewer extends ContentPanel implements IDatabaseModificationObserver
+public class ProteinViewer extends
+        AbstractViewer<IPhosphoNetXClientServiceAsync, IEntityInformationHolder> implements
+        IDatabaseModificationObserver
 {
     private static final String PREFIX = "protein-viewer_";
 
@@ -50,7 +60,7 @@ public class ProteinViewer extends ContentPanel implements IDatabaseModification
     
     static ITabItemFactory createTabItemFactory(
             final IViewContext<IPhosphoNetXClientServiceAsync> viewContext,
-            final ProteinInfo proteinInfo)
+            final Experiment experimentOrNull, final ProteinInfo proteinInfo)
     {
         return new ITabItemFactory()
             {
@@ -62,11 +72,14 @@ public class ProteinViewer extends ContentPanel implements IDatabaseModification
                 public ITabItem create()
                 {
                     ProteinViewer viewer =
-                            new ProteinViewer(viewContext, proteinInfo.getExperimentID(),
-                                    proteinInfo.getId());
+                            new ProteinViewer(viewContext, experimentOrNull, proteinInfo.getId());
                     DatabaseModificationAwareComponent c =
                             new DatabaseModificationAwareComponent(viewer, viewer);
-                    return DefaultTabItem.create("Protein: " + proteinInfo.getDescription(), c,
+                    String description = StringUtils.abbreviate(proteinInfo.getDescription(), 30);
+                    String identifier =
+                            experimentOrNull == null ? "?" : experimentOrNull.getIdentifier();
+                    return DefaultTabItem.create(viewContext.getMessage(
+                            Dict.PROTEIN_IN_EXPERIMENT_TAB_LABEL, description, identifier), c,
                             viewContext, false);
                 }
             };
@@ -78,17 +91,17 @@ public class ProteinViewer extends ContentPanel implements IDatabaseModification
     }
     
     private final IViewContext<IPhosphoNetXClientServiceAsync> viewContext;
+    private final Experiment experimentOrNull;
     private final TechId experimentID;
     private final TechId proteinreferenceID;
-    private final String widgetID;
     
-    private ProteinViewer(IViewContext<IPhosphoNetXClientServiceAsync> viewContext, TechId experimentID,
-            TechId proteinReferenceID)
+    private ProteinViewer(IViewContext<IPhosphoNetXClientServiceAsync> viewContext,
+            Experiment experimentOrNull, TechId proteinReferenceID)
     {
-        widgetID = createWidgetID(proteinReferenceID);
-        setId(widgetID);
+        super(viewContext, "", createWidgetID(proteinReferenceID), false);
         this.viewContext = viewContext;
-        this.experimentID = experimentID;
+        this.experimentOrNull = experimentOrNull;
+        this.experimentID = TechId.create(experimentOrNull);
         this.proteinreferenceID = proteinReferenceID;
         reloadAllData();
     }
@@ -101,11 +114,25 @@ public class ProteinViewer extends ContentPanel implements IDatabaseModification
 
     private void recreateUI(ProteinByExperiment protein)
     {
+        setLayout(new BorderLayout());
+        removeAll();
+        setScrollMode(Scroll.AUTO);
         final Map<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put("Protein Description", protein.getDescription());
-        properties.put("UniProt ID", protein.getUniprotID());
-        final PropertyGrid propertyGrid = new PropertyGrid(viewContext, properties.size());
-        add(propertyGrid);
+        if (experimentOrNull != null)
+        {
+            String identifier = experimentOrNull.getIdentifier();
+            properties.put(viewContext.getMessage(Dict.EXPERIMENT_LABEL), identifier);
+        }
+        properties.put(viewContext.getMessage(Dict.UNIPROT_ID), protein.getUniprotID());
+        properties.put(viewContext.getMessage(Dict.PROTEIN_DESCRIPTION), protein.getDescription());
+        PropertyGrid propertyGrid = new PropertyGrid(viewContext, properties.size());
+        propertyGrid.setProperties(properties);
+        ContentPanel contentPanel = new ContentPanel();
+        contentPanel.add(propertyGrid);
+        BorderLayoutData layoutData = createBorderLayoutData(LayoutRegion.WEST);
+        layoutData.setSize(400);
+        add(contentPanel, layoutData);
+        layout();
     }
 
     public DatabaseModificationKind[] getRelevantModifications()
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/public/phosphonetx-dictionary.js b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/public/phosphonetx-dictionary.js
index 2c16d381ae5..5ecb9cb5fdf 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/public/phosphonetx-dictionary.js
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/client/web/public/phosphonetx-dictionary.js
@@ -11,6 +11,10 @@ var phosphonetx = {
   protein_description: "Protein",
   false_discovery_rate: "FDR",
   
+  // Protein in experiment viewer
+  protein_in_experiment_tab_label: "{0} in {1}",
+  experiment_label: "Experiment",
+  
   // LAST LINE: KEEP IT AT THE END
   lastline: "" // we need a line without a comma
 };
\ No newline at end of file
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java
index c580be21b74..68b5f87703b 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/PhosphoNetXServer.java
@@ -120,6 +120,7 @@ public class PhosphoNetXServer extends AbstractServer<IPhosphoNetXServer> implem
             proteinSequence.setDatabaseNameAndVersion(sequence.getDatabaseNameAndVersion());
             proteinByExperiment.addSequence(proteinSequence);
         }
+        sequences.close();
         return proteinByExperiment;
     }
 
diff --git a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java
index 92ed67fc79c..4a1a8941582 100644
--- a/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java
+++ b/rtd_phosphonetx/source/java/ch/systemsx/cisd/openbis/plugin/phosphonetx/server/dataaccess/IProteinQueryDAO.java
@@ -38,7 +38,7 @@ public interface IProteinQueryDAO extends BaseQuery
     @Select("select pr.id, pr.uniprot_id, pr.description, d.id as data_set_id, p.probability "
             + "from identified_proteins as ip left join proteins as p on ip.prot_id = p.id "
             + "left join data_sets as d on p.dase_id = d.id "
-            + "left join experiments as e on d.expe_id = e.id, " 
+            + "left join experiments as e on d.expe_id = e.id, "
             + "sequences as s left join protein_references as pr on s.prre_id = pr.id "
             + "where e.perm_id = ?{1} and ip.sequ_id = s.id order by pr.description")
     public DataSet<ProteinReferenceWithProbability> listProteinsByExperiment(String experimentPermID);
-- 
GitLab