Open dialogs through DialogCommand with a DialogWB wave bean — never block the Model on Alert.showAndWait() directly. DialogDaemonCommand (boot component) can dispatch OPEN_DIALOG waves. Swap implementations via @Register(DialogCommand.class).
Add the dialog module. Dialogs open on the JavaFX Application Thread via DialogCommand, without blocking your Model logic.
<dependency>
<groupId>org.jrebirth.af</groupId>
<artifactId>dialog</artifactId>
<version>${jrebirth.version}</version>
</dependency>
Minimal example — show an information dialog from a Model:
@Override
protected void doSave(final Wave wave) {
final DialogWB wb = new DialogWB();
wb.setDialogType(DialogWB.DialogType.Info);
wb.setTitle("Saved");
wb.setHeader("Operation complete");
wb.setMessage("Your changes were saved successfully.");
callCommand(DialogCommand.class, wb);
}
DialogDaemonCommand is a @BootComponent that listens for OPEN_DIALOG waves if you prefer wave-based dispatch. BasicOpenDialogCommand (JavaFX Alert) is the default; register a higher-priority DialogCommand to swap implementations.
The JRebirth Dialog module provides a command-based approach to opening dialogs. Instead of creating and managing dialog instances directly in your Models or Views, you call a Command that handles the dialog lifecycle. This keeps dialog logic separate from UI models and ensures dialogs are displayed on the correct thread (JavaFX Application Thread).
The module supports multiple dialog implementations through the DialogCommand registration point, allowing you to swap between basic JavaFX Alert dialogs and third-party libraries like SimpleDialogFX.
The dialog system is built around these components:
DialogCommand.Alert.DialogCommand is the registration point for dialog implementations. It defines three operations corresponding to dialog severity levels:
@RegistrationPoint
public interface DialogCommand extends CommandBean<DialogWB> {
void openInfoDialog();
void openWarningDialog();
void openErrorDialog();
}
AbstractDialogCommand is the base class for all dialog command implementations. It runs on the JavaFX Application Thread (@RunInto(RunType.JAT)) and dispatches to the appropriate dialog method based on the DialogType in the wave bean.
@RunInto(RunType.JAT)
public abstract class AbstractDialogCommand extends AbstractSingleCommand<DialogWB> implements DialogCommand {
protected DialogWB bean;
@Override
protected void initCommand() {
// Nothing to do yet
}
@Override
protected void perform(Wave wave) throws CommandException {
bean = waveBean(wave);
switch (bean.getDialogType()) {
case Info:
openInfoDialog();
break;
case Warning:
openWarningDialog();
break;
case Error:
openErrorDialog();
break;
}
}
@Override
protected void initInnerComponents() {
// Nothing to do yet
}
}
DialogDaemonCommand is a @BootComponent that starts automatically with the application. It listens for OPEN_DIALOG waves on a background thread (@RunInto(RunType.JIT)) and delegates to the registered DialogCommand implementation. This allows any component to open a dialog by simply sending a wave.
/**
* The Class DialogDaemonCommand.
*/
@BootComponent
@RunInto(RunType.JIT)
public class DialogDaemonCommand extends AbstractSingleCommand<DialogWB> {
/** The Constant OPEN_DIALOG_WT. */
public static final String OPEN_DIALOG_WT = "OPEN_DIALOG";
/** The open dialog. */
private static final WaveType OPEN_DIALOG = WBuilder.waveType(OPEN_DIALOG_WT);
/**
* {@inheritDoc}
*/
@Override
protected void initCommand() {
listen(OPEN_DIALOG);
}
/**
* {@inheritDoc}
*/
@Override
protected void perform(Wave wave) throws CommandException {
callCommand(DialogCommand.class, waveBean(wave));
}
/**
* {@inheritDoc}
*/
@Override
protected void initInnerComponents() {
// Nothing to do yet
}
/**
* {@inheritDoc}
*/
@Override
@OnWave(OPEN_DIALOG_WT)
protected void processWave(final Wave wave) {
if (OPEN_DIALOG.equals(wave.waveType())) {
callCommand(DialogCommand.class, waveBean(wave));
}
}
}
DialogWaveBean is the @Bean-annotated interface defining the data carried by dialog waves. It uses the JRebirth Bean processor to generate an implementation class automatically.
Properties:
dialogType() — the severity level (Info, Warning, Error).title() — the dialog window title.header() — the header text.message() — the content message.exception() — an optional exception for error dialogs.@Bean
public interface DialogWaveBean extends WaveBean {
enum DialogType {
Info,
Warning,
Error
}
DialogType dialogType();
String title();
String header();
String message();
Throwable exception();
}
BasicOpenDialogCommand is the default dialog implementation using standard JavaFX Alert dialogs. It is registered with PriorityLevel.Lowest, meaning it will be used unless a higher-priority implementation is available.
@Register(value = DialogCommand.class, priority = PriorityLevel.Lowest)
public class BasicOpenDialogCommand extends AbstractDialogCommand {
/**
* {@inheritDoc}
*/
@Override
public void openInfoDialog() {
final Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(bean.getTitle());
alert.setHeaderText(bean.getHeader());
alert.setContentText(bean.getMessage());
alert.showAndWait();
}
/**
* {@inheritDoc}
*/
@Override
public void openWarningDialog() {
final Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(bean.getTitle());
alert.setHeaderText(bean.getHeader());
alert.setContentText(bean.getMessage());
alert.showAndWait();
}
/**
* {@inheritDoc}
*/
@Override
public void openErrorDialog() {
final Alert alert = new Alert(AlertType.ERROR);
alert.setTitle(bean.getTitle());
alert.setHeaderText(bean.getHeader());
alert.setContentText(bean.getMessage());
alert.showAndWait();
}
}
SimpleDialogCommand provides an alternative implementation using the SimpleDialogFX library. It is registered with PriorityLevel.Low, giving it higher priority than the basic implementation.
@Register(value = DialogCommand.class, priority = PriorityLevel.Low)
public class SimpleDialogCommand extends AbstractDialogCommand implements DialogCommand {
/**
* {@inheritDoc}
*/
@Override
public void openInfoDialog() {
final Dialog dialog = new Dialog(
DialogType.INFORMATION,
bean.getTitle(),
bean.getHeader(),
bean.getMessage());
dialog.showAndWait();
}
/**
* {@inheritDoc}
*/
@Override
public void openWarningDialog() {
final Dialog dialog = new Dialog(
DialogType.WARNING,
bean.getTitle(),
bean.getHeader(),
bean.getMessage());
dialog.showAndWait();
}
/**
* {@inheritDoc}
*/
@Override
public void openErrorDialog() {
final Dialog dialog = new Dialog(
DialogType.ERROR,
bean.getTitle(),
bean.getHeader(),
bean.getMessage());
dialog.showAndWait();
}
}
The simplest way to open a dialog is via callCommand:
final DialogWB wb = new DialogWB();
wb.setDialogType(DialogWB.DialogType.Info);
wb.setTitle("Information");
wb.setHeader("Operation Complete");
wb.setMessage("The file has been saved successfully.");
callCommand(DialogCommand.class, wb);
You can also send a wave to the DialogDaemonCommand:
sendWave(WBuilder.wave()
.waveType(WBuilder.waveType(DialogDaemonCommand.OPEN_DIALOG_WT))
.waveBean(wb));
To provide a custom dialog appearance, create a class extending AbstractDialogCommand and register it with a higher priority:
@Register(value = DialogCommand.class, priority = PriorityLevel.Normal)
public class MyCustomDialogCommand extends AbstractDialogCommand {
// Custom dialog rendering
}