aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-12-18 11:57:32 +0000
committerVaadin Code Review <review@vaadin.com>2012-12-18 11:57:32 +0000
commitca967cbe1d927d7acf5cb72683265557e0b46360 (patch)
tree735c0ba8be97d46d4454c8c5d2c79599a1f7f8ae /client
parente3adf14995d3da532a1350ff472ca8d810953e9d (diff)
parent4b8abdc9386a9d8a3a94f875ad6aa07d115b6470 (diff)
downloadvaadin-framework-ca967cbe1d927d7acf5cb72683265557e0b46360.tar.gz
vaadin-framework-ca967cbe1d927d7acf5cb72683265557e0b46360.zip
Merge "Ensure updateCaption is invoked for new children (#10564)"
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ApplicationConnection.java61
-rw-r--r--client/src/com/vaadin/client/ui/AbstractComponentConnector.java12
2 files changed, 52 insertions, 21 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java
index 05cc88d0ee..ff59a76832 100644
--- a/client/src/com/vaadin/client/ApplicationConnection.java
+++ b/client/src/com/vaadin/client/ApplicationConnection.java
@@ -107,6 +107,14 @@ import com.vaadin.shared.ui.ui.UIConstants;
*/
public class ApplicationConnection {
+ /**
+ * Helper used to return two values when updating the connector hierarchy.
+ */
+ private static class ConnectorHierarchyUpdateResult {
+ private List<ConnectorHierarchyChangeEvent> events = new LinkedList<ConnectorHierarchyChangeEvent>();
+ private List<ServerConnector> parentChanged = new LinkedList<ServerConnector>();
+ }
+
public static final String MODIFIED_CLASSNAME = "v-modified";
public static final String DISABLED_CLASSNAME = "v-disabled";
@@ -1441,18 +1449,21 @@ public class ApplicationConnection {
" * Update of connector states completed", 10);
// Update hierarchy, do not fire events
- Collection<ConnectorHierarchyChangeEvent> pendingHierarchyChangeEvents = updateConnectorHierarchy(json);
+ ConnectorHierarchyUpdateResult connectorHierarchyUpdateResult = updateConnectorHierarchy(json);
updateDuration.logDuration(
" * Update of connector hierarchy completed", 10);
// Fire hierarchy change events
- sendHierarchyChangeEvents(pendingHierarchyChangeEvents);
+ sendHierarchyChangeEvents(connectorHierarchyUpdateResult.events);
updateDuration.logDuration(
" * Hierarchy state change event processing completed",
10);
+ updateCaptions(pendingStateChangeEvents,
+ connectorHierarchyUpdateResult.parentChanged);
+
delegateToWidget(pendingStateChangeEvents);
// Fire state change events.
@@ -1554,6 +1565,36 @@ public class ApplicationConnection {
}
+ private void updateCaptions(
+ Collection<StateChangeEvent> pendingStateChangeEvents,
+ Collection<ServerConnector> parentChanged) {
+ /*
+ * Find all components that might need a caption update based on
+ * pending state and hierarchy changes
+ */
+ HashSet<ServerConnector> needsCaptionUpdate = new HashSet<ServerConnector>(
+ parentChanged);
+
+ // Find components with potentially changed caption state
+ for (StateChangeEvent event : pendingStateChangeEvents) {
+ ServerConnector connector = event.getConnector();
+ needsCaptionUpdate.add(connector);
+ }
+
+ // Update captions for all suitable candidates
+ for (ServerConnector child : needsCaptionUpdate) {
+ if (child instanceof ComponentConnector
+ && ((ComponentConnector) child)
+ .delegateCaptionHandling()) {
+ ServerConnector parent = child.getParent();
+ if (parent instanceof HasComponentsConnector) {
+ ((HasComponentsConnector) parent)
+ .updateCaption((ComponentConnector) child);
+ }
+ }
+ }
+ }
+
private void delegateToWidget(
Collection<StateChangeEvent> pendingStateChangeEvents) {
VConsole.log(" * Running @DelegateToWidget");
@@ -1924,15 +1965,16 @@ public class ApplicationConnection {
* @param json
* The JSON containing the hierarchy information
* @return A collection of events that should be fired when update
- * of hierarchy and state is complete
+ * of hierarchy and state is complete and a list of all
+ * connectors for which the parent has changed
*/
- private Collection<ConnectorHierarchyChangeEvent> updateConnectorHierarchy(
+ private ConnectorHierarchyUpdateResult updateConnectorHierarchy(
ValueMap json) {
- List<ConnectorHierarchyChangeEvent> events = new LinkedList<ConnectorHierarchyChangeEvent>();
+ ConnectorHierarchyUpdateResult result = new ConnectorHierarchyUpdateResult();
VConsole.log(" * Updating connector hierarchy");
if (!json.containsKey("hierarchy")) {
- return events;
+ return result;
}
HashSet<ServerConnector> maybeDetached = new HashSet<ServerConnector>();
@@ -1976,6 +2018,7 @@ public class ApplicationConnection {
}
if (childConnector.getParent() != parentConnector) {
childConnector.setParent(parentConnector);
+ result.parentChanged.add(childConnector);
// Not detached even if previously removed from
// parent
maybeDetached.remove(childConnector);
@@ -2007,7 +2050,7 @@ public class ApplicationConnection {
event.setOldChildren(oldComponents);
event.setConnector(parentConnector);
ccc.setChildComponents(newComponents);
- events.add(event);
+ result.events.add(event);
}
} else if (!newComponents.isEmpty()) {
VConsole.error("Hierachy claims "
@@ -2047,10 +2090,10 @@ public class ApplicationConnection {
* removed from its parent but not added to any other parent
*/
for (ServerConnector removed : maybeDetached) {
- recursivelyDetach(removed, events);
+ recursivelyDetach(removed, result.events);
}
- return events;
+ return result;
}
diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java
index d11be76a80..f8088d63a2 100644
--- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java
+++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java
@@ -151,18 +151,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector
// Style names
updateWidgetStyleNames();
- // Set captions
- if (delegateCaptionHandling()) {
- ServerConnector parent = getParent();
- if (parent instanceof HasComponentsConnector) {
- ((HasComponentsConnector) parent).updateCaption(this);
- } else if (parent == null && !(this instanceof UIConnector)) {
- VConsole.error("Parent of connector "
- + Util.getConnectorString(this)
- + " is null. This is typically an indication of a broken component hierarchy");
- }
- }
-
/*
* updateComponentSize need to be after caption update so caption can be
* taken into account