aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/VGridLayout.java127
-rw-r--r--client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java123
2 files changed, 114 insertions, 136 deletions
diff --git a/client/src/com/vaadin/client/ui/VGridLayout.java b/client/src/com/vaadin/client/ui/VGridLayout.java
index be8353ac6e..8a58c8e1b7 100644
--- a/client/src/com/vaadin/client/ui/VGridLayout.java
+++ b/client/src/com/vaadin/client/ui/VGridLayout.java
@@ -33,7 +33,6 @@ import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorMap;
import com.vaadin.client.LayoutManager;
import com.vaadin.client.StyleConstants;
-import com.vaadin.client.UIDL;
import com.vaadin.client.Util;
import com.vaadin.client.VCaption;
import com.vaadin.client.ui.gridlayout.GridLayoutConnector;
@@ -41,6 +40,7 @@ import com.vaadin.client.ui.layout.ComponentConnectorLayoutSlot;
import com.vaadin.client.ui.layout.VLayoutSlot;
import com.vaadin.shared.ui.AlignmentInfo;
import com.vaadin.shared.ui.MarginInfo;
+import com.vaadin.shared.ui.gridlayout.GridLayoutState.ChildComponentData;
public class VGridLayout extends ComplexPanel {
@@ -499,10 +499,6 @@ public class VGridLayout extends ComplexPanel {
this.col = col;
}
- public boolean hasContent() {
- return hasContent;
- }
-
public boolean hasRelativeHeight() {
if (slot != null) {
return slot.getChild().isRelativeHeight();
@@ -569,66 +565,67 @@ public class VGridLayout extends ComplexPanel {
}
}
- final int row;
- final int col;
+ private int row;
+ private int col;
int colspan = 1;
int rowspan = 1;
- private boolean hasContent;
-
private AlignmentInfo alignment;
/** For internal use only. May be removed or replaced in the future. */
public ComponentConnectorLayoutSlot slot;
- public void updateFromUidl(UIDL cellUidl) {
- // Set cell width
- colspan = cellUidl.hasAttribute("w") ? cellUidl
- .getIntAttribute("w") : 1;
- // Set cell height
- rowspan = cellUidl.hasAttribute("h") ? cellUidl
- .getIntAttribute("h") : 1;
- // ensure we will lose reference to old cells, now overlapped by
- // this cell
- for (int i = 0; i < colspan; i++) {
- for (int j = 0; j < rowspan; j++) {
- if (i > 0 || j > 0) {
- cells[col + i][row + j] = null;
- }
+ public void updateCell(ChildComponentData childComponentData) {
+ if (row != childComponentData.row1
+ || col != childComponentData.column1) {
+ // cell has been moved, update matrix
+ if (col < cells.length && cells.length != 0
+ && row < cells[0].length && cells[col][row] == this) {
+ // Remove old reference if still relevant
+ cells[col][row] = null;
}
+
+ row = childComponentData.row1;
+ col = childComponentData.column1;
+
+ cells[col][row] = this;
}
- UIDL childUidl = cellUidl.getChildUIDL(0); // we are interested
- // about childUidl
- hasContent = childUidl != null;
- if (hasContent) {
- ComponentConnector childConnector = client
- .getPaintable(childUidl);
-
- if (slot == null || slot.getChild() != childConnector) {
- slot = new ComponentConnectorLayoutSlot(CLASSNAME,
- childConnector, getConnector());
- if (childConnector.isRelativeWidth()) {
- slot.getWrapperElement().getStyle()
- .setWidth(100, Unit.PCT);
- }
- Element slotWrapper = slot.getWrapperElement();
- getElement().appendChild(slotWrapper);
-
- Widget widget = childConnector.getWidget();
- insert(widget, slotWrapper, getWidgetCount(), false);
- Cell oldCell = widgetToCell.put(widget, this);
- if (oldCell != null) {
- oldCell.slot.getWrapperElement().removeFromParent();
- oldCell.slot = null;
- }
- }
+ // Set cell width
+ colspan = 1 + childComponentData.column2
+ - childComponentData.column1;
+ // Set cell height
+ rowspan = 1 + childComponentData.row2 - childComponentData.row1;
+ setAlignment(new AlignmentInfo(childComponentData.alignment));
+ }
+
+ public void setComponent(ComponentConnector component) {
+ if (slot == null || slot.getChild() != component) {
+ slot = new ComponentConnectorLayoutSlot(CLASSNAME, component,
+ getConnector());
+ slot.setAlignment(alignment);
+ if (component.isRelativeWidth()) {
+ slot.getWrapperElement().getStyle().setWidth(100, Unit.PCT);
+ }
+ Element slotWrapper = slot.getWrapperElement();
+ getElement().appendChild(slotWrapper);
+
+ Widget widget = component.getWidget();
+ insert(widget, slotWrapper, getWidgetCount(), false);
+ Cell oldCell = widgetToCell.put(widget, this);
+ if (oldCell != null) {
+ oldCell.slot.getWrapperElement().removeFromParent();
+ oldCell.slot = null;
+ }
}
}
public void setAlignment(AlignmentInfo alignmentInfo) {
- slot.setAlignment(alignmentInfo);
+ alignment = alignmentInfo;
+ if (slot != null) {
+ slot.setAlignment(alignmentInfo);
+ }
}
}
@@ -638,8 +635,7 @@ public class VGridLayout extends ComplexPanel {
}
/**
- * Creates a new Cell with the given coordinates. If an existing cell was
- * found, returns that one.
+ * Creates a new Cell with the given coordinates.
* <p>
* For internal use only. May be removed or replaced in the future.
*
@@ -647,12 +643,9 @@ public class VGridLayout extends ComplexPanel {
* @param col
* @return
*/
- public Cell createCell(int row, int col) {
- Cell cell = getCell(row, col);
- if (cell == null) {
- cell = new Cell(row, col);
- cells[col][row] = cell;
- }
+ public Cell createNewCell(int row, int col) {
+ Cell cell = new Cell(row, col);
+ cells[col][row] = cell;
return cell;
}
@@ -734,4 +727,24 @@ public class VGridLayout extends ComplexPanel {
}
}
+ @Override
+ public boolean remove(Widget w) {
+ boolean removed = super.remove(w);
+ if (removed) {
+ Cell cell = widgetToCell.remove(w);
+ if (cell != null) {
+ cell.slot.setCaption(null);
+ cell.slot.getWrapperElement().removeFromParent();
+ cell.slot = null;
+
+ if (cells.length < cell.col && cells.length != 0
+ && cells[0].length < cell.row
+ && cells[cell.col][cell.row] == cell) {
+ cells[cell.col][cell.row] = null;
+ }
+ }
+ }
+ return removed;
+ }
+
}
diff --git a/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java b/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java
index 16125f883e..3284d3e07d 100644
--- a/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java
+++ b/client/src/com/vaadin/client/ui/gridlayout/GridLayoutConnector.java
@@ -15,14 +15,13 @@
*/
package com.vaadin.client.ui.gridlayout;
-import java.util.Iterator;
+import java.util.Map.Entry;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
-import com.vaadin.client.ConnectorMap;
import com.vaadin.client.DirectionalManagedLayout;
import com.vaadin.client.Paintable;
import com.vaadin.client.UIDL;
@@ -33,12 +32,13 @@ import com.vaadin.client.ui.LayoutClickEventHandler;
import com.vaadin.client.ui.VGridLayout;
import com.vaadin.client.ui.VGridLayout.Cell;
import com.vaadin.client.ui.layout.VLayoutSlot;
-import com.vaadin.shared.ui.AlignmentInfo;
+import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.LayoutClickRpc;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.shared.ui.gridlayout.GridLayoutServerRpc;
import com.vaadin.shared.ui.gridlayout.GridLayoutState;
+import com.vaadin.shared.ui.gridlayout.GridLayoutState.ChildComponentData;
import com.vaadin.ui.GridLayout;
@Connect(GridLayout.class)
@@ -60,11 +60,11 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector
};
- private boolean needCaptionUpdate = false;
-
@Override
public void init() {
super.init();
+ getWidget().client = getConnection();
+
getLayoutManager().registerDependency(this,
getWidget().spacingMeasureElement);
}
@@ -98,64 +98,21 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
VGridLayout layout = getWidget();
- layout.client = client;
if (!isRealUpdate(uidl)) {
return;
}
- int cols = getState().columns;
- int rows = getState().rows;
+ initSize();
- layout.columnWidths = new int[cols];
- layout.rowHeights = new int[rows];
+ for (Entry<Connector, ChildComponentData> entry : getState().childData
+ .entrySet()) {
+ ComponentConnector child = (ComponentConnector) entry.getKey();
- layout.setSize(rows, cols);
+ Cell cell = getCell(child);
- final int[] alignments = uidl.getIntArrayAttribute("alignments");
- int alignmentIndex = 0;
-
- for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
- final UIDL r = (UIDL) i.next();
- if ("gr".equals(r.getTag())) {
- for (final Iterator<?> j = r.getChildIterator(); j.hasNext();) {
- final UIDL cellUidl = (UIDL) j.next();
- if ("gc".equals(cellUidl.getTag())) {
- int row = cellUidl.getIntAttribute("y");
- int col = cellUidl.getIntAttribute("x");
-
- Widget previousWidget = null;
-
- Cell cell = layout.getCell(row, col);
- if (cell != null && cell.slot != null) {
- // This is an update. Track if the widget changes
- // and update the caption if that happens. This
- // workaround can be removed once the DOM update is
- // done in onContainerHierarchyChange
- previousWidget = cell.slot.getWidget();
- }
-
- cell = layout.createCell(row, col);
-
- cell.updateFromUidl(cellUidl);
-
- if (cell.hasContent()) {
- cell.setAlignment(new AlignmentInfo(
- alignments[alignmentIndex++]));
- if (cell.slot.getWidget() != previousWidget) {
- // Widget changed or widget moved from another
- // slot. Update its caption as the widget might
- // have called updateCaption when the widget was
- // still in its old slot. This workaround can be
- // removed once the DOM update
- // is done in onContainerHierarchyChange
- updateCaption(ConnectorMap.get(getConnection())
- .getConnector(cell.slot.getWidget()));
- }
- }
- }
- }
- }
+ ChildComponentData childComponentData = entry.getValue();
+ cell.updateCell(childComponentData);
}
layout.colExpandRatioArray = uidl.getIntArrayAttribute("colExpand");
@@ -165,14 +122,22 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector
layout.updateSpacingStyleName(getState().spacing);
- if (needCaptionUpdate) {
- needCaptionUpdate = false;
+ getLayoutManager().setNeedsLayout(this);
+ }
+
+ private Cell getCell(ComponentConnector child) {
+ VGridLayout layout = getWidget();
+ Cell cell = layout.widgetToCell.get(child.getWidget());
- for (ComponentConnector child : getChildComponents()) {
- updateCaption(child);
- }
+ if (cell == null) {
+ ChildComponentData childComponentData = getState().childData
+ .get(child);
+ int row = childComponentData.row1;
+ int col = childComponentData.column1;
+
+ cell = layout.createNewCell(row, col);
}
- getLayoutManager().setNeedsLayout(this);
+ return cell;
}
@Override
@@ -187,33 +152,33 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector
Widget childWidget = oldChild.getWidget();
layout.remove(childWidget);
+ }
- Cell cell = layout.widgetToCell.remove(childWidget);
- cell.slot.setCaption(null);
- cell.slot.getWrapperElement().removeFromParent();
- cell.slot = null;
+ initSize();
+
+ for (ComponentConnector componentConnector : getChildComponents()) {
+ Cell cell = getCell(componentConnector);
+
+ cell.setComponent(componentConnector);
}
}
+ private void initSize() {
+ VGridLayout layout = getWidget();
+ int cols = getState().columns;
+ int rows = getState().rows;
+
+ layout.columnWidths = new int[cols];
+ layout.rowHeights = new int[rows];
+
+ layout.setSize(rows, cols);
+ }
+
@Override
public void updateCaption(ComponentConnector childConnector) {
- if (!childConnector.delegateCaptionHandling()) {
- // Check not required by interface but by workarounds in this class
- // when updateCaption is explicitly called for all children.
- return;
- }
-
VGridLayout layout = getWidget();
Cell cell = layout.widgetToCell.get(childConnector.getWidget());
- if (cell == null) {
- // workaround before updateFromUidl is removed. We currently update
- // the captions at the end of updateFromUidl instead of immediately
- // because the DOM has not been set up at this point (as it is done
- // in updateFromUidl)
- needCaptionUpdate = true;
- return;
- }
if (VCaption.isNeeded(childConnector.getState())) {
VLayoutSlot layoutSlot = cell.slot;
VCaption caption = layoutSlot.getCaption();