From c15594069d1be19986745037398b133594a1821b Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 11 Feb 2016 14:36:21 +0100 Subject: [client] search for the right index to insert locations in the tree instead of inserting them at the end as a result, the location tree should be sorted alphabetically. --- .../dozmod/gui/control/LocationSelector.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LocationSelector.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LocationSelector.java index fe8e9cc4..25a12ae4 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LocationSelector.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LocationSelector.java @@ -25,6 +25,7 @@ import org.openslx.dozmod.Config; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.thrift.cache.MetaDataCache; +import org.openslx.thrifthelper.Comparators; import org.openslx.util.QuickTimer; import org.openslx.util.QuickTimer.Task; @@ -151,10 +152,29 @@ public class LocationSelector extends JPanel { parentNode = rootNode; else parentNode = locationNodesMap.get(location.getParentLocationId()); + // determine the right index to insert the child into + int childrenCount = parentNode.getChildCount(); + int insertionIndex = childrenCount; + if (childrenCount != 0) { + // loop through kids + Enumeration enumeration = parentNode.children(); + while (enumeration.hasMoreElements()) { + DefaultMutableTreeNode currentChild = (DefaultMutableTreeNode) enumeration.nextElement(); + if (currentChild == null) + continue; + Location childLocation = (Location) currentChild.getUserObject(); + if (childLocation == null) + continue; + if (Comparators.location.compare(location, childLocation) <= 0) { + insertionIndex = parentNode.getIndex(currentChild); + break; + } + } + } // insert the current node in the tree model treeModel.insertNodeInto(locationNodesMap.get(location.getLocationId()), // what parentNode, // parent? - parentNode.getChildCount()); // index + insertionIndex); // index } locationTree.setModel(treeModel); -- cgit v1.2.3-55-g7522