Search in sources :

Example 6 with Message

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

the class ReflectionPropertyDispatcherTest method testGetMessages_IgnoreIrrelevantMessages.

@Test
public void testGetMessages_IgnoreIrrelevantMessages() {
    MessageList messageList = new MessageList();
    Message msg1 = Message.builder(ABC, ErrorLevel.ERROR).invalidObjectWithProperties(new Object(), XYZ).create();
    Message msg2 = Message.builder(ABC, ErrorLevel.ERROR).invalidObjectWithProperties(new Object(), ABC).create();
    messageList.add(msg1);
    messageList.add(msg2);
    assertThat(setupPmoDispatcher(XYZ).getMessages(messageList), emptyMessageList());
    assertThat(setupPmoDispatcher(ABC).getMessages(messageList), emptyMessageList());
    assertThat(setupPmoDispatcher("invalidProperty").getMessages(messageList), emptyMessageList());
}
Also used : Message(org.linkki.core.message.Message) ModelObject(org.linkki.core.ui.section.annotations.ModelObject) MessageMatchers.emptyMessageList(org.linkki.core.matcher.MessageMatchers.emptyMessageList) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 7 with Message

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

the class ValidationDisplayStateTest method testFilter.

@Test
public void testFilter() {
    ValidationMarker mandatoryFieldMarker = () -> true;
    ValidationMarker nonMandatoryFieldMarker = () -> false;
    Message m1 = Message.builder("m1", ErrorLevel.ERROR).markers(mandatoryFieldMarker).create();
    Message m2 = Message.builder("m2", ErrorLevel.ERROR).markers(nonMandatoryFieldMarker).create();
    Message m3 = Message.builder("m3", ErrorLevel.ERROR).create();
    MessageList messages = new MessageList(m1, m2, m3);
    assertThat(SHOW_ALL.filter(messages), contains(m1, m2, m3));
    assertThat(HIDE_MANDATORY_FIELD_VALIDATIONS.filter(messages), contains(m2, m3));
}
Also used : Message(org.linkki.core.message.Message) ValidationMarker(org.linkki.util.validation.ValidationMarker) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 8 with Message

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

the class MessagesPanel method updateMessages.

public void updateMessages(MessageList messages) {
    setVisible(!messages.isEmpty());
    VerticalLayout layout = new VerticalLayout();
    for (Message message : messages) {
        Label messageLabel = new Label();
        messageLabel.setIcon(getMessageIcon(message));
        // tag::mandatory[]
        String text = message.getText();
        if (message.isMandatoryFieldMessage()) {
            text += " *";
        }
        messageLabel.setCaption(text);
        // end::mandatory[]
        messageLabel.setContentMode(ContentMode.PREFORMATTED);
        layout.addComponent(messageLabel);
    }
    setContent(layout);
}
Also used : Message(org.linkki.core.message.Message) Label(com.vaadin.ui.Label) VerticalLayout(com.vaadin.ui.VerticalLayout)

Aggregations

Message (org.linkki.core.message.Message)8 Test (org.junit.Test)7 MessageList (org.linkki.core.message.MessageList)7 MessageMatchers.emptyMessageList (org.linkki.core.matcher.MessageMatchers.emptyMessageList)3 ValidationMarker (org.linkki.util.validation.ValidationMarker)3 Label (com.vaadin.ui.Label)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 ValidationService (org.linkki.core.binding.validation.ValidationService)2 ErrorLevel (com.vaadin.server.ErrorMessage.ErrorLevel)1 Button (com.vaadin.ui.Button)1 Component (com.vaadin.ui.Component)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Description (org.hamcrest.Description)1 Matcher (org.hamcrest.Matcher)1 Matchers.contains (org.hamcrest.Matchers.contains)1 Matchers.is (org.hamcrest.Matchers.is)1 Matchers.not (org.hamcrest.Matchers.not)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1