Skip to content

Commit 493f297

Browse files
committed
Provide one button app dialog
1 parent 98fab71 commit 493f297

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

user-interface/src/main/java/life/qbic/datamanager/views/demo/ComponentDemo.java

+35
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,39 @@ public UserInput userInput() {
220220
return steps;
221221
}
222222

223+
private static Div dialogWithOneButton(AppDialog dialog, String dialogType) {
224+
Div content = new Div();
225+
Button showDialog = new Button("Show Dialog");
226+
// Dialog set-up
227+
DialogHeader.withIcon(dialog, dialogType, IconFactory.warningIcon());
228+
DialogFooter.withConfirmOnly(dialog, "Close");
229+
ExampleUserInput userInput = new ExampleUserInput("Expelliarmus");
230+
DialogBody.with(dialog, userInput, userInput);
231+
232+
Div confirmBox = new Div("Click the button and press 'Cancel' or 'Save'");
233+
showDialog.addClickListener(e -> {
234+
dialog.open();
235+
confirmBox.setText("Cancelled the dialog.");
236+
});
237+
238+
dialog.registerCancelAction(() -> {
239+
dialog.close();
240+
if (dialog.hasChanges()) {
241+
confirmBox.setText("Cancelled the dialog although there where changes made!");
242+
} else {
243+
confirmBox.setText("Cancelled the dialog. No changes.");
244+
}
245+
});
246+
dialog.registerConfirmAction(() -> {
247+
dialog.close();
248+
confirmBox.setText("Confirmed the dialog.");
249+
});
250+
251+
content.add(showDialog, confirmBox);
252+
content.addClassNames(FLEX_VERTICAL, GAP_04);
253+
return content;
254+
}
255+
223256
private static Div dialogShowCase(AppDialog dialog, String dialogType) {
224257
Div content = new Div();
225258
Button showDialog = new Button("Show Dialog");
@@ -368,6 +401,8 @@ private static Div dialogShowCase() {
368401
container.add(dialogSectionShowCase());
369402
container.add(createHeading3("Three steps example"));
370403
container.add(stepperDialogShowCase(threeSteps(), "Three steps example"));
404+
container.add(createHeading3("Dialog with one button"));
405+
container.add(dialogWithOneButton(AppDialog.small(), "Dialog with one button"));
371406

372407
return container;
373408
}

user-interface/src/main/java/life/qbic/datamanager/views/general/dialog/DialogFooter.java

+25-5
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,39 @@ private DialogFooter(AppDialog dialog, String abortText, String confirmText) {
1919
addClassNames("flex-horizontal", "gap-04", "footer");
2020
var buttonFactory = new ButtonFactory();
2121
var confirmButton = buttonFactory.createConfirmButton(confirmText);
22-
var cancelButton = buttonFactory.createCancelButton(abortText);
23-
add(cancelButton, confirmButton);
22+
if (abortText != null) {
23+
var cancelButton = buttonFactory.createCancelButton(abortText);
24+
add(cancelButton, confirmButton);
25+
cancelButton.addClickListener(e -> dialog.cancel());
26+
} else {
27+
add(confirmButton);
28+
}
2429
dialog.setFooter(this);
2530
confirmButton.addClickListener(e -> dialog.confirm());
26-
cancelButton.addClickListener(e -> dialog.cancel());
31+
}
32+
33+
private DialogFooter() {
34+
dialog = null;
2735
}
2836

2937
public static DialogFooter with(AppDialog dialog, String abortText, String confirmText) {
3038
return new DialogFooter(dialog, abortText, confirmText);
3139
}
3240

33-
private DialogFooter() {
34-
dialog = null;
41+
/**
42+
* Creates a footer with only one button, a confirm button that also triggers the
43+
* {@link AppDialog#confirm()} action when clicked.
44+
* <p>
45+
* This footer can be used for dialogs that are for display purposes only and do not have any user
46+
* input fields.
47+
*
48+
* @param dialog the dialog to bind to
49+
* @param confirmText the button text to display for the confirmation
50+
* @return A dialog footer bound to the provided dialog with only one button
51+
* @since 1.9.0
52+
*/
53+
public static DialogFooter withConfirmOnly(AppDialog dialog, String confirmText) {
54+
return new DialogFooter(dialog, null, confirmText);
3555
}
3656

3757
public AppDialog getDialog() {

0 commit comments

Comments
 (0)