From: Anna Koskinen Date: Fri, 11 Jan 2013 11:45:32 +0000 (+0200) Subject: Merge of (#8519) to Vaadin 7. X-Git-Tag: 7.0.0.rc1~29^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5b81a29acc9909d45c2299541228992aeb19813c;p=vaadin-framework.git Merge of (#8519) to Vaadin 7. Table does not refresh after selecting more rows than pagination size. Change-Id: I352e15f9e124d13b0171b6bb1b8b287f52a056bc --- diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index a8cee55375..f14c86aa36 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -325,8 +325,10 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // create range of second part unless its length is < 1 VScrollTableRow startOfRange = scrollBody .getRowByRowIndex(startOfSecondRange); - ranges.add(new SelectionRange(startOfRange, getEndIndex() - - startOfSecondRange + 1)); + if (startOfRange != null) { + ranges.add(new SelectionRange(startOfRange, getEndIndex() + - startOfSecondRange + 1)); + } } return ranges; } diff --git a/uitest/src/com/vaadin/tests/components/table/LargeSelectionCausesNPE.html b/uitest/src/com/vaadin/tests/components/table/LargeSelectionCausesNPE.html new file mode 100644 index 0000000000..8ee0bad9ec --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/LargeSelectionCausesNPE.html @@ -0,0 +1,72 @@ + + + + + + +LargeSelectionCausesNPE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LargeSelectionCausesNPE
open/run/com.vaadin.tests.components.table.LargeSelectionCausesNPE?restartApplication
mouseClick8519-292,9
scrollvaadin=runcomvaadintestscomponentstableLargeSelectionCausesNPE::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]5257
waitForElementPresent8519-262
mouseClick8519-26261,-5248:shift
scrollvaadin=runcomvaadintestscomponentstableLargeSelectionCausesNPE::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]0
waitForElementPresent8519-0
mouseClick8519-button23,10
assertText8519-00-version2
mouseClick8519-button
assertText8519-00
+ + diff --git a/uitest/src/com/vaadin/tests/components/table/LargeSelectionCausesNPE.java b/uitest/src/com/vaadin/tests/components/table/LargeSelectionCausesNPE.java new file mode 100644 index 0000000000..fb782b8ded --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/LargeSelectionCausesNPE.java @@ -0,0 +1,166 @@ +package com.vaadin.tests.components.table; + +import java.util.HashSet; +import java.util.Set; + +import com.vaadin.annotations.AutoGenerated; +import com.vaadin.data.Item; +import com.vaadin.data.Property; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.shared.ui.MarginInfo; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; +import com.vaadin.ui.Table; +import com.vaadin.ui.Table.Align; +import com.vaadin.ui.Table.ColumnGenerator; +import com.vaadin.ui.VerticalLayout; + +public class LargeSelectionCausesNPE extends TestBase { + + @AutoGenerated + private Table table; + + private static final String ID = "id"; + private static final String NAME = "name"; + private static final String CODE = "code"; + + @Override + protected void setup() { + addComponent(new SelectionExample()); + } + + @Override + protected String getDescription() { + return "Attempting to update table contents while selection reaches beyond cache limits causes a NPE.
" + + " Select a large amount of rows, e.g. from name2 to name262, return to the top of the table," + + " then try to update the first item twice.
" + + " Test is broken if the original values don't reappear on the second click of the button."; + } + + @Override + protected Integer getTicketNumber() { + return 8519; + } + + public class SelectionExample extends VerticalLayout { + + Table table = new Table(); + Button button = new Button("Update the first item"); + Label nameLabel = new Label(); + + HashSet markedRows = new HashSet(); + Label selected = new Label(); + + public SelectionExample() { + addComponent(table); + addComponent(button); + setMargin(new MarginInfo(true, false, false, false)); + + // Label to indicate current selection + selected.setValue("No selection"); + addComponent(selected); + + // set a style name, so we can style rows and cells + table.setStyleName("iso3166"); + + // size + table.setWidth("100%"); + table.setPageLength(5); + + // selectable + table.setSelectable(true); + table.setMultiSelect(true); + table.setImmediate(true); + + // connect data source + table.setContainerDataSource(getContainer()); + + table.addGeneratedColumn(CODE, columnGenerator); + + // turn on column reordering and collapsing + table.setColumnReorderingAllowed(true); + table.setColumnCollapsingAllowed(true); + + // set column headers + table.setVisibleColumns(new String[] { CODE, NAME, ID }); + table.setColumnHeaders(new String[] { "DummyCode", "DummyName", + "DummyId" }); + + // Column alignment + table.setColumnAlignment(ID, Align.CENTER); + + // Column width + table.setColumnWidth(CODE, 70); + table.setColumnExpandRatio(NAME, 1); + table.setColumnWidth(ID, 70); + + // listen for valueChange, a.k.a 'select' and update the label + table.addValueChangeListener(valueChangeListener); + + button.setId(getTicketNumber() + "-button"); + button.addClickListener(clickListener); + } + + Table.ValueChangeListener valueChangeListener = new Table.ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + // in multiselect mode, a Set of itemIds is returned, + // in singleselect mode the itemId is returned directly + Set value = (Set) event.getProperty().getValue(); + if (null == value || value.size() == 0) { + selected.setValue("No selection"); + } else { + selected.setValue("Selected: " + table.getValue()); + } + } + }; + + Button.ClickListener clickListener = new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + Property nameProperty = table.getContainerProperty(0, NAME); + if (("0").equals(nameLabel.getValue())) { + nameProperty.setValue(NAME + "0-version2"); + nameLabel.setValue("0-version2"); + } else { + nameProperty.setValue(NAME + 0); + nameLabel.setValue("0"); + } + } + }; + + public IndexedContainer getContainer() { + IndexedContainer container = new IndexedContainer(); + container.addContainerProperty(NAME, String.class, null); + container.addContainerProperty(ID, Integer.class, null); + for (int i = 0; i < 264; i++) { + String name = NAME + i; + int id = i; + Item item = container.addItem(id); + item.getItemProperty(NAME).setValue(name); + item.getItemProperty(ID).setValue(id); + } + container.sort(new Object[] { ID }, new boolean[] { true }); + return container; + } + + ColumnGenerator columnGenerator = new ColumnGenerator() { + + public Object generateCell(Table source, Object itemId, + Object columnId) { + Label label = new Label(); + label.setSizeUndefined(); + label.setValue(itemId.toString()); + label.setId(getTicketNumber() + "-" + itemId); + if (0 == (Integer) itemId) { + nameLabel = label; + } + return label; + } + + }; + } + +}