Search in sources :

Example 1 with MessageList

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

the class OkCancelDialogTest method testValidate_ShowsNoInitialMessages.

@Test
public void testValidate_ShowsNoInitialMessages() {
    MessageList messages = new MessageList();
    ValidationService validationService = ValidationService.of(messages);
    OkCancelDialog dialog = new OkCancelDialog("caption");
    dialog.setValidationService(validationService);
    assertThat(dialog, is(not(displayingMessage())));
    assertThat(dialog, is(showingEnabledOkButton()));
}
Also used : ValidationService(org.linkki.core.binding.validation.ValidationService) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 2 with MessageList

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

the class DialogBindingManagerTest method testAfterUpdateUI_ValidatesDialog.

@Test
public void testAfterUpdateUI_ValidatesDialog() {
    MessageList messages = new MessageList();
    OkCancelDialog dialog = new OkCancelDialog("");
    DialogBindingManager manager = new DialogBindingManager(dialog, ValidationService.of(messages));
    manager.afterUpdateUi();
    assertThat(dialog.getValidationService().getValidationMessages(), is(messages));
}
Also used : MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 3 with MessageList

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

the class DialogBindingManagerTest method testBindingsInCreatedContextsDisplayMessagesFromDialog.

@Test
public void testBindingsInCreatedContextsDisplayMessagesFromDialog() {
    OkCancelDialog dialog = new OkCancelDialog("");
    // Use the NOP validation service in the binding manager
    DialogBindingManager manager = new DialogBindingManager(dialog, ValidationService.NOP_VALIDATION_SERVICE);
    BindingContext ctx = manager.startNewContext("foo");
    // Change the dialog's validation service to make sure dialog's validate method is used and
    // not the validation service the manager was created with (so that the dialog could filter
    // the messages)
    MessageList messages = new MessageList(Message.newError("code", "text"));
    dialog.setValidationService(ValidationService.of(messages));
    PropertyDispatcher propertyDispatcher = mock(PropertyDispatcher.class);
    Object pmo = mock(Object.class);
    when(propertyDispatcher.getBoundObject()).thenReturn(pmo);
    when(propertyDispatcher.getMessages(any())).thenReturn(new MessageList());
    ComponentBinding binding = spy(new ComponentBinding(new LabelComponentWrapper(new Label(), new Button()), propertyDispatcher, Handler.NOP_HANDLER, new ArrayList<>()));
    ctx.add(binding);
    ctx.updateUI();
    verify(binding).displayMessages(messages);
}
Also used : ComponentBinding(org.linkki.core.binding.ComponentBinding) Button(com.vaadin.ui.Button) Label(com.vaadin.ui.Label) ArrayList(java.util.ArrayList) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) BindingContext(org.linkki.core.binding.BindingContext) MessageList(org.linkki.core.message.MessageList) LabelComponentWrapper(org.linkki.core.ui.components.LabelComponentWrapper) Test(org.junit.Test)

Example 4 with MessageList

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

the class ReflectionPropertyDispatcher method getMessages.

/**
 * Returns the messages stating the {@link #getBoundObject() bound object} as
 * {@link org.linkki.core.message.Message#getInvalidObjectProperties() invalid} and those the
 * {@code fallbackDispatcher} returns.
 */
@Override
public MessageList getMessages(MessageList messageList) {
    Object boundObject = getBoundObject();
    if (boundObject == null) {
        return new MessageList();
    } else {
        MessageList msgListForBoundObject = messageList.getMessagesFor(boundObject, getProperty());
        msgListForBoundObject.add(fallbackDispatcher.getMessages(messageList));
        // TODO may additionally call a method like "get<Property>NlsText()"
        return msgListForBoundObject;
    }
}
Also used : MessageList(org.linkki.core.message.MessageList)

Example 5 with MessageList

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

the class OkCancelDialog method validate.

/**
 * Retrieves the message list from the validation service and filters it according to its
 * {@link #getValidationDisplayState()}. The filtered messages are returned. If needed, a
 * message from the list is displayed and the OK button is disabled.
 * <p>
 * A previously displayed message is removed if the message list does not contain any messages.
 * If the message list contains a message, the first message with the highest errorLevel is
 * displayed. If the message list contains an error message the OK button is disabled.
 */
public MessageList validate() {
    MessageList messages = validationDisplayState.filter(getValidationService().getValidationMessages());
    messageRow.ifPresent(contentArea::removeComponent);
    messages.getErrorLevel().flatMap(messages::getFirstMessage).ifPresent(this::addMessageRow);
    mayProceed = !messages.containsErrorMsg();
    okButton.setEnabled(mayProceed);
    return messages;
}
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