aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2008-12-19 12:15:03 +0000
committerArtur Signell <artur.signell@itmill.com>2008-12-19 12:15:03 +0000
commit89c800c61dc2641664ff21b87f920ab5d20530d7 (patch)
treef8228f74d94716e56aae5df8b531eff6d0813c4a /src/com/itmill
parentacc7639b62c25d3e30888f108c8d8733ab4b339c (diff)
downloadvaadin-framework-89c800c61dc2641664ff21b87f920ab5d20530d7.tar.gz
vaadin-framework-89c800c61dc2641664ff21b87f920ab5d20530d7.zip
Test case and fix for #2341 - Reserve scrollbar space in tables with relative width
svn changeset:6298/svn branch:trunk
Diffstat (limited to 'src/com/itmill')
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java52
-rw-r--r--src/com/itmill/toolkit/tests/tickets/Ticket2341.java46
2 files changed, 94 insertions, 4 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 1cee3b146d..ba99f2b270 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
@@ -28,6 +28,7 @@ import com.google.gwt.user.client.ui.ScrollListener;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+import com.itmill.toolkit.terminal.gwt.client.BrowserInfo;
import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.MouseEventDetails;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
@@ -63,7 +64,7 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
public static final String CLASSNAME = "i-table";
/**
- * multiple of pagelenght which component will cache when requesting more
+ * multiple of pagelength which component will cache when requesting more
* rows
*/
private static final double CACHE_RATE = 2;
@@ -132,9 +133,13 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
*/
boolean recalcWidths = false;
+ int scrollbarWidthReservedInColumn = -1;
+ int scrollbarWidthReserved = -1;
+ boolean relativeWidth = false;
+
private final ArrayList lazyUnregistryBag = new ArrayList();
private String height;
- private String width;
+ private String width = "";
public IScrollTable() {
bodyContainer.addScrollListener(this);
@@ -153,6 +158,10 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
return;
}
+ if (uidl.hasAttribute("width")) {
+ relativeWidth = uidl.getStringAttribute("width").endsWith("%");
+ }
+
// we may have pending cache row fetch, cancel it. See #2136
rowRequestHandler.cancel();
@@ -569,10 +578,25 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
if (availW > total) {
// natural size is smaller than available space
- final int extraSpace = availW - total;
- final int totalWidthR = total - totalExplicitColumnsWidths;
+ int extraSpace = availW - total;
+ int totalWidthR = total - totalExplicitColumnsWidths;
if (totalWidthR > 0) {
needsReLayout = true;
+
+ /*
+ * If the table has a relative width and there is enough space
+ * for a scrollbar we reserve this in the last column
+ */
+ int scrollbarWidth = getScrollbarWidth();
+ if (relativeWidth && totalWidthR >= scrollbarWidth) {
+ scrollbarWidthReserved = scrollbarWidth + 1; //
+ widths[tHead.getVisibleCellCount() - 1] += scrollbarWidthReserved;
+ totalWidthR += scrollbarWidthReserved;
+ extraSpace -= scrollbarWidthReserved;
+ scrollbarWidthReservedInColumn = tHead
+ .getVisibleCellCount() - 1;
+ }
+
// now we will share this sum relatively to those without
// explicit width
headCells = tHead.iterator();
@@ -640,6 +664,10 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
}
private int getScrollbarWidth() {
+ if (BrowserInfo.get().isIE6()) {
+ return Util.measureHorizontalBorder(bodyContainer.getElement());
+ }
+
return bodyContainer.getOffsetWidth()
- DOM.getElementPropertyInt(bodyContainer.getElement(),
"clientWidth");
@@ -2304,9 +2332,25 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
}
public void setWidth(String width) {
+ if (this.width.equals(width)) {
+ return;
+ }
+
this.width = width;
if (width != null && !"".equals(width)) {
+ int oldWidth = getOffsetWidth();
super.setWidth(width);
+ int newWidth = getOffsetWidth();
+
+ if (scrollbarWidthReservedInColumn != -1 && oldWidth > newWidth
+ && (oldWidth - newWidth) < scrollbarWidthReserved) {
+ int col = scrollbarWidthReservedInColumn;
+ String colKey = getColKeyByIndex(col);
+ setColWidth(scrollbarWidthReservedInColumn, getColWidth(colKey)
+ - (oldWidth - newWidth));
+ scrollbarWidthReservedInColumn = -1;
+ }
+
int innerPixels = getOffsetWidth() - getBorderWidth();
if (innerPixels < 0) {
innerPixels = 0;
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2341.java b/src/com/itmill/toolkit/tests/tickets/Ticket2341.java
new file mode 100644
index 0000000000..be795549d9
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/tickets/Ticket2341.java
@@ -0,0 +1,46 @@
+package com.itmill.toolkit.tests.tickets;
+
+import com.itmill.toolkit.data.Item;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Layout;
+import com.itmill.toolkit.ui.Table;
+import com.itmill.toolkit.ui.Window;
+
+public class Ticket2341 extends com.itmill.toolkit.Application {
+ public void init() {
+ Window main = new Window();
+ setMainWindow(main);
+ constructTables(main.getLayout());
+ }
+
+ private void constructTables(Layout layout) {
+
+ Table t = createTable();
+ layout.addComponent(t);
+ t = createTable();
+ Label l = new Label("A high label to enable scrollbars");
+ l.setHeight("2000px");
+ layout.addComponent(l);
+
+ }
+
+ private Table createTable() {
+ Table t = new Table();
+ t.addContainerProperty("test1", String.class, "");
+ t.addContainerProperty("test2", String.class, "");
+ t.addContainerProperty("test3", String.class, "");
+ t.addContainerProperty("test4", String.class, "");
+ t.setWidth("100%");
+ t.setHeight("300px");
+ for (int i = 0; i < 100; i++) {
+ Item item = t.addItem(i);
+ item.getItemProperty("test1").setValue("testing1 " + i);
+ item.getItemProperty("test2").setValue("testing2 " + i);
+ item.getItemProperty("test3").setValue("testing3 " + i);
+ item.getItemProperty("test4").setValue("testing4 " + i);
+ }
+
+ return t;
+ }
+
+}