Browse Source

fixes #1368

svn changeset:3973/svn branch:trunk
tags/6.7.0.beta1
Matti Tahvonen 16 years ago
parent
commit
98811b95f4

+ 25
- 5
src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java View 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"));
}

+ 35
- 0
src/com/itmill/toolkit/tests/tickets/Ticket1368.java View File

@@ -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);

}
}

+ 10
- 3
src/com/itmill/toolkit/ui/Table.java View 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;
}

Loading…
Cancel
Save