public static interface Dialogs.InputDialogBuilder extends Dialogs.DialogBuilder<Dialogs.InputDialogBuilder>
Modifier and Type | Method and Description |
---|---|
InputDialog |
build()
Builds the input dialog.
|
InputDialog |
show() |
Dialogs.InputDialogBuilder |
withActions(DialogActions actions)
Sets predefined dialog actions.
|
Dialogs.InputDialogBuilder |
withActions(DialogActions actions,
java.util.function.Consumer<InputDialog.InputDialogResult> resultHandler)
Sets dialog actions and result handler.
|
Dialogs.InputDialogBuilder |
withActions(InputDialogAction... actions)
Sets dialog actions.
|
Dialogs.InputDialogBuilder |
withCloseListener(java.util.function.Consumer<InputDialog.InputDialogCloseEvent> listener)
Add close listener to the dialog.
|
Dialogs.InputDialogBuilder |
withParameter(InputParameter parameter)
Adds input parameter to the dialog.
|
Dialogs.InputDialogBuilder |
withParameters(InputParameter... parameters)
Sets input parameters.
|
Dialogs.InputDialogBuilder |
withValidator(java.util.function.Function<InputDialog.ValidationContext,ValidationErrors> validator)
Sets additional handler for field validation.
|
getCaption, withCaption
getHeight, getHeightSizeUnit, getWidth, getWidthSizeUnit, withHeight, withWidth
Dialogs.InputDialogBuilder withParameter(InputParameter parameter)
Example:
dialogs.createInputDialog(this)
.withParameter(
entityParameter("userField", User.class)
.withCaption("User field")
.withRequired(true)
)
.show();
parameter
- input parameter that will be added to the dialogInputParameter.entityParameter(String, Class)
Dialogs.InputDialogBuilder withParameters(InputParameter... parameters)
Example:
dialogs.createInputDialog(this)
.withParameters(
stringParameter("nameField")
.withCaption("Name field caption")
.withDefaultValue("default value"),
intParameter("countField")
.withCaption("Count field caption")
.withRequired(true))
.show();
parameters
- input parametersInputParameter.stringParameter(String)
,
InputParameter.intParameter(String)
Dialogs.InputDialogBuilder withCloseListener(java.util.function.Consumer<InputDialog.InputDialogCloseEvent> listener)
DialogActions
in InputDialog
.listener
- close listener to addDialogs.InputDialogBuilder withActions(InputDialogAction... actions)
InputDialogAction
provides access to input dialog in InputDialogAction.InputDialogActionPerformed
where it is possible to get values form the fields and implement logic to close dialog.
Note, if there is no actions are set input dialog will use DialogActions.OK_CANCEL
by default.
dialogs.createInputDialog(this)
.withCaption("Dialog caption")
.withParameter(parameter("nameField").withCaption("Name"))
.withActions(
action("okAction")
.withCaption("OK")
.withIcon(CubaIcon.DIALOG_OK)
.withHandler(event -> {
InputDialog inputDialog = event.getInputDialog();
String name = inputDialog.getValue("nameField");
// do logic
inputDialog.close(InputDialog.INPUT_DIALOG_OK_ACTION);
}),
action("cancelAction")
.withCaption("Cancel")
.withIcon(CubaIcon.DIALOG_CANCEL)
.withValidationRequired(false)
.withHandler(event -> {
InputDialog inputDialog = event.getInputDialog();
inputDialog.close(InputDialog.INPUT_DIALOG_CANCEL_ACTION);
}))
.show();
actions
- actionsInputDialogAction.action(String)
Dialogs.InputDialogBuilder withActions(DialogActions actions)
DialogActions.OK_CANCEL
.actions
- actionsDialogs.InputDialogBuilder withActions(DialogActions actions, java.util.function.Consumer<InputDialog.InputDialogResult> resultHandler)
withCloseListener(Consumer)
.
Example
dialogs.createInputDialog(this)
.withCaption("Dialog caption")
.withParameter(parameter("nameField").withCaption("Name"))
.withActions(DialogActions.OK_CANCEL, result -> {
switch (result.getCloseActionType()) {
case OK:
String name = result.getValue("nameField");
// do logic
break;
case CANCEL:
// do logic
break;
}
})
.show();
actions
- dialog actionsresultHandler
- result handlerDialogs.InputDialogBuilder withValidator(java.util.function.Function<InputDialog.ValidationContext,ValidationErrors> validator)
ValidationErrors
instance. Returned validation errors will be shown with another errors from fields.
Example
dialogs.createInputDialog(this)
.withParameters(
stringParameter("phoneField").withCaption("Phone"),
stringParameter("addressField").withCaption("Address"))
.withValidator(context -> {
String phone = context.getValue("phoneField");
String address = context.getValue("addressField");
if (Strings.isNullOrEmpty(phone) && Strings.isNullOrEmpty(address)) {
return ValidationErrors.of("Phone or Address should be filled");
}
return ValidationErrors.none();
})
.show();
validator
- validatorInputDialog build()
InputDialog show()