From a86ae744e5ffe3f73cd47b11033c8554605f63c0 Mon Sep 17 00:00:00 2001
From: kaloyane <kaloyane>
Date: Tue, 15 Feb 2011 11:38:52 +0000
Subject: [PATCH] [LMS-2019] - do not show checkboxes in global well search
 (there can be too many of them) - allow launching of  ImageViewer only when a
 single color channel is selected.

SVN: 19965
---
 .../detailviewers/ChannelChooser.java         |  2 +-
 .../detailviewers/ChannelChooserPanel.java    | 13 +++-
 .../detailviewers/ImageUrlUtils.java          |  1 -
 .../detailviewers/LogicalImageViewer.java     | 68 +++++++++++++------
 4 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ChannelChooser.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ChannelChooser.java
index 071cb7fc7a4..7c19486d340 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ChannelChooser.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ChannelChooser.java
@@ -179,7 +179,7 @@ class ChannelChooser
     private Widget createBasicChannelChooser(List<String> channels)
     {
         final ChannelChooserPanel channelChooser =
-                new ChannelChooserPanel(defaultChannelState, channels, basicChannelCodes);
+                new ChannelChooserPanel(defaultChannelState, channels, basicChannelCodes, true);
 
         channelChooser
                 .setSelectionChangedListener(new ChannelChooserPanel.ChannelSelectionListener()
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ChannelChooserPanel.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ChannelChooserPanel.java
index 67491022171..897fe637457 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ChannelChooserPanel.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ChannelChooserPanel.java
@@ -56,6 +56,9 @@ public class ChannelChooserPanel extends LayoutContainer
 
     private ChannelSelectionListener channelSelectionListener;
 
+    /** when set to to true will generate a checkbox per channel */
+    private boolean createCheckBoxes;
+
     private final Listener<BaseEvent> selectionChangeListener = new Listener<BaseEvent>()
         {
 
@@ -68,13 +71,15 @@ public class ChannelChooserPanel extends LayoutContainer
 
     public ChannelChooserPanel(IDefaultChannelState defChannelState)
     {
-        this(defChannelState, Collections.<String> emptyList(), Collections.<String> emptyList());
+        this(defChannelState, Collections.<String> emptyList(), Collections.<String> emptyList(),
+                false);
     }
 
     public ChannelChooserPanel(IDefaultChannelState defChannelState, List<String> names,
-            List<String> selectedChannelsOrNull)
+            List<String> selectedChannelsOrNull, boolean createCheckBoxes)
     {
         this.defaultChannelState = defChannelState;
+        this.createCheckBoxes = createCheckBoxes;
 
         setAutoHeight(true);
         setAutoWidth(true);
@@ -176,7 +181,8 @@ public class ChannelChooserPanel extends LayoutContainer
 
         for (String code : codes)
         {
-            if (addCodeToComboBox(code))
+            boolean codeAdded = addCodeToComboBox(code);
+            if (codeAdded && createCheckBoxes)
             {
                 // also add a checkBockbox for the channel
                 CheckBox checkBox = new CheckBox();
@@ -239,6 +245,7 @@ public class ChannelChooserPanel extends LayoutContainer
 
         String selectedComboValue = channelsComboBox.getSimpleValue();
         boolean showCheckBoxGroup = ScreeningConstants.MERGED_CHANNELS.equals(selectedComboValue);
+
         ensureAtLeastOneCheckboxChecked();
         channelsCheckBoxGroup.setVisible(showCheckBoxGroup);
 
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ImageUrlUtils.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ImageUrlUtils.java
index 0a59a46bf1d..f5d28c88a03 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ImageUrlUtils.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/ImageUrlUtils.java
@@ -141,7 +141,6 @@ public class ImageUrlUtils
     {
         LogicalImageReference images = channelReferences.getBasicImage();
 
-        // TODO KE: Tomek, should we add a "transformerFactorySignature" for each selected channel ?
         List<String> channels = channelReferences.getChannelCodes();
         if (channels != null)
         {
diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/LogicalImageViewer.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/LogicalImageViewer.java
index b67742b7133..2f9f4e15273 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/LogicalImageViewer.java
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/client/application/detailviewers/LogicalImageViewer.java
@@ -79,7 +79,7 @@ public class LogicalImageViewer
 
     private final boolean showColorAdjustmentButton;
 
-    private List<String> currentlySelectedChannelCodes;
+    private String currentlySelectedChannelCode;
 
     public LogicalImageViewer(LogicalImageReference logicalImageReference,
             IViewContext<IScreeningClientServiceAsync> viewContext, String experimentIdentifier,
@@ -167,23 +167,26 @@ public class LogicalImageViewer
 
     private Widget createSeriesImageWidget(final List<ImageChannelStack> channelStackImages)
     {
+        final Button adjustColorsButton = createAdjustColorsButton();
         final IChanneledViewerFactory viewerFactory = new IChanneledViewerFactory()
             {
                 public LayoutContainer create(LogicalImageChannelsReference channelReferences)
                 {
-                    currentlySelectedChannelCodes = channelReferences.getChannelCodes();
+                    currentlySelectedChannelCode = getSelectedChannelCode(channelReferences);
                     String sessionId = getSessionId(viewContext);
+                    setAdjustColorsButtonState(adjustColorsButton,
+                            channelReferences.getChannelCodes());
                     int imageWidth = getImageWidth(logicalImageReference);
                     int imageHeight = getImageHeight(logicalImageReference);
                     return LogicalImageSeriesGrid.create(sessionId, channelStackImages,
                             channelReferences, imageWidth, imageHeight);
                 }
             };
-        return createViewerWithChannelChooser(viewerFactory);
+        return createViewerWithChannelChooser(viewerFactory, adjustColorsButton);
     }
 
     private LayoutContainer createViewerWithChannelChooser(
-            final IChanneledViewerFactory viewerFactory)
+            final IChanneledViewerFactory viewerFactory, final Button adjustColorsButton)
     {
         LayoutContainer container = createMainEmptyContainer();
         if (hasNoChannels())
@@ -200,16 +203,6 @@ public class LogicalImageViewer
         {
             LayoutContainer buttonToolbar = new LayoutContainer();
             buttonToolbar.setLayout(new ColumnLayout());
-            Button adjustColorsButton =
-                    new Button(viewContext.getMessage(Dict.IMAGE_VIEWER_BUTTON),
-                            new SelectionListener<ButtonEvent>()
-                                {
-                                    @Override
-                                    public void componentSelected(ButtonEvent ce)
-                                    {
-                                        launchImageEditor();
-                                    }
-                                });
             buttonToolbar.add(adjustColorsButton);
             Button refreshButton =
                     new Button(viewContext.getMessage(Dict.BUTTON_REFRESH),
@@ -233,6 +226,21 @@ public class LogicalImageViewer
         return container;
     }
 
+    private Button createAdjustColorsButton()
+    {
+        final Button adjustColorsButton =
+                new Button(viewContext.getMessage(Dict.IMAGE_VIEWER_BUTTON),
+                        new SelectionListener<ButtonEvent>()
+                            {
+                                @Override
+                                public void componentSelected(ButtonEvent ce)
+                                {
+                                    launchImageEditor();
+                                }
+                            });
+        return adjustColorsButton;
+    }
+
     private boolean hasNoChannels()
     {
         return logicalImageReference.getChannelsCodes().size() == 0;
@@ -271,16 +279,20 @@ public class LogicalImageViewer
     private Widget getStaticImageWidget()
     {
 
+        final Button adjustColorsButton = createAdjustColorsButton();
         final IChanneledViewerFactory viewerFactory = new IChanneledViewerFactory()
             {
                 public LayoutContainer create(LogicalImageChannelsReference channelReferences)
                 {
-                    currentlySelectedChannelCodes = channelReferences.getChannelCodes();
+                    currentlySelectedChannelCode = getSelectedChannelCode(channelReferences);
+                    setAdjustColorsButtonState(adjustColorsButton,
+                            channelReferences.getChannelCodes());
                     String sessionId = getSessionId(viewContext);
                     return createTilesGrid(channelReferences, sessionId);
                 }
+
             };
-        return createViewerWithChannelChooser(viewerFactory);
+        return createViewerWithChannelChooser(viewerFactory, adjustColorsButton);
     }
 
     private static IDefaultChannelState createDefaultChannelState(
@@ -303,10 +315,9 @@ public class LogicalImageViewer
         urlParams.addParameter(ParameterNames.SERVER_URL, GWT.getHostPageBaseURL());
         urlParams.addParameter(ParameterNames.EXPERIMENT_ID, experimentIdentifier);
 
-        // TODO KE: How do we support the launching of ImageViewer with channel parameters ?
-        if (currentlySelectedChannelCodes != null)
+        if (currentlySelectedChannelCode != null)
         {
-            urlParams.addParameter(ParameterNames.CHANNEL, currentlySelectedChannelCodes);
+            urlParams.addParameter(ParameterNames.CHANNEL, currentlySelectedChannelCode);
         }
         WellLocation wellLocation = logicalImageReference.tryGetWellLocation();
         if (wellLocation != null)
@@ -354,6 +365,25 @@ public class LogicalImageViewer
         return container;
     }
 
+    private static String getSelectedChannelCode(LogicalImageChannelsReference channelReferences)
+    {
+        String newChannelCode = null;
+        List<String> channelCodes = channelReferences.getChannelCodes();
+        if (channelCodes != null && false == channelCodes.isEmpty())
+        {
+            newChannelCode = channelCodes.get(0);
+        }
+        return newChannelCode;
+    }
+
+    private static void setAdjustColorsButtonState(Button adjustColorsButton,
+            List<String> channelCodes)
+    {
+        boolean enabled = channelCodes != null && channelCodes.size() == 1;
+        adjustColorsButton.setEnabled(enabled);
+
+    }
+
     private static String getSessionId(IViewContext<?> viewContext)
     {
         return viewContext.getModel().getSessionContext().getSessionID();
-- 
GitLab