From c94ef5b788000aab16e00246549cbb02513079c4 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Tue, 27 Oct 2009 14:15:49 +0000
Subject: [PATCH] [LMS-1194] fixed reordering of property type assignments

SVN: 13090
---
 .../PropertyTypeAssignmentGrid.java           | 28 +++++++++++--------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentGrid.java
index 307cecf4b70..51836d25ded 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentGrid.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/property_type/PropertyTypeAssignmentGrid.java
@@ -179,6 +179,9 @@ public class PropertyTypeAssignmentGrid extends
 
     private final IDelegatedAction postRegistrationCallback;
 
+    // < entity type, list of etpts assigned to this entity type >
+    private Map<EntityType, List<EntityTypePropertyType<?>>> entityTypePropertyTypes;
+
     private PropertyTypeAssignmentGrid(final IViewContext<ICommonClientServiceAsync> viewContext)
     {
         super(viewContext, BROWSER_ID, GRID_ID,
@@ -292,24 +295,29 @@ public class PropertyTypeAssignmentGrid extends
                 private EntityTypePropertyTypeSelectionWidget createETPTSelectionWidget()
                 {
                     final EntityType entityType = etpt.getEntityType();
-                    final List<EntityTypePropertyType<?>> all = getPropertyTypes(entityType);
+                    // create a new list of items from all etpts assigned to entity type
+                    final List<EntityTypePropertyType<?>> all =
+                            new ArrayList<EntityTypePropertyType<?>>();
+                    all.add(null); // null will be transformed into '(top)'
+                    String initialPropertyTypeCodeOrNull = null;
                     String previousPropertyTypeCodeOrNull =
                             EntityTypePropertyTypeSelectionWidget.TOP_ITEM_CODE;
-                    for (int i = 0; i < all.size(); i++)
+                    for (EntityTypePropertyType<?> currentETPT : getPropertyTypes(entityType))
                     {
                         final String currentPropertyTypeCode =
-                                all.get(i).getPropertyType().getCode();
-                        if (propertyTypeCode.equals(currentPropertyTypeCode))
+                                currentETPT.getPropertyType().getCode();
+                        if (propertyTypeCode.equals(currentPropertyTypeCode) == false)
+                        {
+                            all.add(currentETPT);
+                            previousPropertyTypeCodeOrNull = currentPropertyTypeCode;
+                        } else
                         {
-                            all.remove(i);
-                            break;
+                            initialPropertyTypeCodeOrNull = previousPropertyTypeCodeOrNull;
                         }
-                        previousPropertyTypeCodeOrNull = currentPropertyTypeCode;
                     }
-                    all.add(0, null); // null will be transformed into '(top)'
                     final EntityTypePropertyTypeSelectionWidget result =
                             new EntityTypePropertyTypeSelectionWidget(viewContext, getId(), all,
-                                    previousPropertyTypeCodeOrNull);
+                                    initialPropertyTypeCodeOrNull);
                     FieldUtil.setMandatoryFlag(result, true);
                     return result;
                 }
@@ -389,8 +397,6 @@ public class PropertyTypeAssignmentGrid extends
                     PropertyTypeAssignmentColDefKind.ENTITY_KIND });
     }
 
-    private Map<EntityType, List<EntityTypePropertyType<?>>> entityTypePropertyTypes;
-
     private List<EntityTypePropertyType<?>> getPropertyTypes(EntityType entityType)
     {
         return entityTypePropertyTypes.get(entityType);
-- 
GitLab