From 54758a2060f41ba1b18be0e59b2664c42e5dae79 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Thu, 4 Oct 2012 13:48:40 +0000
Subject: [PATCH] SP-298, BIS-210: '+' button added to allow adding sections
 before a section.

SVN: 26993
---
 .../ui/AbstractRegistrationForm.java          |  2 +-
 .../experiment/ManagedPropertyField.java      | 24 ++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractRegistrationForm.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractRegistrationForm.java
index 661f8ff5911..6515b55e877 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractRegistrationForm.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractRegistrationForm.java
@@ -82,7 +82,7 @@ public abstract class AbstractRegistrationForm extends ContentPanel implements
 
     public static final int SECTION_DEFAULT_FIELD_WIDTH = DEFAULT_FIELD_WIDTH;// -15
 
-    public static final int SECTION_WIDTH = SECTION_FIELD_WIDTH + SECTION_LABEL_WIDTH + 70;// +16
+    public static final int SECTION_WIDTH = SECTION_FIELD_WIDTH + SECTION_LABEL_WIDTH + 80;// +16
 
     protected IMessageProvider messageProvider;
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ManagedPropertyField.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ManagedPropertyField.java
index a80f86cb3e9..be634ee10de 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ManagedPropertyField.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/experiment/ManagedPropertyField.java
@@ -81,12 +81,12 @@ public class ManagedPropertyField extends Field<List<Map<String, String>>>
                 @Override
                 public void componentSelected(ButtonEvent ce)
                 {
-                    addNewSection();
+                    addNewSection(sections.size());
                 }
             });
         addButton.setToolTip("Add a new section.");
         verticalPanel.add(addButton);
-        addNewSection();
+        addNewSection(0);
     }
 
     public Widget getWidget()
@@ -110,7 +110,7 @@ public class ManagedPropertyField extends Field<List<Map<String, String>>>
         return list;
     }
 
-    private void addNewSection()
+    private void addNewSection(int sectionIndex)
     {
         FormPanel formPanel = new FormPanel();
         formPanel.setLabelWidth(AbstractRegistrationForm.DEFAULT_LABEL_WIDTH - SPACING - 2);
@@ -123,9 +123,21 @@ public class ManagedPropertyField extends Field<List<Map<String, String>>>
         final HorizontalPanel horizontalPanel = new HorizontalPanel();
         horizontalPanel.setSpacing(SPACING);
         horizontalPanel.add(formPanel);
+        final Section section = new Section(inputFieldsByCode);
+        Button addBeforeButton = new Button("+");
+        addBeforeButton.setToolTip("Add a new section before this section.");
+        addBeforeButton.addSelectionListener(new SelectionListener<ButtonEvent>()
+            {
+                @Override
+                public void componentSelected(ButtonEvent ce)
+                {
+                    int index = sections.indexOf(section);
+                    addNewSection(index);
+                }
+            });
+        horizontalPanel.add(addBeforeButton);
         Button removeButton = new Button("-");
         removeButton.setToolTip("Delete this section.");
-        final Section section = new Section(inputFieldsByCode);
         removeButton.addSelectionListener(new SelectionListener<ButtonEvent>()
             {
                 @Override
@@ -150,8 +162,8 @@ public class ManagedPropertyField extends Field<List<Map<String, String>>>
                 }
             });
         horizontalPanel.add(removeButton);
-        sections.add(section);
-        verticalPanel.insert(horizontalPanel, verticalPanel.getItemCount() - 1);
+        sections.add(sectionIndex, section);
+        verticalPanel.insert(horizontalPanel, sectionIndex);
         verticalPanel.layout();
     }
 }
-- 
GitLab