Search in sources :

Example 11 with MessageList

use of org.linkki.core.message.MessageList in project linkki by linkki-framework.

the class ValidationDisplayStateTest method testFilter_EmptyMessageList.

@Test
public void testFilter_EmptyMessageList() {
    MessageList emptyMessageList = new MessageList();
    assertThat(SHOW_ALL.filter(emptyMessageList), is(MessageMatchers.emptyMessageList()));
    assertThat(HIDE_MANDATORY_FIELD_VALIDATIONS.filter(emptyMessageList), is(emptyMessageList));
}
Also used : MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 12 with MessageList

use of org.linkki.core.message.MessageList in project linkki by linkki-framework.

the class RegistrationValidationService method getValidationMessages.

@Override
public MessageList getValidationMessages() {
    MessageList messages = new MessageList();
    validateName(registrationPmo.getUser(), messages);
    validatePassword(registrationPmo, messages);
    validateEmail(registrationPmo.getUser(), messages);
    validateBirthday(registrationPmo.getUser(), messages);
    return messages;
}
Also used : MessageList(org.linkki.core.message.MessageList)

Example 13 with MessageList

use of org.linkki.core.message.MessageList in project linkki by linkki-framework.

the class OkCancelDialogTest method testValidate_FiltersMessages.

@Test
public void testValidate_FiltersMessages() {
    ValidationMarker mandatoryFieldMarker = () -> true;
    Message message = Message.builder("error", ErrorLevel.ERROR).markers(mandatoryFieldMarker).create();
    MessageList messages = new MessageList(message);
    ValidationService validationService = ValidationService.of(messages);
    OkCancelDialog dialog = new OkCancelDialog("caption");
    dialog.setValidationService(validationService);
    // mandatory field validations are hidden initially
    assertThat(dialog.getValidationDisplayState(), is(ValidationDisplayState.HIDE_MANDATORY_FIELD_VALIDATIONS));
    MessageList dialogMessage = dialog.validate();
    assertTrue(dialogMessage.isEmpty());
    assertThat(dialog, is(not(displayingMessage())));
    assertThat(dialog, is(showingEnabledOkButton()));
    // mandatory field validations are shown after the first click on the OK button
    getOkButton(dialog).click();
    assertThat(dialog.getValidationDisplayState(), is(ValidationDisplayState.SHOW_ALL));
    dialogMessage = dialog.validate();
    assertThat(dialogMessage, contains(message));
    assertThat(dialog, is(displayingMessage("error")));
    assertThat(dialog, is(showingDisabledOkButton()));
}
Also used : Message(org.linkki.core.message.Message) ValidationMarker(org.linkki.util.validation.ValidationMarker) ValidationService(org.linkki.core.binding.validation.ValidationService) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 14 with MessageList

use of org.linkki.core.message.MessageList in project linkki by linkki-framework.

the class OkCancelDialogTest method testValidate_ShowsErrorsAndWarning.

@Test
public void testValidate_ShowsErrorsAndWarning() {
    MessageList messages = new MessageList();
    ValidationService validationService = ValidationService.of(messages);
    OkCancelDialog dialog = new OkCancelDialog("caption");
    dialog.setValidationService(validationService);
    // MessageList with error and warning: error is displayed, button is disabled
    messages.add(Message.newWarning("warning", "warning"));
    messages.add(Message.newError("error", "error"));
    dialog.validate();
    assertThat(dialog, is(displayingMessage("error")));
    assertThat(dialog, is(showingDisabledOkButton()));
    // MessageList without entries: nothing is displayed, button is enabled
    messages.clear();
    dialog.validate();
    assertThat(dialog, is(not(displayingMessage())));
    assertThat(dialog, is(showingEnabledOkButton()));
    // MessageList with warning: warning is displayed, button is enabled
    messages.add(Message.newWarning("warning", "warning"));
    dialog.validate();
    assertThat(dialog, is(displayingMessage("warning")));
    assertThat(dialog, is(showingEnabledOkButton()));
}
Also used : ValidationService(org.linkki.core.binding.validation.ValidationService) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 15 with MessageList

use of org.linkki.core.message.MessageList in project linkki by linkki-framework.

the class BindingManager method afterUpdateUi.

/**
 * Retrieves the current messages from the validation service and uses them to update the
 * messages in all registered contexts using {@link #updateMessages(MessageList)}. The
 * {@link UiUpdateObserver}s are then notified by {@link #notifyUiUpdateObservers()}.
 * <p>
 * Should be called by all binding contexts after they updated their UI. Will be passed as the
 * after-update handler to the {@link BindingContext} constructor by the
 * {@link DefaultBindingManager}.
 * <p>
 * All overriding methods should call {@link #notifyUiUpdateObservers()} to notify registered
 * {@link UiUpdateObserver}s properly.
 */
public void afterUpdateUi() {
    MessageList messages = this.validationService.getValidationMessages();
    MessageList sortedMessages = messages.sortByErrorLevel();
    updateMessages(sortedMessages);
    notifyUiUpdateObservers();
}
Also used : MessageList(org.linkki.core.message.MessageList)

Aggregations

MessageList (org.linkki.core.message.MessageList)23 Test (org.junit.Test)16 Message (org.linkki.core.message.Message)6 MessageMatchers.emptyMessageList (org.linkki.core.matcher.MessageMatchers.emptyMessageList)4 ValidationService (org.linkki.core.binding.validation.ValidationService)3 ArrayList (java.util.ArrayList)2 PropertyDispatcher (org.linkki.core.binding.dispatcher.PropertyDispatcher)2 LabelComponentWrapper (org.linkki.core.ui.components.LabelComponentWrapper)2 ValidationMarker (org.linkki.util.validation.ValidationMarker)2 Button (com.vaadin.ui.Button)1 Label (com.vaadin.ui.Label)1 Before (org.junit.Before)1 BindingContext (org.linkki.core.binding.BindingContext)1 ComponentBinding (org.linkki.core.binding.ComponentBinding)1 ModelObject (org.linkki.core.ui.section.annotations.ModelObject)1