import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollListener;
private int selectMode = Table.SELECT_MODE_NONE;
- private final HashSet selectedRowKeys = new HashSet();
+ private final HashSet<String> selectedRowKeys = new HashSet<String>();
private boolean initializedAndAttached = false;
+ /**
+ * Flag to indicate if a column width recalculation is needed due update.
+ */
+ private boolean headerChangedDuringUpdate = false;
+
private final TableHead tHead = new TableHead();
private final ScrollPanel bodyContainer = new ScrollPanel();
* This map contains captions and icon urls for actions like: * "33_c" ->
* "Edit" * "33_i" -> "http://dom.com/edit.png"
*/
- private final HashMap actionMap = new HashMap();
+ private final HashMap<Object, String> actionMap = new HashMap<Object, String>();
private String[] visibleColOrder;
private boolean initialContentReceived = false;
private Element scrollPositionElement;
int scrollbarWidthReserved = -1;
boolean relativeWidth = false;
- private final ArrayList lazyUnregistryBag = new ArrayList();
+ private final ArrayList<Panel> lazyUnregistryBag = new ArrayList<Panel>();
private String height;
private String width = "";
private boolean rendering = false;
}
+ @SuppressWarnings("unchecked")
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
rendering = true;
if (client.updateComponent(this, uidl, true)) {
}
if (uidl.hasVariable("selected")) {
- final Set selectedKeys = uidl
+ final Set<String> selectedKeys = uidl
.getStringArrayVariableAsSet("selected");
selectedRowKeys.clear();
- for (final Iterator it = selectedKeys.iterator(); it.hasNext();) {
- selectedRowKeys.add(it.next());
+ for (String string : selectedKeys) {
+ selectedRowKeys.add(string);
}
}
if (!recalcWidths && initializedAndAttached) {
updateBody(rowData, uidl.getIntAttribute("firstrow"), uidl
.getIntAttribute("rows"));
+ if (headerChangedDuringUpdate) {
+ lazyAdjustColumnWidths.schedule(1);
+ }
} else {
if (tBody != null) {
tBody.removeFromParent();
hideScrollPositionAnnotation();
purgeUnregistryBag();
rendering = false;
+ headerChangedDuringUpdate = false;
}
/**
* "subtreecaching" logic.
*/
private void purgeUnregistryBag() {
- for (Iterator iterator = lazyUnregistryBag.iterator(); iterator
+ for (Iterator<Panel> iterator = lazyUnregistryBag.iterator(); iterator
.hasNext();) {
- client.unregisterChildPaintables((HasWidgets) iterator.next());
+ client.unregisterChildPaintables(iterator.next());
}
lazyUnregistryBag.clear();
}
private void updateActionMap(UIDL c) {
- final Iterator it = c.getChildIterator();
+ final Iterator<?> it = c.getChildIterator();
while (it.hasNext()) {
final UIDL action = (UIDL) it.next();
final String key = action.getStringAttribute("key");
}
public String getActionCaption(String actionKey) {
- return (String) actionMap.get(actionKey + "_c");
+ return actionMap.get(actionKey + "_c");
}
public String getActionIcon(String actionKey) {
- return (String) actionMap.get(actionKey + "_i");
+ return actionMap.get(actionKey + "_i");
}
private void updateHeader(String[] strings) {
}
private IScrollTableRow getRenderedRowByKey(String key) {
- final Iterator it = tBody.iterator();
+ final Iterator<Widget> it = tBody.iterator();
IScrollTableRow r = null;
while (it.hasNext()) {
r = (IScrollTableRow) it.next();
if (isDefinedWidth()) {
return width;
} else {
+ if (naturalWidth == 0) {
+ // This is recently revealed column. Try to detect a proper
+ // value (greater of header and data
+ // cols)
+ final int hw = getOffsetWidth();
+ int i = 0;
+ for (Iterator<Widget> it = tHead.iterator(); it.hasNext(); i++) {
+ if (it.next() == this) {
+ break;
+ }
+ }
+ final int cw = tBody.getColWidth(i);
+ naturalWidth = (hw > cw ? hw : cw)
+ + IScrollTableBody.CELL_EXTRA_WIDTH;
+
+ }
return naturalWidth;
}
}
}
public void updateCellsFromUIDL(UIDL uidl) {
- Iterator it = uidl.getChildIterator();
+ Iterator<?> it = uidl.getChildIterator();
HashSet<String> updated = new HashSet<String>();
updated.add("0");
while (it.hasNext()) {
final HeaderCell c = getHeaderCell(cid);
if (!c.isEnabled() || getHeaderCell(index) != c) {
setHeaderCell(index, c);
- if (c.getWidth() == -1) {
- if (initializedAndAttached) {
- // column is not drawn before,
- // we will need a column width recalculation
- initializedAndAttached = false;
- initialContentReceived = false;
- isNewBody = true;
- }
+ if (initializedAndAttached) {
+ headerChangedDuringUpdate = true;
}
}
}
} else {
tHead.removeCell(colKey);
collapsedColumns.add(colKey);
+ lazyAdjustColumnWidths.schedule(1);
}
// update variable to server
for (i = 0; i < visibleColOrder.length; i++) {
cols[i] = visibleColOrder[i];
}
- for (final Iterator it = collapsedColumns.iterator(); it
+ for (final Iterator<String> it = collapsedColumns.iterator(); it
.hasNext();) {
cols[i++] = it.next();
}
private int rowHeight = -1;
- private final List renderedRows = new Vector();
+ private final List<Widget> renderedRows = new Vector<Widget>();
private boolean initDone = false;
renderedRows.add(row);
}
- public Iterator iterator() {
+ public Iterator<Widget> iterator() {
return renderedRows.iterator();
}
if (hCell.isDefinedWidth()) {
totalExplicitColumnsWidths += hCell.getWidth();
} else {
+ totalExplicitColumnsWidths += hCell.getNaturalColumnWidth();
expandRatioDivider += hCell.getExpandRatio();
}
}
newSpace = (int) (w + extraSpace
* hCell.getExpandRatio() / expandRatioDivider);
} else {
- // divide relatively to natural column widths
- newSpace = w + extraSpace * w / totalWidthR;
+ if (totalWidthR != 0) {
+ // divide relatively to natural column widths
+ newSpace = w + extraSpace * w / totalWidthR;
+ } else {
+ newSpace = w;
+ }
}
setColWidth(i, newSpace, false);
}