From: Artur Signell Date: Wed, 4 Apr 2012 21:02:18 +0000 (+0300) Subject: Fixed GridLayout caption problem + small step towards away from UIDL X-Git-Tag: 7.0.0.alpha2~122 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e7a99cf1c39ee693587f7d37f961a05ecb358c6a;p=vaadin-framework.git Fixed GridLayout caption problem + small step towards away from UIDL --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/GridLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/GridLayoutConnector.java index 5c120418fa..b3bcc3e58d 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/GridLayoutConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/GridLayoutConnector.java @@ -11,7 +11,7 @@ import com.google.gwt.user.client.Element; 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; @@ -79,6 +79,7 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector } private GridLayoutServerRPC rpc; + private boolean needCaptionUpdate = false; @Override public void init() { @@ -139,9 +140,12 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector 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++])); @@ -155,32 +159,54 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector 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) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java index 7baf4c101a..a0c0f8f393 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java @@ -444,10 +444,9 @@ public class VGridLayout extends ComplexPanel { * 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() { @@ -578,16 +577,21 @@ public class VGridLayout extends ComplexPanel { } } - 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; }