diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultListChangeListener.java b/main/commons/src/main/java/org/cryptomator/common/vaults/VaultListChangeListener.java index cf514ebb6..674615d34 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/VaultListChangeListener.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/VaultListChangeListener.java @@ -4,6 +4,9 @@ import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import org.cryptomator.common.settings.VaultSettings; +import java.util.List; +import java.util.stream.Collectors; + /** * This listener makes sure to reflect any changes to the vault list back to the settings. */ @@ -19,14 +22,11 @@ public class VaultListChangeListener implements ListChangeListener { public void onChanged(Change c) { while(c.next()) { if (c.wasAdded()) { - for (int i = c.getFrom(); i < c.getTo(); i++) { - Vault v = c.getList().get(i); - vaultSettingsList.add(i, v.getVaultSettings()); - } + List addedSettings = c.getAddedSubList().stream().map(Vault::getVaultSettings).collect(Collectors.toList()); + vaultSettingsList.addAll(c.getFrom(), addedSettings); } else if (c.wasRemoved()) { - for (Vault v : c.getRemoved()) { - vaultSettingsList.remove(v.getVaultSettings()); - } + List removedSettings = c.getRemoved().stream().map(Vault::getVaultSettings).collect(Collectors.toList()); + vaultSettingsList.removeAll(removedSettings); } } }