From e2f28675d6a1dafad026600ffb1c73e86c15ef7a Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Tue, 6 Jul 2010 12:32:37 +0000
Subject: [PATCH] [LMS-1600] make sample browser ids unique

SVN: 16866
---
 .../framework/ComponentProvider.java          |  2 +-
 .../ui/sample/SampleBrowserGrid.java          | 54 ++++++++++++-------
 .../ui/sample/SampleSearchHitGrid.java        |  8 +--
 .../experiment/ExperimentSamplesSection.java  |  9 +++-
 .../sample/ContainerSamplesSection.java       | 11 ++--
 .../sample/DerivedSamplesSection.java         |  7 ++-
 .../client/application/SampleBrowserTest.java |  4 +-
 .../web/client/application/ui/Logout.java     |  5 --
 .../ui/sample/CheckSampleTable.java           |  2 +-
 .../ui/sample/ExportSamplesTestCommand.java   |  2 +-
 .../application/ui/sample/ShowSample.java     |  7 ++-
 11 files changed, 65 insertions(+), 46 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java
index b915f5381e8..6069017394c 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/framework/ComponentProvider.java
@@ -121,7 +121,7 @@ public final class ComponentProvider
                 @Override
                 public String getId()
                 {
-                    return SampleBrowserGrid.BROWSER_ID;
+                    return SampleBrowserGrid.MAIN_BROWSER_ID;
                 }
 
                 @Override
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java
index 13975747e07..1e25d561846 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleBrowserGrid.java
@@ -89,13 +89,15 @@ public class SampleBrowserGrid extends
     private static final String PREFIX = GenericConstants.ID_PREFIX + "sample-browser";
 
     // browser consists of the grid and additional toolbars (paging, filtering)
-    public static final String BROWSER_ID = PREFIX + "_main";
+    public static final String MAIN_BROWSER_ID = PREFIX + "_main";
 
-    public static final String GRID_ID = PREFIX + "_grid";
+    public static final String MAIN_GRID_ID = createGridId(MAIN_BROWSER_ID);
 
-    public static final String EDIT_BUTTON_ID = BROWSER_ID + "_edit-button";
+    public static final String GRID_ID_SUFFIX = "_grid";
 
-    public static final String SHOW_DETAILS_BUTTON_ID = BROWSER_ID + "_show-details-button";
+    public static final String EDIT_BUTTON_ID_SUFFIX = "_edit-button";
+
+    public static final String SHOW_DETAILS_BUTTON_ID_SUFFIX = "_show-details-button";
 
     /** Creates a grid without additional toolbar buttons. It can serve as a entity chooser. */
     public static DisposableEntityChooser<Sample> createChooser(
@@ -107,7 +109,7 @@ public class SampleBrowserGrid extends
                         sampleTypeID);
         ISampleCriteriaProvider criteriaProvider = toolbar;
         final SampleBrowserGrid browserGrid =
-                new SampleBrowserGrid(viewContext, criteriaProvider, GRID_ID, BROWSER_ID, false,
+                new SampleBrowserGrid(viewContext, criteriaProvider, MAIN_BROWSER_ID, false,
                         DisplayTypeIDGenerator.ENTITY_BROWSER_GRID)
                     {
                         @Override
@@ -133,7 +135,7 @@ public class SampleBrowserGrid extends
                         initialSampleTypeOrNull, SampleTypeDisplayID.MAIN_SAMPLE_BROWSER);
         ISampleCriteriaProvider criteriaProvider = toolbar;
         final SampleBrowserGrid browserGrid =
-                new SampleBrowserGrid(viewContext, criteriaProvider, GRID_ID, BROWSER_ID, false,
+                new SampleBrowserGrid(viewContext, criteriaProvider, MAIN_BROWSER_ID, false,
                         DisplayTypeIDGenerator.ENTITY_BROWSER_GRID);
         browserGrid.addGridRefreshListener(toolbar);
         browserGrid.extendBottomToolbar();
@@ -142,14 +144,14 @@ public class SampleBrowserGrid extends
 
     public static IDisposableComponent createGridForContainerSamples(
             final IViewContext<ICommonClientServiceAsync> viewContext,
-            final TechId containerSampleId, final String gridId, final SampleType sampleType)
+            final TechId containerSampleId, final String browserId, final SampleType sampleType)
     {
         final ListSampleDisplayCriteria criteria =
                 ListSampleDisplayCriteria.createForContainer(containerSampleId);
         final String entityTypeCode = sampleType.getCode();
 
         final SampleBrowserGrid browserGrid =
-                createGridAsComponent(viewContext, gridId, criteria, entityTypeCode,
+                createGridAsComponent(viewContext, browserId, criteria, entityTypeCode,
                         DisplayTypeIDGenerator.SAMPLE_DETAILS_GRID);
         browserGrid.updateCriteriaProviderAndRefresh();
         browserGrid.extendBottomToolbar();
@@ -158,14 +160,14 @@ public class SampleBrowserGrid extends
 
     public static IDisposableComponent createGridForDerivedSamples(
             final IViewContext<ICommonClientServiceAsync> viewContext, final TechId parentSampleId,
-            final String gridId, final SampleType sampleType)
+            final String browserId, final SampleType sampleType)
     {
         final ListSampleDisplayCriteria criteria =
                 ListSampleDisplayCriteria.createForParent(parentSampleId);
         final String entityTypeCode = sampleType.getCode();
 
         final SampleBrowserGrid browserGrid =
-                createGridAsComponent(viewContext, gridId, criteria, entityTypeCode,
+                createGridAsComponent(viewContext, browserId, criteria, entityTypeCode,
                         DisplayTypeIDGenerator.SAMPLE_DETAILS_GRID);
         browserGrid.updateCriteriaProviderAndRefresh();
         browserGrid.extendBottomToolbar();
@@ -174,14 +176,14 @@ public class SampleBrowserGrid extends
 
     public static IDisposableComponent createGridForExperimentSamples(
             final IViewContext<ICommonClientServiceAsync> viewContext, final TechId experimentId,
-            final String gridId, final BasicEntityType experimentType)
+            final String browserId, final BasicEntityType experimentType)
     {
         final ListSampleDisplayCriteria criteria =
                 ListSampleDisplayCriteria.createForExperiment(experimentId);
         final String entityTypeCode = experimentType.getCode();
 
         final SampleBrowserGrid browserGrid =
-                createGridAsComponent(viewContext, gridId, criteria, entityTypeCode,
+                createGridAsComponent(viewContext, browserId, criteria, entityTypeCode,
                         DisplayTypeIDGenerator.EXPERIMENT_DETAILS_GRID);
         browserGrid.updateCriteriaProviderAndRefresh();
         browserGrid.extendBottomToolbar();
@@ -189,7 +191,7 @@ public class SampleBrowserGrid extends
     }
 
     private static SampleBrowserGrid createGridAsComponent(
-            final IViewContext<ICommonClientServiceAsync> viewContext, final String gridId,
+            final IViewContext<ICommonClientServiceAsync> viewContext, final String browserId,
             final ListSampleDisplayCriteria criteria, final String entityTypeCode,
             DisplayTypeIDGenerator displayTypeIDGenerator)
     {
@@ -199,7 +201,7 @@ public class SampleBrowserGrid extends
         // be loaded
         boolean refreshAutomatically = false;
         final SampleBrowserGrid browserGrid =
-                new SampleBrowserGrid(viewContext, criteriaProvider, gridId, BROWSER_ID,
+                new SampleBrowserGrid(viewContext, criteriaProvider, browserId,
                         refreshAutomatically, displayTypeIDGenerator)
                     {
                         @Override
@@ -311,10 +313,10 @@ public class SampleBrowserGrid extends
     private final ISampleCriteriaProvider propertyTypesAndCriteriaProvider;
 
     protected SampleBrowserGrid(final IViewContext<ICommonClientServiceAsync> viewContext,
-            ISampleCriteriaProvider criteriaProvider, String gridId, String browserId,
+            ISampleCriteriaProvider criteriaProvider, String browserId,
             boolean refreshAutomatically, IDisplayTypeIDGenerator displayTypeIDGenerator)
     {
-        super(viewContext, gridId, refreshAutomatically, displayTypeIDGenerator);
+        super(viewContext, createGridId(browserId), refreshAutomatically, displayTypeIDGenerator);
         this.propertyTypesAndCriteriaProvider = criteriaProvider;
         this.previousPropertyTypes = null;
 
@@ -346,6 +348,22 @@ public class SampleBrowserGrid extends
         setId(browserId);
     }
 
+    public static final String createGridId(final String browserId)
+    {
+        return browserId + GRID_ID_SUFFIX;
+    }
+
+    public static final String createChildComponentId(final String browserId,
+            final String childSuffix)
+    {
+        return browserId + childSuffix;
+    }
+
+    private final String createChildComponentId(final String childSuffix)
+    {
+        return createChildComponentId(getId(), childSuffix);
+    }
+
     private abstract class OpenEntityDetailsTabCellClickListener implements ICellListener<Sample>
     {
         protected abstract IEntityInformationHolder getEntity(Sample rowItem);
@@ -395,12 +413,12 @@ public class SampleBrowserGrid extends
         String showDetailsTitle = viewContext.getMessage(Dict.BUTTON_SHOW_DETAILS);
         Button showDetailsButton =
                 createSelectedItemButton(showDetailsTitle, asShowEntityInvoker(false));
-        showDetailsButton.setId(SHOW_DETAILS_BUTTON_ID);
+        showDetailsButton.setId(createChildComponentId(SHOW_DETAILS_BUTTON_ID_SUFFIX));
         addButton(showDetailsButton);
 
         String editTitle = viewContext.getMessage(Dict.BUTTON_EDIT);
         Button editButton = createSelectedItemButton(editTitle, asShowEntityInvoker(true));
-        editButton.setId(EDIT_BUTTON_ID);
+        editButton.setId(createChildComponentId(EDIT_BUTTON_ID_SUFFIX));
         addButton(editButton);
 
         final String deleteTitle = viewContext.getMessage(Dict.BUTTON_DELETE);
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleSearchHitGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleSearchHitGrid.java
index 5a8fc77da7d..1609cbd356b 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleSearchHitGrid.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/SampleSearchHitGrid.java
@@ -49,11 +49,6 @@ public class SampleSearchHitGrid extends SampleBrowserGrid implements IDetailedS
     public static final String SEARCH_BROWSER_ID =
             GenericConstants.ID_PREFIX + "sample-search-hit-browser";
 
-    public static final String SEARCH_GRID_ID = SEARCH_BROWSER_ID + "-grid";
-
-    public static final String SHOW_RELATED_DATASETS_BUTTON_ID =
-            SEARCH_GRID_ID + "_show-related-datasets-button";
-
     public static IDisposableComponent create(
             final IViewContext<ICommonClientServiceAsync> viewContext)
     {
@@ -98,7 +93,7 @@ public class SampleSearchHitGrid extends SampleBrowserGrid implements IDetailedS
     private SampleSearchHitGrid(final IViewContext<ICommonClientServiceAsync> viewContext,
             final ISampleCriteriaProvider criteriaProvider)
     {
-        super(viewContext, criteriaProvider, SEARCH_GRID_ID, SEARCH_BROWSER_ID, false,
+        super(viewContext, criteriaProvider, SEARCH_BROWSER_ID, false,
                 DisplayTypeIDGenerator.SAMPLE_SEARCH_RESULT_GRID);
         updateCriteriaProviderAndRefresh();
         extendBottomToolbar();
@@ -117,7 +112,6 @@ public class SampleSearchHitGrid extends SampleBrowserGrid implements IDetailedS
                             showRelatedDataSets(viewContext, SampleSearchHitGrid.this);
                         }
                     });
-        showRelatedDatasetsButton.setId(SHOW_RELATED_DATASETS_BUTTON_ID);
         addButton(showRelatedDatasetsButton);
 
         super.addEntityOperationButtons();
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ExperimentSamplesSection.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ExperimentSamplesSection.java
index 3b6a3691ae5..92798426f74 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ExperimentSamplesSection.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ExperimentSamplesSection.java
@@ -52,14 +52,19 @@ public class ExperimentSamplesSection extends DisposableSectionPanel
     // @Private
     static String createGridId(TechId experimentId)
     {
-        return ID_PREFIX + experimentId + "-grid";
+        return SampleBrowserGrid.createGridId(createBrowserId(experimentId));
+    }
+
+    private static String createBrowserId(TechId experimentId)
+    {
+        return ID_PREFIX + experimentId + "-browser";
     }
 
     @Override
     protected IDisposableComponent createDisposableContent()
     {
         return SampleBrowserGrid.createGridForExperimentSamples(viewContext.getCommonViewContext(),
-                experimentId, createGridId(experimentId), experimentType);
+                experimentId, createBrowserId(experimentId), experimentType);
     }
 
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/ContainerSamplesSection.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/ContainerSamplesSection.java
index d553fc67c79..6a718d2cac3 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/ContainerSamplesSection.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/ContainerSamplesSection.java
@@ -16,8 +16,8 @@
 
 package ch.systemsx.cisd.openbis.plugin.generic.client.web.client.application.sample;
 
-import ch.systemsx.cisd.openbis.generic.client.web.client.application.DisposableSectionPanel;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.Dict;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.DisposableSectionPanel;
 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.SingleSectionPanel;
@@ -48,7 +48,12 @@ public class ContainerSamplesSection extends DisposableSectionPanel
     // @Private
     static String createGridId(TechId containerId)
     {
-        return ID_PREFIX + containerId + "-grid";
+        return SampleBrowserGrid.createGridId(createBrowserId(containerId));
+    }
+
+    private static String createBrowserId(TechId containerId)
+    {
+        return ID_PREFIX + containerId + "-browser";
     }
 
     @Override
@@ -56,7 +61,7 @@ public class ContainerSamplesSection extends DisposableSectionPanel
     {
         TechId containerId = TechId.create(container);
         return SampleBrowserGrid.createGridForContainerSamples(viewContext.getCommonViewContext(),
-                containerId, createGridId(containerId), container.getSampleType());
+                containerId, createBrowserId(containerId), container.getSampleType());
     }
 
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/DerivedSamplesSection.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/DerivedSamplesSection.java
index e64f8ab1a36..9743717fc8a 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/DerivedSamplesSection.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/DerivedSamplesSection.java
@@ -45,10 +45,9 @@ public class DerivedSamplesSection extends DisposableSectionPanel
         this.parent = parent;
     }
 
-    // @Private
-    static String createGridId(TechId parentId)
+    private static String createBrowserId(TechId parentId)
     {
-        return ID_PREFIX + parentId + "-grid";
+        return ID_PREFIX + parentId + "-browser";
     }
 
     @Override
@@ -56,7 +55,7 @@ public class DerivedSamplesSection extends DisposableSectionPanel
     {
         TechId parentId = TechId.create(parent);
         return SampleBrowserGrid.createGridForDerivedSamples(viewContext.getCommonViewContext(),
-                parentId, createGridId(parentId), parent.getSampleType());
+                parentId, createBrowserId(parentId), parent.getSampleType());
     }
 
 }
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SampleBrowserTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SampleBrowserTest.java
index 7e218b83f7d..9e572530e83 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SampleBrowserTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SampleBrowserTest.java
@@ -52,12 +52,12 @@ public class SampleBrowserTest extends AbstractGWTTestCase
         loginAndGotoListSamplesTab();
         remoteConsole.prepare(new ListSamples("CISD", "MASTER_PLATE"));
         ChangeTableColumnSettingsCommand settingsCommand =
-                new ChangeTableColumnSettingsCommand(SampleBrowserGrid.GRID_ID);
+                new ChangeTableColumnSettingsCommand(SampleBrowserGrid.MAIN_GRID_ID);
         settingsCommand.hiddenChangeEvent(CommonSampleColDefKind.CODE.name(), true);
         settingsCommand.widthChangeEvent(CommonSampleColDefKind.REGISTRATOR.name(),
                 2 * DEFAULT_COLUMN_WIDTH);
         remoteConsole.prepare(settingsCommand);
-        remoteConsole.prepare(new Logout(SampleBrowserGrid.GRID_ID));
+        remoteConsole.prepare(new Logout());
         Login login = new Login("test", "a");
         remoteConsole.prepare(login);
         remoteConsole.prepare(new InvokeActionMenu(ActionMenuKind.SAMPLE_MENU_BROWSE));
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/Logout.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/Logout.java
index f0e48c30787..5621bfe4a52 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/Logout.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/Logout.java
@@ -28,11 +28,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.GWTTestU
  */
 public class Logout extends AbstractDefaultTestCommand
 {
-    public Logout(String callbackClassId)
-    {
-        super();
-    }
-
     public Logout()
     {
     }
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/CheckSampleTable.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/CheckSampleTable.java
index 3711cbd8a70..f29e1357346 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/CheckSampleTable.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/CheckSampleTable.java
@@ -28,7 +28,7 @@ public class CheckSampleTable extends CheckTableCommand
 {
     public CheckSampleTable()
     {
-        super(SampleBrowserGrid.GRID_ID);
+        super(SampleBrowserGrid.MAIN_GRID_ID);
     }
 
 }
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/ExportSamplesTestCommand.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/ExportSamplesTestCommand.java
index 142c204df99..6b004bc0100 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/ExportSamplesTestCommand.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/ExportSamplesTestCommand.java
@@ -52,7 +52,7 @@ public class ExportSamplesTestCommand extends AbstractDefaultTestCommand
     public void execute()
     {
         SampleBrowserGrid sampleBrowserGrid =
-                (SampleBrowserGrid) GWTTestUtil.getWidgetWithID(SampleBrowserGrid.BROWSER_ID);
+                (SampleBrowserGrid) GWTTestUtil.getWidgetWithID(SampleBrowserGrid.MAIN_BROWSER_ID);
         // we do not create view context earlier (e.g. in the class constructor), because we have to
         // wait until client is loaded and viewContext is available.
         IViewContext<ICommonClientServiceAsync> viewContext = getViewContext();
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/ShowSample.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/ShowSample.java
index 978d0900153..9ea63747918 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/ShowSample.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/sample/ShowSample.java
@@ -44,10 +44,13 @@ public final class ShowSample extends AbstractDefaultTestCommand
     @SuppressWarnings("unchecked")
     public void execute()
     {
-        final Widget widget = GWTTestUtil.getWidgetWithID(SampleBrowserGrid.GRID_ID);
+        final Widget widget = GWTTestUtil.getWidgetWithID(SampleBrowserGrid.MAIN_GRID_ID);
         assertTrue(widget instanceof Grid);
         final Grid<BaseEntityModel<Sample>> table = (Grid<BaseEntityModel<Sample>>) widget;
         GridTestUtils.fireSelectRow(table, CommonSampleColDefKind.CODE.id(), code);
-        GWTTestUtil.clickButtonWithID(SampleBrowserGrid.SHOW_DETAILS_BUTTON_ID);
+        GWTTestUtil
+                .clickButtonWithID(SampleBrowserGrid.createChildComponentId(
+                        SampleBrowserGrid.MAIN_BROWSER_ID,
+                        SampleBrowserGrid.SHOW_DETAILS_BUTTON_ID_SUFFIX));
     }
 }
-- 
GitLab