Browse Source

moved all simple dialogs to Dialogs

Jan-Peter Klein 2 months ago
parent
commit
40fbfd10d1

+ 34 - 5
src/main/java/org/cryptomator/ui/dialogs/Dialogs.java

@@ -1,5 +1,6 @@
 package org.cryptomator.ui.dialogs;
 
+import org.cryptomator.common.settings.Settings;
 import org.cryptomator.common.vaults.Vault;
 import org.cryptomator.ui.controls.FontAwesome5Icon;
 import org.slf4j.Logger;
@@ -7,16 +8,15 @@ import org.slf4j.LoggerFactory;
 
 import javafx.collections.ObservableList;
 import javafx.stage.Stage;
+import java.util.function.Consumer;
 
 
 public class Dialogs {
 
 	private static final Logger LOG = LoggerFactory.getLogger(Dialogs.class);
 
-	private Dialogs() {}
-
-	public static void showRemoveVaultDialog(SimpleDialog.Builder simpleDialogBuilder, Stage mainWindow, Vault vault, ObservableList<Vault> vaults) {
-		simpleDialogBuilder.setOwner(mainWindow) //
+	public static SimpleDialog buildRemoveVaultDialog(SimpleDialog.Builder simpleDialogBuilder, Stage window, Vault vault, ObservableList<Vault> vaults) {
+		return simpleDialogBuilder.setOwner(window) //
 				.setTitleKey("removeVault.title", vault.getDisplayName()) //
 				.setMessageKey("removeVault.message") //
 				.setDescriptionKey("removeVault.description") //
@@ -28,6 +28,35 @@ public class Dialogs {
 					vaults.remove(vault);
 					v.close();
 				}) //
-				.build().showAndWait();
+				.build();
+	}
+
+	public static SimpleDialog buildRemoveCertDialog(SimpleDialog.Builder simpleDialogBuilder, Stage window, Settings settings) {
+		return simpleDialogBuilder.setOwner(window) //
+				.setTitleKey("removeCert.title") //
+				.setMessageKey("removeCert.message") //
+				.setDescriptionKey("removeCert.description") //
+				.setIcon(FontAwesome5Icon.QUESTION) //
+				.setOkButtonKey("removeCert.confirmBtn") //
+				.setCancelButtonKey("generic.button.cancel").setOkAction(v -> {
+					settings.licenseKey.set(null);
+					v.close();
+				}) //
+				.setCancelAction(Stage::close) //
+				.build();
 	}
+
+	public static SimpleDialog buildDokanySupportEndDialog(SimpleDialog.Builder simpleDialogBuilder, Stage window, Consumer<Stage> cancelAction) {
+		return simpleDialogBuilder.setOwner(window) //
+				.setTitleKey("dokanySupportEnd.title") //
+				.setMessageKey("dokanySupportEnd.message") //
+				.setDescriptionKey("dokanySupportEnd.description") //
+				.setIcon(FontAwesome5Icon.QUESTION) //
+				.setOkButtonKey("generic.button.close") //
+				.setCancelButtonKey("dokanySupportEnd.preferencesBtn") //
+				.setOkAction(Stage::close) //
+				.setCancelAction(cancelAction) //
+				.build();
+	}
+
 }

+ 10 - 15
src/main/java/org/cryptomator/ui/fxapp/FxApplicationWindows.java

@@ -5,8 +5,8 @@ import dagger.Lazy;
 import org.cryptomator.common.vaults.Vault;
 import org.cryptomator.common.vaults.VaultState;
 import org.cryptomator.integrations.tray.TrayIntegrationProvider;
+import org.cryptomator.ui.dialogs.Dialogs;
 import org.cryptomator.ui.dialogs.SimpleDialog;
-import org.cryptomator.ui.controls.FontAwesome5Icon;
 import org.cryptomator.ui.error.ErrorComponent;
 import org.cryptomator.ui.lock.LockComponent;
 import org.cryptomator.ui.mainwindow.MainWindowComponent;
@@ -57,7 +57,7 @@ public class FxApplicationWindows {
 	private final VaultOptionsComponent.Factory vaultOptionsWindow;
 	private final ShareVaultComponent.Factory shareVaultWindow;
 	private final FilteredList<Window> visibleWindows;
-	private final Provider<SimpleDialog.Builder> simpleDialogProvider;
+	private final Provider<SimpleDialog.Builder> simpleDialogBuilder;
 
 	@Inject
 	public FxApplicationWindows(@PrimaryStage Stage primaryStage, //
@@ -72,7 +72,7 @@ public class FxApplicationWindows {
 								VaultOptionsComponent.Factory vaultOptionsWindow, //
 								ShareVaultComponent.Factory shareVaultWindow, //
 								ExecutorService executor, //
-								Provider<SimpleDialog.Builder> simpleDialogProvider) {
+								Provider<SimpleDialog.Builder> simpleDialogBuilder) {
 		this.primaryStage = primaryStage;
 		this.trayIntegration = trayIntegration;
 		this.mainWindow = mainWindow;
@@ -86,7 +86,7 @@ public class FxApplicationWindows {
 		this.vaultOptionsWindow = vaultOptionsWindow;
 		this.shareVaultWindow = shareVaultWindow;
 		this.visibleWindows = Window.getWindows().filtered(Window::isShowing);
-		this.simpleDialogProvider = simpleDialogProvider;
+		this.simpleDialogBuilder = simpleDialogBuilder;
 	}
 
 	public void initialize() {
@@ -150,19 +150,14 @@ public class FxApplicationWindows {
 
 	public void showDokanySupportEndWindow() {
 		CompletableFuture.runAsync(() -> {
-			simpleDialogProvider.get().setOwner(mainWindow.get().window()) //
-					.setTitleKey("dokanySupportEnd.title") //
-					.setMessageKey("dokanySupportEnd.message") //
-					.setDescriptionKey("dokanySupportEnd.description") //
-					.setIcon(FontAwesome5Icon.QUESTION) //
-					.setOkButtonKey("generic.button.close") //
-					.setCancelButtonKey("dokanySupportEnd.preferencesBtn") //
-					.setOkAction(Stage::close) //
-					.setCancelAction(v -> {
+			Dialogs.buildDokanySupportEndDialog(
+					simpleDialogBuilder.get(),
+					mainWindow.get().window(),
+					v -> {
 						showPreferencesWindow(SelectedPreferencesTab.VOLUME);
 						v.close();
-					}) //
-					.build().showAndWait();
+					}
+			).showAndWait();
 		}, Platform::runLater);
 	}
 

+ 4 - 5
src/main/java/org/cryptomator/ui/mainwindow/VaultDetailMissingVaultController.java

@@ -5,7 +5,6 @@ import org.cryptomator.common.vaults.VaultListManager;
 import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.dialogs.Dialogs;
 import org.cryptomator.ui.dialogs.SimpleDialog;
-import org.cryptomator.ui.controls.FontAwesome5Icon;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -30,19 +29,19 @@ public class VaultDetailMissingVaultController implements FxController {
 	private final ObservableList<Vault> vaults;
 	private final ResourceBundle resourceBundle;
 	private final Stage window;
-	private final Provider<SimpleDialog.Builder> simpleDialogProvider;
+	private final Provider<SimpleDialog.Builder> simpleDialogBuilder;
 
 	@Inject
 	public VaultDetailMissingVaultController(ObjectProperty<Vault> vault, //
 											 ObservableList<Vault> vaults, //
 											 ResourceBundle resourceBundle, //
 											 @MainWindow Stage window, //
-											 Provider<SimpleDialog.Builder> simpleDialogProvider) {
+											 Provider<SimpleDialog.Builder> simpleDialogBuilder) {
 		this.vault = vault;
 		this.vaults = vaults;
 		this.resourceBundle = resourceBundle;
 		this.window = window;
-		this.simpleDialogProvider = simpleDialogProvider;
+		this.simpleDialogBuilder = simpleDialogBuilder;
 	}
 
 	@FXML
@@ -52,7 +51,7 @@ public class VaultDetailMissingVaultController implements FxController {
 
 	@FXML
 	void didClickRemoveVault() {
-		Dialogs.showRemoveVaultDialog(simpleDialogProvider.get(),window,vault.get(),vaults);
+		Dialogs.buildRemoveVaultDialog(simpleDialogBuilder.get(),window,vault.get(),vaults).showAndWait();
 	}
 
 	@FXML

+ 4 - 5
src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnknownErrorController.java

@@ -5,7 +5,6 @@ import org.cryptomator.common.vaults.VaultListManager;
 import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.dialogs.Dialogs;
 import org.cryptomator.ui.dialogs.SimpleDialog;
-import org.cryptomator.ui.controls.FontAwesome5Icon;
 import org.cryptomator.ui.fxapp.FxApplicationWindows;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,7 +27,7 @@ public class VaultDetailUnknownErrorController implements FxController {
 	private final Stage errorWindow;
 	private final ObservableList<Vault> vaults;
 	private final Stage mainWindow;
-	private final Provider<SimpleDialog.Builder> simpleDialogProvider;
+	private final Provider<SimpleDialog.Builder> simpleDialogBuilder;
 
 	@Inject
 	public VaultDetailUnknownErrorController(@MainWindow Stage mainWindow, //
@@ -36,13 +35,13 @@ public class VaultDetailUnknownErrorController implements FxController {
 											 ObservableList<Vault> vaults, //
 											 FxApplicationWindows appWindows, //
 											 @Named("errorWindow") Stage errorWindow, //
-											 Provider<SimpleDialog.Builder> simpleDialogProvider) {
+											 Provider<SimpleDialog.Builder> simpleDialogBuilder) {
 		this.mainWindow = mainWindow;
 		this.vault = vault;
 		this.vaults = vaults;
 		this.appWindows = appWindows;
 		this.errorWindow = errorWindow;
-		this.simpleDialogProvider = simpleDialogProvider;
+		this.simpleDialogBuilder = simpleDialogBuilder;
 	}
 
 	@FXML
@@ -57,6 +56,6 @@ public class VaultDetailUnknownErrorController implements FxController {
 
 	@FXML
 	void didClickRemoveVault() {
-		Dialogs.showRemoveVaultDialog(simpleDialogProvider.get(),mainWindow,vault.get(),vaults);
+		Dialogs.buildRemoveVaultDialog(simpleDialogBuilder.get(),mainWindow,vault.get(),vaults).showAndWait();
 	}
 }

+ 4 - 5
src/main/java/org/cryptomator/ui/mainwindow/VaultListContextMenuController.java

@@ -5,7 +5,6 @@ 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.FontAwesome5Icon;
 import org.cryptomator.ui.dialogs.Dialogs;
 import org.cryptomator.ui.dialogs.SimpleDialog;
 import org.cryptomator.ui.fxapp.FxApplicationWindows;
@@ -49,7 +48,7 @@ public class VaultListContextMenuController implements FxController {
 	private final ObservableValue<Boolean> selectedVaultUnlockable;
 	private final ObservableValue<Boolean> selectedVaultLockable;
 	private final ObservableList<Vault> vaults;
-	private final Provider<SimpleDialog.Builder> simpleDialogProvider;
+	private final Provider<SimpleDialog.Builder> simpleDialogBuilder;
 
 
 	@Inject
@@ -60,7 +59,7 @@ public class VaultListContextMenuController implements FxController {
 								   VaultService vaultService, //
 								   KeychainManager keychain, //
 								   VaultOptionsComponent.Factory vaultOptionsWindow, //
-								   Provider<SimpleDialog.Builder> simpleDialogProvider) {
+								   Provider<SimpleDialog.Builder> simpleDialogBuilder) {
 		this.selectedVault = selectedVault;
 		this.vaults = vaults;
 		this.mainWindow = mainWindow;
@@ -68,7 +67,7 @@ public class VaultListContextMenuController implements FxController {
 		this.vaultService = vaultService;
 		this.keychain = keychain;
 		this.vaultOptionsWindow = vaultOptionsWindow;
-		this.simpleDialogProvider = simpleDialogProvider;
+		this.simpleDialogBuilder = simpleDialogBuilder;
 
 		this.selectedVaultState = selectedVault.flatMap(Vault::stateProperty).orElse(null);
 		this.selectedVaultPassphraseStored = selectedVault.map(this::isPasswordStored).orElse(false);
@@ -84,7 +83,7 @@ public class VaultListContextMenuController implements FxController {
 	@FXML
 	public void didClickRemoveVault() {
 		var vault = Objects.requireNonNull(selectedVault.get());
-		Dialogs.showRemoveVaultDialog(simpleDialogProvider.get(),mainWindow,vault,vaults);
+		Dialogs.buildRemoveVaultDialog(simpleDialogBuilder.get(),mainWindow,vault,vaults).showAndWait();
 	}
 
 	@FXML

+ 4 - 5
src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java

@@ -11,7 +11,6 @@ import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.common.VaultService;
 import org.cryptomator.ui.dialogs.Dialogs;
 import org.cryptomator.ui.dialogs.SimpleDialog;
-import org.cryptomator.ui.controls.FontAwesome5Icon;
 import org.cryptomator.ui.fxapp.FxApplicationWindows;
 import org.cryptomator.ui.preferences.SelectedPreferencesTab;
 import org.slf4j.Logger;
@@ -74,7 +73,7 @@ public class VaultListController implements FxController {
 	private final ResourceBundle resourceBundle;
 	private final FxApplicationWindows appWindows;
 	private final ObservableValue<Double> cellSize;
-	private final Provider<SimpleDialog.Builder> simpleDialogProvider;
+	private final Provider<SimpleDialog.Builder> simpleDialogBuilder;
 
 	public ListView<Vault> vaultList;
 	public StackPane root;
@@ -94,7 +93,7 @@ public class VaultListController implements FxController {
 						ResourceBundle resourceBundle, //
 						FxApplicationWindows appWindows, //
 						Settings settings, //
-						Provider<SimpleDialog.Builder> simpleDialogProvider) {
+						Provider<SimpleDialog.Builder> simpleDialogBuilder) {
 		this.mainWindow = mainWindow;
 		this.vaults = vaults;
 		this.selectedVault = selectedVault;
@@ -104,7 +103,7 @@ public class VaultListController implements FxController {
 		this.vaultListManager = vaultListManager;
 		this.resourceBundle = resourceBundle;
 		this.appWindows = appWindows;
-		this.simpleDialogProvider = simpleDialogProvider;
+		this.simpleDialogBuilder = simpleDialogBuilder;
 
 		this.emptyVaultList = Bindings.isEmpty(vaults);
 
@@ -212,7 +211,7 @@ public class VaultListController implements FxController {
 	private void pressedShortcutToRemoveVault() {
 		final var vault = selectedVault.get();
 		if (vault != null && EnumSet.of(LOCKED, MISSING, ERROR, NEEDS_MIGRATION).contains(vault.getState())) {
-			Dialogs.showRemoveVaultDialog(simpleDialogProvider.get(),mainWindow,vault,vaults);
+			Dialogs.buildRemoveVaultDialog(simpleDialogBuilder.get(),mainWindow,vault,vaults).showAndWait();
 		}
 	}
 

+ 5 - 16
src/main/java/org/cryptomator/ui/preferences/SupporterCertificateController.java

@@ -5,8 +5,8 @@ import org.cryptomator.common.LicenseHolder;
 import org.cryptomator.common.settings.Settings;
 import org.cryptomator.common.settings.UiTheme;
 import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.dialogs.Dialogs;
 import org.cryptomator.ui.dialogs.SimpleDialog;
-import org.cryptomator.ui.controls.FontAwesome5Icon;
 
 import javax.inject.Inject;
 import javax.inject.Provider;
@@ -28,7 +28,7 @@ public class SupporterCertificateController implements FxController {
 	private final Stage window;
 	private final LicenseHolder licenseHolder;
 	private final Settings settings;
-	private final Provider<SimpleDialog.Builder> simpleDialogProvider;
+	private final Provider<SimpleDialog.Builder> simpleDialogBuilder;
 
 	@FXML
 	private TextArea supporterCertificateField;
@@ -38,12 +38,12 @@ public class SupporterCertificateController implements FxController {
 								   @PreferencesWindow Stage window,  //
 								   LicenseHolder licenseHolder, //
 								   Settings settings, //
-								   Provider<SimpleDialog.Builder> simpleDialogProvider) {
+								   Provider<SimpleDialog.Builder> simpleDialogBuilder) {
 		this.application = application;
 		this.window = window;
 		this.licenseHolder = licenseHolder;
 		this.settings = settings;
-		this.simpleDialogProvider = simpleDialogProvider;
+		this.simpleDialogBuilder = simpleDialogBuilder;
 	}
 
 	@FXML
@@ -90,18 +90,7 @@ public class SupporterCertificateController implements FxController {
 
 	@FXML
 	void didClickRemoveCert() {
-		simpleDialogProvider.get().setOwner(window) //
-				.setTitleKey("removeCert.title") //
-				.setMessageKey("removeCert.message") //
-				.setDescriptionKey("removeCert.description") //
-				.setIcon(FontAwesome5Icon.QUESTION) //
-				.setOkButtonKey("removeCert.confirmBtn") //
-				.setCancelButtonKey("generic.button.cancel").setOkAction(v -> {
-					settings.licenseKey.set(null);
-					v.close();
-				}) //
-				.setCancelAction(Stage::close) //
-				.build().showAndWait();
+		Dialogs.buildRemoveCertDialog(simpleDialogBuilder.get(),window,settings).showAndWait();
 	}
 
 	public LicenseHolder getLicenseHolder() {