mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-20 01:26:52 -04:00
implement CustomDialogBuilder
This commit is contained in:
@@ -12,6 +12,7 @@ public enum FxmlFile {
|
||||
CONVERTVAULT_HUBTOPASSWORD_START("/fxml/convertvault_hubtopassword_start.fxml"), //
|
||||
CONVERTVAULT_HUBTOPASSWORD_CONVERT("/fxml/convertvault_hubtopassword_convert.fxml"), //
|
||||
CONVERTVAULT_HUBTOPASSWORD_SUCCESS("/fxml/convertvault_hubtopassword_success.fxml"), //
|
||||
CUSTOM_DIALOG("/fxml/custom_dialog.fxml"), //
|
||||
DOKANY_SUPPORT_END("/fxml/dokany_support_end.fxml"), //
|
||||
ERROR("/fxml/error.fxml"), //
|
||||
FORGET_PASSWORD("/fxml/forget_password.fxml"), //
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.cryptomator.ui.controls;
|
||||
|
||||
import org.cryptomator.ui.common.FxmlFile;
|
||||
import org.cryptomator.ui.quit.QuitComponent;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class CustomDialogBuilder {
|
||||
|
||||
public CustomDialogBuilder() {
|
||||
}
|
||||
|
||||
public void showDialog(ResourceBundle resourceBundle, Stage owner, FontAwesome5Icon icon, String title, String message, String description, Runnable okAction, String okText) {
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader(getResource(FxmlFile.CUSTOM_DIALOG), resourceBundle);
|
||||
Pane pane = loader.load();
|
||||
|
||||
CustomDialogController controller = loader.getController();
|
||||
controller.setIcon(icon);
|
||||
controller.setMessage(message);
|
||||
controller.setDescription(description);
|
||||
controller.setOkButtonText(okText);
|
||||
controller.setOkAction(okAction);
|
||||
|
||||
Stage dialogStage = new Stage();
|
||||
dialogStage.setTitle(title);
|
||||
dialogStage.initModality(Modality.WINDOW_MODAL);
|
||||
dialogStage.initOwner(owner);
|
||||
dialogStage.setScene(new Scene(pane));
|
||||
dialogStage.setResizable(false);
|
||||
controller.setDialogStage(dialogStage);
|
||||
|
||||
dialogStage.showAndWait();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); // Handle loading errors
|
||||
}
|
||||
}
|
||||
|
||||
private URL getResource(FxmlFile fxmlFile) {
|
||||
return getClass().getResource(fxmlFile.getRessourcePathString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.cryptomator.ui.controls;
|
||||
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class CustomDialogController implements FxController {
|
||||
|
||||
@FXML
|
||||
private Label message;
|
||||
@FXML
|
||||
private Label description;
|
||||
@FXML
|
||||
private FontAwesome5IconView icon;
|
||||
@FXML
|
||||
private Button okButton;
|
||||
|
||||
private Stage dialogStage;
|
||||
private Runnable okAction;
|
||||
|
||||
public void setDialogStage(Stage stage) {
|
||||
this.dialogStage = stage;
|
||||
}
|
||||
|
||||
public void setIcon(FontAwesome5Icon glyph) {
|
||||
icon.setGlyph(glyph);
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message.setText(message);
|
||||
}
|
||||
|
||||
public void setDescription(String desc) {
|
||||
this.description.setText(desc);
|
||||
}
|
||||
|
||||
public void setOkAction(Runnable action) {
|
||||
this.okAction = action;
|
||||
}
|
||||
|
||||
public void setOkButtonText(String text) {
|
||||
okButton.setText(text);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleOk() {
|
||||
if (okAction != null) {
|
||||
okAction.run();
|
||||
}
|
||||
dialogStage.close();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleCancel() {
|
||||
dialogStage.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import org.cryptomator.cryptofs.DirStructure;
|
||||
import org.cryptomator.ui.addvaultwizard.AddVaultWizardComponent;
|
||||
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.preferences.SelectedPreferencesTab;
|
||||
import org.cryptomator.ui.removevault.RemoveVaultComponent;
|
||||
@@ -208,7 +210,16 @@ 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())) {
|
||||
removeVaultDialogue.vault(vault).build().showRemoveVault();
|
||||
new CustomDialogBuilder().showDialog(resourceBundle, mainWindow, //
|
||||
FontAwesome5Icon.CROWN, //
|
||||
String.format(resourceBundle.getString("removeVault.title"), vault.getDisplayName()), //
|
||||
resourceBundle.getString("removeVault.message"), //
|
||||
resourceBundle.getString("removeVault.description"), //
|
||||
() -> {
|
||||
vaults.remove(vault);
|
||||
LOG.debug("Removing vault {}.", vault.getDisplayName());
|
||||
}, //
|
||||
resourceBundle.getString("removeVault.confirmBtn"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +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.removecert.RemoveCertComponent;
|
||||
import org.cryptomator.ui.controls.CustomDialogBuilder;
|
||||
import org.cryptomator.ui.controls.FontAwesome5Icon;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javafx.application.Application;
|
||||
@@ -14,6 +15,7 @@ import javafx.fxml.FXML;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextFormatter;
|
||||
import javafx.stage.Stage;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@PreferencesScoped
|
||||
public class SupporterCertificateController implements FxController {
|
||||
@@ -26,18 +28,18 @@ public class SupporterCertificateController implements FxController {
|
||||
private final Stage window;
|
||||
private final LicenseHolder licenseHolder;
|
||||
private final Settings settings;
|
||||
private final RemoveCertComponent.Builder removeCert;
|
||||
private final ResourceBundle resourceBundle;
|
||||
|
||||
@FXML
|
||||
private TextArea supporterCertificateField;
|
||||
|
||||
@Inject
|
||||
SupporterCertificateController(Application application, @PreferencesWindow Stage window, LicenseHolder licenseHolder, Settings settings, RemoveCertComponent.Builder removeCert) {
|
||||
SupporterCertificateController(Application application, @PreferencesWindow Stage window, LicenseHolder licenseHolder, Settings settings, ResourceBundle resourceBundle) {
|
||||
this.application = application;
|
||||
this.window = window;
|
||||
this.licenseHolder = licenseHolder;
|
||||
this.settings = settings;
|
||||
this.removeCert = removeCert;
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -84,7 +86,13 @@ public class SupporterCertificateController implements FxController {
|
||||
|
||||
@FXML
|
||||
void didClickRemoveCert() {
|
||||
removeCert.build().showRemoveCert(window);
|
||||
new CustomDialogBuilder().showDialog(resourceBundle, window, //
|
||||
FontAwesome5Icon.QUESTION, //
|
||||
resourceBundle.getString("removeCert.title"), //
|
||||
resourceBundle.getString("removeCert.message"), //
|
||||
resourceBundle.getString("removeCert.description"), //
|
||||
() -> settings.licenseKey.set(null), //
|
||||
resourceBundle.getString("removeCert.confirmBtn"));
|
||||
}
|
||||
|
||||
public LicenseHolder getLicenseHolder() {
|
||||
|
||||
Reference in New Issue
Block a user