From 34f8fa1e0aac43adddf86e63004a45357fc7094c Mon Sep 17 00:00:00 2001 From: Nadim Ritter Date: Thu, 1 Feb 2024 15:57:18 +0100 Subject: [PATCH] SEBSERV-427 - fix selection issue --- .../session/ClientConnectionTable.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) 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(); + } + }