diff options
author | Jonathan Bauer | 2016-02-11 14:36:21 +0100 |
---|---|---|
committer | Jonathan Bauer | 2016-02-11 14:36:21 +0100 |
commit | c15594069d1be19986745037398b133594a1821b (patch) | |
tree | bffb27c64ee95f0d60ae93b9bb4032fe7fed99e8 /dozentenmodul/src/main/java/org | |
parent | [client] Improve some texts (image -> vm mostly) (diff) | |
download | tutor-module-c15594069d1be19986745037398b133594a1821b.tar.gz tutor-module-c15594069d1be19986745037398b133594a1821b.tar.xz tutor-module-c15594069d1be19986745037398b133594a1821b.zip |
[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.
Diffstat (limited to 'dozentenmodul/src/main/java/org')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/LocationSelector.java | 22 |
1 files changed, 21 insertions, 1 deletions
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); |