Skip to content
Snippets Groups Projects
Commit a2cf4074 authored by juanf's avatar juanf
Browse files

SP-624 BIS-398: Ordering Bugfix. Ongoing work.

SVN: 28994
parent d8226c9d
No related branches found
No related tags found
No related merge requests found
package ch.systemsx.cisd.openbis.generic.shared.basic.dto; package ch.systemsx.cisd.openbis.generic.shared.basic.dto;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
public class NewETNewPTAssigments implements Serializable public class NewETNewPTAssigments implements Serializable
...@@ -40,6 +38,7 @@ public class NewETNewPTAssigments implements Serializable ...@@ -40,6 +38,7 @@ public class NewETNewPTAssigments implements Serializable
if(entity.getAssignedPropertyTypes().get(i).getPropertyType().getCode().equals(code)) { if(entity.getAssignedPropertyTypes().get(i).getPropertyType().getCode().equals(code)) {
entity.getAssignedPropertyTypes().remove(i); entity.getAssignedPropertyTypes().remove(i);
assigments.remove(i); assigments.remove(i);
break;
} }
} }
...@@ -62,10 +61,11 @@ public class NewETNewPTAssigments implements Serializable ...@@ -62,10 +61,11 @@ public class NewETNewPTAssigments implements Serializable
} }
// //
// Update Internal List - Reorder the items due to an insert // Update Lists - This Reorder the items due to an insert
// //
EntityTypePropertyType<?> newEtpt = getEntityTypePropertyType(entity.getEntityKind(), newAssigment);
//Internal List
EntityTypePropertyType<?> newEtpt = getEntityTypePropertyType(entity.getEntityKind(), newAssigment);
switch (entity.getEntityKind()) switch (entity.getEntityKind())
{ {
case SAMPLE: case SAMPLE:
...@@ -86,46 +86,15 @@ public class NewETNewPTAssigments implements Serializable ...@@ -86,46 +86,15 @@ public class NewETNewPTAssigments implements Serializable
break; break;
} }
// //External List
// Update Internal List - Second pass set proper positions after reordering assigments.add(insertPos, newAssigment);
//
for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) {
entity.getAssignedPropertyTypes().get(i).setOrdinal((long) i + 1);
}
// //
// Update Visible List with internal list order // Update Ordinal - Internal/External List
// //
assigments.add(newAssigment);
for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) { for(int i = 0; i < entity.getAssignedPropertyTypes().size(); i++) {
EntityTypePropertyType<?> etpt = entity.getAssignedPropertyTypes().get(i); entity.getAssignedPropertyTypes().get(i).setOrdinal((long) i + 1);
String code = etpt.getPropertyType().getCode(); assigments.get(i).getAssignment().setOrdinal((long) i + 1);
for(NewPTNewAssigment assigment:assigments) {
if(assigment.getPropertyType().getCode().equals(code)) {
assigment.getAssignment().setOrdinal((long) (i + 1));
}
}
}
//
// Update Visible List order
//
Collections.sort(assigments, new NewPTNewAssigmentComparator());
}
private class NewPTNewAssigmentComparator implements Comparator<NewPTNewAssigment>{
@Override
public int compare(NewPTNewAssigment arg0, NewPTNewAssigment arg1)
{
int isEqualIfZero = 0;
if(arg0.getAssignment().getOrdinal() > arg1.getAssignment().getOrdinal()) {
isEqualIfZero = 1;
} else if(arg0.getAssignment().getOrdinal() < arg1.getAssignment().getOrdinal()) {
isEqualIfZero = -1;
}
return isEqualIfZero;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment