From 34f8fa1e0aac43adddf86e63004a45357fc7094c Mon Sep 17 00:00:00 2001 From: Nadim Ritter Date: Thu, 1 Feb 2024 15:57:18 +0100 Subject: [PATCH 1/3] 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(); + } + } From acc50ee94d47a0b07cec7f1a008f0f124f02f18a Mon Sep 17 00:00:00 2001 From: Nadim Ritter Date: Thu, 1 Feb 2024 16:41:40 +0100 Subject: [PATCH 2/3] make code java 8 compatible --- .../gui/service/session/ClientConnectionTable.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 6cc273fc..d28e6342 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 @@ -827,7 +827,11 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate final Set result = new HashSet<>(); for (int i = 0; i < selectionIndices.length; i++) { - UpdatableTableItem item = this.tableMapping.values().stream().toList().get(selectionIndices[i]); + UpdatableTableItem item = this.tableMapping.values() + .stream() + .collect(Collectors.toList()) + .get(selectionIndices[i]); + result.add(item.staticData.connectionToken); } From 840b5071566e4acfca0378967c586b7d42fe90a9 Mon Sep 17 00:00:00 2001 From: Nadim Ritter Date: Wed, 7 Feb 2024 16:23:29 +0100 Subject: [PATCH 3/3] SEBSERV-427 improve getSelectedTableIndices --- .../service/session/ClientConnectionTable.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 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 d28e6342..28214040 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 @@ -9,6 +9,7 @@ package ch.ethz.seb.sebserver.gui.service.session; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -843,16 +844,19 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate return new int[]{}; } - List selectedTableIndices = new ArrayList<>(); + int[] selectedTableIndices = new int[connectionTokens.size()]; + int index = 0; + int tableIndices = 0; + for (UpdatableTableItem item : this.tableMapping.values()) { if (connectionTokens.contains(item.staticData.connectionToken)) { - selectedTableIndices.add(index); + selectedTableIndices[index] = tableIndices; + index++; } - index++; + tableIndices++; } - - return selectedTableIndices.stream().mapToInt(i -> i).toArray(); + return selectedTableIndices; } -} +} \ No newline at end of file