replaced RemoveVaultComponent.Builder with CustomDialogBuilder in all places

This commit is contained in:
Jan-Peter Klein
2024-10-22 18:53:06 +02:00
parent 7fcbb57ab1
commit 62d7b7a0c0
6 changed files with 98 additions and 20 deletions

View File

@@ -16,7 +16,6 @@ import org.cryptomator.ui.common.StageInitializer;
import org.cryptomator.ui.error.ErrorComponent;
import org.cryptomator.ui.fxapp.PrimaryStage;
import org.cryptomator.ui.migration.MigrationComponent;
import org.cryptomator.ui.removevault.RemoveVaultComponent;
import org.cryptomator.ui.stats.VaultStatisticsComponent;
import org.cryptomator.ui.wrongfilealert.WrongFileAlertComponent;
@@ -30,7 +29,7 @@ import javafx.stage.Stage;
import java.util.Map;
import java.util.ResourceBundle;
@Module(subcomponents = {AddVaultWizardComponent.class, MigrationComponent.class, RemoveVaultComponent.class, VaultStatisticsComponent.class, WrongFileAlertComponent.class, ErrorComponent.class})
@Module(subcomponents = {AddVaultWizardComponent.class, MigrationComponent.class, VaultStatisticsComponent.class, WrongFileAlertComponent.class, ErrorComponent.class})
abstract class MainWindowModule {
@Provides

View File

@@ -3,10 +3,14 @@ package org.cryptomator.ui.mainwindow;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultListManager;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.removevault.RemoveVaultComponent;
import org.cryptomator.ui.controls.CustomDialogBuilder;
import org.cryptomator.ui.controls.FontAwesome5Icon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javafx.beans.property.ObjectProperty;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
@@ -18,16 +22,21 @@ import static org.cryptomator.common.Constants.CRYPTOMATOR_FILENAME_GLOB;
@MainWindowScoped
public class VaultDetailMissingVaultController implements FxController {
private static final Logger LOG = LoggerFactory.getLogger(VaultDetailMissingVaultController.class);
private final ObjectProperty<Vault> vault;
private final RemoveVaultComponent.Builder removeVault;
private final ObservableList<Vault> vaults;
private final ResourceBundle resourceBundle;
private final Stage window;
@Inject
public VaultDetailMissingVaultController(ObjectProperty<Vault> vault, RemoveVaultComponent.Builder removeVault, ResourceBundle resourceBundle, @MainWindow Stage window) {
public VaultDetailMissingVaultController(ObjectProperty<Vault> vault, //
ObservableList<Vault> vaults, //
ResourceBundle resourceBundle, //
@MainWindow Stage window) {
this.vault = vault;
this.removeVault = removeVault;
this.vaults = vaults;
this.resourceBundle = resourceBundle;
this.window = window;
}
@@ -39,7 +48,20 @@ public class VaultDetailMissingVaultController implements FxController {
@FXML
void didClickRemoveVault() {
removeVault.vault(vault.get()).build().showRemoveVault();
new CustomDialogBuilder() //
.setTitle(String.format(resourceBundle.getString("removeVault.title"), vault.get().getDisplayName())) //
.setMessage(resourceBundle.getString("removeVault.message")) //
.setDescription(resourceBundle.getString("removeVault.description")) //
.setIcon(FontAwesome5Icon.QUESTION) //
.setOkButtonText(resourceBundle.getString("removeVault.confirmBtn")) //
.setCancelButtonText(resourceBundle.getString("generic.button.cancel")) //
.setOkAction(v -> {
LOG.debug("Removing vault {}.", vault.get().getDisplayName());
vaults.remove(vault.get());
v.close();
}) //
.setCancelAction(Stage::close) //
.buildAndShow(window);
}
@FXML

View File

@@ -3,29 +3,43 @@ package org.cryptomator.ui.mainwindow;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultListManager;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.controls.CustomDialogBuilder;
import org.cryptomator.ui.controls.FontAwesome5Icon;
import org.cryptomator.ui.fxapp.FxApplicationWindows;
import org.cryptomator.ui.removevault.RemoveVaultComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Named;
import javafx.beans.property.ObjectProperty;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.stage.Stage;
import java.util.ResourceBundle;
@MainWindowScoped
public class VaultDetailUnknownErrorController implements FxController {
private static final Logger LOG = LoggerFactory.getLogger(VaultDetailUnknownErrorController.class);
private final ObjectProperty<Vault> vault;
private final FxApplicationWindows appWindows;
private final Stage errorWindow;
private final RemoveVaultComponent.Builder removeVault;
private final ObservableList<Vault> vaults;
private final ResourceBundle resourceBundle;
private final Stage mainWindow;
@Inject
public VaultDetailUnknownErrorController(ObjectProperty<Vault> vault, FxApplicationWindows appWindows, @Named("errorWindow") Stage errorWindow, RemoveVaultComponent.Builder removeVault) {
public VaultDetailUnknownErrorController(@MainWindow Stage mainWindow,
ObjectProperty<Vault> vault, ObservableList<Vault> vaults, //
ResourceBundle resourceBundle, //
FxApplicationWindows appWindows, @Named("errorWindow") Stage errorWindow) {
this.mainWindow = mainWindow;
this.vault = vault;
this.vaults = vaults;
this.resourceBundle = resourceBundle;
this.appWindows = appWindows;
this.errorWindow = errorWindow;
this.removeVault = removeVault;
}
@FXML
@@ -40,6 +54,19 @@ public class VaultDetailUnknownErrorController implements FxController {
@FXML
void didClickRemoveVault() {
removeVault.vault(vault.get()).build().showRemoveVault();
new CustomDialogBuilder() //
.setTitle(String.format(resourceBundle.getString("removeVault.title"), vault.get().getDisplayName())) //
.setMessage(resourceBundle.getString("removeVault.message")) //
.setDescription(resourceBundle.getString("removeVault.description")) //
.setIcon(FontAwesome5Icon.QUESTION) //
.setOkButtonText(resourceBundle.getString("removeVault.confirmBtn")) //
.setCancelButtonText(resourceBundle.getString("generic.button.cancel")) //
.setOkAction(v -> {
LOG.debug("Removing vault {}.", vault.get().getDisplayName());
vaults.remove(vault.get());
v.close();
}) //
.setCancelAction(Stage::close) //
.buildAndShow(mainWindow);
}
}

View File

@@ -5,19 +5,24 @@ import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultState;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.common.VaultService;
import org.cryptomator.ui.controls.CustomDialogBuilder;
import org.cryptomator.ui.controls.FontAwesome5Icon;
import org.cryptomator.ui.fxapp.FxApplicationWindows;
import org.cryptomator.ui.removevault.RemoveVaultComponent;
import org.cryptomator.ui.vaultoptions.SelectedVaultOptionsTab;
import org.cryptomator.ui.vaultoptions.VaultOptionsComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.stage.Stage;
import java.util.EnumSet;
import java.util.Objects;
import java.util.ResourceBundle;
import static org.cryptomator.common.vaults.VaultState.Value.ERROR;
import static org.cryptomator.common.vaults.VaultState.Value.LOCKED;
@@ -28,27 +33,36 @@ import static org.cryptomator.common.vaults.VaultState.Value.UNLOCKED;
@MainWindowScoped
public class VaultListContextMenuController implements FxController {
private static final Logger LOG = LoggerFactory.getLogger(VaultListContextMenuController.class);
private final ReadOnlyObjectProperty<Vault> selectedVault;
private final Stage mainWindow;
private final FxApplicationWindows appWindows;
private final VaultService vaultService;
private final KeychainManager keychain;
private final RemoveVaultComponent.Builder removeVault;
private final VaultOptionsComponent.Factory vaultOptionsWindow;
private final ObservableValue<VaultState.Value> selectedVaultState;
private final ObservableValue<Boolean> selectedVaultPassphraseStored;
private final ObservableValue<Boolean> selectedVaultRemovable;
private final ObservableValue<Boolean> selectedVaultUnlockable;
private final ObservableValue<Boolean> selectedVaultLockable;
private final ObservableList<Vault> vaults;
private final ResourceBundle resourceBundle;
@Inject
VaultListContextMenuController(ObjectProperty<Vault> selectedVault, @MainWindow Stage mainWindow, FxApplicationWindows appWindows, VaultService vaultService, KeychainManager keychain, RemoveVaultComponent.Builder removeVault, VaultOptionsComponent.Factory vaultOptionsWindow) {
VaultListContextMenuController(ObjectProperty<Vault> selectedVault,
ObservableList<Vault> vaults, //
ResourceBundle resourceBundle, //
@MainWindow Stage mainWindow, FxApplicationWindows appWindows, VaultService vaultService, KeychainManager keychain, VaultOptionsComponent.Factory vaultOptionsWindow) {
this.selectedVault = selectedVault;
this.vaults = vaults;
this.resourceBundle = resourceBundle;
this.mainWindow = mainWindow;
this.appWindows = appWindows;
this.vaultService = vaultService;
this.keychain = keychain;
this.removeVault = removeVault;
this.vaultOptionsWindow = vaultOptionsWindow;
this.selectedVaultState = selectedVault.flatMap(Vault::stateProperty).orElse(null);
@@ -65,7 +79,21 @@ public class VaultListContextMenuController implements FxController {
@FXML
public void didClickRemoveVault() {
var vault = Objects.requireNonNull(selectedVault.get());
removeVault.vault(vault).build().showRemoveVault();
new CustomDialogBuilder() //
.setTitle(String.format(resourceBundle.getString("removeVault.title"), vault.getDisplayName())) //
.setMessage(resourceBundle.getString("removeVault.message")) //
.setDescription(resourceBundle.getString("removeVault.description")) //
.setIcon(FontAwesome5Icon.QUESTION) //
.setOkButtonText(resourceBundle.getString("removeVault.confirmBtn")) //
.setCancelButtonText(resourceBundle.getString("generic.button.cancel")) //
.setOkAction(v -> {
LOG.debug("Removing vault {}.", vault.getDisplayName());
vaults.remove(vault);
v.close();
}) //
.setCancelAction(Stage::close) //
.buildAndShow(mainWindow);
}
@FXML

View File

@@ -214,8 +214,8 @@ public class VaultListController implements FxController {
.setOkButtonText(resourceBundle.getString("removeVault.confirmBtn")) //
.setCancelButtonText(resourceBundle.getString("generic.button.cancel")) //
.setOkAction(v -> {
vaults.remove(vault);
LOG.debug("Removing vault {}.", vault.getDisplayName());
vaults.remove(vault);
v.close();
}) //
.setCancelAction(Stage::close) //