]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #1368
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 5 Mar 2008 12:57:39 +0000 (12:57 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 5 Mar 2008 12:57:39 +0000 (12:57 +0000)
svn changeset:3973/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
src/com/itmill/toolkit/tests/tickets/Ticket1368.java [new file with mode: 0644]
src/com/itmill/toolkit/ui/Table.java

index 2074aa156240a745c1fa5f08c089d4b90ed923cf..7be62f03daa22967856922fa4fcc41cfc9dec0b7 100644 (file)
@@ -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 (file)
index 0000000..70b5f38
--- /dev/null
@@ -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
index dc73c913d72fec3411930abca9d4d2b721dad8c9..0ef9951f186ddd26dcdd27865cd65966a8cae187 100644 (file)
@@ -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;
     }