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()));
}
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));
}
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);
}
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;
}
}
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;
}
Aggregations