Search in sources :

Example 1 with LabelComponentWrapper

use of org.linkki.core.ui.components.LabelComponentWrapper 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 LabelComponentWrapper

use of org.linkki.core.ui.components.LabelComponentWrapper 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 3 with LabelComponentWrapper

use of org.linkki.core.ui.components.LabelComponentWrapper in project linkki by linkki-framework.

the class BindingContextTest method testBind_BoundComponentsAreMadeImmediate.

@Test
public void testBind_BoundComponentsAreMadeImmediate() {
    setUpPmo();
    TextField field = new TextField();
    BindingDefinition fieldDefintion = mock(BindingDefinition.class);
    when(fieldDefintion.required()).thenReturn(RequiredType.REQUIRED);
    when(fieldDefintion.enabled()).thenReturn(EnabledType.ENABLED);
    when(fieldDefintion.visible()).thenReturn(VisibleType.VISIBLE);
    ElementDescriptor fieldDescriptor = new ElementDescriptor(fieldDefintion, "value", Void.class, new ArrayList<>());
    // Precondition
    assertThat(field.isImmediate(), is(false));
    context.bind(pmo, fieldDescriptor, new LabelComponentWrapper(field));
    assertThat(field.isImmediate(), is(true));
}
Also used : BindingDefinition(org.linkki.core.ui.section.annotations.BindingDefinition) TextField(com.vaadin.ui.TextField) UITextField(org.linkki.core.ui.section.annotations.UITextField) ElementDescriptor(org.linkki.core.ui.section.descriptor.ElementDescriptor) LabelComponentWrapper(org.linkki.core.ui.components.LabelComponentWrapper) Test(org.junit.Test)

Example 4 with LabelComponentWrapper

use of org.linkki.core.ui.components.LabelComponentWrapper in project linkki by linkki-framework.

the class BindAnnotationDescriptorTest method testCreateBinding_CreatesLabelBindingForLabel.

@Test
public void testCreateBinding_CreatesLabelBindingForLabel() {
    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 Label()));
    assertThat(binding, is(instanceOf(ElementBinding.class)));
}
Also used : Bind(org.linkki.core.binding.annotations.Bind) BindAnnotationDescriptor(org.linkki.core.ui.section.descriptor.BindAnnotationDescriptor) Label(com.vaadin.ui.Label) 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 5 with LabelComponentWrapper

use of org.linkki.core.ui.components.LabelComponentWrapper in project linkki by linkki-framework.

the class BindAnnotationDescriptorTest method testCreateBinding_CreatesButtonBindingForButton.

@Test
public void testCreateBinding_CreatesButtonBindingForButton() {
    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 Button()));
    assertThat(binding, is(instanceOf(ElementBinding.class)));
}
Also used : Bind(org.linkki.core.binding.annotations.Bind) Button(com.vaadin.ui.Button) BindAnnotationDescriptor(org.linkki.core.ui.section.descriptor.BindAnnotationDescriptor) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) ElementBinding(org.linkki.core.binding.ElementBinding) LabelComponentWrapper(org.linkki.core.ui.components.LabelComponentWrapper) Test(org.junit.Test)

Aggregations

LabelComponentWrapper (org.linkki.core.ui.components.LabelComponentWrapper)8 Test (org.junit.Test)6 PropertyDispatcher (org.linkki.core.binding.dispatcher.PropertyDispatcher)5 Label (com.vaadin.ui.Label)3 ElementBinding (org.linkki.core.binding.ElementBinding)3 Bind (org.linkki.core.binding.annotations.Bind)3 BindAnnotationDescriptor (org.linkki.core.ui.section.descriptor.BindAnnotationDescriptor)3 Button (com.vaadin.ui.Button)2 TextField (com.vaadin.ui.TextField)2 ArrayList (java.util.ArrayList)2 MessageList (org.linkki.core.message.MessageList)2 Component (com.vaadin.ui.Component)1 Before (org.junit.Before)1 BindingContext (org.linkki.core.binding.BindingContext)1 ComponentBinding (org.linkki.core.binding.ComponentBinding)1 LinkkiAspectDefinition (org.linkki.core.binding.aspect.definition.LinkkiAspectDefinition)1 BindingDefinition (org.linkki.core.ui.section.annotations.BindingDefinition)1 UITextField (org.linkki.core.ui.section.annotations.UITextField)1 ElementDescriptor (org.linkki.core.ui.section.descriptor.ElementDescriptor)1 Handler (org.linkki.util.handler.Handler)1