diff options
author | Artur Signell <artur.signell@itmill.com> | 2009-06-30 18:50:15 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2009-06-30 18:50:15 +0000 |
commit | cc8fea3db2dc2db69fd8abbf445ab73122a4c3f7 (patch) | |
tree | 7a222b59bb1403f212289b9317b2fbc5d63474fe | |
parent | 8e1be11a741a0941c4e8afcec6854e9926e19d26 (diff) | |
download | vaadin-framework-cc8fea3db2dc2db69fd8abbf445ab73122a4c3f7.tar.gz vaadin-framework-cc8fea3db2dc2db69fd8abbf445ab73122a4c3f7.zip |
Test case and fix for #1623 - Table: Client side should dynamically adjust pagelength variable
svn changeset:8273/svn branch:6.0
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java | 30 | ||||
-rw-r--r-- | src/com/vaadin/tests/components/table/TablePageLengthUpdate.java | 77 | ||||
-rw-r--r-- | src/com/vaadin/ui/Table.java | 6 |
3 files changed, 113 insertions, 0 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index 62c14a69bf..2f73f87655 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -2076,6 +2076,9 @@ public class VScrollTable extends FlowPanel implements Table, ScrollListener { } } tBodyMeasurementsDone = true; + + updatePageLength(); + return rowHeight; } } @@ -2654,6 +2657,32 @@ public class VScrollTable extends FlowPanel implements Table, ScrollListener { } + /** + * Determines the pagelength when the table height is fixed. + */ + public void updatePageLength() { + if (tBody == null) { + return; + } + + if (height == null || height.equals("")) { + return; + } + + int rowHeight = tBody.getRowHeight(); + int bodyH = bodyContainer.getOffsetHeight(); + int rowsAtOnce = bodyH / rowHeight; + boolean anotherPartlyVisible = ((bodyH % rowHeight) != 0); + if (anotherPartlyVisible) { + rowsAtOnce++; + } + + pageLength = rowsAtOnce; + + client.updateVariable(paintableId, "pagelength", pageLength, false); + + } + @Override public void setWidth(String width) { if (this.width.equals(width)) { @@ -2818,6 +2847,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollListener { this.height = height; super.setHeight(height); setContainerHeight(); + updatePageLength(); } /* diff --git a/src/com/vaadin/tests/components/table/TablePageLengthUpdate.java b/src/com/vaadin/tests/components/table/TablePageLengthUpdate.java new file mode 100644 index 0000000000..2f856db269 --- /dev/null +++ b/src/com/vaadin/tests/components/table/TablePageLengthUpdate.java @@ -0,0 +1,77 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.data.util.MethodProperty; +import com.vaadin.terminal.Sizeable; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextField; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; + +public class TablePageLengthUpdate extends TestBase { + + private Label pageLengthLabel; + private Table table; + + @Override + protected String getDescription() { + return "When the height is set for a table, the pagelength should be updated according to what is actually displayed. The table pagelength is initially 100 and the height is 100px. After clicking update the pageLength label should display the correct value (?)."; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void setup() { + table = new Table(); + table.setWidth("400px"); + table.setHeight("100px"); + table.setPageLength(100); + table.addContainerProperty("p1", String.class, null); + table.addContainerProperty("p2", String.class, null); + table.addContainerProperty("p3", String.class, null); + + for (int i = 0; i < 10; i++) { + table.addItem(new Object[] { "a" + i, "b" + i, "c" + i }, "" + i); + } + + addComponent(table); + + pageLengthLabel = new Label(""); + updatePageLengthLabel(); + addComponent(pageLengthLabel); + + Button updateButton = new Button("Update pageLength", + new ClickListener() { + + public void buttonClick(ClickEvent event) { + updatePageLengthLabel(); + } + }); + addComponent(updateButton); + + TextField tableHeight = new TextField("Table height", + new MethodProperty(this, "tableHeight")); + tableHeight.setImmediate(true); + addComponent(tableHeight); + } + + public String getTableHeight() { + return "" + (int) table.getHeight() + + Sizeable.UNIT_SYMBOLS[table.getHeightUnits()]; + } + + public void setTableHeight(String height) { + table.setHeight(height); + } + + protected void updatePageLengthLabel() { + pageLengthLabel.setValue("Pagelength: " + table.getPageLength()); + } + +} diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 0cce132666..c3d0e66809 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -1752,6 +1752,12 @@ public class Table extends AbstractSelect implements Action.Container, super.changeVariables(source, variables); + // Client might update the pagelength if Table height is fixed + if (variables.containsKey("pagelength")) { + // Sets pageLength directly to avoid repaint that setter causes + pageLength = (Integer) variables.get("pagelength"); + } + // Page start index if (variables.containsKey("firstvisible")) { final Integer value = (Integer) variables.get("firstvisible"); |