diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java index adabece4..6cc273fc 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java @@ -431,7 +431,7 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate } private void sortTable() { - // SEBSERV-427 get all selected indices here and store connectionTokens for selection in Set + Set connectionTokens = getSelectedConnectionTokens(); this.sortList.clear(); this.sortList.addAll(this.tableMapping.values()); @@ -443,7 +443,10 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate this.tableMapping.put(item.connectionId, item); } - // SEBSERV-427 apply selected connectionTokens back to table index selection + if(!connectionTokens.isEmpty()){ + this.table.deselectAll(); + this.table.select(getSelectedTableIndices(connectionTokens)); + } } private void notifySelectionChange() { @@ -816,4 +819,36 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate } } + private Set getSelectedConnectionTokens(){ + final int[] selectionIndices = this.table.getSelectionIndices(); + if (selectionIndices == null) { + return Collections.emptySet(); + } + + final Set result = new HashSet<>(); + for (int i = 0; i < selectionIndices.length; i++) { + UpdatableTableItem item = this.tableMapping.values().stream().toList().get(selectionIndices[i]); + result.add(item.staticData.connectionToken); + } + + return result; + } + + private int[] getSelectedTableIndices(Set connectionTokens){ + if(connectionTokens.isEmpty()){ + return new int[]{}; + } + + List selectedTableIndices = new ArrayList<>(); + int index = 0; + for (UpdatableTableItem item : this.tableMapping.values()) { + if (connectionTokens.contains(item.staticData.connectionToken)) { + selectedTableIndices.add(index); + } + index++; + } + + return selectedTableIndices.stream().mapToInt(i -> i).toArray(); + } + }