Browse Source

Test case and fix for #1623 - Table: Client side should dynamically adjust pagelength variable

svn changeset:8273/svn branch:6.0
tags/6.7.0.beta1
Artur Signell 15 years ago
parent
commit
cc8fea3db2

+ 30
- 0
src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java View File

@@ -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();
}

/*

+ 77
- 0
src/com/vaadin/tests/components/table/TablePageLengthUpdate.java View File

@@ -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());
}

}

+ 6
- 0
src/com/vaadin/ui/Table.java View File

@@ -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");

Loading…
Cancel
Save