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;
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;
*/
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);
return;
}
+ if (uidl.hasAttribute("width")) {
+ relativeWidth = uidl.getStringAttribute("width").endsWith("%");
+ }
+
// we may have pending cache row fetch, cancel it. See #2136
rowRequestHandler.cancel();
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();
}
private int getScrollbarWidth() {
+ if (BrowserInfo.get().isIE6()) {
+ return Util.measureHorizontalBorder(bodyContainer.getElement());
+ }
+
return bodyContainer.getOffsetWidth()
- DOM.getElementPropertyInt(bodyContainer.getElement(),
"clientWidth");
}
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;
--- /dev/null
+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;
+ }
+
+}