From 68a80d11c0e3034a9e14a38ed483a716ab6198e5 Mon Sep 17 00:00:00 2001
From: kaloyane <kaloyane>
Date: Fri, 16 Sep 2011 09:33:24 +0000
Subject: [PATCH] [LMS-2538] Sanofi: do not show irrelevant analysis procedures

SVN: 22967
---
 .../ui/widget/SimpleModelComboBox.java        | 15 ++++++++
 .../AnalysisProcedureChooser.java             | 34 +++++++++++--------
 .../server/dataaccess/IScreeningQuery.java    |  6 +++-
 3 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/SimpleModelComboBox.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/SimpleModelComboBox.java
index 65bfc4d68cf..3dd7736e671 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/SimpleModelComboBox.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/SimpleModelComboBox.java
@@ -126,4 +126,19 @@ public class SimpleModelComboBox<T> extends SimpleComboBox<LabeledItem<T>>
     {
         return se.getSelectedItem().getValue().getItem();
     }
+
+    public LabeledItem<T> findModelForVal(T val)
+    {
+        LabeledItem<T> result = null;
+        for (SimpleComboValue<LabeledItem<T>> c : getStore().getModels())
+        {
+            if (c.getValue().getItem().equals(value))
+            {
+                result = c.getValue();
+                break;
+            }
+        }
+        return result;
+    }
+
 }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/AnalysisProcedureChooser.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/AnalysisProcedureChooser.java
index 98800f971c3..cf36f2e0624 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/AnalysisProcedureChooser.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/AnalysisProcedureChooser.java
@@ -27,7 +27,6 @@ import com.extjs.gxt.ui.client.widget.Component;
 import com.extjs.gxt.ui.client.widget.LayoutContainer;
 import com.extjs.gxt.ui.client.widget.VerticalPanel;
 import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
-import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
 import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.Widget;
@@ -35,6 +34,8 @@ import com.google.gwt.user.client.ui.Widget;
 import ch.systemsx.cisd.common.shared.basic.utils.StringUtils;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.GenericConstants;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.LabeledItem;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.SimpleModelComboBox;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider;
 import ch.systemsx.cisd.openbis.plugin.screening.client.web.client.IScreeningClientServiceAsync;
 import ch.systemsx.cisd.openbis.plugin.screening.client.web.client.application.Dict;
@@ -157,7 +158,7 @@ class AnalysisProcedureChooser extends LayoutContainer
 
     private final AnalysisProcedureLister analysisProcedureLister;
 
-    private final SimpleComboBox<String> analysisProceduresComboBox;
+    private final SimpleModelComboBox<String> analysisProceduresComboBox;
 
     private final Listener<BaseEvent> selectionChangeListener = new Listener<BaseEvent>()
         {
@@ -185,10 +186,10 @@ class AnalysisProcedureChooser extends LayoutContainer
         initSelection(selectedAnalysisProcedureOrNull, triggerInitialSelectionEvent);
     }
 
-    private SimpleComboBox<String> createLayout(boolean horizontalLayout)
+    private SimpleModelComboBox<String> createLayout(boolean horizontalLayout)
     {
 
-        SimpleComboBox<String> comboBox = createProceduresComboBox();
+        SimpleModelComboBox<String> comboBox = createProceduresComboBox();
         Widget layoutPanel;
         if (horizontalLayout)
         {
@@ -275,11 +276,12 @@ class AnalysisProcedureChooser extends LayoutContainer
                 + GenericConstants.LABEL_SEPARATOR;
     }
 
-    private SimpleComboBox<String> createProceduresComboBox()
+    private SimpleModelComboBox<String> createProceduresComboBox()
     {
-        SimpleComboBox<String> comboBox = new SimpleComboBox<String>();
+        SimpleModelComboBox<String> comboBox =
+                new SimpleModelComboBox<String>(messageProvider,
+                        new ArrayList<LabeledItem<String>>(), COMBOX_WIDTH_PX);
 
-        comboBox.setWidth(COMBOX_WIDTH_PX);
         comboBox.setTriggerAction(TriggerAction.ALL);
         comboBox.setAllowBlank(false);
         comboBox.setEditable(false);
@@ -317,9 +319,9 @@ class AnalysisProcedureChooser extends LayoutContainer
 
     private void addCodeToComboBox(String code)
     {
-        if (analysisProceduresComboBox.findModel(code) == null)
+        if (analysisProceduresComboBox.findModelForVal(code) == null)
         {
-            analysisProceduresComboBox.add(code);
+            analysisProceduresComboBox.add(new LabeledItem<String>(code, code));
         }
     }
 
@@ -333,17 +335,18 @@ class AnalysisProcedureChooser extends LayoutContainer
 
         String comboBoxValue = analysisCodeToComboBoxValue(analysisProcedureOrNull);
 
-        if (UNSPECIFIED_PROCEDURE.equals(comboBoxValue)
-                || analysisProceduresComboBox.findModel(comboBoxValue) == null)
+        LabeledItem<String> valueToSelect =
+                analysisProceduresComboBox.findModelForVal(comboBoxValue);
+        if (UNSPECIFIED_PROCEDURE.equals(comboBoxValue) || valueToSelect == null)
         {
-            comboBoxValue = getFirstValueFromCombo();
+            valueToSelect = getFirstValueFromCombo();
         }
 
-        analysisProceduresComboBox.setSimpleValue(comboBoxValue);
+        analysisProceduresComboBox.setSimpleValue(valueToSelect);
 
     }
 
-    private String getFirstValueFromCombo()
+    private LabeledItem<String> getFirstValueFromCombo()
     {
         return analysisProceduresComboBox.getStore().getAt(0).getValue();
     }
@@ -357,7 +360,7 @@ class AnalysisProcedureChooser extends LayoutContainer
 
     private AnalysisProcedureCriteria getSelectionAsCriteria()
     {
-        String selection = analysisProceduresComboBox.getSimpleValue();
+        String selection = analysisProceduresComboBox.getChosenItem();
         String analysisProcedureOrNull = comboBoxValueToAnalysisProcedure(selection);
         return StringUtils.isBlank(analysisProcedureOrNull) ? AnalysisProcedureCriteria
                 .createNoProcedures() : AnalysisProcedureCriteria
@@ -388,4 +391,5 @@ class AnalysisProcedureChooser extends LayoutContainer
     {
         return UNSPECIFIED_PROCEDURE.equals(comboBoxValue) ? null : comboBoxValue;
     }
+
 }
\ No newline at end of file
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/IScreeningQuery.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/IScreeningQuery.java
index d4c1203a3ca..added4d60cb 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/IScreeningQuery.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/dataaccess/IScreeningQuery.java
@@ -316,10 +316,14 @@ public interface IScreeningQuery extends BaseQuery
                     + "  where "
                     + "       dst_pt.prty_id = (select id from property_types where code='ANALYSIS_PROCEDURE' and is_internal_namespace=true)";
 
+    final static String AT_LEAST_ONE_WELL_EXISTS = "EXISTS (select wells.id "
+            + "             from samples wells "
+            + "                     join samples plates on wells.samp_id_part_of = plates.id "
+            + "             where plates.expe_id = exp.id) ";
     @Select(sql = ANALYSIS_PROCEDURE_SELECT)
     public List<AnalysisProcedureResult> listAllAnalysisProcedures();
 
-    @Select(sql = ANALYSIS_PROCEDURE_SELECT + " and exp.id = ?{1} ")
+    @Select(sql = ANALYSIS_PROCEDURE_SELECT + " and exp.id = ?{1} and " + AT_LEAST_ONE_WELL_EXISTS)
     public List<AnalysisProcedureResult> listAnalysisProceduresForExperiment(long experimentId);
 
 }
-- 
GitLab