aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2008-09-11 12:44:33 +0000
committerMarc Englund <marc.englund@itmill.com>2008-09-11 12:44:33 +0000
commit0bd4eba37b1bcceff7fb28eff9771811ed6a4199 (patch)
tree94570e528758e23819e7307bb20c278569300baa
parentd5b6cabba7eaa595429b19e13e3cb233b87500fe (diff)
downloadvaadin-framework-0bd4eba37b1bcceff7fb28eff9771811ed6a4199.tar.gz
vaadin-framework-0bd4eba37b1bcceff7fb28eff9771811ed6a4199.zip
Force-table-to-recalculate-column-widths feature. Fixes #1983 (see ticket for more)
svn changeset:5389/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java26
-rw-r--r--src/com/itmill/toolkit/tests/tickets/Ticket1983.java57
-rw-r--r--src/com/itmill/toolkit/ui/Table.java13
3 files changed, 88 insertions, 8 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
index 0d576af198..4b9e6051af 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
@@ -131,6 +131,13 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
private int oldAvailPixels;
private boolean emitClickEvents;
+ /*
+ * Read from the "recalcWidths" -attribute. When it is true, the table will
+ * recalculate the widths for columns - desirable in some cases. For #1983,
+ * marked experimental.
+ */
+ boolean recalcWidths = false;
+
public IScrollTable() {
bodyContainer.addScrollListener(this);
@@ -170,6 +177,8 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
totalRows = newTotalRows;
}
+ recalcWidths = uidl.hasAttribute("recalcWidths");
+
pageLength = uidl.getIntAttribute("pagelength");
if (pageLength == 0) {
pageLength = totalRows;
@@ -245,7 +254,7 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
}
updateHeader(uidl.getStringArrayAttribute("vcolorder"));
- if (initializedAndAttached) {
+ if (!recalcWidths && initializedAndAttached) {
updateBody(rowData, uidl.getIntAttribute("firstrow"), uidl
.getIntAttribute("rows"));
} else {
@@ -973,10 +982,15 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
DOM.setStyleAttribute(captionContainer, "overflow", "");
}
width = w;
- DOM.setStyleAttribute(captionContainer, "width", (w
- - DRAG_WIDGET_WIDTH - 4)
- + "px");
- setWidth(w + "px");
+ if (w == -1) {
+ DOM.setStyleAttribute(captionContainer, "width", "");
+ setWidth("");
+ } else {
+ DOM.setStyleAttribute(captionContainer, "width", (w
+ - DRAG_WIDGET_WIDTH - 4)
+ + "px");
+ setWidth(w + "px");
+ }
}
public int getWidth() {
@@ -1323,6 +1337,8 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
if (col.hasAttribute("width")) {
final String width = col.getStringAttribute("width");
c.setWidth(Integer.parseInt(width));
+ } else if (recalcWidths) {
+ c.setWidth(-1);
}
}
// check for orphaned header cells
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1983.java b/src/com/itmill/toolkit/tests/tickets/Ticket1983.java
index 0948cb89c2..f8fafedbfd 100644
--- a/src/com/itmill/toolkit/tests/tickets/Ticket1983.java
+++ b/src/com/itmill/toolkit/tests/tickets/Ticket1983.java
@@ -9,6 +9,7 @@ import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.SplitPanel;
import com.itmill.toolkit.ui.Table;
import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Button.ClickEvent;
/**
* Test class for ticket 1983
@@ -23,6 +24,9 @@ public class Ticket1983 extends Application {
private static class TestLayout extends SplitPanel {
boolean isLong = true;
+ final Table table = new MyTable();
+ final String propId = "col";
+ final String propId2 = "col2";
public TestLayout() {
super(ORIENTATION_HORIZONTAL);
@@ -44,13 +48,26 @@ public class Ticket1983 extends Application {
leftSide.setHeight("100%");
final IndexedContainer dataSource = new IndexedContainer();
- final String propId = "col";
dataSource.addContainerProperty(propId, String.class, null);
+ dataSource.addContainerProperty(propId2, String.class, null);
final Object itemId = dataSource.addItem();
dataSource.getItem(itemId).getItemProperty(propId).setValue(
"Very long value that makes a scrollbar appear for sure");
+ dataSource.getItem(itemId).getItemProperty(propId2).setValue(
+ "Very long value that makes a scrollbar appear for sure");
+
+ for (int i = 0; i < 150; i++) {
+ Object id = dataSource.addItem();
+ dataSource
+ .getItem(id)
+ .getItemProperty(propId)
+ .setValue(
+ (i == 100 ? "Very long value that makes a scrollbar appear for sure"
+ : "Short"));
+ dataSource.getItem(id).getItemProperty(propId2).setValue(
+ "Short");
+ }
- final Table table = new Table();
table.setSizeFull();
table.setContainerDataSource(dataSource);
table.setVisibleColumns(new Object[] { propId });
@@ -65,6 +82,8 @@ public class Ticket1983 extends Application {
if (isLong) {
dataSource.getItem(itemId).getItemProperty(propId)
.setValue("Short value");
+ dataSource.getItem(itemId).getItemProperty(propId2)
+ .setValue("Short value");
isLong = false;
} else {
dataSource
@@ -72,15 +91,47 @@ public class Ticket1983 extends Application {
.getItemProperty(propId)
.setValue(
"Very long value that makes a scrollbar appear for sure");
+ dataSource
+ .getItem(itemId)
+ .getItemProperty(propId2)
+ .setValue(
+ "Very long value that makes a scrollbar appear for sure");
isLong = true;
}
// Works the same way with or without repaint request
table.requestRepaint();
}
});
- leftSide.setFirstComponent(button);
+
+ OrderedLayout ol = new OrderedLayout();
+ ol.addComponent(button);
+ leftSide.setFirstComponent(ol);
+
+ button = new Button("Two col");
+ button.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ Button b = event.getButton();
+ if (((Boolean) b.getValue()).booleanValue()) {
+ table
+ .setVisibleColumns(new Object[] { propId,
+ propId2 });
+ } else {
+ table.setVisibleColumns(new Object[] { propId });
+ }
+
+ }
+
+ });
+ button.setSwitchMode(true);
+ ol.addComponent(button);
return leftSide;
}
}
+
+ static class MyTable extends Table {
+ MyTable() {
+ alwaysRecalculateColumnWidths = true;
+ }
+ }
}
diff --git a/src/com/itmill/toolkit/ui/Table.java b/src/com/itmill/toolkit/ui/Table.java
index 0d22f641ad..d9421395f5 100644
--- a/src/com/itmill/toolkit/ui/Table.java
+++ b/src/com/itmill/toolkit/ui/Table.java
@@ -312,6 +312,12 @@ public class Table extends AbstractSelect implements Action.Container,
private int clickListenerCount;
+ /*
+ * EXPERIMENTAL feature: will tell the client to re-calculate column widths
+ * if set to true. Currently no setter: extend to enable.
+ */
+ protected boolean alwaysRecalculateColumnWidths = false;
+
/* Table constructors */
/**
@@ -1795,6 +1801,13 @@ public class Table extends AbstractSelect implements Action.Container,
rows = reqRowsToPaint;
} else {
rows = cells[0].length;
+ if (alwaysRecalculateColumnWidths) {
+ // TODO experimental feature for now: tell the client to
+ // recalculate column widths.
+ // We'll only do this for paints that do not originate from
+ // table scroll/cache requests (i.e when reqRowsToPaint<0)
+ target.addAttribute("recalcWidths", true);
+ }
}
if (!isNullSelectionAllowed() && getNullSelectionItemId() != null