fi.evolver.ai.vaadin.component.FileInfoDialogUtils Maven / Gradle / Ivy
package fi.evolver.ai.vaadin.component;
import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import fi.evolver.ai.vaadin.component.i18n.VaadinTranslations;
public class FileInfoDialogUtils {
private FileInfoDialogUtils() {}
public static Dialog createFileInfoDialog(VaadinTranslations t) {
Dialog dialog = new Dialog();
dialog.getElement().setAttribute("aria-label", UI.getCurrent().getTranslation("component.fileInfoDialog.label"));
VerticalLayout dialogLayout = createDialogLayout(dialog, t);
dialog.add(dialogLayout);
return dialog;
}
private static VerticalLayout createDialogLayout(Dialog dialog, VaadinTranslations t) {
VerticalLayout dialogLayout = createDialogBaseLayout(t);
Button confirmButton = new Button("OK", e -> {
dialog.close();
});
confirmButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
HorizontalLayout buttonLayout = new HorizontalLayout(confirmButton);
buttonLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.CENTER);
dialogLayout.add(buttonLayout);
return dialogLayout;
}
public static VerticalLayout createDialogBaseLayout(VaadinTranslations t) {
H2 heading = new H2(t.getTranslation("component.fileInfoDialog.title"));
heading.getStyle()
.set("margin", "var(--lumo-space-m) 0 0 0")
.set("font-size", "1.5em").set("font-weight", "bold");
VerticalLayout contentLayout = new VerticalLayout(new Html(createDialogContent(t)));
contentLayout.setSpacing(false);
contentLayout.setPadding(false);
contentLayout.setAlignItems(FlexComponent.Alignment.STRETCH);
VerticalLayout dialogLayout = new VerticalLayout(heading, contentLayout);
dialogLayout.setPadding(false);
dialogLayout.setAlignItems(FlexComponent.Alignment.STRETCH);
dialogLayout.getStyle().set("width", "300px").set("max-width", "100%");
return dialogLayout;
}
private static String createDialogContent(VaadinTranslations t) {
return """
%s
.c, .cpp, .css, .csv, .docx, .gif, .html, .java, .jpeg, .jpg, .js, .json, .md, .pdf, .php, .png, .pptx, .py, .rb, .tar, .tex, .ts, .txt, .xlsx, .xml, .zip
""".formatted(t.getTranslation("component.fileInfoDialog.content"));
}
}