diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java index fc751d862..f66ef36be 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java @@ -11,7 +11,10 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; @@ -25,6 +28,7 @@ public class VaultListController implements FxController { private final ObservableList vaults; private final ObjectProperty selectedVault; + private final BooleanProperty selectedVaultRemovable; private final VaultListCellFactory cellFactory; private final AddVaultWizardComponent.Builder addVaultWizard; private final RemoveVaultComponent.Builder removeVault; @@ -41,6 +45,7 @@ public class VaultListController implements FxController { this.removeVault = removeVault; this.noVaultSelected = selectedVault.isNull(); this.emptyVaultList = Bindings.isEmpty(vaults); + this.selectedVaultRemovable = new SimpleBooleanProperty(false); selectedVault.addListener(this::selectedVaultDidChange); } @@ -59,12 +64,22 @@ public class VaultListController implements FxController { } private void selectedVaultDidChange(@SuppressWarnings("unused") ObservableValue observableValue, @SuppressWarnings("unused") Vault oldValue, Vault newValue) { + if(oldValue != null){ + oldValue.lockedProperty().removeListener((ChangeListener) this::updateSelectedVaultRemovable); + } if (newValue == null) { return; } VaultListManager.redetermineVaultState(newValue); + selectedVaultRemovable.setValue(newValue.isLocked()); + newValue.lockedProperty().addListener((ChangeListener) this::updateSelectedVaultRemovable); } + private void updateSelectedVaultRemovable(ObservableValue observableValue, Boolean oldVal, Boolean newVal) { + selectedVaultRemovable.setValue(newVal); + } + + @FXML public void didClickAddVault() { addVaultWizard.build().showAddVaultWizard(); @@ -97,4 +112,13 @@ public class VaultListController implements FxController { public boolean isNoVaultSelected() { return noVaultSelected.get(); } + + public BooleanProperty selectedVaultRemovableProperty() { + return selectedVaultRemovable; + } + + public boolean isSelectedVaultRemovable() { + return selectedVaultRemovable.get(); + } + } diff --git a/main/ui/src/main/resources/fxml/vault_list.fxml b/main/ui/src/main/resources/fxml/vault_list.fxml index 942074639..e7362ffbb 100644 --- a/main/ui/src/main/resources/fxml/vault_list.fxml +++ b/main/ui/src/main/resources/fxml/vault_list.fxml @@ -19,7 +19,7 @@ - +