diff options
27 files changed, 865 insertions, 888 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java index e6d3af9d7b..9bd3ed8af2 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java @@ -15,16 +15,11 @@ */ package com.vaadin.tests.components.grid; -import java.util.ArrayList; -import java.util.List; - import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.data.bean.Person; import com.vaadin.ui.Grid; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; -import com.vaadin.ui.renderers.NumberRenderer; /** * Tests the layouting of Grid's details row when it contains a HorizontalLayout @@ -33,33 +28,13 @@ import com.vaadin.ui.renderers.NumberRenderer; * @author Vaadin Ltd */ @SuppressWarnings("serial") -public class GridDetailsLayoutExpand extends AbstractTestUI { +public class GridDetailsLayoutExpand extends SimpleGridUI { @Override protected void setup(VaadinRequest request) { - final Grid<Person> grid = new Grid<>(); + Grid<Person> grid = createGrid(); grid.setSizeFull(); - grid.addColumn(Person::getFirstName); - grid.addColumn(Person::getAge, new NumberRenderer()); - - List<Person> persons = new ArrayList<>(); - Person person = new Person(); - person.setFirstName("Nicolaus Copernicus"); - person.setAge(1543); - persons.add(person); - - person = new Person(); - person.setFirstName("Galileo Galilei"); - person.setAge(1564); - persons.add(person); - - person = new Person(); - person.setFirstName("Johannes Kepler"); - person.setAge(1571); - persons.add(person); - - grid.setItems(persons); addComponent(grid); grid.setDetailsGenerator(item -> { diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeight.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeight.java new file mode 100644 index 0000000000..afc86dbcaf --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeight.java @@ -0,0 +1,193 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.grid.HeightMode; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.RadioButtonGroup; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.renderers.NumberRenderer; + +/** + * Tests that Grid gets correct height based on height mode, and resizes + * properly with details row if height is undefined. + * + * @author Vaadin Ltd + */ +public class GridHeight extends AbstractReindeerTestUI { + + static final String FULL = "Full"; + static final String UNDEFINED = "Undefined"; + static final String PX100 = "100px"; + static final Integer ROW3 = 3; + + static final Object[] gridHeights = { FULL, UNDEFINED, ROW3 }; + static final String[] gridWidths = { FULL, UNDEFINED }; + static final String[] detailsRowHeights = { FULL, UNDEFINED, PX100 }; + + private Grid<Person> grid; + private Map<Person, VerticalLayout> detailsLayouts = new HashMap<>(); + private RadioButtonGroup<String> detailsHeightSelector; + + @Override + protected void setup(VaadinRequest request) { + + grid = new Grid<>(); + + grid.addColumn(Person::getFirstName); + grid.addColumn(Person::getAge, new NumberRenderer()); + + grid.setItems(createPersons()); + + grid.setDetailsGenerator(person -> { + if (!detailsLayouts.containsKey(person)) { + createDetailsLayout(person); + } + return detailsLayouts.get(person); + }); + + grid.addItemClickListener(click -> grid.setDetailsVisible( + click.getItem(), !grid.isDetailsVisible(click.getItem()))); + + addComponent(createOptionLayout()); + addComponent(grid); + } + + private List<Person> createPersons() { + Person person1 = new Person(); + person1.setFirstName("Nicolaus Copernicus"); + person1.setAge(1543); + + Person person2 = new Person(); + person2.setFirstName("Galileo Galilei"); + person2.setAge(1564); + + Person person3 = new Person(); + person3.setFirstName("Johannes Kepler"); + person3.setAge(1571); + + return Arrays.asList(person1, person2, person3); + } + + private void createDetailsLayout(Person person) { + VerticalLayout detailsLayout = new VerticalLayout(); + setDetailsHeight(detailsLayout, detailsHeightSelector.getValue()); + detailsLayout.setWidth("100%"); + + Label lbl1 = new Label("details row"); + lbl1.setId("lbl1"); + lbl1.setSizeUndefined(); + detailsLayout.addComponent(lbl1); + detailsLayout.setComponentAlignment(lbl1, Alignment.MIDDLE_CENTER); + + detailsLayouts.put(person, detailsLayout); + } + + private Component createOptionLayout() { + HorizontalLayout optionLayout = new HorizontalLayout(); + RadioButtonGroup<Object> gridHeightSelector = new RadioButtonGroup<>( + "Grid height"); + gridHeightSelector.setItems(Arrays.asList(gridHeights)); + gridHeightSelector.setId("gridHeightSelector"); + + gridHeightSelector.setItemCaptionGenerator(this::generateCaption); + + gridHeightSelector.addValueChangeListener(event -> { + Object value = event.getValue(); + if (UNDEFINED.equals(value)) { + grid.setHeightUndefined(); + grid.setHeightMode(HeightMode.UNDEFINED); + } else if (FULL.equals(value)) { + grid.setHeight("100%"); + grid.setHeightMode(HeightMode.CSS); + } else if (ROW3.equals(value)) { + grid.setHeightByRows(ROW3); + grid.setHeightMode(HeightMode.ROW); + } + }); + gridHeightSelector.setValue(UNDEFINED); + optionLayout.addComponent(gridHeightSelector); + + RadioButtonGroup<String> gridWidthSelector = new RadioButtonGroup<>( + "Grid width", Arrays.asList(gridWidths)); + gridWidthSelector.setId("gridWidthSelector"); + gridWidthSelector.addValueChangeListener(event -> { + Object value = event.getValue(); + if (UNDEFINED.equals(value)) { + grid.setWidthUndefined(); + } else if (FULL.equals(value)) { + grid.setWidth("100%"); + } + }); + gridWidthSelector.setValue(UNDEFINED); + optionLayout.addComponent(gridWidthSelector); + + detailsHeightSelector = new RadioButtonGroup<>("Details row height"); + detailsHeightSelector.setItems(Arrays.asList(detailsRowHeights)); + detailsHeightSelector.setId("detailsHeightSelector"); + detailsHeightSelector.addValueChangeListener(event -> { + Object value = event.getValue(); + for (VerticalLayout detailsLayout : detailsLayouts.values()) { + setDetailsHeight(detailsLayout, value); + } + }); + detailsHeightSelector.setValue(PX100); + optionLayout.addComponent(detailsHeightSelector); + return optionLayout; + } + + private void setDetailsHeight(VerticalLayout detailsLayout, Object value) { + if (UNDEFINED.equals(value)) { + detailsLayout.setHeightUndefined(); + } else if (FULL.equals(value)) { + detailsLayout.setHeight("100%"); + } else if (PX100.equals(value)) { + detailsLayout.setHeight(PX100); + } + } + + @Override + protected String getTestDescription() { + return "Grid with undefined height should display all rows and resize when details row is opened." + + "<br>Grid with full height is always 400px high regardless or details row." + + "<br>Grid with row height should always be the height of those rows regardless of details row."; + } + + @Override + protected Integer getTicketNumber() { + return 19690; + } + + private String generateCaption(Object item) { + if (item instanceof String) { + return item.toString(); + } else { + return item + " rows"; + } + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java new file mode 100644 index 0000000000..edfd6bb356 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java @@ -0,0 +1,80 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.LinkedList; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import com.vaadin.data.ValueProvider; +import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.ListDataProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.renderers.NumberRenderer; + +public class GridInTabSheet extends AbstractReindeerTestUI { + + private AtomicInteger index = new AtomicInteger(0); + + @Override + protected void setup(VaadinRequest request) { + TabSheet sheet = new TabSheet(); + final Grid<Integer> grid = new Grid<>(); + grid.setSelectionMode(SelectionMode.MULTI); + grid.addColumn(ValueProvider.identity(), new NumberRenderer()) + .setId("count"); + + LinkedList<Integer> items = IntStream.range(0, 3).boxed() + .collect(Collectors.toCollection(LinkedList::new)); + ListDataProvider<Integer> provider = DataProvider.ofCollection(items); + grid.setDataProvider(provider); + + sheet.addTab(grid, "Grid"); + sheet.addTab(new Label("Hidden"), "Label"); + + addComponent(sheet); + addComponent(new Button("Add row to Grid", event -> { + items.add(100 + index.getAndIncrement()); + provider.refreshAll(); + })); + + Button remove = new Button("Remove row from Grid", event -> { + Object firstItemId = items.get(0); + if (firstItemId != null) { + items.remove(0); + provider.refreshAll(); + } + }); + addComponent(remove); + Button addGenerator = new Button("Add CellStyleGenerator", event -> { + grid.setStyleGenerator(item -> { + if (item % 2 == 1) { + return null; + } + return "count"; + }); + }); + + addComponent(addGenerator); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInWindowResize.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInWindowResize.java new file mode 100644 index 0000000000..ddca27bad7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInWindowResize.java @@ -0,0 +1,72 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.data.bean.Address; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; + +public class GridInWindowResize extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid<Person> grid = new Grid<>(); + + grid.addColumn(Person::getFirstName); + grid.addColumn(Person::getLastName); + grid.addColumn(person -> person.getAddress().getCity()); + + grid.setItems(createPersons()); + grid.setSizeFull(); + + VerticalLayout vl = new VerticalLayout(grid); + vl.setSizeFull(); + Button resize = new Button("resize"); + VerticalLayout vl2 = new VerticalLayout(vl, resize); + vl2.setSizeFull(); + + final Window window = new Window(null, vl2); + addWindow(window); + + window.center(); + window.setModal(true); + window.setWidth("600px"); + window.setHeight("400px"); + + resize.addClickListener(event -> window.setWidth("400px")); + } + + private Stream<Person> createPersons() { + return IntStream.range(0, 100).mapToObj(index -> createPerson()); + } + + private Person createPerson() { + Person person = new Person(); + person.setFirstName("1"); + person.setFirstName("1"); + person.setAddress(new Address()); + person.getAddress().setCity("1"); + return person; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java new file mode 100644 index 0000000000..1c0a662abb --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java @@ -0,0 +1,73 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.Date; +import java.util.Random; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.tests.util.PortableRandom; +import com.vaadin.tests.util.TestDataGenerator; +import com.vaadin.ui.Grid; +import com.vaadin.ui.renderers.NumberRenderer; + +public class GridInitiallyHiddenColumns extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + Grid<Person> grid = new Grid<>(); + + grid.addColumn(Person::getFirstName).setHidden(true).setHidable(true) + .setCaption("First Name"); + grid.addColumn(Person::getLastName).setHidable(true) + .setCaption("Last Name"); + grid.addColumn(Person::getAge, new NumberRenderer()).setHidden(true) + .setHidable(true).setCaption("Age"); + + grid.setItems(createPersons()); + + addComponent(grid); + } + + private Stream<Person> createPersons() { + Random random = new Random(100); + return IntStream.range(0, 100).mapToObj(index -> createPerson(random)); + } + + private Person createPerson(Random random) { + Person person = new Person(); + person.setFirstName(TestDataGenerator.getFirstName(random)); + person.setLastName(TestDataGenerator.getLastName(random)); + person.setBirthDate(TestDataGenerator.getBirthDate(random)); + person.setAge((int) ((new Date(2014 - 1900, 1, 1).getTime() + - person.getBirthDate().getTime()) / 1000 / 3600 / 24 / 365)); + + return person; + } + + public static String createRandomString(PortableRandom random, int len) { + StringBuilder b = new StringBuilder(); + for (int i = 0; i < len; i++) { + b.append((char) (random.nextInt('z' - 'a') + 'a')); + } + + return b.toString(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridItemSetChange.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridItemSetChange.java new file mode 100644 index 0000000000..64c5d72552 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridItemSetChange.java @@ -0,0 +1,62 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.ListDataProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.tests.util.Person; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; + +public class GridItemSetChange extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid<Person> grid = new Grid<>(); + + grid.addColumn(Person::getFirstName); + grid.addColumn(Person::getLastName); + + List<Person> persons = new ArrayList<>(); + Person person = new Person(); + person.setFirstName("Foo"); + person.setLastName("Bar"); + persons.add(person); + + ListDataProvider<Person> provider = DataProvider.ofCollection(persons); + grid.setDataProvider(provider); + + addComponent(grid); + + addComponent(new Button("Reset", event -> { + persons.clear(); + person.setLastName("Baz"); + persons.add(person); + provider.refreshAll(); + })); + + addComponent(new Button("Modify", event -> { + person.setLastName("Spam"); + provider.refreshItem(person); + })); + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java new file mode 100644 index 0000000000..1ab3523896 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java @@ -0,0 +1,78 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Grid; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Label; + +/** + * Tests that details row displays GridLayout contents properly. + * + * @author Vaadin Ltd + */ +public class GridLayoutDetailsRow extends SimpleGridUI { + + @Override + protected void setup(VaadinRequest request) { + final Grid<Person> grid = createGrid(); + grid.setSizeFull(); + + addComponent(grid); + + grid.setDetailsGenerator(item -> { + final GridLayout detailsLayout = new GridLayout(); + detailsLayout.setSizeFull(); + detailsLayout.setHeightUndefined(); + + final Label lbl1 = new Label("test1"); + lbl1.setId("lbl1"); + lbl1.setWidth("200px"); + detailsLayout.addComponent(lbl1); + + final Label lbl2 = new Label("test2"); + lbl2.setId("lbl2"); + detailsLayout.addComponent(lbl2); + + final Label lbl3 = new Label("test3"); + lbl3.setId("lbl3"); + detailsLayout.addComponent(lbl3); + + final Label lbl4 = new Label("test4"); + lbl4.setId("lbl4"); + detailsLayout.addComponent(lbl4); + + return detailsLayout; + }); + + grid.addItemClickListener(click -> { + final Person person = click.getItem(); + grid.setDetailsVisible(person, !grid.isDetailsVisible(person)); + }); + } + + @Override + protected String getTestDescription() { + return "GridLayout as part of Grid detail row should be correctly computed/displayed."; + } + + @Override + protected Integer getTicketNumber() { + return 18619; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridReplaceContainer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridReplaceContainer.java new file mode 100644 index 0000000000..9ea74b8136 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridReplaceContainer.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.Optional; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; + +public class GridReplaceContainer extends SimpleGridUI { + + @Override + protected void setup(VaadinRequest request) { + final Grid<Person> grid = createGrid(); + + grid.setSelectionMode(SelectionMode.SINGLE); + + grid.addSelectionListener(event -> { + Optional<Person> selected = event.getFirstSelectedItem(); + if (selected.isPresent()) { + log("Now selected: " + selected.get().getAge()); + } else { + log("Now selected: null"); + } + }); + + addComponent(grid); + Button b = new Button("Re-set data source", + event -> grid.setItems(createPersons())); + addComponent(b); + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/SimpleGridUI.java b/uitest/src/main/java/com/vaadin/tests/components/grid/SimpleGridUI.java new file mode 100644 index 0000000000..68e539dbb8 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/SimpleGridUI.java @@ -0,0 +1,62 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Grid; +import com.vaadin.ui.renderers.NumberRenderer; + +/** + * @author Vaadin Ltd + * + */ +public abstract class SimpleGridUI extends AbstractTestUIWithLog { + + protected Grid<Person> createGrid() { + Grid<Person> grid = new Grid<>(); + + grid.addColumn(Person::getFirstName); + grid.addColumn(Person::getAge, new NumberRenderer()); + + grid.setItems(createPersons()); + return grid; + } + + protected List<Person> createPersons() { + List<Person> persons = new ArrayList<>(); + Person person = new Person(); + person.setFirstName("Nicolaus Copernicus"); + person.setAge(1543); + persons.add(person); + + person = new Person(); + person.setFirstName("Galileo Galilei"); + person.setAge(1564); + persons.add(person); + + person = new Person(); + person.setFirstName("Johannes Kepler"); + person.setAge(1571); + persons.add(person); + + return persons; + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInGridLayout.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInGridLayout.java deleted file mode 100644 index c980d060de..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInGridLayout.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.ui.Grid; - -public class GridInGridLayout extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - final VerticalLayout layout = new VerticalLayout(); - final CssLayout cssLayout = new CssLayout(); - cssLayout.setWidth("100%"); - layout.setHeight("320px"); - layout.setMargin(true); - addComponent(cssLayout); - cssLayout.addComponent(layout); - - final Grid grid = new Grid(); - grid.setSizeFull(); - for (int i = 0; i < 20; i++) { - Grid.Column column = grid.addColumn("" + i); - column.setHidable(true); - column.setEditable(true); - } - grid.setEditorEnabled(true); - grid.setColumnReorderingAllowed(true); - for (int i = 0; i < 300; i++) { - grid.addRow("Foo", "Bar", "far", "bar", "bar", "Foo", "Bar", "Bar", - "bar", "bar", "Foo", "Bar", "Bar", "bar", "bar", "Foo", - "Bar", "Bar", "bar", "bar"); - - } - layout.addComponent(grid); - grid.setHeight("300px"); - grid.setWidth("400px"); - } - - @Override - protected Integer getTicketNumber() { - return 18698; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInTabSheet.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInTabSheet.java deleted file mode 100644 index 557596d10b..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInTabSheet.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Label; -import com.vaadin.ui.TabSheet; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.CellReference; -import com.vaadin.v7.ui.Grid.CellStyleGenerator; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridInTabSheet extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - TabSheet sheet = new TabSheet(); - final Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.MULTI); - grid.addColumn("count", Integer.class); - for (Integer i = 0; i < 3; ++i) { - grid.addRow(i); - } - - sheet.addTab(grid, "Grid"); - sheet.addTab(new Label("Hidden"), "Label"); - - addComponent(sheet); - addComponent(new Button("Add row to Grid", new Button.ClickListener() { - - private Integer k = 0; - - @Override - public void buttonClick(ClickEvent event) { - grid.addRow(100 + (k++)); - } - })); - addComponent( - new Button("Remove row from Grid", new Button.ClickListener() { - - private Integer k = 0; - - @Override - public void buttonClick(ClickEvent event) { - Object firstItemId = grid.getContainerDataSource() - .firstItemId(); - if (firstItemId != null) { - grid.getContainerDataSource() - .removeItem(firstItemId); - } - } - })); - addComponent(new Button("Add CellStyleGenerator", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.setCellStyleGenerator(new CellStyleGenerator() { - @Override - public String getStyle( - CellReference cellReference) { - int rowIndex = ((Integer) cellReference - .getItemId()).intValue(); - Object propertyId = cellReference - .getPropertyId(); - if (rowIndex % 4 == 1) { - return null; - } else if (rowIndex % 4 == 3 - && "Column 1".equals(propertyId)) { - return null; - } - return propertyId.toString().replace(' ', '_'); - } - }); - } - })); - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInWindowResize.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInWindowResize.java deleted file mode 100644 index 8c8c782866..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInWindowResize.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; - -public class GridInWindowResize extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid g = new Grid(); - IndexedContainer cont = new IndexedContainer(); - for (int j = 0; j < 3; j++) { - cont.addContainerProperty("" + j, String.class, ""); - } - - for (int k = 0; k < 100; k++) { - Item addItem = cont.addItem(k); - for (int j = 0; j < 3; j++) { - addItem.getItemProperty("" + j).setValue(1 + ""); - } - } - g.setContainerDataSource(cont); - g.setSizeFull(); - - VerticalLayout vl = new VerticalLayout(g); - vl.setSizeFull(); - Button resize = new Button("resize"); - VerticalLayout vl2 = new VerticalLayout(vl, resize); - vl2.setSizeFull(); - - final Window w = new Window(null, vl2); - addWindow(w); - - w.center(); - w.setModal(true); - w.setWidth("600px"); - w.setHeight("400px"); - - resize.addClickListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - w.setWidth("400px"); - } - }); - - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumns.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumns.java deleted file mode 100644 index 6901dbd1d8..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumns.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.fieldgroup.ComplexPerson; -import com.vaadin.v7.ui.Grid; - -public class GridInitiallyHiddenColumns extends AbstractTestUIWithLog { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.setContainerDataSource(ComplexPerson.createContainer(100)); - grid.setColumns("firstName", "lastName", "age"); - grid.getColumn("firstName").setHidden(true).setHidable(true); - grid.getColumn("lastName").setHidable(true); - grid.getColumn("age").setHidden(true).setHidable(true); - - addComponent(grid); - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridItemSetChange.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridItemSetChange.java deleted file mode 100644 index 3eb7123ce5..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridItemSetChange.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.tests.util.Person; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.ui.Grid; - -public class GridItemSetChange extends AbstractReindeerTestUI { - - public static class SneakyBeanContainer extends BeanItemContainer<Person> { - - private Person p = new Person("Foo", "Bar", "", "", "", 0, ""); - - public SneakyBeanContainer() throws IllegalArgumentException { - super(Person.class); - addItem(p); - } - - public void reset() { - internalRemoveAllItems(); - p.setLastName("Baz"); - internalAddItemAtEnd(p, createBeanItem(p), false); - fireItemSetChange(); - } - } - - @Override - protected void setup(VaadinRequest request) { - final SneakyBeanContainer c = new SneakyBeanContainer(); - Grid g = new Grid(c); - g.setColumns("firstName", "lastName"); - addComponent(g); - addComponent(new Button("Reset", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - c.reset(); - } - })); - addComponent(new Button("Modify", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - c.getItem(c.firstItemId()).getItemProperty("lastName") - .setValue("Spam"); - } - })); - } - -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRow.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRow.java deleted file mode 100644 index 877143b502..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRow.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.Component; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.Label; -import com.vaadin.v7.event.ItemClickEvent; -import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.DetailsGenerator; -import com.vaadin.v7.ui.Grid.RowReference; - -/** - * Tests that details row displays GridLayout contents properly. - * - * @author Vaadin Ltd - */ -public class GridLayoutDetailsRow extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.setSizeFull(); - grid.addColumn("name", String.class); - grid.addColumn("born", Integer.class); - - grid.addRow("Nicolaus Copernicus", 1543); - grid.addRow("Galileo Galilei", 1564); - grid.addRow("Johannes Kepler", 1571); - - addComponent(grid); - - grid.setDetailsGenerator(new DetailsGenerator() { - @Override - public Component getDetails(final RowReference rowReference) { - final GridLayout detailsLayout = new GridLayout(); - detailsLayout.setSizeFull(); - detailsLayout.setHeightUndefined(); - - final Label lbl1 = new Label("test1"); - lbl1.setId("lbl1"); - lbl1.setWidth("200px"); - detailsLayout.addComponent(lbl1); - - final Label lbl2 = new Label("test2"); - lbl2.setId("lbl2"); - detailsLayout.addComponent(lbl2); - - final Label lbl3 = new Label("test3"); - lbl3.setId("lbl3"); - detailsLayout.addComponent(lbl3); - - final Label lbl4 = new Label("test4"); - lbl4.setId("lbl4"); - detailsLayout.addComponent(lbl4); - - return detailsLayout; - } - }); - - grid.addItemClickListener(new ItemClickListener() { - @Override - public void itemClick(final ItemClickEvent event) { - final Object itemId = event.getItemId(); - grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); - } - }); - } - - @Override - protected String getTestDescription() { - return "GridLayout as part of Grid detail row should be correctly computed/displayed."; - } - - @Override - protected Integer getTicketNumber() { - return 18619; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridMissingProperty.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridMissingProperty.java deleted file mode 100644 index 99b2a53aad..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridMissingProperty.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.vaadin.v7.tests.components.grid; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.data.Property; -import com.vaadin.v7.data.util.AbstractInMemoryContainer; -import com.vaadin.v7.data.util.BeanItem; -import com.vaadin.v7.ui.Grid; - -public class GridMissingProperty extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - - final Folder folder = new Folder("Folder name"); - final BeanItem<Entry> folderItem = new BeanItem<>(folder); - - final File file = new File("File name", "10kB"); - final BeanItem<Entry> fileItem = new BeanItem<>(file); - - @SuppressWarnings("unchecked") - TestContainer container = new TestContainer( - Arrays.asList(folderItem, fileItem), - Arrays.asList("name", "size")); - - grid.setContainerDataSource(container); - grid.setSelectionMode(Grid.SelectionMode.SINGLE); - grid.setEditorEnabled(true); - - addComponent(grid); - } - - @Override - protected String getTestDescription() { - return "Grid Editor should not throw exception even when items are missing properties."; - } - - private class TestContainer - extends AbstractInMemoryContainer<Object, String, BeanItem> { - - private final List<BeanItem<Entry>> items; - private final List<String> pids; - - public TestContainer(List<BeanItem<Entry>> items, List<String> pids) { - this.items = items; - this.pids = pids; - } - - @Override - protected List<Object> getAllItemIds() { - List<Object> ids = new ArrayList<>(); - for (BeanItem<Entry> item : items) { - ids.add(item.getBean()); - } - return ids; - } - - @Override - protected BeanItem<Entry> getUnfilteredItem(Object itemId) { - for (BeanItem<Entry> item : items) { - if (item.getBean().equals(itemId)) { - return item; - } - } - return null; - } - - @Override - public Collection<?> getContainerPropertyIds() { - return pids; - } - - @Override - public Property getContainerProperty(Object itemId, Object propertyId) { - return getItem(itemId).getItemProperty(propertyId); - } - - @Override - public Class<?> getType(Object propertyId) { - return String.class; - } - } - - public class Entry { - private String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Entry(String name) { - this.name = name; - } - } - - public class Folder extends Entry { - - public Folder(String name) { - super(name); - } - } - - public class File extends Entry { - private String size; - - public File(String name, String size) { - super(name); - this.size = size; - } - - public String getSize() { - return size; - } - - public void setSize(String size) { - this.size = size; - } - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridRendererChange.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridRendererChange.java deleted file mode 100644 index eef549f07a..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridRendererChange.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.renderers.ButtonRenderer; -import com.vaadin.v7.ui.renderers.HtmlRenderer; -import com.vaadin.v7.ui.renderers.TextRenderer; - -public class GridRendererChange extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - - final Grid grid = new Grid(); - grid.setColumns("num", "foo"); - grid.getColumn("num").setRenderer(new ButtonRenderer()); - - for (int i = 0; i < 1000; i++) { - grid.addRow(String.format("<b>line %d</b>", i), "" + i); - } - - Button button = new Button("Set ButtonRenderer", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.getColumn("num").setRenderer(new ButtonRenderer()); - } - }); - - Button buttonHtml = new Button("Set HTMLRenderer", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.getColumn("num").setRenderer(new HtmlRenderer()); - } - }); - - Button buttonText = new Button("Set TextRenderer", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.getColumn("num").setRenderer(new TextRenderer()); - } - }); - - addComponent(new HorizontalLayout(button, buttonHtml, buttonText)); - addComponent(grid); - } -}
\ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReplaceContainer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReplaceContainer.java deleted file mode 100644 index 61b366c66b..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReplaceContainer.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.v7.data.Container.Indexed; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.event.SelectionEvent; -import com.vaadin.v7.event.SelectionEvent.SelectionListener; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridReplaceContainer extends AbstractTestUIWithLog { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.SINGLE); - grid.setContainerDataSource(createContainer()); - grid.addSelectionListener(new SelectionListener() { - - @Override - public void select(SelectionEvent event) { - Bean selected = (Bean) grid.getSelectedRow(); - if (selected != null) { - log("Now selected: " + selected.getData()); - } else { - log("Now selected: null"); - } - - } - }); - addComponent(grid); - Button b = new Button("Re-set data source", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.setContainerDataSource(createContainer()); - } - }); - addComponent(b); - } - - public static class Bean { - private int id; - private String data; - - public Bean(int id, String data) { - this.id = id; - this.data = data; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - } - - private Indexed createContainer() { - BeanItemContainer<Bean> bic = new BeanItemContainer<>(Bean.class); - bic.addBean(new Bean(1, "First item")); - bic.addBean(new Bean(2, "Second item")); - bic.addBean(new Bean(3, "Third item")); - return bic; - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeightTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeightTest.java new file mode 100644 index 0000000000..6571d92f11 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeightTest.java @@ -0,0 +1,180 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.number.IsCloseTo.closeTo; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.RadioButtonGroupElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests that Grid gets correct height based on height mode, and resizes + * properly with details row if height is undefined. + * + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridHeightTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + waitForElementPresent(By.className("v-grid")); + } + + @Test + @Ignore + public void testGridHeightAndResizingUndefined() + throws InterruptedException { + assertNoErrors(testGridHeightAndResizing(GridHeight.UNDEFINED)); + } + + @Test + @Ignore + public void testGridHeightAndResizingRow() throws InterruptedException { + assertNoErrors(testGridHeightAndResizing(GridHeight.ROW3)); + } + + @Test + public void testGridHeightAndResizingFull() throws InterruptedException { + assertNoErrors(testGridHeightAndResizing(GridHeight.FULL)); + } + + private Map<AssertionError, Object[]> testGridHeightAndResizing( + Object gridHeight) throws InterruptedException { + Map<AssertionError, Object[]> errors = new HashMap<>(); + String caption; + if (GridHeight.ROW3.equals(gridHeight)) { + caption = gridHeight + " rows"; + } else { + caption = (String) gridHeight; + } + $(RadioButtonGroupElement.class).id("gridHeightSelector") + .selectByText(caption); + for (String gridWidth : GridHeight.gridWidths) { + $(RadioButtonGroupElement.class).id("gridWidthSelector") + .selectByText(gridWidth); + for (String detailsRowHeight : GridHeight.detailsRowHeights) { + $(RadioButtonGroupElement.class).id("detailsHeightSelector") + .selectByText(detailsRowHeight); + sleep(500); + + GridElement grid = $(GridElement.class).first(); + int initialHeight = grid.getSize().getHeight(); + try { + // check default height + assertGridHeight(getExpectedInitialHeight(gridHeight), + initialHeight); + } catch (AssertionError e) { + errors.put(e, new Object[] { gridHeight, gridWidth, + detailsRowHeight, "initial" }); + Assert.fail(); + } + + grid.getRow(2).click(5, 5); + waitForElementPresent(By.id("lbl1")); + + int openHeight = grid.getSize().getHeight(); + try { + // check height with details row opened + assertGridHeight(getExpectedOpenedHeight(gridHeight, + detailsRowHeight), openHeight); + } catch (AssertionError e) { + errors.put(e, new Object[] { gridHeight, gridWidth, + detailsRowHeight, "opened" }); + } + + grid.getRow(2).click(5, 5); + waitForElementNotPresent(By.id("lbl1")); + + int afterHeight = grid.getSize().getHeight(); + try { + // check height with details row closed again + assertThat("Unexpected Grid Height", afterHeight, + is(initialHeight)); + } catch (AssertionError e) { + errors.put(e, new Object[] { gridHeight, gridWidth, + detailsRowHeight, "closed" }); + } + } + } + return errors; + } + + private void assertNoErrors(Map<AssertionError, Object[]> errors) { + if (!errors.isEmpty()) { + StringBuilder sb = new StringBuilder("Exceptions: "); + for (Entry<AssertionError, Object[]> entry : errors.entrySet()) { + sb.append("\n"); + for (Object value : entry.getValue()) { + sb.append(value); + sb.append(" - "); + } + sb.append(entry.getKey().getMessage()); + } + Assert.fail(sb.toString()); + } + } + + private int getExpectedInitialHeight(Object gridHeight) { + int result = 0; + if (GridHeight.UNDEFINED.equals(gridHeight) + || GridHeight.ROW3.equals(gridHeight)) { + result = 81; + } else if (GridHeight.FULL.equals(gridHeight)) { + // pre-existing issue + result = 400; + } + return result; + } + + private int getExpectedOpenedHeight(Object gridHeight, + Object detailsRowHeight) { + int result = 0; + if (GridHeight.UNDEFINED.equals(gridHeight)) { + if (GridHeight.PX100.equals(detailsRowHeight)) { + result = 182; + } else if (GridHeight.FULL.equals(detailsRowHeight)) { + result = 131; + } else if (GridHeight.UNDEFINED.equals(detailsRowHeight)) { + result = 100; + } + } else if (GridHeight.ROW3.equals(gridHeight) + || GridHeight.FULL.equals(gridHeight)) { + result = getExpectedInitialHeight(gridHeight); + } + return result; + } + + private void assertGridHeight(int expected, int actual) { + assertThat("Unexpected Grid Height", (double) actual, + closeTo(expected, 1)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInTabSheetTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInTabSheetTest.java index d84de08f78..56437a9a70 100644 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInTabSheetTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInTabSheetTest.java @@ -13,15 +13,15 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.v7.tests.components.grid; +package com.vaadin.tests.components.grid; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import org.junit.Test; -import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.elements.NotificationElement; import com.vaadin.testbench.elements.TabSheetElement; import com.vaadin.testbench.parallel.TestCategory; diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInWindowResizeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInWindowResizeTest.java index 57c77df8de..f371d949e3 100644 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInWindowResizeTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInWindowResizeTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.v7.tests.components.grid; +package com.vaadin.tests.components.grid; import java.util.Collections; import java.util.List; @@ -22,8 +22,8 @@ import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.remote.DesiredCapabilities; -import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.parallel.Browser; import com.vaadin.tests.tb3.MultiBrowserTest; diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumnsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java index 857c29dab5..017ef14e2b 100644 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumnsTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.v7.tests.components.grid; +package com.vaadin.tests.components.grid; import java.util.List; @@ -34,7 +34,7 @@ public class GridInitiallyHiddenColumnsTest extends SingleBrowserTest { openTestURL("debug"); GridElement grid = $(GridElement.class).first(); Assert.assertEquals("Rowling", grid.getCell(0, 0).getText()); - Assert.assertEquals("Scott", grid.getCell(1, 0).getText()); + Assert.assertEquals("Barks", grid.getCell(1, 0).getText()); getSidebarOpenButton(grid).click(); getColumnHidingToggle(grid, "First Name").click(); @@ -43,10 +43,10 @@ public class GridInitiallyHiddenColumnsTest extends SingleBrowserTest { Assert.assertEquals("Umberto", grid.getCell(0, 0).getText()); Assert.assertEquals("Rowling", grid.getCell(0, 1).getText()); - Assert.assertEquals("25", grid.getCell(0, 2).getText()); - Assert.assertEquals("Dan", grid.getCell(1, 0).getText()); - Assert.assertEquals("Scott", grid.getCell(1, 1).getText()); - Assert.assertEquals("54", grid.getCell(1, 2).getText()); + Assert.assertEquals("40", grid.getCell(0, 2).getText()); + Assert.assertEquals("Alex", grid.getCell(1, 0).getText()); + Assert.assertEquals("Barks", grid.getCell(1, 1).getText()); + Assert.assertEquals("25", grid.getCell(1, 2).getText()); } diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridItemSetChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridItemSetChangeTest.java index e07381403c..0e3175315e 100644 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridItemSetChangeTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridItemSetChangeTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.v7.tests.components.grid; +package com.vaadin.tests.components.grid; import static org.junit.Assert.assertEquals; diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRowTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridLayoutDetailsRowTest.java index 6c9b5a7907..0754f2b8ad 100644 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRowTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridLayoutDetailsRowTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.v7.tests.components.grid; +package com.vaadin.tests.components.grid; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.number.IsCloseTo.closeTo; diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridReplaceContainerTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridReplaceContainerTest.java index 2184d8ce2f..6e1536c6a2 100644 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridReplaceContainerTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridReplaceContainerTest.java @@ -13,13 +13,13 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.v7.tests.components.grid; +package com.vaadin.tests.components.grid; import org.junit.Assert; import org.junit.Test; -import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; import com.vaadin.tests.tb3.SingleBrowserTest; public class GridReplaceContainerTest extends SingleBrowserTest { diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridMissingPropertyTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridMissingPropertyTest.java deleted file mode 100644 index 9de41cc1a7..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridMissingPropertyTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.vaadin.v7.tests.components.grid; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement; -import com.vaadin.testbench.elements.GridElement.GridEditorElement; -import com.vaadin.testbench.elements.TextFieldElement; -import com.vaadin.tests.tb3.SingleBrowserTest; - -public class GridMissingPropertyTest extends SingleBrowserTest { - - @Test - public void testCellEditable() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - // Row with missing property - grid.getCell(0, 0).doubleClick(); - GridEditorElement editor = grid.getEditor(); - - assertTrue("Cell with property should be editable", - editor.isEditable(0)); - assertFalse("Cell without property should not be editable", - editor.isEditable(1)); - - editor.cancel(); - - // Row with all properties - grid.getCell(1, 0).doubleClick(); - editor = grid.getEditor(); - - assertTrue("Cell with property should be editable", - editor.isEditable(0)); - assertTrue("Cell with property should be editable", - editor.isEditable(1)); - - editor.cancel(); - } - - @Test - public void testEditCell() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - GridEditorElement editor; - TextFieldElement editorField; - - grid.getCell(0, 0).doubleClick(); - editor = grid.getEditor(); - editorField = editor.getField(0).wrap(TextFieldElement.class); - editorField.setValue("New Folder Name"); - editor.save(); - assertEquals("New Folder Name", grid.getCell(0, 0).getText()); - - grid.getCell(1, 0).doubleClick(); - editor = grid.getEditor(); - editorField = editor.getField(1).wrap(TextFieldElement.class); - editorField.setValue("10 MB"); - editor.save(); - assertEquals("10 MB", grid.getCell(1, 1).getText()); - - grid.getCell(1, 0).doubleClick(); - editor = grid.getEditor(); - editorField = editor.getField(0).wrap(TextFieldElement.class); - editorField.setValue("New File Name"); - editor.save(); - assertEquals("New File Name", grid.getCell(1, 0).getText()); - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridRendererChangeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridRendererChangeTest.java deleted file mode 100644 index a8c3f97c86..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridRendererChangeTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Collections; -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.elements.GridElement; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.tb3.MultiBrowserTest; - -public class GridRendererChangeTest extends MultiBrowserTest { - - @Test - public void testChangeRenderer() { - setDebug(true); - openTestURL(); - - GridCellElement cell = $(GridElement.class).first().getCell(0, 0); - assertTrue("No button in the first cell.", - cell.isElementPresent(By.tagName("button"))); - int width = cell.getSize().getWidth(); - - List<ButtonElement> buttons = $(ButtonElement.class).all(); - Collections.reverse(buttons); - - // Order: TextRenderer, HTMLRenderer, ButtonRenderer - for (ButtonElement button : buttons) { - button.click(); - assertNoErrorNotifications(); - cell = $(GridElement.class).first().getCell(0, 0); - assertEquals("Cell size changed", width, cell.getSize().getWidth()); - } - - assertTrue("No button in the first cell.", - cell.isElementPresent(By.tagName("button"))); - } - -} |