// will hold the UIDL security key (for XSS protection) once received
private String uidlSecurityKey = "init";
+ private static final FastStringMap<FastStringSet> allStateFieldsCache = FastStringMap
+ .create();
+
private final HashMap<String, String> resourcesMap = new HashMap<String, String>();
/**
Type stateType = AbstractConnector
.getStateType(component);
- Set<String> changedProperties = sce
- .getChangedProperties();
- for (String propertyName : changedProperties) {
+ FastStringSet changedProperties = sce
+ .getChangedPropertiesFastSet();
+ JsArrayString dump = changedProperties.dump();
+ for (int i = 0; i < dump.length(); i++) {
+ String propertyName = dump.get(i);
Property property = stateType
.getProperty(propertyName);
String method = property
private void unregisterRemovedConnectors() {
int unregistered = 0;
- List<ServerConnector> currentConnectors = new ArrayList<ServerConnector>(
- connectorMap.getConnectors());
- for (ServerConnector c : currentConnectors) {
+ JsArrayObject<ServerConnector> currentConnectors = connectorMap
+ .getConnectorsAsJsArray();
+ int size = currentConnectors.size();
+ for (int i = 0; i < size; i++) {
+ ServerConnector c = currentConnectors.get(i);
if (c.getParent() != null) {
if (!c.getParent().getChildren().contains(c)) {
VConsole.error("ERROR: Connector is connected to a parent but the parent does not contain the connector");
.getName(), null), stateJson, state,
ApplicationConnection.this);
- Set<String> changedProperties = new HashSet<String>();
+ FastStringSet changedProperties = FastStringSet
+ .create();
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, "");
+ FastStringSet allStateFields = getAllStateFields(AbstractConnector
+ .getStateType(connector));
+ changedProperties.addAll(allStateFields);
}
StateChangeEvent event = new StateChangeEvent(
// 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, "");
+ FastStringSet changedProperties = getAllStateFields(AbstractConnector
+ .getStateType(connector));
StateChangeEvent event = new StateChangeEvent(connector,
changedProperties);
return events;
}
+ private FastStringSet getAllStateFields(Type type) {
+ FastStringSet fields;
+ fields = allStateFieldsCache.get(type.getBaseTypeName());
+ if (fields == null) {
+ fields = FastStringSet.create();
+ addAllStateFields(type, fields, "");
+ allStateFieldsCache.put(type.getBaseTypeName(), fields);
+ }
+ return fields;
+ }
+
/**
* Recursively adds the names of all properties in the provided
* state type.
* the base name of the current object
*/
private void addAllStateFields(Type type,
- Set<String> foundProperties, String context) {
+ FastStringSet foundProperties, String context) {
try {
JsArrayObject<Property> properties = type
.getPropertiesAsArray();
* @param context
* the base name of the current object
*/
- private void addJsonFields(JSONObject json, Set<String> fields,
+ private void addJsonFields(JSONObject json, FastStringSet fields,
String context) {
for (String key : json.keySet()) {
String fieldName = context + key;
return result;
}
- HashSet<ServerConnector> maybeDetached = new HashSet<ServerConnector>();
+ FastStringSet maybeDetached = FastStringSet.create();
ValueMap hierarchies = json.getValueMap("hierarchy");
JsArrayString hierarchyKeys = hierarchies.getKeyArray();
result.parentChanged.add(childConnector);
// Not detached even if previously removed from
// parent
- maybeDetached.remove(childConnector);
+ maybeDetached.remove(childConnectorId);
}
}
* cleared if it is later on added to some other
* parent.
*/
- maybeDetached.add(oldChild);
+ maybeDetached.add(oldChild.getConnectorId());
}
}
} catch (final Throwable e) {
* Connector is in maybeDetached at this point if it has been
* removed from its parent but not added to any other parent
*/
- for (ServerConnector removed : maybeDetached) {
+ JsArrayString maybeDetachedArray = maybeDetached.dump();
+ for (int i = 0; i < maybeDetachedArray.length(); i++) {
+ ServerConnector removed = connectorMap
+ .getConnector(maybeDetachedArray.get(i));
recursivelyDetach(removed, result.events);
}
package com.vaadin.client.communication;
import java.io.Serializable;
-import java.util.Collections;
+import java.util.HashSet;
import java.util.Set;
import com.google.gwt.event.shared.EventHandler;
+import com.vaadin.client.FastStringSet;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
*/
public static final Type<StateChangeHandler> TYPE = new Type<StateChangeHandler>();
- private Set<String> changedProperties;
+ private final FastStringSet changedProperties;
+
+ /**
+ * Used to cache a Set representation of the changedProperties if one is
+ * needed.
+ */
+ private Set<String> changedPropertiesSet;
@Override
public Type<StateChangeHandler> getAssociatedType() {
return TYPE;
}
+ /**
+ * Creates a new state change event.
+ *
+ * @param connector
+ * the event whose state has changed
+ * @param changedPropertiesSet
+ * a set of names of the changed properties
+ * @deprecated As of 7.0.1, use
+ * {@link #StateChangeEvent(ServerConnector, FastStringSet)}
+ * instead for improved performance.
+ */
+ @Deprecated
+ public StateChangeEvent(ServerConnector connector,
+ Set<String> changedPropertiesSet) {
+ setConnector(connector);
+ this.changedPropertiesSet = changedPropertiesSet;
+ changedProperties = FastStringSet.create();
+ for (String property : changedPropertiesSet) {
+ changedProperties.add(property);
+ }
+ }
+
/**
* Creates a new state change event.
*
* a set of names of the changed properties
*/
public StateChangeEvent(ServerConnector connector,
- Set<String> changedProperties) {
+ FastStringSet changedProperties) {
setConnector(connector);
this.changedProperties = changedProperties;
}
* Gets the properties that have changed.
*
* @return a set of names of the changed properties
+ *
+ * @deprecated As of 7.0.1, use {@link #getChangedPropertiesFastSet()} or
+ * {@link #hasPropertyChanged(String)} instead for improved
+ * performance.
*/
+ @Deprecated
public Set<String> getChangedProperties() {
- return Collections.unmodifiableSet(changedProperties);
+ if (changedPropertiesSet == null) {
+ changedPropertiesSet = new HashSet<String>();
+ changedProperties.addAllTo(changedPropertiesSet);
+ }
+ return changedPropertiesSet;
+ }
+
+ /**
+ * Gets the properties that have changed.
+ *
+ * @return a set of names of the changed properties
+ *
+ */
+ public FastStringSet getChangedPropertiesFastSet() {
+ return changedProperties;
+ }
+
+ /**
+ * Checks whether the give property has changed.
+ *
+ * @param property
+ * the name of the property to check
+ * @return <code>true</code> if the property has changed, else
+ * <code>false></code>
+ */
+ public boolean hasPropertyChanged(String property) {
+ return changedProperties.contains(property);
}
}
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ComponentConnector;
-import com.vaadin.client.ConnectorMap;
import com.vaadin.client.HasComponentsConnector;
import com.vaadin.client.LayoutManager;
import com.vaadin.client.ServerConnector;
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
- ConnectorMap paintableMap = ConnectorMap.get(getConnection());
-
- Set<String> changedProperties = stateChangeEvent.getChangedProperties();
- if (changedProperties.contains("id")) {
+ if (stateChangeEvent.hasPropertyChanged("id")) {
if (getState().id != null) {
getWidget().getElement().setId(getState().id);
} else if (!initialStateEvent) {
*
* @see com.vaadin.client.ComponentConnector#flush()
*/
+ @Override
public void flush() {
// No generic implementation. Override if needed
}
import java.util.Map;
import java.util.Set;
+import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.web.bindery.event.shared.HandlerRegistration;
import com.vaadin.client.ApplicationConnection;
+import com.vaadin.client.FastStringMap;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.Util;
import com.vaadin.client.VConsole;
private String id;
private HandlerManager handlerManager;
- private Map<String, HandlerManager> statePropertyHandlerManagers;
+ private FastStringMap<HandlerManager> statePropertyHandlerManagers;
private Map<String, Collection<ClientRpc>> rpcImplementations;
private final boolean debugLogging = false;
}
if (statePropertyHandlerManagers != null
&& event instanceof StateChangeEvent) {
- for (String property : ((StateChangeEvent) event)
- .getChangedProperties()) {
- HandlerManager manager = statePropertyHandlerManagers
- .get(property);
- if (manager != null) {
- manager.fireEvent(event);
+ StateChangeEvent stateChangeEvent = (StateChangeEvent) event;
+ JsArrayString keys = statePropertyHandlerManagers.getKeys();
+ for (int i = 0; i < keys.length(); i++) {
+ String property = keys.get(i);
+ if (stateChangeEvent.hasPropertyChanged(property)) {
+ statePropertyHandlerManagers.get(property).fireEvent(event);
}
}
}
private HandlerManager ensureHandlerManager(String propertyName) {
if (statePropertyHandlerManagers == null) {
- statePropertyHandlerManagers = new HashMap<String, HandlerManager>();
+ statePropertyHandlerManagers = FastStringMap.create();
}
HandlerManager manager = statePropertyHandlerManagers.get(propertyName);
if (manager == null) {
package com.vaadin.client.ui.button;
-import java.util.Set;
-
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
blurHandlerRegistration = EventHelper.updateBlurHandler(this,
blurHandlerRegistration);
- Set<String> changedProperties = stateChangeEvent.getChangedProperties();
- if (changedProperties.contains("caption")
- || changedProperties.contains("htmlContentAllowed")) {
+ if (stateChangeEvent.hasPropertyChanged("caption")
+ || stateChangeEvent.hasPropertyChanged("htmlContentAllowed")) {
// Set text
if (getState().htmlContentAllowed) {
getWidget().setHtml(getState().caption);
*/
package com.vaadin.client.ui.colorpicker;
-import java.util.Set;
-
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.vaadin.client.communication.StateChangeEvent;
public void onStateChanged(StateChangeEvent stateChangeEvent) {
// NOTE: this method is called after @DelegateToWidget
super.onStateChanged(stateChangeEvent);
- Set<String> changedProperties = stateChangeEvent.getChangedProperties();
- if (changedProperties.contains("color")) {
+ if (stateChangeEvent.hasPropertyChanged("color")) {
refreshColor();
if (getState().showDefaultCaption
setCaption(getState().color);
}
}
- if (changedProperties.contains("caption")
- || changedProperties.contains("htmlContentAllowed")
- || changedProperties.contains("showDefaultCaption")) {
+ if (stateChangeEvent.hasPropertyChanged("caption")
+ || stateChangeEvent.hasPropertyChanged("htmlContentAllowed")
+ || stateChangeEvent.hasPropertyChanged("showDefaultCaption")) {
setCaption(getCaption());
}
*/
package com.vaadin.client.ui.colorpicker;
-import java.util.Set;
-
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
- Set<String> changedProperties = stateChangeEvent.getChangedProperties();
- if (changedProperties.contains("cursorX")
- || changedProperties.contains("cursorY")) {
+ if (stateChangeEvent.hasPropertyChanged("cursorX")
+ || stateChangeEvent.hasPropertyChanged("cursorY")) {
getWidget().setCursor(getState().cursorX, getState().cursorY);
}
- if (changedProperties.contains("bgColor")) {
+ if (stateChangeEvent.hasPropertyChanged("bgColor")) {
getWidget().setBGColor(getState().bgColor);
}
}
*/
package com.vaadin.client.ui.colorpicker;
-import java.util.Set;
-
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
- Set<String> changedProperties = stateChangeEvent.getChangedProperties();
- if (changedProperties.contains("rowCount")
- || changedProperties.contains("columnCount")
- || changedProperties.contains("updateGrid")) {
+ if (stateChangeEvent.hasPropertyChanged("rowCount")
+ || stateChangeEvent.hasPropertyChanged("columnCount")
+ || stateChangeEvent.hasPropertyChanged("updateGrid")) {
getWidget().updateGrid(getState().rowCount, getState().columnCount);
}
- if (changedProperties.contains("changedX")
- || changedProperties.contains("changedY")
- || changedProperties.contains("changedColor")
- || changedProperties.contains("updateColor")) {
+ if (stateChangeEvent.hasPropertyChanged("changedX")
+ || stateChangeEvent.hasPropertyChanged("changedY")
+ || stateChangeEvent.hasPropertyChanged("changedColor")
+ || stateChangeEvent.hasPropertyChanged("updateColor")) {
getWidget().updateColor(getState().changedColor,
getState().changedX, getState().changedY);