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;
}
total += w;
i++;
}
+
tHead.disableBrowserIntelligence();
if (height == null) {
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);
}
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)
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"));
}
--- /dev/null
+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
*/
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;
}