Iterator<?> it = uidl.getChildIterator();
HashSet<String> updated = new HashSet<String>();
boolean refreshContentWidths = initializedAndAttached
&& hadScrollBars != willHaveScrollbars();
while (it.hasNext()) {
final UIDL col = (UIDL) it.next();
final String cid = col.getStringAttribute("cid");
updated.add(cid);
String caption = buildCaptionHtmlSnippet(col);
HeaderCell c = getHeaderCell(cid);
if (c == null) {
c = new HeaderCell(cid, caption);
availableCells.put(cid, c);
if (initializedAndAttached) {
// we will need a column width recalculation
initializedAndAttached = false;
initialContentReceived = false;
isNewBody = true;
}
} else {
c.setText(caption);
}
if (col.hasAttribute("sortable")) {
c.setSortable(true);
c.setSorted(false);
} else {
c.setSortable(false);
}
if (col.hasAttribute("align")) {
c.setAlign(col.getStringAttribute("align").charAt(0));
} else {
c.setAlign(ALIGN_LEFT);
}
if (col.hasAttribute("width") && !c.isResizing) {
// Make sure to accomodate for the sort indicator if
// necessary.
int width = col.getIntAttribute("width");
int widthWithoutAddedIndent = width;
// get min width with indent, no padding
int minWidth = c.getMinWidth(true, false);
if (width < minWidth) {
width = minWidth;
}
if (scrollBody != null && width != c.getWidthWithIndent()) {
// Do a more thorough update if a column is resized from
// the server *after* the header has been properly
// initialized
final int colIx = getColIndexByKey(c.cid);
final int newWidth = width;
Scheduler.get().scheduleDeferred(
new ScheduledCommand() {
@Override
public void execute() {
setColWidth(colIx, newWidth, true);
}
});
refreshContentWidths = true;
} else {
// get min width with no indent or padding
minWidth = c.getMinWidth(false, false);
if (widthWithoutAddedIndent < minWidth) {
widthWithoutAddedIndent = minWidth;
}
// save min width without indent
c.setWidth(widthWithoutAddedIndent, true);
}
} else if (col.hasAttribute("er")) {
c.setUndefinedWidth();
c.setExpandRatio(col.getFloatAttribute("er"));
} else if (recalcWidths) {
c.setUndefinedWidth();
} else {
boolean hadExpandRatio = c.getExpandRatio() > 0;
boolean hadDefinedWidth = c.isDefinedWidth();
if (hadExpandRatio || hadDefinedWidth) {
// Someone has removed a expand width or the defined
// width on the server side (setting it to -1), make the
// column undefined again and measure columns again.
c.setUndefinedWidth();
c.setExpandRatio(0);
refreshContentWidths = true;
}
}
if (col.hasAttribute("collapsed")) {
// ensure header is properly removed from parent (case when
// collapsing happens via servers side api)
if (c.isAttached()) {
c.removeFromParent();
headerChangedDuringUpdate = true;