mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-21 12:11:28 +00:00
changed resolveText() to throw Exceptions
removed fxApplication scope
This commit is contained in:
@@ -11,6 +11,7 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import java.util.IllegalFormatException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -19,7 +20,7 @@ public class CustomDialog {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CustomDialog.class);
|
||||
private final ResourceBundle resourceBundle;
|
||||
|
||||
private Stage dialogStage;
|
||||
private final Stage dialogStage;
|
||||
|
||||
CustomDialog(Builder builder) {
|
||||
this.resourceBundle = builder.resourceBundle;
|
||||
@@ -56,10 +57,14 @@ public class CustomDialog {
|
||||
}
|
||||
|
||||
private String resolveText(String key, String[] args) {
|
||||
String text = (key == null || key.isEmpty() || !resourceBundle.containsKey(key))
|
||||
? String.format("N/A - Key '%s' not found", key)
|
||||
: resourceBundle.getString(key);
|
||||
return args != null && args.length > 0 ? String.format(text, (Object[]) args) : text;
|
||||
if (key == null || key.isEmpty() || !resourceBundle.containsKey(key)) {
|
||||
throw new IllegalArgumentException(String.format("Invalid key: '%s'. Key not found in ResourceBundle.", key)); }
|
||||
String text = resourceBundle.getString(key);
|
||||
try {
|
||||
return args != null && args.length > 0 ? String.format(text, (Object[]) args) : text;
|
||||
} catch (IllegalFormatException e) {
|
||||
throw new IllegalArgumentException("Formatting error: Check if arguments match placeholders in the text.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@@ -77,7 +82,6 @@ public class CustomDialog {
|
||||
private Consumer<Stage> okAction = Stage::close;
|
||||
private Consumer<Stage> cancelAction = Stage::close;
|
||||
|
||||
@Inject
|
||||
public Builder(ResourceBundle resourceBundle) {
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,6 @@ abstract class FxApplicationModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
@FxApplicationScoped
|
||||
static CustomDialog.Builder provideCustomDialog(ResourceBundle resourceBundle) {
|
||||
return new CustomDialog.Builder(resourceBundle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user