| /** |
| * Copyright (c) 2012, 2015 - Lunifera GmbH (Austria), Loetz GmbH&Co.KG and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner - initial API and implementation |
| */ |
| package org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.presentation; |
| |
| import static org.junit.Assert.assertEquals; |
| import static org.junit.Assert.assertFalse; |
| import static org.junit.Assert.assertNotNull; |
| import static org.junit.Assert.assertNull; |
| import static org.junit.Assert.assertSame; |
| import static org.junit.Assert.assertTrue; |
| |
| import java.util.ArrayList; |
| import java.util.Collection; |
| import java.util.HashMap; |
| import java.util.List; |
| import java.util.Locale; |
| import java.util.Map; |
| |
| import org.junit.Before; |
| import org.junit.Test; |
| import org.eclipse.osbp.ecview.core.common.context.ContextException; |
| import org.eclipse.osbp.ecview.core.common.context.IViewContext; |
| import org.eclipse.osbp.ecview.core.common.editpart.DelegatingEditPartManager; |
| import org.eclipse.osbp.ecview.core.common.editpart.IConverterEditpart; |
| import org.eclipse.osbp.ecview.core.common.editpart.IElementEditpart; |
| import org.eclipse.osbp.ecview.core.common.editpart.IEmbeddableEditpart; |
| import org.eclipse.osbp.ecview.core.common.editpart.IViewEditpart; |
| import org.eclipse.osbp.ecview.core.common.model.binding.YBeanValueBindingEndpoint; |
| import org.eclipse.osbp.ecview.core.common.model.binding.YBindingSet; |
| import org.eclipse.osbp.ecview.core.common.model.binding.YDetailValueBindingEndpoint; |
| import org.eclipse.osbp.ecview.core.common.model.core.CoreModelFactory; |
| import org.eclipse.osbp.ecview.core.common.model.core.YDelegateConverter; |
| import org.eclipse.osbp.ecview.core.common.model.core.YElement; |
| import org.eclipse.osbp.ecview.core.common.model.core.YEmbeddableCollectionEndpoint; |
| import org.eclipse.osbp.ecview.core.common.model.core.YEmbeddableMultiSelectionEndpoint; |
| import org.eclipse.osbp.ecview.core.common.model.core.YEmbeddableSelectionEndpoint; |
| import org.eclipse.osbp.ecview.core.common.model.core.YView; |
| import org.eclipse.osbp.ecview.core.common.presentation.DelegatingConverterFactory; |
| import org.eclipse.osbp.ecview.core.common.presentation.IConverterFactory; |
| import org.eclipse.osbp.ecview.core.common.presentation.IWidgetPresentation; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YColumn; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YGridLayout; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YSelectionType; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YTable; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YTextField; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.util.SimpleExtensionModelFactory; |
| import org.eclipse.osbp.ecview.core.ui.core.editparts.extension.ITableEditpart; |
| import org.eclipse.osbp.ecview.core.ui.core.editparts.extension.ITextFieldEditpart; |
| import org.eclipse.osbp.runtime.common.i18n.II18nService; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.VaadinRenderer; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.common.AbstractVaadinWidgetPresenter; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.internal.TablePresentation; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.emf.model.EmfBar; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.emf.model.EmfFoo; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.emf.model.ModelFactory; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.emf.model.ModelPackage; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.model.Bar; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.model.Foo; |
| import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.model.ValueBean; |
| import org.osgi.framework.BundleException; |
| import org.osgi.service.cm.ConfigurationException; |
| |
| import com.vaadin.data.Container; |
| import com.vaadin.data.Container.Indexed; |
| import com.vaadin.ui.AbstractSelect.ItemCaptionMode; |
| import com.vaadin.ui.Component; |
| import com.vaadin.ui.CssLayout; |
| import com.vaadin.ui.Table; |
| import com.vaadin.ui.TextField; |
| import com.vaadin.ui.UI; |
| |
| /** |
| * Tests the {@link TablePresentation}. |
| */ |
| @SuppressWarnings("restriction") |
| public class TablePresentationTests { |
| |
| private SimpleExtensionModelFactory factory = new SimpleExtensionModelFactory(); |
| private CssLayout rootLayout = new CssLayout(); |
| |
| /** |
| * Setup tests. |
| * |
| * @throws ConfigurationException |
| * @throws BundleException |
| */ |
| @Before |
| public void setup() throws ConfigurationException, BundleException { |
| UI.setCurrent(new DefaultUI()); |
| UI.getCurrent().setContent(rootLayout); |
| } |
| |
| /** |
| * Tests rendering issues. |
| * |
| * @throws Exception |
| */ |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_isRendered_unrender_byModel() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yGridLayout |
| // .........> yTable |
| YView yView = factory.createView(); |
| YGridLayout yGridlayout = factory.createGridLayout(); |
| yView.setContent(yGridlayout); |
| YTable yTable = factory.createTable(); |
| yTable.setType(String.class); |
| yGridlayout.getElements().add(yTable); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart tableEditpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable); |
| IWidgetPresentation<Component> presentation = tableEditpart |
| .getPresentation(); |
| assertTrue(presentation.isRendered()); |
| assertFalse(presentation.isDisposed()); |
| |
| yGridlayout.getElements().remove(yTable); |
| assertFalse(presentation.isRendered()); |
| assertFalse(presentation.isDisposed()); |
| } |
| |
| /** |
| * Tests the internal structure. |
| * |
| * @throws Exception |
| */ |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_InternalStructure() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yTable |
| YView yView = factory.createView(); |
| YTable yTable = factory.createTable(); |
| yTable.setType(String.class); |
| yView.setContent(yTable); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart tableEditpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable); |
| IWidgetPresentation<Component> presentation = tableEditpart |
| .getPresentation(); |
| |
| Table label = (Table) presentation.getWidget(); |
| assertNotNull(label); |
| } |
| |
| /** |
| * Test the internal structure based on CSS. |
| * |
| * @throws Exception |
| */ |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_InternalStructure__CSS() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yTable |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setCssID("ID_0815"); |
| yTable1.setCssClass("anyOtherClass"); |
| yTable1.setType(String.class); |
| yLayout.getElements().add(yTable1); |
| YTable yTable2 = factory.createTable(); |
| yTable2.setType(String.class); |
| yLayout.getElements().add(yTable2); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| ITableEditpart table2Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable2); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| IWidgetPresentation<Component> table2Presentation = table2Editpart |
| .getPresentation(); |
| |
| Table label1 = (Table) table1Presentation.getWidget(); |
| Table label2 = (Table) table2Presentation.getWidget(); |
| |
| // assert css class |
| |
| assertTrue(label1.getStyleName().contains("anyOtherClass")); |
| assertTrue(label2.getStyleName().contains( |
| AbstractVaadinWidgetPresenter.CSS_CLASS_CONTROL)); |
| |
| // assert css id |
| assertEquals("ID_0815", label1.getId()); |
| assertEquals(table2Editpart.getId(), label2.getId()); |
| } |
| |
| /** |
| * Test the internal structure based on CSS. |
| * |
| * @throws Exception |
| */ |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_Bindings() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yTable |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(String.class); |
| yLayout.getElements().add(yTable1); |
| YTable yTable2 = factory.createTable(); |
| yTable2.setType(String.class); |
| yLayout.getElements().add(yTable2); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart label1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| ITableEditpart label2Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable2); |
| IWidgetPresentation<Component> table1Presentation = label1Editpart |
| .getPresentation(); |
| IWidgetPresentation<Component> table2Presentation = label2Editpart |
| .getPresentation(); |
| Table label1 = (Table) table1Presentation.getWidget(); |
| Table label2 = (Table) table2Presentation.getWidget(); |
| |
| // start tests |
| // |
| assertTrue(label1.isVisible()); |
| assertTrue(label1.isEnabled()); |
| assertFalse(label1.isReadOnly()); |
| |
| assertTrue(label2.isVisible()); |
| assertTrue(label2.isEnabled()); |
| assertFalse(label2.isReadOnly()); |
| |
| yTable1.setVisible(false); |
| assertFalse(label1.isVisible()); |
| |
| yTable1.setEnabled(false); |
| assertFalse(label1.isEnabled()); |
| |
| } |
| |
| /** |
| * Test the internal structure based on CSS. |
| * |
| * @throws Exception |
| */ |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_CollectionBinding_Native() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(String.class); |
| yLayout.getElements().add(yTable1); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| |
| // start tests |
| // |
| |
| Container.Indexed container = (Indexed) table1.getContainerDataSource(); |
| assertEquals(0, container.size()); |
| |
| // add |
| container.addItem("Blabla"); |
| assertEquals(1, yTable1.getCollection().size()); |
| assertEquals(1, container.size()); |
| |
| yTable1.getCollection().add("Huhu"); |
| assertEquals(2, yTable1.getCollection().size()); |
| assertEquals(2, container.size()); |
| |
| // add at index |
| yTable1.getCollection().add(0, "First"); |
| assertEquals("First", yTable1.getCollection().get(0)); |
| assertEquals("First", container.getItemIds(0, 1).get(0)); |
| |
| container.addItemAt(0, "Another First"); |
| assertEquals("Another First", yTable1.getCollection().get(0)); |
| assertEquals("Another First", container.getItemIds(0, 1).get(0)); |
| |
| // move |
| yTable1.getCollection().move(1, 0); |
| assertEquals("First", yTable1.getCollection().get(0)); |
| assertEquals("First", container.getItemIds(0, 1).get(0)); |
| |
| // remove all |
| container.removeAllItems(); |
| assertEquals(0, yTable1.getCollection().size()); |
| assertEquals(0, container.size()); |
| } |
| |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_Converter() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(Bar.class); |
| yLayout.getElements().add(yTable1); |
| |
| YColumn col_name = factory.createColumn(); |
| col_name.setPropertyPath("name"); |
| yTable1.getColumns().add(col_name); |
| |
| YColumn col_Foo = factory.createColumn(); |
| col_Foo.setPropertyPath("myfoo"); |
| yTable1.getColumns().add(col_Foo); |
| |
| // Create the converter here |
| YDelegateConverter converter = CoreModelFactory.eINSTANCE.createYDelegateConverter(); |
| converter.setConverterId("myFoo-ToString"); |
| col_Foo.setConverter(converter); |
| |
| // register the converter factory here |
| DelegatingConverterFactory.getInstance().addDelegate( |
| new ConverterFactory()); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| |
| assertNull(table1.getConverter("name")); |
| assertTrue(table1.getConverter("myfoo").getClass() == FooToStringConverter.class); |
| |
| // start tests |
| // |
| Container.Indexed container = (Indexed) table1.getContainerDataSource(); |
| assertEquals(0, container.size()); |
| |
| assertNull(table1.getValue()); |
| assertNull(yTable1.getSelection()); |
| |
| // add |
| Bar bar1 = new Bar(); |
| bar1.setName("Bar1"); |
| Foo foo1 = new Foo(); |
| foo1.setName("Foo1"); |
| bar1.setMyfoo(foo1); |
| |
| Bar bar2 = new Bar(); |
| bar2.setName("Bar2"); |
| Foo foo2 = new Foo(); |
| foo2.setName("Foo2"); |
| bar2.setMyfoo(foo2); |
| |
| yTable1.getCollection().add(bar1); |
| yTable1.getCollection().add(bar2); |
| assertEquals(2, container.size()); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| // test set selection |
| yTable1.setSelection(bar1); |
| yTable1.setSelection(bar2); |
| |
| // test set selection null |
| yTable1.setSelection(null); |
| table1.setValue(bar1); |
| table1.setValue(bar2); |
| |
| // test set selection null |
| table1.setValue(null); |
| |
| // test remove element that is selected |
| // add |
| table1.setValue(bar2); |
| |
| yTable1.getCollection().clear(); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| yTable1.getCollection().add(bar1); |
| yTable1.getCollection().add(bar2); |
| assertEquals(2, container.size()); |
| |
| } |
| |
| /** |
| * Test the internal structure based on CSS. |
| * |
| * @throws Exception |
| */ |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_CollectionBinding_TableToTable() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(String.class); |
| yLayout.getElements().add(yTable1); |
| YTable yTable2 = factory.createTable(); |
| yTable2.setType(String.class); |
| yLayout.getElements().add(yTable2); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| ITableEditpart table2Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable2); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| IWidgetPresentation<Component> table2Presentation = table2Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| Table table2 = (Table) table2Presentation.getWidget(); |
| |
| Container.Indexed indexedDs1 = (Indexed) table1 |
| .getContainerDataSource(); |
| Container.Indexed indexedDs2 = (Indexed) table2 |
| .getContainerDataSource(); |
| |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| |
| // start tests |
| // |
| |
| YEmbeddableCollectionEndpoint endp1 = yTable1 |
| .createCollectionEndpoint(); |
| YEmbeddableCollectionEndpoint endp2 = yTable2 |
| .createCollectionEndpoint(); |
| yBindingSet.addBinding(endp1, endp2); |
| |
| assertEquals(0, yTable1.getCollection().size()); |
| assertEquals(0, yTable2.getCollection().size()); |
| assertEquals(0, indexedDs1.size()); |
| assertEquals(0, indexedDs2.size()); |
| |
| // add to yTable1 |
| yTable1.getCollection().add("Huhu"); |
| assertEquals(1, yTable2.getCollection().size()); |
| assertEquals("Huhu", yTable2.getCollection().get(0)); |
| assertEquals("Huhu", indexedDs1.getItemIds(0, 1).get(0)); |
| assertEquals("Huhu", indexedDs2.getItemIds(0, 1).get(0)); |
| assertEquals(1, indexedDs1.size()); |
| assertEquals(1, indexedDs2.size()); |
| |
| // add to yTable1 |
| yTable1.getCollection().add("Huhu2"); |
| assertEquals(2, yTable2.getCollection().size()); |
| assertEquals("Huhu", yTable2.getCollection().get(0)); |
| assertEquals("Huhu2", yTable2.getCollection().get(1)); |
| assertEquals("Huhu", yTable1.getCollection().get(0)); |
| assertEquals("Huhu2", yTable1.getCollection().get(1)); |
| assertEquals("Huhu", indexedDs1.getItemIds(0, 1).get(0)); |
| assertEquals("Huhu2", indexedDs1.getItemIds(1, 1).get(0)); |
| assertEquals("Huhu", indexedDs2.getItemIds(0, 1).get(0)); |
| assertEquals("Huhu2", indexedDs2.getItemIds(1, 1).get(0)); |
| assertEquals(2, indexedDs1.size()); |
| assertEquals(2, indexedDs2.size()); |
| |
| // remove from yTable2 |
| yTable2.getCollection().remove("Huhu"); |
| assertEquals(1, yTable1.getCollection().size()); |
| assertEquals(1, yTable2.getCollection().size()); |
| assertEquals(1, indexedDs1.size()); |
| assertEquals(1, indexedDs2.size()); |
| |
| // add another to yTable2 |
| yTable2.getCollection().add("Blabla"); |
| assertEquals(2, yTable1.getCollection().size()); |
| assertEquals(2, yTable2.getCollection().size()); |
| assertEquals("Huhu2", yTable1.getCollection().get(0)); |
| assertEquals("Blabla", yTable1.getCollection().get(1)); |
| assertEquals("Huhu2", yTable2.getCollection().get(0)); |
| assertEquals("Blabla", yTable2.getCollection().get(1)); |
| assertEquals("Huhu2", indexedDs1.getItemIds(0, 1).get(0)); |
| assertEquals("Blabla", indexedDs1.getItemIds(1, 1).get(0)); |
| assertEquals("Huhu2", indexedDs2.getItemIds(0, 1).get(0)); |
| assertEquals("Blabla", indexedDs2.getItemIds(1, 1).get(0)); |
| assertEquals(2, indexedDs1.size()); |
| assertEquals(2, indexedDs2.size()); |
| |
| yTable2.getCollection().move(0, 1); |
| assertEquals(2, yTable1.getCollection().size()); |
| assertEquals(2, yTable2.getCollection().size()); |
| assertEquals("Blabla", yTable1.getCollection().get(0)); |
| assertEquals("Huhu2", yTable1.getCollection().get(1)); |
| assertEquals("Blabla", yTable2.getCollection().get(0)); |
| assertEquals("Huhu2", yTable2.getCollection().get(1)); |
| assertEquals("Blabla", indexedDs1.getItemIds(0, 1).get(0)); |
| assertEquals("Huhu2", indexedDs1.getItemIds(1, 1).get(0)); |
| assertEquals("Blabla", indexedDs2.getItemIds(0, 1).get(0)); |
| assertEquals("Huhu2", indexedDs2.getItemIds(1, 1).get(0)); |
| assertEquals(2, indexedDs1.size()); |
| assertEquals(2, indexedDs2.size()); |
| |
| yTable2.getCollection().clear(); |
| assertEquals(0, yTable1.getCollection().size()); |
| assertEquals(0, yTable2.getCollection().size()); |
| assertEquals(0, indexedDs1.size()); |
| assertEquals(0, indexedDs2.size()); |
| } |
| |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_SelectionBinding_Single_Native() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(String.class); |
| yLayout.getElements().add(yTable1); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| |
| // start tests |
| // |
| Container.Indexed container = (Indexed) table1.getContainerDataSource(); |
| assertEquals(0, container.size()); |
| |
| assertNull(table1.getValue()); |
| assertNull(yTable1.getSelection()); |
| |
| // add |
| yTable1.getCollection().add("Huhu"); |
| yTable1.getCollection().add("Haha"); |
| assertEquals(2, container.size()); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| // test set selection |
| yTable1.setSelection("Huhu"); |
| assertEquals("Huhu", yTable1.getSelection()); |
| assertEquals("Huhu", table1.getValue()); |
| |
| table1.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| |
| // test set selection null |
| table1.setValue(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| table1.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| |
| yTable1.setSelection(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| // test remove element that is selected |
| // add |
| yTable1.getCollection().add("Huhu"); |
| yTable1.getCollection().add("Haha"); |
| assertEquals(2, container.size()); |
| |
| yTable1.setSelection("Huhu"); |
| assertEquals("Huhu", yTable1.getSelection()); |
| assertEquals("Huhu", table1.getValue()); |
| |
| yTable1.getCollection().remove("Huhu"); |
| assertNull(table1.getValue()); |
| assertNull(yTable1.getSelection()); |
| |
| // test remove element that is selected |
| // add |
| yTable1.getCollection().add("Huhu"); |
| assertEquals(2, container.size()); |
| |
| yTable1.setSelection("Huhu"); |
| assertEquals("Huhu", yTable1.getSelection()); |
| assertEquals("Huhu", table1.getValue()); |
| |
| table1.setValue(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| } |
| |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_SelectionBinding_Single_EmptyCollection() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(String.class); |
| yLayout.getElements().add(yTable1); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| |
| // start tests |
| // |
| Container.Indexed container = (Indexed) table1.getContainerDataSource(); |
| assertEquals(0, container.size()); |
| |
| assertNull(table1.getValue()); |
| assertNull(yTable1.getSelection()); |
| |
| // add |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| // test set selection |
| yTable1.setSelection("Huhu"); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| } |
| |
| /** |
| * Test the internal structure based on CSS. |
| * |
| * @throws Exception |
| */ |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_SelectionBinding_TableToTable() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(String.class); |
| yLayout.getElements().add(yTable1); |
| YTable yTable2 = factory.createTable(); |
| yTable2.setType(String.class); |
| yLayout.getElements().add(yTable2); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| ITableEditpart table2Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable2); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| IWidgetPresentation<Component> table2Presentation = table2Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| Table table2 = (Table) table2Presentation.getWidget(); |
| |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| |
| // start tests |
| // |
| |
| YEmbeddableCollectionEndpoint endp1 = yTable1 |
| .createCollectionEndpoint(); |
| YEmbeddableCollectionEndpoint endp2 = yTable2 |
| .createCollectionEndpoint(); |
| yBindingSet.addBinding(endp1, endp2); |
| |
| YEmbeddableSelectionEndpoint endpSel1 = yTable1 |
| .createSelectionEndpoint(); |
| YEmbeddableSelectionEndpoint endpSel2 = yTable2 |
| .createSelectionEndpoint(); |
| yBindingSet.addBinding(endpSel1, endpSel2); |
| |
| Container.Indexed container1 = (Indexed) table1 |
| .getContainerDataSource(); |
| Container.Indexed container2 = (Indexed) table2 |
| .getContainerDataSource(); |
| assertEquals(0, container1.size()); |
| assertEquals(0, container2.size()); |
| |
| assertNull(table1.getValue()); |
| assertNull(yTable1.getSelection()); |
| |
| // add |
| yTable1.getCollection().add("Huhu"); |
| yTable2.getCollection().add("Haha"); |
| assertEquals(2, container1.size()); |
| assertEquals(2, container2.size()); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| // test set selection |
| yTable1.setSelection("Huhu"); |
| assertEquals("Huhu", yTable1.getSelection()); |
| assertEquals("Huhu", table1.getValue()); |
| assertEquals("Huhu", yTable2.getSelection()); |
| assertEquals("Huhu", table2.getValue()); |
| |
| table1.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| assertEquals("Haha", yTable2.getSelection()); |
| assertEquals("Haha", table2.getValue()); |
| |
| // test set selection null |
| table1.setValue(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| table1.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| assertEquals("Haha", yTable2.getSelection()); |
| assertEquals("Haha", table2.getValue()); |
| |
| table2.setValue(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| table2.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| assertEquals("Haha", yTable2.getSelection()); |
| assertEquals("Haha", table2.getValue()); |
| |
| yTable1.setSelection(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| table2.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| assertEquals("Haha", yTable2.getSelection()); |
| assertEquals("Haha", table2.getValue()); |
| |
| yTable2.setSelection(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| // test remove element that is selected |
| // add |
| assertEquals(2, container1.size()); |
| assertEquals(2, container2.size()); |
| |
| yTable1.setSelection("Huhu"); |
| assertEquals("Huhu", yTable1.getSelection()); |
| assertEquals("Huhu", yTable2.getSelection()); |
| assertEquals("Huhu", table1.getValue()); |
| assertEquals("Huhu", table2.getValue()); |
| |
| yTable1.getCollection().remove("Huhu"); |
| assertNull(table1.getValue()); |
| assertNull(table2.getValue()); |
| assertNull(yTable1.getSelection()); |
| assertNull(yTable2.getSelection()); |
| |
| // test remove element that is selected |
| // add |
| yTable2.getCollection().add("Huhu"); |
| assertEquals(2, container1.size()); |
| assertEquals(2, container2.size()); |
| |
| yTable1.setSelection("Huhu"); |
| assertEquals("Huhu", yTable1.getSelection()); |
| assertEquals("Huhu", table1.getValue()); |
| assertEquals("Huhu", yTable2.getSelection()); |
| assertEquals("Huhu", table2.getValue()); |
| |
| table2.setValue(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| } |
| |
| /** |
| * Test the automatic disposal of bindings |
| * |
| * @throws ContextException |
| */ |
| @Test |
| public void testBindingIsDisposed() throws ContextException { |
| YView yView = factory.createView(); |
| YGridLayout yGridlayout = factory.createGridLayout(); |
| yView.setContent(yGridlayout); |
| YTable yTable = factory.createTable(); |
| yTable.setType(String.class); |
| yGridlayout.getElements().add(yTable); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart tableEditpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable); |
| IWidgetPresentation<Component> presentation = tableEditpart |
| .getPresentation(); |
| assertTrue(presentation.isRendered()); |
| assertFalse(presentation.isDisposed()); |
| assertEquals(6, presentation.getUIBindings().size()); |
| |
| presentation.dispose(); |
| assertFalse(presentation.isRendered()); |
| assertTrue(presentation.isDisposed()); |
| assertEquals(0, presentation.getUIBindings().size()); |
| } |
| |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_SelectionBinding_Multi_EmptyCollection() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable = factory.createTable(); |
| yTable.setSelectionType(YSelectionType.MULTI); |
| yTable.setType(String.class); |
| yLayout.getElements().add(yTable); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart tableEditpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable); |
| IWidgetPresentation<Component> tablePresentation = tableEditpart |
| .getPresentation(); |
| Table table1 = (Table) tablePresentation.getWidget(); |
| |
| // start tests |
| // |
| Container.Indexed container = (Indexed) table1.getContainerDataSource(); |
| assertEquals(0, container.size()); |
| |
| assertTrue(asList(table1.getValue()).isEmpty()); |
| assertTrue(yTable.getMultiSelection().isEmpty()); |
| |
| // test set selection by model |
| yTable.getMultiSelection().add("Huhu"); |
| assertEquals("Huhu", yTable.getMultiSelection().get(0)); |
| assertEquals("Huhu", asList(table1.getValue()).get(0)); |
| assertEquals(1, yTable.getMultiSelection().size()); |
| assertEquals(1, asList(table1.getValue()).size()); |
| |
| yTable.getMultiSelection().add("Haha"); |
| assertEquals("Huhu", yTable.getMultiSelection().get(0)); |
| assertEquals("Haha", yTable.getMultiSelection().get(1)); |
| // no sort order defined by vaadin -> Set |
| assertTrue(asList(table1.getValue()).contains("Huhu")); |
| assertTrue(asList(table1.getValue()).contains("Haha")); |
| assertEquals(2, yTable.getMultiSelection().size()); |
| assertEquals(2, asList(table1.getValue()).size()); |
| |
| // remove selection |
| yTable.getMultiSelection().remove("Huhu"); |
| assertEquals("Haha", yTable.getMultiSelection().get(0)); |
| assertEquals("Haha", asList(table1.getValue()).get(0)); |
| assertEquals(1, yTable.getMultiSelection().size()); |
| assertEquals(1, asList(table1.getValue()).size()); |
| |
| yTable.getMultiSelection().clear(); |
| assertEquals(0, yTable.getMultiSelection().size()); |
| assertEquals(0, asList(table1.getValue()).size()); |
| |
| // test set selection by widget |
| List<String> selection = new ArrayList<String>(); |
| selection.add("Huhu"); |
| table1.setValue(selection); |
| assertEquals("Huhu", yTable.getMultiSelection().get(0)); |
| assertEquals("Huhu", asList(table1.getValue()).get(0)); |
| assertEquals(1, yTable.getMultiSelection().size()); |
| assertEquals(1, asList(table1.getValue()).size()); |
| |
| selection = new ArrayList<String>(); |
| selection.add("Huhu"); |
| selection.add("Haha"); |
| table1.setValue(selection); |
| assertEquals("Huhu", yTable.getMultiSelection().get(0)); |
| assertEquals("Haha", yTable.getMultiSelection().get(1)); |
| assertTrue(asList(table1.getValue()).contains("Huhu")); |
| assertTrue(asList(table1.getValue()).contains("Haha")); |
| assertEquals(2, yTable.getMultiSelection().size()); |
| assertEquals(2, asList(table1.getValue()).size()); |
| |
| selection = new ArrayList<String>(); |
| selection.add("Haha"); |
| table1.setValue(selection); |
| assertEquals("Haha", yTable.getMultiSelection().get(0)); |
| assertEquals("Haha", asList(table1.getValue()).get(0)); |
| assertEquals(1, yTable.getMultiSelection().size()); |
| assertEquals(1, asList(table1.getValue()).size()); |
| |
| selection = new ArrayList<String>(); |
| table1.setValue(selection); |
| assertEquals(0, yTable.getMultiSelection().size()); |
| assertEquals(0, asList(table1.getValue()).size()); |
| } |
| |
| /** |
| * Test the internal structure based on CSS. |
| * |
| * @throws Exception |
| */ |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_SelectionBinding_Multi_ListToList() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setSelectionType(YSelectionType.MULTI); |
| yTable1.setType(String.class); |
| yLayout.getElements().add(yTable1); |
| YTable yTable2 = factory.createTable(); |
| yTable2.setSelectionType(YSelectionType.MULTI); |
| yTable2.setType(String.class); |
| yLayout.getElements().add(yTable2); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| ITableEditpart table2Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable2); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| IWidgetPresentation<Component> table2Presentation = table2Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| Table table2 = (Table) table2Presentation.getWidget(); |
| |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| |
| // start tests |
| // |
| |
| YEmbeddableCollectionEndpoint endp1 = yTable1 |
| .createCollectionEndpoint(); |
| YEmbeddableCollectionEndpoint endp2 = yTable2 |
| .createCollectionEndpoint(); |
| yBindingSet.addBinding(endp1, endp2); |
| |
| YEmbeddableMultiSelectionEndpoint endpSel1 = yTable1 |
| .createMultiSelectionEndpoint(); |
| YEmbeddableMultiSelectionEndpoint endpSel2 = yTable2 |
| .createMultiSelectionEndpoint(); |
| yBindingSet.addBinding(endpSel1, endpSel2); |
| |
| Container.Indexed container1 = (Indexed) table1 |
| .getContainerDataSource(); |
| Container.Indexed container2 = (Indexed) table2 |
| .getContainerDataSource(); |
| assertEquals(0, container1.size()); |
| assertEquals(0, container2.size()); |
| |
| assertTrue(asList(table1.getValue()).isEmpty()); |
| assertTrue(yTable1.getMultiSelection().isEmpty()); |
| assertTrue(asList(table2.getValue()).isEmpty()); |
| assertTrue(yTable2.getMultiSelection().isEmpty()); |
| |
| // add |
| yTable1.getCollection().add("Huhu"); |
| yTable2.getCollection().add("Haha"); |
| assertEquals(2, container1.size()); |
| assertEquals(2, container2.size()); |
| |
| assertTrue(asList(table1.getValue()).isEmpty()); |
| assertTrue(yTable1.getMultiSelection().isEmpty()); |
| assertTrue(asList(table2.getValue()).isEmpty()); |
| assertTrue(yTable2.getMultiSelection().isEmpty()); |
| |
| // test set selection |
| yTable1.getMultiSelection().add("Huhu"); |
| assertEquals("Huhu", yTable1.getMultiSelection().get(0)); |
| assertEquals("Huhu", asList(table1.getValue()).get(0)); |
| assertEquals(1, yTable1.getMultiSelection().size()); |
| assertEquals(1, asList(table1.getValue()).size()); |
| assertEquals("Huhu", yTable2.getMultiSelection().get(0)); |
| assertEquals("Huhu", asList(table2.getValue()).get(0)); |
| assertEquals(1, yTable2.getMultiSelection().size()); |
| assertEquals(1, asList(table2.getValue()).size()); |
| |
| yTable2.getMultiSelection().add("Haha"); |
| assertEquals("Huhu", yTable1.getMultiSelection().get(0)); |
| assertEquals("Haha", yTable1.getMultiSelection().get(1)); |
| assertTrue(asList(table1.getValue()).contains("Huhu")); |
| assertTrue(asList(table1.getValue()).contains("Haha")); |
| assertEquals(2, yTable1.getMultiSelection().size()); |
| assertEquals(2, asList(table1.getValue()).size()); |
| assertEquals("Huhu", yTable2.getMultiSelection().get(0)); |
| assertEquals("Haha", yTable2.getMultiSelection().get(1)); |
| assertTrue(asList(table2.getValue()).contains("Huhu")); |
| assertTrue(asList(table2.getValue()).contains("Haha")); |
| assertEquals(2, yTable2.getMultiSelection().size()); |
| assertEquals(2, asList(table2.getValue()).size()); |
| |
| yTable1.getMultiSelection().remove("Huhu"); |
| assertEquals("Haha", yTable1.getMultiSelection().get(0)); |
| assertEquals("Haha", asList(table1.getValue()).get(0)); |
| assertEquals(1, yTable1.getMultiSelection().size()); |
| assertEquals(1, asList(table1.getValue()).size()); |
| assertEquals("Haha", yTable2.getMultiSelection().get(0)); |
| assertEquals("Haha", asList(table2.getValue()).get(0)); |
| assertEquals(1, yTable2.getMultiSelection().size()); |
| assertEquals(1, asList(table2.getValue()).size()); |
| |
| // clear |
| yTable2.getMultiSelection().clear(); |
| assertTrue(asList(table1.getValue()).isEmpty()); |
| assertTrue(yTable1.getMultiSelection().isEmpty()); |
| assertTrue(asList(table2.getValue()).isEmpty()); |
| assertTrue(yTable2.getMultiSelection().isEmpty()); |
| |
| // test set selection null |
| List<String> selection = new ArrayList<String>(); |
| selection.add("Huhu"); |
| table1.setValue(selection); |
| assertEquals("Huhu", yTable1.getMultiSelection().get(0)); |
| assertEquals("Huhu", asList(table1.getValue()).get(0)); |
| assertEquals(1, yTable1.getMultiSelection().size()); |
| assertEquals(1, asList(table1.getValue()).size()); |
| assertEquals("Huhu", yTable2.getMultiSelection().get(0)); |
| assertEquals("Huhu", asList(table2.getValue()).get(0)); |
| assertEquals(1, yTable2.getMultiSelection().size()); |
| assertEquals(1, asList(table2.getValue()).size()); |
| |
| selection.add("Haha"); |
| table2.setValue(selection); |
| assertEquals("Huhu", yTable1.getMultiSelection().get(0)); |
| assertEquals("Haha", yTable1.getMultiSelection().get(1)); |
| assertTrue(asList(table1.getValue()).contains("Huhu")); |
| assertTrue(asList(table1.getValue()).contains("Haha")); |
| assertEquals(2, yTable1.getMultiSelection().size()); |
| assertEquals(2, asList(table1.getValue()).size()); |
| assertEquals("Huhu", yTable2.getMultiSelection().get(0)); |
| assertEquals("Haha", yTable2.getMultiSelection().get(1)); |
| assertTrue(asList(table2.getValue()).contains("Huhu")); |
| assertTrue(asList(table2.getValue()).contains("Haha")); |
| assertEquals(2, yTable2.getMultiSelection().size()); |
| assertEquals(2, asList(table2.getValue()).size()); |
| |
| table2.setValue(new ArrayList<String>()); |
| assertTrue(asList(table2.getValue()).isEmpty()); |
| assertTrue(yTable2.getMultiSelection().isEmpty()); |
| assertTrue(asList(table1.getValue()).isEmpty()); |
| assertTrue(yTable1.getMultiSelection().isEmpty()); |
| } |
| |
| /** |
| * Test the internal structure based on CSS. |
| * |
| * @throws Exception |
| */ |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_SelectionBinding_Single_ListToList() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(String.class); |
| yLayout.getElements().add(yTable1); |
| YTable yTable2 = factory.createTable(); |
| yTable2.setType(String.class); |
| yLayout.getElements().add(yTable2); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| ITableEditpart table2Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable2); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| IWidgetPresentation<Component> table2Presentation = table2Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| Table table2 = (Table) table2Presentation.getWidget(); |
| |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| |
| // start tests |
| // |
| |
| YEmbeddableCollectionEndpoint endp1 = yTable1 |
| .createCollectionEndpoint(); |
| YEmbeddableCollectionEndpoint endp2 = yTable2 |
| .createCollectionEndpoint(); |
| yBindingSet.addBinding(endp1, endp2); |
| |
| YEmbeddableSelectionEndpoint endpSel1 = yTable1 |
| .createSelectionEndpoint(); |
| YEmbeddableSelectionEndpoint endpSel2 = yTable2 |
| .createSelectionEndpoint(); |
| yBindingSet.addBinding(endpSel1, endpSel2); |
| |
| Container.Indexed container1 = (Indexed) table1 |
| .getContainerDataSource(); |
| Container.Indexed container2 = (Indexed) table2 |
| .getContainerDataSource(); |
| assertEquals(0, container1.size()); |
| assertEquals(0, container2.size()); |
| |
| assertNull(table1.getValue()); |
| assertNull(yTable1.getSelection()); |
| |
| // add |
| yTable1.getCollection().add("Huhu"); |
| yTable2.getCollection().add("Haha"); |
| assertEquals(2, container1.size()); |
| assertEquals(2, container2.size()); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| // test set selection |
| yTable1.setSelection("Huhu"); |
| assertEquals("Huhu", yTable1.getSelection()); |
| assertEquals("Huhu", table1.getValue()); |
| assertEquals("Huhu", yTable2.getSelection()); |
| assertEquals("Huhu", table2.getValue()); |
| |
| table1.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| assertEquals("Haha", yTable2.getSelection()); |
| assertEquals("Haha", table2.getValue()); |
| |
| // test set selection null |
| table1.setValue(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| table1.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| assertEquals("Haha", yTable2.getSelection()); |
| assertEquals("Haha", table2.getValue()); |
| |
| table2.setValue(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| table2.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| assertEquals("Haha", yTable2.getSelection()); |
| assertEquals("Haha", table2.getValue()); |
| |
| yTable1.setSelection(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| table2.setValue("Haha"); |
| assertEquals("Haha", yTable1.getSelection()); |
| assertEquals("Haha", table1.getValue()); |
| assertEquals("Haha", yTable2.getSelection()); |
| assertEquals("Haha", table2.getValue()); |
| |
| yTable2.setSelection(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| |
| // test remove element that is selected |
| // add |
| assertEquals(2, container1.size()); |
| assertEquals(2, container2.size()); |
| |
| yTable1.setSelection("Huhu"); |
| assertEquals("Huhu", yTable1.getSelection()); |
| assertEquals("Huhu", yTable2.getSelection()); |
| assertEquals("Huhu", table1.getValue()); |
| assertEquals("Huhu", table2.getValue()); |
| |
| yTable1.getCollection().remove("Huhu"); |
| assertNull(table1.getValue()); |
| assertNull(table2.getValue()); |
| assertNull(yTable1.getSelection()); |
| assertNull(yTable2.getSelection()); |
| |
| // test remove element that is selected |
| // add |
| yTable2.getCollection().add("Huhu"); |
| assertEquals(2, container1.size()); |
| assertEquals(2, container2.size()); |
| |
| yTable1.setSelection("Huhu"); |
| assertEquals("Huhu", yTable1.getSelection()); |
| assertEquals("Huhu", table1.getValue()); |
| assertEquals("Huhu", yTable2.getSelection()); |
| assertEquals("Huhu", table2.getValue()); |
| |
| table2.setValue(null); |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yTable2.getSelection()); |
| assertNull(table2.getValue()); |
| } |
| |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_SelectionBinding_Single_DetailBinding_ToBean() |
| throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(Bar.class); |
| yLayout.getElements().add(yTable1); |
| YTextField yText = factory.createTextField(); |
| yLayout.getElements().add(yText); |
| |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| YDetailValueBindingEndpoint yDetailEndpoint = yTable1 |
| .createSelectionEndpoint().createDetailValueEndpoint(); |
| yDetailEndpoint.setPropertyPath("myfoo.name"); |
| yDetailEndpoint.setType(Bar.class); |
| yBindingSet.addBinding(yText.createValueEndpoint(), yDetailEndpoint); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| |
| ITextFieldEditpart textEditpart = DelegatingEditPartManager |
| .getInstance().getEditpart(viewContext,yText); |
| IWidgetPresentation<Component> textPresentation = textEditpart |
| .getPresentation(); |
| TextField text = (TextField) textPresentation.getWidget(); |
| |
| // start tests |
| // |
| Container.Indexed container = (Indexed) table1.getContainerDataSource(); |
| assertEquals(0, container.size()); |
| |
| assertNull(table1.getValue()); |
| assertNull(yTable1.getSelection()); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| // add |
| Bar bar1 = new Bar(); |
| bar1.setName("Bar1"); |
| Foo foo1 = new Foo(); |
| foo1.setName("Foo1"); |
| bar1.setMyfoo(foo1); |
| |
| Bar bar2 = new Bar(); |
| bar2.setName("Bar2"); |
| Foo foo2 = new Foo(); |
| foo2.setName("Foo2"); |
| bar2.setMyfoo(foo2); |
| |
| yTable1.getCollection().add(bar1); |
| yTable1.getCollection().add(bar2); |
| assertEquals(2, container.size()); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| // test set selection |
| yTable1.setSelection(bar1); |
| assertEquals("Foo1", yText.getValue()); |
| assertEquals("Foo1", text.getValue()); |
| |
| yTable1.setSelection(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| // test set selection null |
| yTable1.setSelection(null); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| table1.setValue(bar1); |
| assertEquals("Foo1", yText.getValue()); |
| assertEquals("Foo1", text.getValue()); |
| |
| table1.setValue(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| // test set selection null |
| table1.setValue(null); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| // test remove element that is selected |
| // add |
| table1.setValue(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| yTable1.getCollection().clear(); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| // test setValue to textfield |
| yTable1.getCollection().add(bar1); |
| yTable1.getCollection().add(bar2); |
| assertEquals(2, container.size()); |
| |
| yTable1.setSelection(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| yText.setValue("Foo2_1"); |
| assertEquals("Foo2_1", foo2.getName()); |
| assertEquals("Foo2_1", text.getValue()); |
| |
| text.setValue("Foo2_2"); |
| assertEquals("Foo2_2", foo2.getName()); |
| assertEquals("Foo2_2", yText.getValue()); |
| |
| yTable1.setSelection(bar1); |
| assertEquals("Foo1", yText.getValue()); |
| assertEquals("Foo1", text.getValue()); |
| |
| yText.setValue("Foo1_1"); |
| assertEquals("Foo1_1", foo1.getName()); |
| assertEquals("Foo1_1", text.getValue()); |
| |
| text.setValue("Foo1_2"); |
| assertEquals("Foo1_2", foo1.getName()); |
| assertEquals("Foo1_2", yText.getValue()); |
| |
| } |
| |
| @Test |
| public void test_SelectionBinding_Single_WithAttributePath() |
| throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(Bar.class); |
| yLayout.getElements().add(yTable1); |
| YTextField yText = factory.createTextField(); |
| yLayout.getElements().add(yText); |
| |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| YEmbeddableSelectionEndpoint selectionBindingEndpoint = yTable1 |
| .createSelectionEndpoint(); |
| selectionBindingEndpoint.setAttributePath("myfoo.name"); |
| yBindingSet.addBinding(yText.createValueEndpoint(), |
| selectionBindingEndpoint); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| |
| ITextFieldEditpart textEditpart = DelegatingEditPartManager |
| .getInstance().getEditpart(viewContext,yText); |
| IWidgetPresentation<Component> textPresentation = textEditpart |
| .getPresentation(); |
| TextField text = (TextField) textPresentation.getWidget(); |
| |
| // start tests |
| // |
| Container.Indexed container = (Indexed) table1.getContainerDataSource(); |
| assertEquals(0, container.size()); |
| |
| assertNull(table1.getValue()); |
| assertNull(yTable1.getSelection()); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| // add |
| Bar bar1 = new Bar(); |
| bar1.setName("Bar1"); |
| Foo foo1 = new Foo(); |
| foo1.setName("Foo1"); |
| bar1.setMyfoo(foo1); |
| |
| Bar bar2 = new Bar(); |
| bar2.setName("Bar2"); |
| Foo foo2 = new Foo(); |
| foo2.setName("Foo2"); |
| bar2.setMyfoo(foo2); |
| |
| yTable1.getCollection().add(bar1); |
| yTable1.getCollection().add(bar2); |
| assertEquals(2, container.size()); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| // test set selection |
| yTable1.setSelection(bar1); |
| assertEquals("Foo1", yText.getValue()); |
| assertEquals("Foo1", text.getValue()); |
| |
| yTable1.setSelection(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| // test set selection null |
| yTable1.setSelection(null); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| table1.setValue(bar1); |
| assertEquals("Foo1", yText.getValue()); |
| assertEquals("Foo1", text.getValue()); |
| |
| table1.setValue(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| // test set selection null |
| table1.setValue(null); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| // test remove element that is selected |
| // add |
| table1.setValue(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| yTable1.getCollection().clear(); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| // test setValue to textfield |
| yTable1.getCollection().add(bar1); |
| yTable1.getCollection().add(bar2); |
| assertEquals(2, container.size()); |
| |
| yTable1.setSelection(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| yText.setValue("Foo2_1"); |
| assertEquals("Foo2_1", foo2.getName()); |
| assertEquals("Foo2_1", text.getValue()); |
| |
| text.setValue("Foo2_2"); |
| assertEquals("Foo2_2", foo2.getName()); |
| assertEquals("Foo2_2", yText.getValue()); |
| |
| yTable1.setSelection(bar1); |
| assertEquals("Foo1", yText.getValue()); |
| assertEquals("Foo1", text.getValue()); |
| |
| yText.setValue("Foo1_1"); |
| assertEquals("Foo1_1", foo1.getName()); |
| assertEquals("Foo1_1", text.getValue()); |
| |
| text.setValue("Foo1_2"); |
| assertEquals("Foo1_2", foo1.getName()); |
| assertEquals("Foo1_2", yText.getValue()); |
| |
| } |
| |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_SelectionBinding_Single_DetailBinding_ToEmf() |
| throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable1 = factory.createTable(); |
| yTable1.setType(EmfBar.class); |
| yTable1.setEmfNsURI(ModelPackage.eINSTANCE.getNsURI()); |
| yLayout.getElements().add(yTable1); |
| YTextField yText = factory.createTextField(); |
| yLayout.getElements().add(yText); |
| |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| YDetailValueBindingEndpoint yDetailEndpoint = yTable1 |
| .createSelectionEndpoint().createDetailValueEndpoint(); |
| yDetailEndpoint.setType(EmfBar.class); |
| yDetailEndpoint.getFeatures().add( |
| ModelPackage.eINSTANCE.getEmfBar_Myfoo()); |
| yDetailEndpoint.getFeatures().add( |
| ModelPackage.eINSTANCE.getEmfFoo_Name()); |
| yBindingSet.addBinding(yText.createValueEndpoint(), yDetailEndpoint); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable1); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| Table table1 = (Table) table1Presentation.getWidget(); |
| |
| ITextFieldEditpart textEditpart = DelegatingEditPartManager |
| .getInstance().getEditpart(viewContext,yText); |
| IWidgetPresentation<Component> textPresentation = textEditpart |
| .getPresentation(); |
| TextField text = (TextField) textPresentation.getWidget(); |
| |
| // start tests |
| // |
| Container.Indexed container = (Indexed) table1.getContainerDataSource(); |
| assertEquals(0, container.size()); |
| |
| assertNull(table1.getValue()); |
| assertNull(yTable1.getSelection()); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| // add |
| EmfBar bar1 = ModelFactory.eINSTANCE.createEmfBar(); |
| bar1.setName("Bar1"); |
| EmfFoo foo1 = ModelFactory.eINSTANCE.createEmfFoo(); |
| foo1.setName("Foo1"); |
| bar1.setMyfoo(foo1); |
| |
| EmfBar bar2 = ModelFactory.eINSTANCE.createEmfBar(); |
| bar2.setName("Bar2"); |
| EmfFoo foo2 = ModelFactory.eINSTANCE.createEmfFoo(); |
| foo2.setName("Foo2"); |
| bar2.setMyfoo(foo2); |
| |
| yTable1.getCollection().add(bar1); |
| yTable1.getCollection().add(bar2); |
| assertEquals(2, container.size()); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| // test set selection |
| yTable1.setSelection(bar1); |
| assertEquals("Foo1", yText.getValue()); |
| assertEquals("Foo1", text.getValue()); |
| |
| yTable1.setSelection(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| // test set selection null |
| yTable1.setSelection(null); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| table1.setValue(bar1); |
| assertEquals("Foo1", yText.getValue()); |
| assertEquals("Foo1", text.getValue()); |
| |
| table1.setValue(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| // test set selection null |
| table1.setValue(null); |
| assertNull(yText.getValue()); |
| assertNull(text.getValue()); |
| |
| // test remove element that is selected |
| // add |
| table1.setValue(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| yTable1.getCollection().clear(); |
| |
| assertNull(yTable1.getSelection()); |
| assertNull(table1.getValue()); |
| |
| // test setValue to textfield |
| yTable1.getCollection().add(bar1); |
| yTable1.getCollection().add(bar2); |
| assertEquals(2, container.size()); |
| |
| yTable1.setSelection(bar2); |
| assertEquals("Foo2", yText.getValue()); |
| assertEquals("Foo2", text.getValue()); |
| |
| yText.setValue("Foo2_1"); |
| assertEquals("Foo2_1", foo2.getName()); |
| assertEquals("Foo2_1", text.getValue()); |
| |
| text.setValue("Foo2_2"); |
| assertEquals("Foo2_2", foo2.getName()); |
| assertEquals("Foo2_2", yText.getValue()); |
| |
| yTable1.setSelection(bar1); |
| assertEquals("Foo1", yText.getValue()); |
| assertEquals("Foo1", text.getValue()); |
| |
| yText.setValue("Foo1_1"); |
| assertEquals("Foo1_1", foo1.getName()); |
| assertEquals("Foo1_1", text.getValue()); |
| |
| text.setValue("Foo1_2"); |
| assertEquals("Foo1_2", foo1.getName()); |
| assertEquals("Foo1_2", yText.getValue()); |
| |
| } |
| |
| @Test |
| public void test_i18n() throws ContextException { |
| |
| // switch the global locale to german |
| Locale.setDefault(Locale.GERMAN); |
| |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable = factory.createTable(); |
| yTable.setType(String.class); |
| yLayout.getElements().add(yTable); |
| |
| // set the i18n key |
| yTable.setLabelI18nKey(I18nServiceForTests.KEY__AGE); |
| |
| // prepare the I18nService and pass it to the renderer |
| Map<String, Object> parameter = new HashMap<String, Object>(); |
| Map<String, Object> services = new HashMap<String, Object>(); |
| parameter.put(IViewContext.PARAM_SERVICES, services); |
| services.put(II18nService.ID, new I18nServiceForTests()); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, parameter); |
| ITableEditpart editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable); |
| TablePresentation presentation = editpart.getPresentation(); |
| |
| assertEquals("Alter", presentation.getWidget().getCaption()); |
| |
| viewContext.setLocale(Locale.ENGLISH); |
| assertEquals("Age", presentation.getWidget().getCaption()); |
| } |
| |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_Readonly_Binding() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable = factory.createTable(); |
| yTable.setType(String.class); |
| yLayout.getElements().add(yTable); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable); |
| IWidgetPresentation<Component> presentation = editpart |
| .getPresentation(); |
| Table table = (Table) presentation.getWidget(); |
| |
| ValueBean bean = new ValueBean(false); |
| YBeanValueBindingEndpoint yBeanBinding = factory |
| .createBeanBindingEndpoint(); |
| yBeanBinding.setBean(bean); |
| yBeanBinding.setPropertyPath("boolValue"); |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| yBindingSet.addBinding(yTable.createEditableEndpoint(), yBeanBinding); |
| |
| // test binding |
| assertFalse(yTable.isEditable()); |
| assertFalse(!table.isReadOnly()); |
| assertFalse(bean.isBoolValue()); |
| |
| bean.setBoolValue(true); |
| assertTrue(yTable.isEditable()); |
| assertTrue(!table.isReadOnly()); |
| assertTrue(bean.isBoolValue()); |
| } |
| |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_Visible_Binding() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable = factory.createTable(); |
| yTable.setType(String.class); |
| yLayout.getElements().add(yTable); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable); |
| IWidgetPresentation<Component> presentation = editpart |
| .getPresentation(); |
| Table table = (Table) presentation.getWidget(); |
| |
| ValueBean bean = new ValueBean(false); |
| YBeanValueBindingEndpoint yBeanBinding = factory |
| .createBeanBindingEndpoint(); |
| yBeanBinding.setBean(bean); |
| yBeanBinding.setPropertyPath("boolValue"); |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| yBindingSet.addBinding(yTable.createVisibleEndpoint(), yBeanBinding); |
| |
| // test binding |
| assertFalse(yTable.isVisible()); |
| assertFalse(table.isVisible()); |
| assertFalse(bean.isBoolValue()); |
| |
| bean.setBoolValue(true); |
| assertTrue(yTable.isVisible()); |
| assertTrue(table.isVisible()); |
| assertTrue(bean.isBoolValue()); |
| } |
| |
| @Test |
| // BEGIN SUPRESS CATCH EXCEPTION |
| public void test_Enabled_Binding() throws Exception { |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable = factory.createTable(); |
| yTable.setType(String.class); |
| yLayout.getElements().add(yTable); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable); |
| IWidgetPresentation<Component> presentation = editpart |
| .getPresentation(); |
| Table table = (Table) presentation.getWidget(); |
| |
| ValueBean bean = new ValueBean(false); |
| YBeanValueBindingEndpoint yBeanBinding = factory |
| .createBeanBindingEndpoint(); |
| yBeanBinding.setBean(bean); |
| yBeanBinding.setPropertyPath("boolValue"); |
| YBindingSet yBindingSet = yView.getOrCreateBindingSet(); |
| yBindingSet.addBinding(yTable.createEnabledEndpoint(), yBeanBinding); |
| |
| // test binding |
| assertFalse(yTable.isEnabled()); |
| assertFalse(table.isEnabled()); |
| assertFalse(bean.isBoolValue()); |
| |
| bean.setBoolValue(true); |
| assertTrue(yTable.isEnabled()); |
| assertTrue(table.isEnabled()); |
| assertTrue(bean.isBoolValue()); |
| } |
| |
| @Test |
| public void test_type_String() throws ContextException { |
| |
| // END SUPRESS CATCH EXCEPTION |
| // build the view model |
| // ...> yView |
| // ......> yText |
| YView yView = factory.createView(); |
| YGridLayout yLayout = factory.createGridLayout(); |
| yView.setContent(yLayout); |
| YTable yTable = factory.createTable(); |
| yTable.setType(String.class); |
| yLayout.getElements().add(yTable); |
| |
| VaadinRenderer renderer = new VaadinRenderer(); |
| IViewContext viewContext = renderer.render(rootLayout, yView, null); |
| |
| ITableEditpart table1Editpart = DelegatingEditPartManager.getInstance() |
| .getEditpart(viewContext,yTable); |
| IWidgetPresentation<Component> table1Presentation = table1Editpart |
| .getPresentation(); |
| Table table = (Table) table1Presentation.getWidget(); |
| |
| // start tests |
| // |
| yTable.getCollection().add("Blabla"); |
| yTable.getCollection().add("Huhu"); |
| |
| // For String values NO BeanItemContainer is prepared. |
| Container.Indexed container = (Indexed) table.getContainerDataSource(); |
| assertEquals(0, container.getContainerPropertyIds().size()); |
| |
| String itemCaption = table.getItemCaption(container.getItemIds() |
| .iterator().next()); |
| assertEquals("Blabla", itemCaption); |
| assertSame(ItemCaptionMode.ID, table.getItemCaptionMode()); |
| |
| } |
| |
| private Collection<?> castCollection(Object value) { |
| return (Collection<?>) value; |
| } |
| |
| private List<?> asList(Object value) { |
| return value != null ? new ArrayList<Object>(castCollection(value)) |
| : new ArrayList<Object>(); |
| } |
| |
| private static class ConverterFactory implements IConverterFactory { |
| |
| @Override |
| public boolean isFor(IViewContext uiContext, IConverterEditpart editpart) { |
| return true; |
| } |
| |
| @Override |
| public Object createConverter(IViewContext uiContext, |
| IConverterEditpart editpart) throws IllegalArgumentException { |
| return new FooToStringConverter(); |
| } |
| } |
| |
| |
| /** |
| * Converts the object foo to a string value. |
| */ |
| @SuppressWarnings("serial") |
| private static class FooToStringConverter implements com.vaadin.data.util.converter.Converter<String, Foo> { |
| |
| @Override |
| public Foo convertToModel(String value, |
| Class<? extends Foo> targetType, Locale locale) |
| throws com.vaadin.data.util.converter.Converter.ConversionException { |
| return null; |
| } |
| |
| @Override |
| public String convertToPresentation(Foo value, |
| Class<? extends String> targetType, Locale locale) |
| throws com.vaadin.data.util.converter.Converter.ConversionException { |
| return value != null ? value.toString() : null; |
| } |
| |
| @Override |
| public Class<Foo> getModelType() { |
| return Foo.class; |
| } |
| |
| @Override |
| public Class<String> getPresentationType() { |
| return String.class; |
| } |
| |
| } |
| } |