From b64146a9ddff6e83ad1ab73df8503e19153289c0 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Mon, 6 Sep 2010 09:45:00 +0000
Subject: [PATCH] [LMS-1690] screening solution with only one server call

SVN: 17720
---
 .../ui/material/MaterialBrowserGrid.java      |  38 +-----
 .../ui/material/MaterialBrowserToolbar.java   |  40 +-----
 .../dto/ListMaterialDisplayCriteria.java      |  15 +--
 .../web/client/IScreeningClientService.java   |  15 ++-
 .../client/IScreeningClientServiceAsync.java  |  15 +--
 .../ExperimentWellMaterialBrowserGrid.java    | 116 ++++++++++++++++++
 .../ExperimentWellMaterialsSection.java       |  52 +-------
 .../web/server/ScreeningClientService.java    |  22 +++-
 .../screening/server/ScreeningServer.java     |  19 ++-
 .../server/ScreeningServerLogger.java         |   8 +-
 .../server/dataaccess/IScreeningQuery.java    |  13 +-
 .../screening/shared/IScreeningServer.java    |  12 +-
 12 files changed, 193 insertions(+), 172 deletions(-)
 create mode 100644 screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ExperimentWellMaterialBrowserGrid.java

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserGrid.java
index bffef38d8ae..7fd5a85889c 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserGrid.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserGrid.java
@@ -16,7 +16,6 @@
 
 package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.material;
 
-import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
@@ -40,9 +39,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.Ab
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.ColumnDefsAndConfigs;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.DisposableEntityChooser;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IBrowserGridActionInvoker;
-import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.material.MaterialBrowserToolbar.BasicMaterialCriteriaProvider;
-import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.material.MaterialBrowserToolbar.FilterByIdMaterialCriteriaProvider;
-import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.material.MaterialBrowserToolbar.IMaterialCriteriaProvider;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedActionWithResult;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListMaterialDisplayCriteria;
@@ -81,26 +77,10 @@ public class MaterialBrowserGrid extends
         return createWithTypeChooser(viewContext, true);
     }
 
-    /**
-     * Creates a browser with a toolbar which allows to choose the material type. Allows to show or
-     * edit material details. Only materials with given ids will be shown.
-     */
-    public static DisposableEntityChooser<Material> createWithTypeChooser(
-            final IViewContext<ICommonClientServiceAsync> viewContext,
-            final Collection<Long> allowedMaterialIdsOrNull)
-    {
-        return createWithTypeChooser(viewContext, true, allowedMaterialIdsOrNull);
-    }
-
     private static DisposableEntityChooser<Material> createWithTypeChooser(
-            final IViewContext<ICommonClientServiceAsync> viewContext, boolean detailsAvailable,
-            final Collection<Long> allowedMaterialIdsOrNull)
+            final IViewContext<ICommonClientServiceAsync> viewContext, boolean detailsAvailable)
     {
-        IMaterialCriteriaProvider materialCriteriaProvider =
-                allowedMaterialIdsOrNull == null ? new BasicMaterialCriteriaProvider()
-                        : new FilterByIdMaterialCriteriaProvider(allowedMaterialIdsOrNull);
-        final MaterialBrowserToolbar toolbar =
-                new MaterialBrowserToolbar(viewContext, null, materialCriteriaProvider);
+        final MaterialBrowserToolbar toolbar = new MaterialBrowserToolbar(viewContext, null);
         final ICriteriaProvider<ListMaterialDisplayCriteria> criteriaProvider = toolbar;
         final MaterialBrowserGrid browserGrid =
                 createBrowserGrid(viewContext, criteriaProvider, detailsAvailable);
@@ -109,12 +89,6 @@ public class MaterialBrowserGrid extends
         return browserGrid.asDisposableWithToolbar(toolbar);
     }
 
-    private static DisposableEntityChooser<Material> createWithTypeChooser(
-            final IViewContext<ICommonClientServiceAsync> viewContext, boolean detailsAvailable)
-    {
-        return createWithTypeChooser(viewContext, detailsAvailable, null);
-    }
-
     /**
      * If the material type is given, does not show the toolbar with material type selection and
      * refreshes the grid automatically.<br>
@@ -168,9 +142,9 @@ public class MaterialBrowserGrid extends
 
     }
 
-    private final ICriteriaProvider<ListMaterialDisplayCriteria> criteriaProvider;
+    protected final ICriteriaProvider<ListMaterialDisplayCriteria> criteriaProvider;
 
-    private MaterialBrowserGrid(final IViewContext<ICommonClientServiceAsync> viewContext,
+    protected MaterialBrowserGrid(final IViewContext<ICommonClientServiceAsync> viewContext,
             boolean refreshAutomatically,
             ICriteriaProvider<ListMaterialDisplayCriteria> criteriaProvider)
     {
@@ -186,7 +160,7 @@ public class MaterialBrowserGrid extends
         return criteriaProvider;
     }
 
-    private void extendBottomToolbar(boolean detailsAvailable)
+    protected void extendBottomToolbar(boolean detailsAvailable)
     {
         if (detailsAvailable && viewContext.isSimpleMode() == false)
         {
@@ -225,7 +199,7 @@ public class MaterialBrowserGrid extends
         allowMultipleSelection(); // we allow deletion of multiple materials
     }
 
-    private void addGridRefreshListener(MaterialBrowserToolbar toolbar)
+    protected void addGridRefreshListener(MaterialBrowserToolbar toolbar)
     {
         toolbar.setCriteriaChangedListeners(createGridRefreshDelegatedAction());
     }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserToolbar.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserToolbar.java
index 2bd913701a4..4bbdc03cebd 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserToolbar.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserToolbar.java
@@ -19,7 +19,6 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.materi
 import static ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind.createOrDelete;
 import static ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind.edit;
 
-import java.util.Collection;
 import java.util.Set;
 
 import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
@@ -46,7 +45,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKin
  * 
  * @author Izabela Adamczyk
  */
-class MaterialBrowserToolbar extends ToolBar implements
+public class MaterialBrowserToolbar extends ToolBar implements
         ICriteriaProvider<ListMaterialDisplayCriteria>
 {
     public static final String ID = "material-browser-toolbar";
@@ -55,16 +54,13 @@ class MaterialBrowserToolbar extends ToolBar implements
 
     private final IViewContext<ICommonClientServiceAsync> viewContext;
 
-    private final IMaterialCriteriaProvider materialCriteriaProvider;
-
     public MaterialBrowserToolbar(final IViewContext<ICommonClientServiceAsync> viewContext,
-            MaterialType initValueOrNull, IMaterialCriteriaProvider materialCriteriaProvider)
+            MaterialType initValueOrNull)
     {
         this.viewContext = viewContext;
         this.selectMaterialTypeCombo =
                 MaterialTypeSelectionWidget
                         .createWithInitialValue(viewContext, initValueOrNull, ID);
-        this.materialCriteriaProvider = materialCriteriaProvider;
         display();
     }
 
@@ -97,7 +93,7 @@ class MaterialBrowserToolbar extends ToolBar implements
         {
             return null;
         }
-        return materialCriteriaProvider.getMaterialCriteria(selectedType);
+        return ListMaterialDisplayCriteria.createForMaterialType(selectedType);
     }
 
     @Override
@@ -129,34 +125,4 @@ class MaterialBrowserToolbar extends ToolBar implements
         }
     }
 
-    public interface IMaterialCriteriaProvider
-    {
-        public ListMaterialDisplayCriteria getMaterialCriteria(MaterialType type);
-    }
-
-    public static class BasicMaterialCriteriaProvider implements IMaterialCriteriaProvider
-    {
-
-        public ListMaterialDisplayCriteria getMaterialCriteria(MaterialType type)
-        {
-            return ListMaterialDisplayCriteria.createForMaterialType(type);
-        }
-    }
-
-    public static class FilterByIdMaterialCriteriaProvider implements IMaterialCriteriaProvider
-    {
-        private final Collection<Long> allowedMaterialIds;
-
-        public FilterByIdMaterialCriteriaProvider(Collection<Long> allowedMaterialIds)
-        {
-            this.allowedMaterialIds = allowedMaterialIds;
-        }
-
-        public ListMaterialDisplayCriteria getMaterialCriteria(MaterialType type)
-        {
-            return ListMaterialDisplayCriteria.createForMaterialTypeAndMaterialIds(type,
-                    allowedMaterialIds);
-        }
-    }
-
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ListMaterialDisplayCriteria.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ListMaterialDisplayCriteria.java
index defa44eef71..3a898230427 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ListMaterialDisplayCriteria.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/dto/ListMaterialDisplayCriteria.java
@@ -16,8 +16,6 @@
 
 package ch.systemsx.cisd.openbis.generic.client.web.client.dto;
 
-import java.util.Collection;
-
 import com.google.gwt.user.client.rpc.IsSerializable;
 
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListMaterialCriteria;
@@ -34,22 +32,15 @@ public class ListMaterialDisplayCriteria extends DefaultResultSetConfig<String,
 {
     public static ListMaterialDisplayCriteria createForMaterialType(final MaterialType materialType)
     {
-        return new ListMaterialDisplayCriteria(materialType, null);
-    }
-
-    public static ListMaterialDisplayCriteria createForMaterialTypeAndMaterialIds(
-            final MaterialType materialType, final Collection<Long> materialIds)
-    {
-        return new ListMaterialDisplayCriteria(materialType, materialIds);
+        return new ListMaterialDisplayCriteria(materialType);
     }
 
     private ListMaterialCriteria listCriteria;
 
-    private ListMaterialDisplayCriteria(final MaterialType materialType,
-            final Collection<Long> materialIdsOrNull)
+    private ListMaterialDisplayCriteria(final MaterialType materialType)
     {
         assert materialType != null : "material type not set";
-        this.listCriteria = new ListMaterialCriteria(materialType, materialIdsOrNull);
+        this.listCriteria = new ListMaterialCriteria(materialType);
     }
 
     public ListMaterialCriteria getListCriteria()
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientService.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientService.java
index 51b8997f058..7eb89f700a0 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientService.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientService.java
@@ -16,7 +16,6 @@
 
 package ch.systemsx.cisd.openbis.plugin.screening.client.web.client;
 
-import java.util.Collection;
 import java.util.List;
 
 import ch.systemsx.cisd.openbis.generic.client.web.client.IClientService;
@@ -24,12 +23,14 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientService;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GenericTableResultSet;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.IResultSetConfig;
+import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListMaterialDisplayCriteria;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableExportCriteria;
 import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Vocabulary;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.LibraryRegistrationInfo;
@@ -75,11 +76,6 @@ public interface IScreeningClientService extends IClientService
      */
     public PlateImages getPlateContentForDataset(TechId datasetId);
 
-    /**
-     * @return ids of materials in experiment with specified id.
-     */
-    public Collection<Long> listExperimentMaterials(TechId experimentTechId);
-
     /**
      * @return well locations which belong to a parent plate connected to a specified experiment(s)
      *         and have specified material(s) inside.
@@ -101,6 +97,12 @@ public interface IScreeningClientService extends IClientService
             IResultSetConfig<String, GenericTableRow> resultSetConfig, TechId sampleId)
             throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException;
 
+    /**
+     * Lists {@link Material}s of specified type in experiment with specified id.
+     */
+    public ResultSet<Material> listExperimentMaterials(TechId experimentId,
+            ListMaterialDisplayCriteria criteria);
+
     /**
      * Like {@link ICommonClientService#prepareExportSamples(TableExportCriteria)}, but for
      * GenericTableRow.
@@ -121,4 +123,5 @@ public interface IScreeningClientService extends IClientService
      * Returns plate geometry vocabulary.
      */
     public Vocabulary getPlateGeometryVocabulary() throws UserFailureException;
+
 }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientServiceAsync.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientServiceAsync.java
index 00153dadb85..bac854bcfef 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientServiceAsync.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/IScreeningClientServiceAsync.java
@@ -16,7 +16,6 @@
 
 package ch.systemsx.cisd.openbis.plugin.screening.client.web.client;
 
-import java.util.Collection;
 import java.util.List;
 
 import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -25,11 +24,13 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.IClientServiceAsync;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GenericTableResultSet;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.IResultSetConfig;
+import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListMaterialDisplayCriteria;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableExportCriteria;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Vocabulary;
 import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.LibraryRegistrationInfo;
@@ -62,12 +63,6 @@ public interface IScreeningClientServiceAsync extends IClientServiceAsync
     /** @see IScreeningClientService#getDataSetInfo(TechId) */
     public void getDataSetInfo(TechId datasetTechId, AsyncCallback<ExternalData> callback);
 
-    /**
-     * @see IScreeningClientService#listExperimentMaterials(TechId)
-     */
-    public void listExperimentMaterials(TechId experimentId,
-            AsyncCallback<Collection<Long>> callback);
-
     /**
      * @see IScreeningClientService#listPlateWells(DefaultResultSetConfig,
      *      PlateMaterialsSearchCriteria)
@@ -111,4 +106,10 @@ public interface IScreeningClientServiceAsync extends IClientServiceAsync
      * @see IScreeningClientService#getPlateGeometryVocabulary()
      */
     public void getPlateGeometryVocabulary(AsyncCallback<Vocabulary> callback);
+
+    /**
+     * @see IScreeningClientService#listExperimentMaterials(TechId, ListMaterialDisplayCriteria)
+     */
+    public void listExperimentMaterials(TechId experimentId, ListMaterialDisplayCriteria criteria,
+            AsyncCallback<ResultSet<Material>> callback);
 }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ExperimentWellMaterialBrowserGrid.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ExperimentWellMaterialBrowserGrid.java
new file mode 100644
index 00000000000..e4cde4ed26e
--- /dev/null
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ExperimentWellMaterialBrowserGrid.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2008 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.plugin.screening.client.web.client.application.detailviewers;
+
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.DisposableEntityChooser;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.material.MaterialBrowserGrid;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.material.MaterialBrowserToolbar;
+import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig;
+import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListMaterialDisplayCriteria;
+import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet;
+import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableExportCriteria;
+import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
+import ch.systemsx.cisd.openbis.plugin.screening.client.web.client.IScreeningClientServiceAsync;
+
+/**
+ * A {@link MaterialBrowserGrid} extension for showing materials used in wells of an experiment.
+ * 
+ * @author Piotr Buczek
+ */
+public class ExperimentWellMaterialBrowserGrid extends MaterialBrowserGrid
+{
+    /**
+     * Creates a browser with a toolbar which allows to choose the material type. Allows to show or
+     * edit material details.
+     */
+    public static DisposableEntityChooser<Material> createForExperiment(
+            final IViewContext<IScreeningClientServiceAsync> screeningViewContext,
+            TechId experimentId)
+    {
+        return createWithTypeChooser(screeningViewContext, experimentId);
+    }
+
+    private static DisposableEntityChooser<Material> createWithTypeChooser(
+            final IViewContext<IScreeningClientServiceAsync> screeningViewContext,
+            final TechId experimentId)
+    {
+        final MaterialBrowserToolbar toolbar =
+                new MaterialBrowserToolbar(screeningViewContext.getCommonViewContext(), null);
+        final ICriteriaProvider<ListMaterialDisplayCriteria> criteriaProvider = toolbar;
+        final ExperimentWellMaterialBrowserGrid browserGrid =
+                createBrowserGrid(screeningViewContext, criteriaProvider, experimentId);
+        browserGrid.addGridRefreshListener(toolbar);
+        browserGrid.extendBottomToolbar(true);
+        return browserGrid.asDisposableWithToolbar(toolbar);
+    }
+
+    private static ExperimentWellMaterialBrowserGrid createBrowserGrid(
+            final IViewContext<IScreeningClientServiceAsync> screeningViewContext,
+            final ICriteriaProvider<ListMaterialDisplayCriteria> criteriaProvider,
+            final TechId experimentId)
+    {
+        return new ExperimentWellMaterialBrowserGrid(screeningViewContext, true, criteriaProvider,
+                experimentId);
+    }
+
+    private final IViewContext<IScreeningClientServiceAsync> screeningViewContext;
+
+    private final TechId experimentId;
+
+    protected ExperimentWellMaterialBrowserGrid(
+            final IViewContext<IScreeningClientServiceAsync> screeningViewContext,
+            boolean refreshAutomatically,
+            ICriteriaProvider<ListMaterialDisplayCriteria> criteriaProvider, TechId experimentId)
+    {
+        super(screeningViewContext.getCommonViewContext(), refreshAutomatically, criteriaProvider);
+        this.screeningViewContext = screeningViewContext;
+        this.experimentId = experimentId;
+    }
+
+    @Override
+    protected ICriteriaProvider<ListMaterialDisplayCriteria> getCriteriaProvider()
+    {
+        return criteriaProvider;
+    }
+
+    @Override
+    protected void listEntities(DefaultResultSetConfig<String, Material> resultSetConfig,
+            AbstractAsyncCallback<ResultSet<Material>> callback)
+    {
+        criteria.copyPagingConfig(resultSetConfig);
+        screeningViewContext.getService().listExperimentMaterials(experimentId, criteria, callback);
+    }
+
+    // TODO 2010-09-06, Piotr Buczek: check
+    @Override
+    protected void prepareExportEntities(TableExportCriteria<Material> exportCriteria,
+            AbstractAsyncCallback<String> callback)
+    {
+        viewContext.getService().prepareExportMaterials(exportCriteria, callback);
+    }
+
+    // TODO 2010-09-06, Piotr Buczek: set experiment
+    // @Override
+    // protected void showEntityViewer(Material material, boolean editMode, boolean active)
+    // {
+    // showEntityInformationHolderViewer(material, editMode, active);
+    // }
+
+}
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ExperimentWellMaterialsSection.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ExperimentWellMaterialsSection.java
index e75687356d7..cdd820c5070 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ExperimentWellMaterialsSection.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ExperimentWellMaterialsSection.java
@@ -1,14 +1,8 @@
 package ch.systemsx.cisd.openbis.plugin.screening.client.web.client.application.detailviewers;
 
-import java.util.Collection;
-
-import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync;
-import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.DisposableSectionPanel;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.IViewContext;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.IDisposableComponent;
-import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.material.MaterialBrowserGrid;
-import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedAction;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.plugin.screening.client.web.client.IScreeningClientServiceAsync;
@@ -28,8 +22,6 @@ public class ExperimentWellMaterialsSection extends DisposableSectionPanel
 
     private final IEntityInformationHolderWithIdentifier experiment;
 
-    private Collection<Long> allowedMaterialIds;
-
     public ExperimentWellMaterialsSection(
             IViewContext<IScreeningClientServiceAsync> screeningViewContext,
             IEntityInformationHolderWithIdentifier experiment)
@@ -41,51 +33,11 @@ public class ExperimentWellMaterialsSection extends DisposableSectionPanel
         setDisplayID(DisplayTypeIDGenerator.PLATE_MATERIAL_BROWSER, ID_SUFFIX);
     }
 
-    @Override
-    protected void showContent()
-    {
-        IDelegatedAction onSuccessAction = new IDelegatedAction()
-            {
-                public void execute()
-                {
-                    ExperimentWellMaterialsSection.super.showContent();
-                }
-            };
-        screeningViewContext.getService().listExperimentMaterials(
-                TechId.create(experiment),
-                new ListMaterialIdsCallback(viewContext.getCommonViewContext(), this,
-                        onSuccessAction));
-    }
-
     @Override
     protected IDisposableComponent createDisposableContent()
     {
-        return MaterialBrowserGrid.createWithTypeChooser(viewContext.getCommonViewContext(),
-                allowedMaterialIds);
-    }
-
-    private final class ListMaterialIdsCallback extends AbstractAsyncCallback<Collection<Long>>
-    {
-
-        private final IDelegatedAction onSuccessAction;
-
-        private ExperimentWellMaterialsSection section;
-
-        public ListMaterialIdsCallback(final IViewContext<ICommonClientServiceAsync> viewContext,
-                ExperimentWellMaterialsSection section, IDelegatedAction onSuccessAction)
-        {
-            super(viewContext);
-            this.section = section;
-            this.onSuccessAction = onSuccessAction;
-        }
-
-        @Override
-        protected void process(Collection<Long> result)
-        {
-            section.allowedMaterialIds = result;
-            onSuccessAction.execute();
-        }
-
+        return ExperimentWellMaterialBrowserGrid.createForExperiment(screeningViewContext, TechId
+                .create(experiment));
     }
 
 }
\ No newline at end of file
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/server/ScreeningClientService.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/server/ScreeningClientService.java
index 002666c851b..d8367e373a2 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/server/ScreeningClientService.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/server/ScreeningClientService.java
@@ -16,7 +16,6 @@
 
 package ch.systemsx.cisd.openbis.plugin.screening.client.web.server;
 
-import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -37,6 +36,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.DefaultResultSetConfig;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.GenericTableResultSet;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.IResultSetConfig;
+import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ListMaterialDisplayCriteria;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.ResultSet;
 import ch.systemsx.cisd.openbis.generic.client.web.client.dto.TableExportCriteria;
 import ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException;
@@ -50,6 +50,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableColumnHeader;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericTableRow;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Vocabulary;
 import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifierFactory;
@@ -311,9 +312,22 @@ public final class ScreeningClientService extends AbstractClientService implemen
                 .listImageChannelStacks(sessionToken, datasetCode, datastoreCode, wellLocation);
     }
 
-    public Collection<Long> listExperimentMaterials(TechId experimentId)
+    public ResultSet<Material> listExperimentMaterials(final TechId experimentId,
+            final ListMaterialDisplayCriteria displayCriteria)
     {
-        final String sessionToken = getSessionToken();
-        return server.listExperimentMaterials(sessionToken, experimentId);
+        try
+        {
+            return listEntities(displayCriteria, new IOriginalDataProvider<Material>()
+                {
+                    public List<Material> getOriginalData() throws UserFailureException
+                    {
+                        return server.listExperimentMaterials(getSessionToken(), experimentId,
+                                displayCriteria.getListCriteria().getMaterialType());
+                    }
+                });
+        } catch (final ch.systemsx.cisd.common.exceptions.UserFailureException e)
+        {
+            throw UserFailureExceptionTranslator.translate(e);
+        }
     }
 }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java
index dec15a8020c..492e7f68bcc 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java
@@ -42,6 +42,9 @@ import ch.systemsx.cisd.openbis.generic.server.plugin.ISampleTypeSlaveServerPlug
 import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListMaterialCriteria;
+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.SampleParentWithDerived;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Vocabulary;
@@ -246,17 +249,20 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl
                 materialTypeIdentifierOrNull);
     }
 
-    public Collection<Long> listExperimentMaterials(String sessionToken, TechId experimentId)
+    public List<Material> listExperimentMaterials(String sessionToken, TechId experimentId,
+            MaterialType materialType)
     {
         // TODO 2010-09-01, Piotr Buczek: move it to some BO when we have more queries like that
         IScreeningQuery dao = createDAO(getDAOFactory());
-        DataIterator<Long> iterator = dao.getMaterialsForExperimentWells(experimentId.getId());
-        Collection<Long> result = new ArrayList<Long>();
-        for (Long l : iterator)
+        DataIterator<Long> materialIdsIterator =
+                dao.getMaterialsForExperimentWells(experimentId.getId(), materialType.getId());
+        Collection<Long> materialIds = new ArrayList<Long>();
+        for (Long id : materialIdsIterator)
         {
-            result.add(l);
+            materialIds.add(id);
         }
-        return result;
+        return commonServer.listMaterials(sessionToken, new ListMaterialCriteria(materialType,
+                materialIds), true);
     }
 
     private static IScreeningQuery createDAO(IDAOFactory daoFactory)
@@ -297,4 +303,5 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl
     {
         return MINOR_VERSION;
     }
+
 }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServerLogger.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServerLogger.java
index 995b9be958b..de8f71dd203 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServerLogger.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServerLogger.java
@@ -25,6 +25,8 @@ import ch.systemsx.cisd.common.spring.IInvocationLoggerContext;
 import ch.systemsx.cisd.openbis.generic.server.AbstractServerLogger;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
+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.NewAttachment;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived;
@@ -208,9 +210,11 @@ final class ScreeningServerLogger extends AbstractServerLogger implements IScree
         return null;
     }
 
-    public Collection<Long> listExperimentMaterials(String sessionToken, TechId experimentId)
+    public List<Material> listExperimentMaterials(String sessionToken, TechId experimentId,
+            MaterialType materialType)
     {
-        logAccess(sessionToken, "listExperimentMaterials", "experimentId(%s)", experimentId);
+        logAccess(sessionToken, "listExperimentMaterials", "experimentId(%s), materialType(%s)",
+                experimentId, materialType);
         return null;
     }
 
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 01cb5665e4d..b77622205f5 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
@@ -210,17 +210,6 @@ public interface IScreeningQuery extends BaseQuery
             + "         and pt.is_internal_namespace = true and space.code = ?{1} and pl.code = ?{2}")
     public PlateGeometryContainer tryGetPlateGeometry(String spaceCode, String plateCode);
 
-    /**
-     * Returns the ids of all materials used in specified experiment.
-     */
-    @Select(sql = "SELECT distinct well_material.id            "
-            + "      FROM samples pl                           "
-            + "      JOIN samples well ON well.samp_id_part_of = pl.id"
-            + "      JOIN sample_properties well_props ON well_props.samp_id = well.id"
-            + "      JOIN materials well_material ON well_material.id = well_props.mate_prop_id"
-            + "     WHERE pl.expe_id = ?{1}", fetchSize = FETCH_SIZE)
-    public DataIterator<Long> getMaterialsForExperimentWells(long experimentId);
-
     /**
      * Returns the ids of materials of specified type and used in specified experiment.
      */
@@ -230,7 +219,7 @@ public interface IScreeningQuery extends BaseQuery
             + "      JOIN sample_properties well_props ON well_props.samp_id = well.id"
             + "      JOIN materials well_material ON well_material.id = well_props.mate_prop_id"
             + "     WHERE pl.expe_id = ?{1}                   "
-            + "       AND well_material.maty_id = {2}", fetchSize = FETCH_SIZE)
+            + "       AND well_material.maty_id = ?{2}", fetchSize = FETCH_SIZE)
     public DataIterator<Long> getMaterialsForExperimentWells(long experimentId, long materialTypeId);
 
 }
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/IScreeningServer.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/IScreeningServer.java
index 62c23602212..056a1c77e1a 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/IScreeningServer.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/IScreeningServer.java
@@ -16,7 +16,6 @@
 
 package ch.systemsx.cisd.openbis.plugin.screening.shared;
 
-import java.util.Collection;
 import java.util.List;
 
 import org.springframework.transaction.annotation.Transactional;
@@ -32,6 +31,8 @@ import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.AbstractT
 import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.AbstractTechIdPredicate.ExperimentTechIdPredicate;
 import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
+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.RoleWithHierarchy;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived;
@@ -79,12 +80,15 @@ public interface IScreeningServer extends IServer
             @AuthorizationGuard(guardClass = PlateMaterialsSearchCriteriaPredicate.class) PlateMaterialsSearchCriteria materialCriteria);
 
     /**
-     * Loads all ids of materials connected with the specified experiment.
+     * Loads all materials of specified type connected with the specified experiment.
+     * 
+     * @param materialType
      */
     @Transactional(readOnly = true)
     @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER)
-    public Collection<Long> listExperimentMaterials(String sessionToken,
-            @AuthorizationGuard(guardClass = ExperimentTechIdPredicate.class) TechId experimentId);
+    public List<Material> listExperimentMaterials(String sessionToken,
+            @AuthorizationGuard(guardClass = ExperimentTechIdPredicate.class) TechId experimentId,
+            MaterialType materialType);
 
     @Transactional
     @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER)
-- 
GitLab