Search in sources :

Example 6 with BindingContext

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

the class PmoBasedDialogFactory method newOkCancelDialog.

/**
 * Creates a new {@link OkCancelDialog}.
 *
 * @param title The dialog title.
 * @param okHandler The called when OK is clicked.
 * @param pmos The presentation model objects providing the data and the layout information.
 * @return A dialog with the content defined by the given PMO.
 */
public OkCancelDialog newOkCancelDialog(String title, Handler okHandler, Object... pmos) {
    OkCancelDialog dialog = new OkCancelDialog(title, okHandler, ButtonOption.OK_CANCEL);
    DialogBindingManager bindingManager = new DialogBindingManager(dialog, validationService, propertyBehaviorProvider);
    BindingContext bindingContext = bindingManager.startNewContext(dialog.getClass());
    for (Object pmo : pmos) {
        AbstractSection content;
        if (pmo instanceof ContainerPmo) {
            content = pmoBasedSectionFactory.createTableSection((ContainerPmo<?>) pmo, bindingContext);
        } else {
            content = pmoBasedSectionFactory.createSection(pmo, bindingContext);
        }
        float expRatio = 0f;
        if (pmo == pmos[pmos.length - 1]) {
            expRatio = 1f;
        }
        dialog.addContent(content, expRatio);
    }
    bindingContext.updateUI();
    return dialog;
}
Also used : ContainerPmo(org.linkki.core.ui.table.ContainerPmo) AbstractSection(org.linkki.core.ui.section.AbstractSection) PresentationModelObject(org.linkki.core.PresentationModelObject) BindingContext(org.linkki.core.binding.BindingContext)

Example 7 with BindingContext

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

the class PmoBasedTableSectionFactoryTest method testCreateSection_SectionHasAddButtonInHeader.

@Test
public void testCreateSection_SectionHasAddButtonInHeader() {
    TestTablePmo containerPmo = new TestTablePmo();
    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(0), is(instanceOf(HorizontalLayout.class)));
    HorizontalLayout header = (HorizontalLayout) tableSection.getComponent(0);
    // caption, add button and close button
    assertThat(header.getComponentCount(), is(3));
    assertThat(header.getComponent(1), is(instanceOf(Button.class)));
    Button addButton = (Button) header.getComponent(1);
    assertThat(addButton.getIcon(), is(FontAwesome.PLUS));
}
Also used : Button(com.vaadin.ui.Button) BindingContext(org.linkki.core.binding.BindingContext) TestBindingContext(org.linkki.core.binding.TestBindingContext) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Test(org.junit.Test)

Example 8 with BindingContext

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

the class PmoBasedTableSectionFactoryTest method testCreateSection_TableIsAddedAndBound.

@Test
public void testCreateSection_TableIsAddedAndBound() {
    TestTablePmo containerPmo = new TestTablePmo();
    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 9 with BindingContext

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

the class GettingStartedUI method init.

@Override
protected void init(VaadinRequest request) {
    Page.getCurrent().setTitle("Linkki :: Getting Started");
    DefaultPmoBasedSectionFactory sectionFactory = new DefaultPmoBasedSectionFactory();
    AbstractSection section = sectionFactory.createSection(new ReportSectionPmo(new Report()), new BindingContext("report-context", PropertyBehaviorProvider.NO_BEHAVIOR_PROVIDER, Handler.NOP_HANDLER));
    setContent(section);
}
Also used : ReportSectionPmo(org.linkki.samples.gettingstarted.pmo.ReportSectionPmo) DefaultPmoBasedSectionFactory(org.linkki.core.ui.section.DefaultPmoBasedSectionFactory) Report(org.linkki.samples.gettingstarted.model.Report) AbstractSection(org.linkki.core.ui.section.AbstractSection) BindingContext(org.linkki.core.binding.BindingContext)

Example 10 with BindingContext

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

the class BindingSampleUI method init.

@Override
protected void init(VaadinRequest request) {
    Page.getCurrent().setTitle("linkki Sample :: Bindings");
    List<Contact> personStorage = new ArrayList<>();
    BindingManager bindingManager = new DefaultBindingManager(ValidationService.NOP_VALIDATION_SERVICE);
    BindingContext context = bindingManager.startNewContext("binding-sample");
    ContactComponent contactComponent = new ContactComponent(p -> save(p, personStorage), context);
    ContactsTableComponent contactsTable = new ContactsTableComponent(personStorage, contactComponent::editContact, context);
    bindingManager.addUiUpdateObserver(contactsTable);
    HorizontalSplitPanel panel = new HorizontalSplitPanel(contactComponent, contactsTable);
    panel.setLocked(true);
    setContent(panel);
}
Also used : DefaultBindingManager(org.linkki.core.binding.DefaultBindingManager) BindingManager(org.linkki.core.binding.BindingManager) ContactsTableComponent(org.linkki.samples.binding.components.ContactsTableComponent) HorizontalSplitPanel(com.vaadin.ui.HorizontalSplitPanel) ArrayList(java.util.ArrayList) ContactComponent(org.linkki.samples.binding.components.ContactComponent) BindingContext(org.linkki.core.binding.BindingContext) DefaultBindingManager(org.linkki.core.binding.DefaultBindingManager) Contact(org.linkki.samples.binding.model.Contact)

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