From d85b87ecfe6837d985fe8284f80e0839e73430f3 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Wed, 14 Oct 2009 11:58:37 +0000
Subject: [PATCH] fixed moving vocabulary term to the beginning of a list of
 terms

SVN: 12968
---
 .../ui/vocabulary/VocabularyTermGrid.java     | 31 +++++++++----------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java
index 808d8e08478..0a128429667 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java
@@ -218,6 +218,10 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm
                 {
                     term.setDescription(descriptionField.getValue());
                     term.setLabel(labelField.getValue());
+                    if (termSelectionWidget != null)
+                    {
+                        term.setOrdinal(extractPreviousTermOrdinal() + 1);
+                    }
 
                     viewContext.getService().updateVocabularyTerm(term, registrationCallback);
                 }
@@ -241,24 +245,19 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm
                             new VocabularyTermSelectionWidget(getId() + term, "Position after",
                                     mandatory, allTerms, previousTermCodeOrNull);
                     result.setEmptyText("empty value == beginning");
-
-                    result
-                            .addSelectionChangedListener(new SelectionChangedListener<VocabularyTermModel>()
-                                {
-                                    @Override
-                                    public void selectionChanged(
-                                            SelectionChangedEvent<VocabularyTermModel> se)
-                                    {
-                                        VocabularyTermModel selectedItem = se.getSelectedItem();
-                                        // set ordinal to:
-                                        // - 0 if nothing is selected,
-                                        // - (otherwise) selected term's ordinal + 1
-                                        term.setOrdinal((selectedItem != null) ? selectedItem
-                                                .getTerm().getOrdinal() + 1 : 0);
-                                    }
-                                });
                     return result;
                 }
+
+                /**
+                 * extracts ordinal of a term after which edited terms should be put
+                 */
+                private Long extractPreviousTermOrdinal()
+                {
+                    // - 0 if nothing is selected (move to the beginning),
+                    // - (otherwise) selected term's ordinal
+                    VocabularyTermModel selectedItem = termSelectionWidget.getValue();
+                    return selectedItem != null ? selectedItem.getTerm().getOrdinal() : 0;
+                }
             };
     }
 
-- 
GitLab