import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentConnector;
-import com.vaadin.terminal.gwt.client.ConnectorMap;
+import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent;
import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
}
private GridLayoutServerRPC rpc;
+ private boolean needCaptionUpdate = false;
@Override
public void init() {
final UIDL r = (UIDL) i.next();
if ("gr".equals(r.getTag())) {
for (final Iterator<?> j = r.getChildIterator(); j.hasNext();) {
- final UIDL c = (UIDL) j.next();
- if ("gc".equals(c.getTag())) {
- Cell cell = layout.getCell(c);
+ final UIDL cellUidl = (UIDL) j.next();
+ if ("gc".equals(cellUidl.getTag())) {
+ int row = cellUidl.getIntAttribute("y");
+ int col = cellUidl.getIntAttribute("x");
+
+ Cell cell = layout.getCell(row, col, cellUidl);
if (cell.hasContent()) {
cell.setAlignment(new AlignmentInfo(
alignments[alignmentIndex++]));
layout.colExpandRatioArray = uidl.getIntArrayAttribute("colExpand");
layout.rowExpandRatioArray = uidl.getIntArrayAttribute("rowExpand");
- // clean non rendered components
- for (Widget w : nonRenderedWidgets) {
- Cell cell = layout.widgetToCell.remove(w);
- cell.slot.setCaption(null);
-
- if (w.getParent() == layout) {
- w.removeFromParent();
- ConnectorMap paintableMap = ConnectorMap.get(client);
- paintableMap.unregisterConnector(paintableMap.getConnector(w));
- }
- cell.slot.getWrapperElement().removeFromParent();
- cell.slot = null;
- }
-
layout.updateMarginStyleNames(new VMarginInfo(getState()
.getMarginsBitmask()));
layout.updateSpacingStyleName(getState().isSpacing());
+ if (needCaptionUpdate) {
+ needCaptionUpdate = false;
+
+ for (ComponentConnector child : getChildren()) {
+ updateCaption(child);
+ }
+ }
getLayoutManager().setNeedsUpdate(this);
}
+ @Override
+ public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
+ super.onConnectorHierarchyChange(event);
+
+ VGridLayout layout = getWidget();
+
+ // clean non rendered components
+ for (ComponentConnector oldChild : event.getOldChildren()) {
+ if (oldChild.getParent() == this) {
+ continue;
+ }
+
+ Widget childWidget = oldChild.getWidget();
+ layout.remove(childWidget);
+
+ Cell cell = layout.widgetToCell.remove(childWidget);
+ cell.slot.setCaption(null);
+ cell.slot.getWrapperElement().removeFromParent();
+ cell.slot = null;
+ }
+
+ }
+
public void updateCaption(ComponentConnector childConnector) {
VGridLayout layout = getWidget();
+ Cell cell = layout.widgetToCell.get(childConnector.getWidget());
+ if (cell == null) {
+ // workaround before updateFromUidl is removed. Update the
+ // captions at the end of updateFromUidl instead of immediately
+ needCaptionUpdate = true;
+ return;
+ }
if (VCaption.isNeeded(childConnector.getState())) {
- Cell cell = layout.widgetToCell.get(childConnector.getWidget());
VLayoutSlot layoutSlot = cell.slot;
VCaption caption = layoutSlot.getCaption();
if (caption == null) {
* Private helper class.
*/
class Cell {
- public Cell(UIDL c) {
- row = c.getIntAttribute("y");
- col = c.getIntAttribute("x");
- updateFromUidl(c);
+ public Cell(int row, int col) {
+ this.row = row;
+ this.col = col;
}
public boolean hasContent() {
}
}
- Cell getCell(UIDL c) {
- int row = c.getIntAttribute("y");
- int col = c.getIntAttribute("x");
+ /**
+ * Returns the Cell with the given coordinates. Creates a new Cell if an
+ * existing was not found and also updates the Cell based on the given UIDL.
+ *
+ * @param row
+ * @param col
+ * @return
+ */
+ Cell getCell(int row, int col, UIDL c) {
Cell cell = cells[col][row];
if (cell == null) {
- cell = new Cell(c);
+ cell = new Cell(row, col);
cells[col][row] = cell;
- } else {
- cell.updateFromUidl(c);
}
+ cell.updateFromUidl(c);
return cell;
}