From: Matti Tahvonen Date: Wed, 5 Mar 2008 12:57:39 +0000 (+0000) Subject: fixes #1368 X-Git-Tag: 6.7.0.beta1~4987 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=98811b95f452d3aba3998f31a314dc5cdce7bdb7;p=vaadin-framework.git fixes #1368 svn changeset:3973/svn branch:trunk --- 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 2074aa1562..7be62f03da 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java @@ -497,18 +497,23 @@ public class IScrollTable extends Composite implements Table, ScrollListener, final int[] widths = new int[tHead.visibleCells.size()]; + if (width == null) { + // if this is a re-init, remove old manually fixed size + bodyContainer.setWidth(""); + tHead.setWidth(""); + super.setWidth(""); + } + tHead.enableBrowserIntelligence(); // first loop: collect natural widths while (headCells.hasNext()) { final HeaderCell hCell = (HeaderCell) headCells.next(); - int w; - if (hCell.getWidth() > 0) { + int w = hCell.getWidth(); + if (w > 0) { // server has defined column width explicitly - w = hCell.getWidth(); totalExplicitColumnsWidths += w; } else { - final int hw = DOM.getElementPropertyInt(hCell.getElement(), - "offsetWidth"); + final int hw = hCell.getOffsetWidth(); final int cw = tBody.getColWidth(i); w = (hw > cw ? hw : cw) + IScrollTableBody.CELL_EXTRA_WIDTH; } @@ -516,6 +521,7 @@ public class IScrollTable extends Composite implements Table, ScrollListener, total += w; i++; } + tHead.disableBrowserIntelligence(); if (height == null) { @@ -916,6 +922,10 @@ public class IScrollTable extends Composite implements Table, ScrollListener, DOM.setElementProperty(captionContainer, "className", CLASSNAME + "-caption-container"); + + // ensure no clipping initially (problem on column additions) + DOM.setStyleAttribute(captionContainer, "overflow", "visible"); + DOM.sinkEvents(captionContainer, Event.MOUSEEVENTS); DOM.appendChild(td, captionContainer); @@ -926,6 +936,10 @@ public class IScrollTable extends Composite implements Table, ScrollListener, } public void setWidth(int w) { + if (width == -1) { + // go to default mode, clip content if necessary + DOM.setStyleAttribute(captionContainer, "overflow", ""); + } width = w; DOM.setStyleAttribute(captionContainer, "width", (w - DRAG_WIDGET_WIDTH - 4) @@ -1244,6 +1258,12 @@ public class IScrollTable extends Composite implements Table, ScrollListener, if (c == null) { c = new HeaderCell(cid, col.getStringAttribute("caption")); availableCells.put(cid, c); + if (initializedAndAttached) { + // we will need a column width recalculation + initializedAndAttached = false; + initialContentReceived = false; + isNewBody = true; + } } else { c.setText(col.getStringAttribute("caption")); } diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1368.java b/src/com/itmill/toolkit/tests/tickets/Ticket1368.java new file mode 100644 index 0000000000..70b5f383ba --- /dev/null +++ b/src/com/itmill/toolkit/tests/tickets/Ticket1368.java @@ -0,0 +1,35 @@ +package com.itmill.toolkit.tests.tickets; + +import com.itmill.toolkit.Application; +import com.itmill.toolkit.tests.TestForTablesInitialColumnWidthLogicRendering; +import com.itmill.toolkit.ui.ComboBox; +import com.itmill.toolkit.ui.Table; +import com.itmill.toolkit.ui.Window; + +/** + */ +public class Ticket1368 extends Application { + + private Table t; + + public void init() { + + final Window mainWin = new Window("Test app to #1368"); + setMainWindow(mainWin); + + t = TestForTablesInitialColumnWidthLogicRendering.getTestTable(3, 5); + + mainWin.addComponent(t); + + ComboBox addColumn = new ComboBox(); + addColumn.setImmediate(true); + addColumn.setNewItemsAllowed(true); + addColumn.setNewItemHandler(new ComboBox.NewItemHandler() { + public void addNewItem(String newItemCaption) { + t.addContainerProperty(newItemCaption, String.class, "-"); + } + }); + mainWin.addComponent(addColumn); + + } +} \ No newline at end of file diff --git a/src/com/itmill/toolkit/ui/Table.java b/src/com/itmill/toolkit/ui/Table.java index dc73c913d7..0ef9951f18 100644 --- a/src/com/itmill/toolkit/ui/Table.java +++ b/src/com/itmill/toolkit/ui/Table.java @@ -2163,11 +2163,18 @@ public class Table extends AbstractSelect implements Action.Container, */ public boolean addContainerProperty(Object propertyId, Class type, Object defaultValue) throws UnsupportedOperationException { - if (!super.addContainerProperty(propertyId, type, defaultValue)) { - return false; - } + + boolean visibleColAdded = false; if (!visibleColumns.contains(propertyId)) { visibleColumns.add(propertyId); + visibleColAdded = true; + } + + if (!super.addContainerProperty(propertyId, type, defaultValue)) { + if(visibleColAdded) { + visibleColumns.remove(propertyId); + } + return false; } return true; }