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