Browse Source

add validation for required parameters and changed exception message

Jan-Peter Klein 2 months ago
parent
commit
a0667ff361

+ 8 - 1
src/main/java/org/cryptomator/ui/dialogs/SimpleDialog.java

@@ -12,6 +12,7 @@ import javafx.stage.Stage;
 import java.io.IOException;
 import java.io.UncheckedIOException;
 import java.util.IllegalFormatException;
+import java.util.Objects;
 import java.util.ResourceBundle;
 import java.util.function.Consumer;
 
@@ -128,10 +129,16 @@ public class SimpleDialog {
 		}
 
 		public SimpleDialog build() {
+			Objects.requireNonNull(titleKey,"SimpleDialog titleKey must be set.");
+			Objects.requireNonNull(messageKey,"SimpleDialog messageKey must be set.");
+			Objects.requireNonNull(descriptionKey,"SimpleDialog descriptionKey must be set.");
+			Objects.requireNonNull(okButtonKey,"SimpleDialog okButtonKey must be set.");
+			Objects.requireNonNull(cancelButtonKey,"SimpleDialog cancelButtonKey must be set.");
+
 			try {
 				return new SimpleDialog(this);
 			} catch (IOException e) {
-				throw new UncheckedIOException("Failed to create CustomDialog.", e);
+				throw new UncheckedIOException("Failed to create SimpleDialog.", e);
 			}
 		}
 	}

+ 2 - 2
src/main/resources/fxml/custom_dialog.fxml

@@ -41,8 +41,8 @@
 			<Region VBox.vgrow="ALWAYS" minHeight="18"/>
 			<ButtonBar buttonMinWidth="120" buttonOrder="+CI">
 				<buttons>
-					<Button fx:id="cancelButton" text="CANCEL" ButtonBar.buttonData="CANCEL_CLOSE" cancelButton="true" onAction="#handleCancel"/>
-					<Button fx:id="okButton" text="OK" ButtonBar.buttonData="FINISH" defaultButton="true" onAction="#handleOk"/>
+					<Button fx:id="cancelButton" ButtonBar.buttonData="CANCEL_CLOSE" cancelButton="true" onAction="#handleCancel"/>
+					<Button fx:id="okButton" ButtonBar.buttonData="FINISH" defaultButton="true" onAction="#handleOk"/>
 				</buttons>
 			</ButtonBar>
 		</VBox>