diff options
author | John Ahlroos <john@vaadin.com> | 2012-08-29 09:15:02 +0300 |
---|---|---|
committer | John Ahlroos <john@vaadin.com> | 2012-08-29 09:15:02 +0300 |
commit | 62b86fc5c854bd17132798756b34c960a45ee07d (patch) | |
tree | 0bc17cb9eca2a9be54bb426d458a342280356109 /client | |
parent | 9f4ba8e57ea6944951c6a7e597b068defcb9b823 (diff) | |
parent | f7f5c6b09ad7f11315373c72cf83e3ebc4ad6aaf (diff) | |
download | vaadin-framework-62b86fc5c854bd17132798756b34c960a45ee07d.tar.gz vaadin-framework-62b86fc5c854bd17132798756b34c960a45ee07d.zip |
Merge branch 'master' into layoutgraph
Diffstat (limited to 'client')
7 files changed, 104 insertions, 31 deletions
diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java index 2eccd9bb8c..1150f122b2 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java @@ -207,7 +207,6 @@ public class ApplicationConfiguration implements EntryPoint { private boolean standalone; private ErrorMessage communicationError; private ErrorMessage authorizationError; - private boolean useDebugIdInDom = true; private int heartbeatInterval; private HashMap<Integer, String> unknownComponents; @@ -327,9 +326,6 @@ public class ApplicationConfiguration implements EntryPoint { uiId = jsoConfiguration.getConfigInteger(UIConstants.UI_ID_PARAMETER) .intValue(); - // null -> true - useDebugIdInDom = jsoConfiguration.getConfigBoolean("useDebugIdInDom") != Boolean.FALSE; - // null -> false standalone = jsoConfiguration.getConfigBoolean("standalone") == Boolean.TRUE; @@ -401,10 +397,6 @@ public class ApplicationConfiguration implements EntryPoint { return getJsoConfiguration(id).getApplicationVersion(); } - public boolean useDebugIdInDOM() { - return useDebugIdInDom; - } - public Class<? extends ServerConnector> getConnectorClassByEncodedTag( int tag) { Class<? extends ServerConnector> type = classes.get(tag); diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 450972ddc6..a984433907 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -18,6 +18,7 @@ package com.vaadin.terminal.gwt.client; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -74,6 +75,7 @@ import com.vaadin.terminal.gwt.client.metadata.Property; import com.vaadin.terminal.gwt.client.metadata.Type; import com.vaadin.terminal.gwt.client.metadata.TypeData; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.terminal.gwt.client.ui.AbstractConnector; import com.vaadin.terminal.gwt.client.ui.VContextMenu; import com.vaadin.terminal.gwt.client.ui.UI.UIConnector; import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager; @@ -1130,13 +1132,14 @@ public class ApplicationConnection { int startProcessing = updateDuration.elapsedMillis(); // Ensure that all connectors that we are about to update exist - createConnectorsIfNeeded(json); + Set<ServerConnector> createdConnectors = createConnectorsIfNeeded(json); updateDuration.logDuration(" * Creating connectors completed", 10); // Update states, do not fire events - Collection<StateChangeEvent> pendingStateChangeEvents = updateConnectorState(json); + Collection<StateChangeEvent> pendingStateChangeEvents = updateConnectorState( + json, createdConnectors); updateDuration.logDuration( " * Update of connector states completed", 10); @@ -1280,17 +1283,9 @@ public class ApplicationConnection { ServerConnector connector = sce.getConnector(); if (connector instanceof ComponentConnector) { ComponentConnector component = (ComponentConnector) connector; - Type type = TypeData.getType(component.getClass()); - Type stateType; - try { - stateType = type.getMethod("getState") - .getReturnType(); - } catch (NoDataException e) { - throw new RuntimeException( - "Can not find the state type for " - + type.getSignature(), e); - } + Type stateType = AbstractConnector + .getStateType(component); Set<String> changedProperties = sce .getChangedProperties(); @@ -1385,13 +1380,15 @@ public class ApplicationConnection { VConsole.log("* Unregistered " + unregistered + " connectors"); } - private void createConnectorsIfNeeded(ValueMap json) { + private Set<ServerConnector> createConnectorsIfNeeded(ValueMap json) { VConsole.log(" * Creating connectors (if needed)"); if (!json.containsKey("types")) { - return; + return Collections.emptySet(); } + Set<ServerConnector> createdConnectors = new HashSet<ServerConnector>(); + ValueMap types = json.getValueMap("types"); JsArrayString keyArray = types.getKeyArray(); for (int i = 0; i < keyArray.length(); i++) { @@ -1411,7 +1408,8 @@ public class ApplicationConnection { // Connector does not exist so we must create it if (connectorClass != UIConnector.class) { // create, initialize and register the paintable - getConnector(connectorId, connectorType); + connector = getConnector(connectorId, connectorType); + createdConnectors.add(connector); } else { // First UIConnector update. Before this the // UIConnector has been created but not @@ -1421,11 +1419,13 @@ public class ApplicationConnection { uIConnector); uIConnector.doInit(connectorId, ApplicationConnection.this); + createdConnectors.add(uIConnector); } } catch (final Throwable e) { VConsole.error(e); } } + return createdConnectors; } private void updateVaadin6StyleConnectors(ValueMap json) { @@ -1480,12 +1480,15 @@ public class ApplicationConnection { } private Collection<StateChangeEvent> updateConnectorState( - ValueMap json) { + ValueMap json, Set<ServerConnector> newConnectors) { ArrayList<StateChangeEvent> events = new ArrayList<StateChangeEvent>(); VConsole.log(" * Updating connector states"); if (!json.containsKey("state")) { return events; } + HashSet<ServerConnector> remainingNewConnectors = new HashSet<ServerConnector>( + newConnectors); + // set states for all paintables mentioned in "state" ValueMap states = json.getValueMap("state"); JsArrayString keyArray = states.getKeyArray(); @@ -1514,6 +1517,16 @@ public class ApplicationConnection { Set<String> changedProperties = new HashSet<String>(); addJsonFields(stateJson, changedProperties, ""); + if (newConnectors.contains(connector)) { + remainingNewConnectors.remove(connector); + // Fire events for properties using the default + // value for newly created connectors + addAllStateFields( + AbstractConnector + .getStateType(connector), + changedProperties, ""); + } + StateChangeEvent event = new StateChangeEvent( connector, changedProperties); @@ -1524,10 +1537,59 @@ public class ApplicationConnection { } } + // Fire events for properties using the default value for newly + // created connectors even if there were no state changes + for (ServerConnector connector : remainingNewConnectors) { + Set<String> changedProperties = new HashSet<String>(); + addAllStateFields( + AbstractConnector.getStateType(connector), + changedProperties, ""); + + StateChangeEvent event = new StateChangeEvent(connector, + changedProperties); + + events.add(event); + + } + return events; } /** + * Recursively adds the names of all properties in the provided + * state type. + * + * @param type + * the type to process + * @param foundProperties + * a set of all currently added properties + * @param context + * the base name of the current object + */ + private void addAllStateFields(Type type, + Set<String> foundProperties, String context) { + try { + Collection<Property> properties = type.getProperties(); + for (Property property : properties) { + String propertyName = context + property.getName(); + foundProperties.add(propertyName); + + Type propertyType = property.getType(); + if (propertyType.hasProperties()) { + addAllStateFields(propertyType, foundProperties, + propertyName + "."); + } + } + } catch (NoDataException e) { + throw new IllegalStateException( + "No property info for " + + type + + ". Did you remember to compile the right widgetset?", + e); + } + } + + /** * Recursively adds the names of all fields in all objects in the * provided json object. * diff --git a/client/src/com/vaadin/terminal/gwt/client/ComponentLocator.java b/client/src/com/vaadin/terminal/gwt/client/ComponentLocator.java index 7c75913126..70f2efa982 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ComponentLocator.java +++ b/client/src/com/vaadin/terminal/gwt/client/ComponentLocator.java @@ -459,7 +459,7 @@ public class ComponentLocator { ServerConnector connector = ConnectorMap.get(client) .getConnector(id); if (connector == null) { - // Lookup by debugId + // Lookup by component id // TODO Optimize this connector = findConnectorById(client.getRootConnector(), id.substring(5)); @@ -615,7 +615,7 @@ public class ComponentLocator { private ServerConnector findConnectorById(ServerConnector root, String id) { SharedState state = root.getState(); if (state instanceof ComponentState - && id.equals(((ComponentState) state).getDebugId())) { + && id.equals(((ComponentState) state).getId())) { return root; } for (ServerConnector child : root.getChildren()) { diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java b/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java index d869cc2599..d019ff27e0 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java @@ -94,4 +94,8 @@ public class Type { return TypeDataStore.findSerializer(this); } + public boolean hasProperties() { + return TypeDataStore.hasProperties(this); + } + } diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java index 9c19410c88..0fc8f3b3bf 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java @@ -223,4 +223,8 @@ public class TypeDataStore { } return (JSONSerializer<?>) factoryCreator.invoke(null); } + + public static boolean hasProperties(Type type) { + return get().properties.containsKey(type); + } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java index 9ccf1deb7c..b0ad12adde 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java @@ -124,8 +124,8 @@ implements ComponentConnector { public void onStateChanged(StateChangeEvent stateChangeEvent) { ConnectorMap paintableMap = ConnectorMap.get(getConnection()); - if (getState().getDebugId() != null) { - getWidget().getElement().setId(getState().getDebugId()); + if (getState().getId() != null) { + getWidget().getElement().setId(getState().getId()); } else { getWidget().getElement().removeAttribute("id"); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java index fabd750f8b..69b3b47338 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java @@ -280,10 +280,8 @@ StateChangeHandler { * @return A new state object */ protected SharedState createState() { - Type connectorType = TypeData.getType(getClass()); try { - Type stateType = connectorType.getMethod("getState") - .getReturnType(); + Type stateType = getStateType(this); Object stateInstance = stateType.createInstance(); return (SharedState) stateInstance; } catch (NoDataException e) { @@ -296,6 +294,19 @@ StateChangeHandler { } + public static Type getStateType(ServerConnector connector) { + try { + return TypeData.getType(connector.getClass()).getMethod("getState") + .getReturnType(); + } catch (NoDataException e) { + throw new IllegalStateException( + "There is no information about the state for " + + Util.getSimpleName(connector) + + ". Did you remember to compile the right widgetset?", + e); + } + } + @Override public ServerConnector getParent() { return parent; |