Search in sources :

Example 1 with BindingContext

use of org.linkki.core.binding.BindingContext 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 BindingContext

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

the class PmoNlsServiceSectionTest method setUp.

@Before
public void setUp() {
    BindingContext context = TestBindingContext.create();
    BaseSection section = new DefaultPmoBasedSectionFactory().createBaseSection(new SamplePmo(), context);
    HorizontalLayout header = (HorizontalLayout) section.getComponent(0);
    sectionHeader = (Label) header.getComponent(0);
    GridLayout sectionContent = (GridLayout) ((Panel) section.getComponent(1)).getContent();
    textfieldLabelWithTranslation = (Label) sectionContent.getComponent(0, 0);
    textfieldLabelWithoutTranslation = (Label) sectionContent.getComponent(0, 1);
    buttonLabelWithTranslation = (Label) sectionContent.getComponent(0, 2);
    buttonWithTranslatedCaption = (Button) sectionContent.getComponent(1, 2);
    invisibleButtonLabelWithTranslation = (Label) sectionContent.getComponent(0, 3);
    buttonWithoutTranslatedCaption = (Button) sectionContent.getComponent(1, 3);
    // test setup
    PmoNlsService.get();
    textfieldLabelTranslation = getLabelTranslation(SamplePmo.PROPERTY_TEXTFIELD);
    assertThat(textfieldLabelTranslation, is(not(SamplePmo.PMO_LABEL)));
    buttonLabelTranslation = getLabelTranslation(SamplePmo.PROPERTY_MYBUTTON);
    assertThat(buttonLabelTranslation, is(not(SamplePmo.PMO_LABEL)));
    buttonCaptionTranslation = getCaptionTranslation(SamplePmo.PROPERTY_MYBUTTON);
    assertThat(buttonCaptionTranslation, is(not(SamplePmo.PMO_CAPTION)));
    assertThat(getLabelTranslation(SamplePmo.PROPERTY_CBFIELD), is(SamplePmo.PMO_LABEL));
    assertThat(getLabelTranslation(SamplePmo.PROPERTY_MYBUTTON2), is(buttonLabelTranslation));
    assertThat(getCaptionTranslation(SamplePmo.PROPERTY_MYBUTTON2), is(SamplePmo.PMO_CAPTION));
}
Also used : SamplePmo(org.linkki.core.nls.pmo.sample.SamplePmo) BaseSection(org.linkki.core.ui.section.BaseSection) GridLayout(com.vaadin.ui.GridLayout) DefaultPmoBasedSectionFactory(org.linkki.core.ui.section.DefaultPmoBasedSectionFactory) BindingContext(org.linkki.core.binding.BindingContext) TestBindingContext(org.linkki.core.binding.TestBindingContext) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Before(org.junit.Before)

Example 3 with BindingContext

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

the class PmoBasedTableSectionFactoryTest method testCreateSection_NoAnnotation.

@Test
public void testCreateSection_NoAnnotation() {
    NoAnnotationTablePmo containerPmo = new NoAnnotationTablePmo();
    BindingContext bindingContext = TestBindingContext.create();
    PmoBasedTableSectionFactory<TestRowPmo> factory = new PmoBasedTableSectionFactory<TestRowPmo>(containerPmo, bindingContext);
    TableSection<TestRowPmo> tableSection = factory.createSection();
    assertThat(tableSection, is(notNullValue()));
    // header and table
    assertThat(tableSection.getComponentCount(), is(2));
    assertThat(tableSection.getComponent(1), is(instanceOf(Table.class)));
    Table table = (Table) tableSection.getComponent(1);
    assertThat(table.getContainerDataSource(), is(instanceOf(TableBinding.class)));
    TableBinding<?> tableBinding = (TableBinding<?>) table.getContainerDataSource();
    assertThat(bindingContext.getTableBindings(), hasItem(tableBinding));
}
Also used : Table(com.vaadin.ui.Table) BindingContext(org.linkki.core.binding.BindingContext) TestBindingContext(org.linkki.core.binding.TestBindingContext) TableBinding(org.linkki.core.binding.TableBinding) Test(org.junit.Test)

Example 4 with BindingContext

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

the class CustomLayoutUI method init.

@Override
protected void init(VaadinRequest request) {
    Page.getCurrent().setTitle("Linkki :: Custom Layout Sample");
    BindingContext bindingContext = new BindingContext();
    AbstractSection section = new DefaultPmoBasedSectionFactory().createSection(new AddressSectionPmo(), bindingContext);
    setContent(section);
}
Also used : AddressSectionPmo(org.linkki.samples.customlayout.pmo.AddressSectionPmo) DefaultPmoBasedSectionFactory(org.linkki.core.ui.section.DefaultPmoBasedSectionFactory) AbstractSection(org.linkki.core.ui.section.AbstractSection) BindingContext(org.linkki.core.binding.BindingContext)

Example 5 with BindingContext

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

the class DynamicFieldUI method init.

@Override
protected void init(VaadinRequest request) {
    Page.getCurrent().setTitle("Linkki :: Dynamic Fields Sample");
    List<Car> carStorage = getCarStorage();
    BindingContext bindingContext = new BindingContext();
    TableSection<CarRowPmo> table = new DefaultPmoBasedSectionFactory().createTableSection(new CarTablePmo(carStorage, () -> new NewCarDialog(carStorage, bindingContext::updateUI)), bindingContext);
    setContent(table);
}
Also used : NewCarDialog(org.linkki.samples.dynamicfield.components.NewCarDialog) DefaultPmoBasedSectionFactory(org.linkki.core.ui.section.DefaultPmoBasedSectionFactory) Car(org.linkki.samples.dynamicfield.model.Car) CarTablePmo(org.linkki.samples.dynamicfield.pmo.CarTablePmo) BindingContext(org.linkki.core.binding.BindingContext) CarRowPmo(org.linkki.samples.dynamicfield.pmo.CarRowPmo)

Aggregations

BindingContext (org.linkki.core.binding.BindingContext)10 Test (org.junit.Test)4 TestBindingContext (org.linkki.core.binding.TestBindingContext)4 DefaultPmoBasedSectionFactory (org.linkki.core.ui.section.DefaultPmoBasedSectionFactory)4 AbstractSection (org.linkki.core.ui.section.AbstractSection)3 Button (com.vaadin.ui.Button)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Table (com.vaadin.ui.Table)2 ArrayList (java.util.ArrayList)2 TableBinding (org.linkki.core.binding.TableBinding)2 GridLayout (com.vaadin.ui.GridLayout)1 HorizontalSplitPanel (com.vaadin.ui.HorizontalSplitPanel)1 Label (com.vaadin.ui.Label)1 Before (org.junit.Before)1 PresentationModelObject (org.linkki.core.PresentationModelObject)1 BindingManager (org.linkki.core.binding.BindingManager)1 ComponentBinding (org.linkki.core.binding.ComponentBinding)1 DefaultBindingManager (org.linkki.core.binding.DefaultBindingManager)1 PropertyDispatcher (org.linkki.core.binding.dispatcher.PropertyDispatcher)1 MessageList (org.linkki.core.message.MessageList)1