Search in sources :

Example 1 with PropertyBehaviorProvider

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

the class BindingContextTest method testBuilder_WithPropertyDispatcherFactory.

@Test
void testBuilder_WithPropertyDispatcherFactory() {
    AtomicBoolean createDispatcherChainCalled = new AtomicBoolean(false);
    PropertyDispatcherFactory testPropertyDispatcherFactory = new PropertyDispatcherFactory() {

        @Override
        public PropertyDispatcher createDispatcherChain(Object pmo, BoundProperty boundProperty, PropertyBehaviorProvider behaviorProvider) {
            createDispatcherChainCalled.set(true);
            return super.createDispatcherChain(pmo, boundProperty, behaviorProvider);
        }
    };
    BindingContext context = new BindingContextBuilder().propertyDispatcherFactory(testPropertyDispatcherFactory).build();
    TestButtonPmo buttonPmo = new TestButtonPmo();
    TestUiComponent button = new TestUiComponent();
    buttonPmo.setEnabled(false);
    ComponentWrapper buttonWrapper = new TestComponentWrapper(button);
    context.bind(buttonPmo, BoundProperty.of(""), Arrays.asList(new EnabledAspectDefinition(EnabledType.DYNAMIC)), buttonWrapper);
    assertThat(createDispatcherChainCalled.get()).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BoundProperty(org.linkki.core.binding.descriptor.property.BoundProperty) TestComponentWrapper(org.linkki.core.defaults.nls.TestComponentWrapper) BindingContextBuilder(org.linkki.core.binding.BindingContext.BindingContextBuilder) EnabledAspectDefinition(org.linkki.core.defaults.ui.aspects.EnabledAspectDefinition) PresentationModelObject(org.linkki.core.pmo.PresentationModelObject) PropertyBehaviorProvider(org.linkki.core.binding.dispatcher.behavior.PropertyBehaviorProvider) TestUiComponent(org.linkki.core.defaults.nls.TestUiComponent) PropertyDispatcherFactory(org.linkki.core.binding.dispatcher.PropertyDispatcherFactory) TestComponentWrapper(org.linkki.core.defaults.nls.TestComponentWrapper) ComponentWrapper(org.linkki.core.binding.wrapper.ComponentWrapper) Test(org.junit.jupiter.api.Test)

Example 2 with PropertyBehaviorProvider

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

the class BindingManagerTest method testUpdateAll.

@Test
void testUpdateAll() {
    BindingManager bindingManager = spy(new BindingManager(MessageList::new) {

        @Override
        protected BindingContext newBindingContext(String name, PropertyBehaviorProvider behaviorProvider) {
            return spy(new BindingContextBuilder().name(name).propertyBehaviorProvider(behaviorProvider).build());
        }

        @Override
        protected BindingContext newBindingContext(String name) {
            return newBindingContext(name, PropertyBehaviorProvider.NO_BEHAVIOR_PROVIDER);
        }
    });
    BindingContext context1 = bindingManager.createContext("context1", PropertyBehaviorProvider.NO_BEHAVIOR_PROVIDER);
    BindingContext context2 = bindingManager.createContext("context2", PropertyBehaviorProvider.NO_BEHAVIOR_PROVIDER);
    bindingManager.updateAll();
    verify(context1).uiUpdated();
    verify(context2).uiUpdated();
    verify(bindingManager).afterUpdateUi();
}
Also used : BindingContextBuilder(org.linkki.core.binding.BindingContext.BindingContextBuilder) PropertyBehaviorProvider(org.linkki.core.binding.dispatcher.behavior.PropertyBehaviorProvider) BindingContext(org.linkki.core.binding.BindingContext) Test(org.junit.jupiter.api.Test)

Example 3 with PropertyBehaviorProvider

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

the class BindingSampleView method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    removeAll();
    // can be switched with URL:
    // http://localhost:8080/linkki-sample-test-playground-vaadin23/binding/readOnly
    boolean readOnly = StringUtils.equals("readOnly", parameter);
    BindingManager bindingManager = new DefaultBindingManager(ValidationService.NOP_VALIDATION_SERVICE);
    // tag::property-behavior[]
    PropertyBehaviorProvider behaviorProvider = PropertyBehaviorProvider.with(PropertyBehavior.readOnly(() -> readOnly));
    // end::property-behavior[]
    // tag::property-behavior-binding-manager
    BindingContext context = bindingManager.createContext("binding-sample", behaviorProvider);
    // end::property-behavior-binding-manager
    ContactComponent contactComponent = new ContactComponent(p -> save(p, PERSON_STORAGE), context);
    ContactsTableComponent contactsTable = new ContactsTableComponent(PERSON_STORAGE, contactComponent::editContact, context);
    // Make ContactsTableComponent call uiUpdated explicitly to switch between label or table
    bindingManager.addUiUpdateObserver(contactsTable);
    SplitLayout panel = new SplitLayout(contactComponent, contactsTable);
    panel.setOrientation(Orientation.HORIZONTAL);
    panel.setSplitterPosition(50);
    panel.setSizeFull();
    add(panel);
    setSizeFull();
}
Also used : DefaultBindingManager(org.linkki.core.binding.manager.DefaultBindingManager) BindingManager(org.linkki.core.binding.manager.BindingManager) SplitLayout(com.vaadin.flow.component.splitlayout.SplitLayout) ContactsTableComponent(org.linkki.samples.playground.binding.components.ContactsTableComponent) ContactComponent(org.linkki.samples.playground.binding.components.ContactComponent) PropertyBehaviorProvider(org.linkki.core.binding.dispatcher.behavior.PropertyBehaviorProvider) BindingContext(org.linkki.core.binding.BindingContext) DefaultBindingManager(org.linkki.core.binding.manager.DefaultBindingManager)

Example 4 with PropertyBehaviorProvider

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

the class BindingContextTest method testBuilder_WithNameAndPropertyBehaviorProvider.

@Test
void testBuilder_WithNameAndPropertyBehaviorProvider() {
    PropertyBehaviorProvider testPropertyBehaviorProvider = new PropertyBehaviorProvider() {

        @Override
        public Collection<PropertyBehavior> getBehaviors() {
            return Collections.emptyList();
        }
    };
    BindingContext context = new BindingContextBuilder().propertyBehaviorProvider(testPropertyBehaviorProvider).build();
    assertThat(context.getBehaviorProvider()).isEqualTo(testPropertyBehaviorProvider);
}
Also used : BindingContextBuilder(org.linkki.core.binding.BindingContext.BindingContextBuilder) PropertyBehavior(org.linkki.core.binding.dispatcher.behavior.PropertyBehavior) PropertyBehaviorProvider(org.linkki.core.binding.dispatcher.behavior.PropertyBehaviorProvider) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyBehaviorProvider (org.linkki.core.binding.dispatcher.behavior.PropertyBehaviorProvider)4 Test (org.junit.jupiter.api.Test)3 BindingContextBuilder (org.linkki.core.binding.BindingContext.BindingContextBuilder)3 BindingContext (org.linkki.core.binding.BindingContext)2 SplitLayout (com.vaadin.flow.component.splitlayout.SplitLayout)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BoundProperty (org.linkki.core.binding.descriptor.property.BoundProperty)1 PropertyDispatcherFactory (org.linkki.core.binding.dispatcher.PropertyDispatcherFactory)1 PropertyBehavior (org.linkki.core.binding.dispatcher.behavior.PropertyBehavior)1 BindingManager (org.linkki.core.binding.manager.BindingManager)1 DefaultBindingManager (org.linkki.core.binding.manager.DefaultBindingManager)1 ComponentWrapper (org.linkki.core.binding.wrapper.ComponentWrapper)1 TestComponentWrapper (org.linkki.core.defaults.nls.TestComponentWrapper)1 TestUiComponent (org.linkki.core.defaults.nls.TestUiComponent)1 EnabledAspectDefinition (org.linkki.core.defaults.ui.aspects.EnabledAspectDefinition)1 PresentationModelObject (org.linkki.core.pmo.PresentationModelObject)1 ContactComponent (org.linkki.samples.playground.binding.components.ContactComponent)1 ContactsTableComponent (org.linkki.samples.playground.binding.components.ContactsTableComponent)1