From ee81dca71c8615b9ae8e1b5d1280a4bdf1e36f72 Mon Sep 17 00:00:00 2001 From: Martin Beyer Date: Wed, 26 Aug 2020 17:23:39 +0200 Subject: [PATCH] Nice implementation of only one stats window per vault --- .../VaultDetailUnlockedController.java | 18 +++++++++++------- .../ui/stats/VaultStatisticsComponent.java | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java index 93525a8b4..dd386ed53 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java @@ -1,6 +1,8 @@ package org.cryptomator.ui.mainwindow; -import javafx.beans.property.BooleanProperty; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import javafx.beans.property.ObjectProperty; import javafx.beans.property.ReadOnlyObjectProperty; import javafx.fxml.FXML; @@ -16,15 +18,22 @@ public class VaultDetailUnlockedController implements FxController { private final ReadOnlyObjectProperty vault; private final VaultService vaultService; + private final LoadingCache vaultStatisticsWindows; private final VaultStatisticsComponent.Builder vaultStatisticsWindow; @Inject public VaultDetailUnlockedController(ObjectProperty vault, VaultService vaultService, VaultStatisticsComponent.Builder vaultStatisticsWindow) { this.vault = vault; this.vaultService = vaultService; + this.vaultStatisticsWindows = CacheBuilder.newBuilder().build(CacheLoader.from(this::provideVaultStatisticsComponent)); + //TODO make the binding a weak Binding via weakValues this.vaultStatisticsWindow = vaultStatisticsWindow; } + private VaultStatisticsComponent provideVaultStatisticsComponent(Vault vault) { + return vaultStatisticsWindow.vault(vault).build(); + } + @FXML public void revealAccessLocation() { vaultService.reveal(vault.get()); @@ -38,12 +47,7 @@ public class VaultDetailUnlockedController implements FxController { @FXML public void showVaultStatistics() { - //vaultStatisticsWindow.build() - BooleanProperty showingStats = vault.get().showingStatsProperty(); - if (!showingStats.get()) { - vaultStatisticsWindow.vault(vault.get()).build().showVaultStatisticsWindow(); - showingStats.setValue(true); - } + vaultStatisticsWindows.getUnchecked(vault.get()).showVaultStatisticsWindow(); } /* Getter/Setter */ diff --git a/main/ui/src/main/java/org/cryptomator/ui/stats/VaultStatisticsComponent.java b/main/ui/src/main/java/org/cryptomator/ui/stats/VaultStatisticsComponent.java index 18c596793..8d48ef52e 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/stats/VaultStatisticsComponent.java +++ b/main/ui/src/main/java/org/cryptomator/ui/stats/VaultStatisticsComponent.java @@ -24,6 +24,7 @@ public interface VaultStatisticsComponent { stage.setScene(scene().get()); stage.sizeToScene(); stage.show(); + stage.requestFocus(); } @Subcomponent.Builder