Search in sources :

Example 1 with NewsRecord

use of org.komunumo.data.db.tables.records.NewsRecord in project komunumo-server by komunumo.

the class NewsDialog method createForm.

@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<NewsRecord> binder) {
    final var title = new TextField("Title");
    final var subtitle = new TextField("Subtitle");
    final var teaser = new RichTextEditor();
    final var message = new RichTextEditor();
    final var showFrom = new DateTimePicker("Show from");
    final var showTo = new DateTimePicker("Show to");
    title.setRequiredIndicatorVisible(true);
    title.setValueChangeMode(EAGER);
    subtitle.setValueChangeMode(EAGER);
    formLayout.add(title, subtitle, new CustomLabel("Teaser"), teaser, new CustomLabel("Message"), message, showFrom, showTo);
    binder.forField(title).withValidator(new StringLengthValidator("Please enter the title of the news (max. 255 chars)", 1, 255)).bind(NewsRecord::getTitle, NewsRecord::setTitle);
    binder.forField(subtitle).withValidator(new StringLengthValidator("The subtitle is too long (max. 255 chars)", 0, 255)).bind(NewsRecord::getSubtitle, NewsRecord::setSubtitle);
    binder.forField(teaser.asHtml()).withValidator(new StringLengthValidator("The teaser is too long (max. 1'000 chars)", 0, 1_000)).bind(NewsRecord::getTeaser, NewsRecord::setTeaser);
    binder.forField(message.asHtml()).withValidator(new StringLengthValidator("The message is too long (max. 100'000 chars)", 0, 100_000)).bind(NewsRecord::getMessage, NewsRecord::setMessage);
    binder.forField(showFrom).withValidator(value -> value == null || showTo.isEmpty() || value.isBefore(showTo.getValue()), "The show from date must be before the show to date").bind(NewsRecord::getShowFrom, NewsRecord::setShowFrom);
    binder.forField(showTo).withValidator(value -> value == null || showFrom.isEmpty() || value.isAfter(showFrom.getValue()), "The show to date must be after the show from date").bind(NewsRecord::getShowTo, NewsRecord::setShowTo);
}
Also used : NewsRecord(org.komunumo.data.db.tables.records.NewsRecord) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) CustomLabel(org.komunumo.ui.component.CustomLabel) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor) Binder(com.vaadin.flow.data.binder.Binder) NewsRecord(org.komunumo.data.db.tables.records.NewsRecord) NotNull(org.jetbrains.annotations.NotNull) TextField(com.vaadin.flow.component.textfield.TextField) DateTimePicker(org.komunumo.ui.component.DateTimePicker) EditDialog(org.komunumo.ui.component.EditDialog) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) CustomLabel(org.komunumo.ui.component.CustomLabel) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) TextField(com.vaadin.flow.component.textfield.TextField) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor) DateTimePicker(org.komunumo.ui.component.DateTimePicker)

Aggregations

FormLayout (com.vaadin.flow.component.formlayout.FormLayout)1 RichTextEditor (com.vaadin.flow.component.richtexteditor.RichTextEditor)1 TextField (com.vaadin.flow.component.textfield.TextField)1 Binder (com.vaadin.flow.data.binder.Binder)1 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)1 EAGER (com.vaadin.flow.data.value.ValueChangeMode.EAGER)1 NotNull (org.jetbrains.annotations.NotNull)1 NewsRecord (org.komunumo.data.db.tables.records.NewsRecord)1 CustomLabel (org.komunumo.ui.component.CustomLabel)1 DateTimePicker (org.komunumo.ui.component.DateTimePicker)1 EditDialog (org.komunumo.ui.component.EditDialog)1