Search in sources :

Example 1 with PropertyDispatcher

use of org.linkki.core.binding.dispatcher.PropertyDispatcher 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 2 with PropertyDispatcher

use of org.linkki.core.binding.dispatcher.PropertyDispatcher in project linkki by linkki-framework.

the class PropertyDispatcherFactory method createDispatcherChain.

public PropertyDispatcher createDispatcherChain(Object pmo, BindingDescriptor bindingDescriptor, PropertyBehaviorProvider behaviorProvider) {
    requireNonNull(pmo, "pmo must not be null");
    requireNonNull(bindingDescriptor, "bindingDescriptor must not be null");
    requireNonNull(behaviorProvider, "behaviorProvider must not be null");
    // @formatter:off
    String modelPropertyName = bindingDescriptor.getModelPropertyName();
    String modelObjectName = bindingDescriptor.getModelObjectName();
    String pmoPropertyName = bindingDescriptor.getPmoPropertyName();
    ExceptionPropertyDispatcher exceptionDispatcher = newExceptionDispatcher(pmo, modelObjectName, pmoPropertyName);
    ReflectionPropertyDispatcher reflectionDispatcher = newReflectionDispatcher(pmo, pmoPropertyName, modelObjectName, modelPropertyName, exceptionDispatcher);
    StaticValueDispatcher bindingAnnotationDispatcher = new StaticValueDispatcher(reflectionDispatcher);
    PropertyDispatcher customDispatchers = createCustomDispatchers(pmo, bindingDescriptor, bindingAnnotationDispatcher);
    return new BehaviorDependentDispatcher(customDispatchers, behaviorProvider);
// @formatter:on
}
Also used : BehaviorDependentDispatcher(org.linkki.core.binding.dispatcher.BehaviorDependentDispatcher) ReflectionPropertyDispatcher(org.linkki.core.binding.dispatcher.ReflectionPropertyDispatcher) ExceptionPropertyDispatcher(org.linkki.core.binding.dispatcher.ExceptionPropertyDispatcher) ReflectionPropertyDispatcher(org.linkki.core.binding.dispatcher.ReflectionPropertyDispatcher) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) ExceptionPropertyDispatcher(org.linkki.core.binding.dispatcher.ExceptionPropertyDispatcher) StaticValueDispatcher(org.linkki.core.binding.dispatcher.StaticValueDispatcher)

Example 3 with PropertyDispatcher

use of org.linkki.core.binding.dispatcher.PropertyDispatcher in project linkki by linkki-framework.

the class BindAnnotationDescriptorTest method testCreateBinding_CreatesFieldBindingForField.

@Test
public void testCreateBinding_CreatesFieldBindingForField() {
    BindAnnotationDescriptor descriptor = new BindAnnotationDescriptor(mock(Bind.class), new ArrayList<>());
    PropertyDispatcher dispatcher = mock(PropertyDispatcher.class);
    ElementBinding binding = descriptor.createBinding(dispatcher, Handler.NOP_HANDLER, new LabelComponentWrapper(new TextField()));
    assertThat(binding, is(instanceOf(ComponentBinding.class)));
}
Also used : Bind(org.linkki.core.binding.annotations.Bind) BindAnnotationDescriptor(org.linkki.core.ui.section.descriptor.BindAnnotationDescriptor) TextField(com.vaadin.ui.TextField) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) ElementBinding(org.linkki.core.binding.ElementBinding) LabelComponentWrapper(org.linkki.core.ui.components.LabelComponentWrapper) Test(org.junit.Test)

Example 4 with PropertyDispatcher

use of org.linkki.core.binding.dispatcher.PropertyDispatcher in project linkki by linkki-framework.

the class ButtonPmoBindingTest method testButtonClickIsForwaredToPmo.

@Test
public void testButtonClickIsForwaredToPmo() {
    ButtonPmo pmo = mock(ButtonPmo.class);
    PropertyDispatcher propertyDispatcher = new org.linkki.core.binding.dispatcher.ButtonPmoDispatcher(new ReflectionPropertyDispatcher(() -> pmo, StringUtils.EMPTY, wrappedDispatcher));
    ButtonPmoBinding buttonPmoBinding = new ButtonPmoBinding(button, propertyDispatcher, bindingContext::updateUI);
    bindingContext.add(buttonPmoBinding);
    button.click();
    verify(pmo).onClick();
}
Also used : ButtonPmo(org.linkki.core.ButtonPmo) ReflectionPropertyDispatcher(org.linkki.core.binding.dispatcher.ReflectionPropertyDispatcher) ReflectionPropertyDispatcher(org.linkki.core.binding.dispatcher.ReflectionPropertyDispatcher) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) Test(org.junit.Test)

Example 5 with PropertyDispatcher

use of org.linkki.core.binding.dispatcher.PropertyDispatcher in project linkki by linkki-framework.

the class ButtonPmoBindingTest method testUpdateFromPmo_LambdaPmo.

@Test
public void testUpdateFromPmo_LambdaPmo() {
    ButtonPmo lambdaPmo = () -> System.out.println("click");
    PropertyDispatcher propertyDispatcher = new org.linkki.core.binding.dispatcher.ButtonPmoDispatcher(new ReflectionPropertyDispatcher(() -> lambdaPmo, StringUtils.EMPTY, wrappedDispatcher));
    ButtonPmoBinding binding = new ButtonPmoBinding(button, propertyDispatcher, bindingContext::updateUI);
    bindingContext.add(binding);
    binding.updateFromPmo();
    assertThat(button.isVisible(), is(true));
    assertThat(button.isEnabled(), is(true));
}
Also used : ButtonPmo(org.linkki.core.ButtonPmo) ReflectionPropertyDispatcher(org.linkki.core.binding.dispatcher.ReflectionPropertyDispatcher) ReflectionPropertyDispatcher(org.linkki.core.binding.dispatcher.ReflectionPropertyDispatcher) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) Test(org.junit.Test)

Aggregations

PropertyDispatcher (org.linkki.core.binding.dispatcher.PropertyDispatcher)14 Test (org.junit.Test)13 TestModelObject (org.linkki.core.binding.BindingContextTest.TestModelObject)4 ReflectionPropertyDispatcher (org.linkki.core.binding.dispatcher.ReflectionPropertyDispatcher)4 LabelComponentWrapper (org.linkki.core.ui.components.LabelComponentWrapper)4 ElementBinding (org.linkki.core.binding.ElementBinding)3 Bind (org.linkki.core.binding.annotations.Bind)3 ModelObject (org.linkki.core.ui.section.annotations.ModelObject)3 BindAnnotationDescriptor (org.linkki.core.ui.section.descriptor.BindAnnotationDescriptor)3 Button (com.vaadin.ui.Button)2 Label (com.vaadin.ui.Label)2 ButtonPmo (org.linkki.core.ButtonPmo)2 TextField (com.vaadin.ui.TextField)1 ArrayList (java.util.ArrayList)1 BindingContext (org.linkki.core.binding.BindingContext)1 ComponentBinding (org.linkki.core.binding.ComponentBinding)1 BehaviorDependentDispatcher (org.linkki.core.binding.dispatcher.BehaviorDependentDispatcher)1 ExceptionPropertyDispatcher (org.linkki.core.binding.dispatcher.ExceptionPropertyDispatcher)1 StaticValueDispatcher (org.linkki.core.binding.dispatcher.StaticValueDispatcher)1 MessageList (org.linkki.core.message.MessageList)1