summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-03-15 13:41:46 +0200
committerArtur Signell <artur@vaadin.com>2012-03-15 13:41:46 +0200
commit92e7ba655ab8ee048994b86640edea4388cad28e (patch)
tree1aff1f1706b8b4c812a7719410724efcfc477608 /src
parent484e96efad5ed606d46e353b16bc2f6960bad9ce (diff)
downloadvaadin-framework-92e7ba655ab8ee048994b86640edea4388cad28e.tar.gz
vaadin-framework-92e7ba655ab8ee048994b86640edea4388cad28e.zip
#8500 Converted AbstractOrderedLayout to use hierarchy change events.
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java95
1 files changed, 31 insertions, 64 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java
index cd791fba08..1bcc6242fa 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractOrderedLayoutConnector.java
@@ -3,16 +3,13 @@
*/
package com.vaadin.terminal.gwt.client.ui;
-import java.util.Iterator;
import java.util.List;
-import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.Style;
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.DirectionalManagedLayout;
import com.vaadin.terminal.gwt.client.LayoutManager;
import com.vaadin.terminal.gwt.client.UIDL;
@@ -24,8 +21,6 @@ import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot;
public abstract class AbstractOrderedLayoutConnector extends
AbstractComponentContainerConnector implements DirectionalManagedLayout {
- private List<ComponentConnector> previousChildren;
-
@Override
public void init() {
getLayoutManager().registerDependency(this,
@@ -69,22 +64,8 @@ public abstract class AbstractOrderedLayoutConnector extends
ValueMap expandRatios = uidl.getMapAttribute("expandRatios");
ValueMap alignments = uidl.getMapAttribute("alignments");
- int currentIndex = 0;
- // TODO Support reordering elements!
- // FIXME: move to connectorHierarchyChanged!!
- for (final Iterator<Object> it = uidl.getChildIterator(); it.hasNext();) {
- final UIDL childUIDL = (UIDL) it.next();
- final ComponentConnector child = client.getPaintable(childUIDL);
- Widget widget = child.getWidget();
-
- VLayoutSlot slot = layout.getSlotForChild(widget);
-
- if (widget.getParent() != layout) {
- slot = new ComponentConnectorLayoutSlot(getWidget()
- .getStylePrimaryName(), child);
- }
- layout.addOrMove(slot, currentIndex++);
-
+ for (ComponentConnector child : getChildren()) {
+ VLayoutSlot slot = layout.getSlotForChild(child.getWidget());
String pid = child.getConnectorId();
AlignmentInfo alignment;
@@ -102,48 +83,6 @@ public abstract class AbstractOrderedLayoutConnector extends
expandRatio = 0;
}
slot.setExpandRatio(expandRatio);
-
- if (!childUIDL.getBooleanAttribute("cached")) {
- child.updateFromUIDL(childUIDL, client);
- }
-
- previousChildren.remove(child);
- }
-
- if (previousChildren != null) {
- for (ComponentConnector child : previousChildren) {
- Widget widget = child.getWidget();
-
- // Don't remove and unregister if it has been moved to a
- // different
- // parent. Slot element will be left behind, but that is taken
- // care
- // of later
- if (widget.getParent() == getWidget()) {
- layout.removeSlot(layout.getSlotForChild(widget));
-
- ConnectorMap vPaintableMap = ConnectorMap.get(client);
- vPaintableMap.unregisterConnector(child);
- }
- }
- }
- // Remove empty layout slots left behind after children have moved to
- // other paintables
- while (true) {
- int childCount = layout.getElement().getChildCount();
- if (childCount <= 1) {
- // Stop if no more slots (spacing element is always present)
- break;
- }
-
- Node lastSlot = layout.getElement().getChild(childCount - 2);
- if (lastSlot.getChildCount() == 0) {
- // Remove if empty
- lastSlot.removeFromParent();
- } else {
- // Stop searching when last slot is not empty
- break;
- }
}
int bitMask = uidl.getIntAttribute("margins");
@@ -287,7 +226,35 @@ public abstract class AbstractOrderedLayoutConnector extends
@Override
public void connectorHierarchyChanged(
com.vaadin.terminal.gwt.client.ConnectorHierarchyChangedEvent event) {
- previousChildren = event.getOldChildren();
+ super.connectorHierarchyChanged(event);
+ List<ComponentConnector> previousChildren = event.getOldChildren();
+ int currentIndex = 0;
+ VMeasuringOrderedLayout layout = getWidget();
+
+ for (ComponentConnector child : getChildren()) {
+ Widget childWidget = child.getWidget();
+ VLayoutSlot slot = layout.getSlotForChild(childWidget);
+
+ if (childWidget.getParent() != layout) {
+ // If the child widget was previously attached to another
+ // AbstractOrderedLayout a slot might be found that belongs to
+ // another AbstractOrderedLayout. In this case we discard it and
+ // create a new slot.
+ slot = new ComponentConnectorLayoutSlot(getWidget()
+ .getStylePrimaryName(), child);
+ }
+ layout.addOrMove(slot, currentIndex++);
+ }
+
+ for (ComponentConnector child : previousChildren) {
+ Widget widget = child.getWidget();
+ if (child.getParent() != this) {
+ // Remove slot if the connector is no longer a child of this
+ // layout
+ layout.removeSlot(layout.getSlotForChild(widget));
+ }
+ }
+
};
}