* before the component is updated so the value is correct if called from
* updatedFromUIDL.
*
+ * @param paintable
+ * The connector to register event listeners for
* @param eventIdentifier
* The identifier for the event
* @return true if at least one listener has been registered on server side
* for the event identified by eventIdentifier.
+ * @deprecated Use {@link ComponentState#hasEventListener(String)}
+ * instead
*/
+ @Deprecated
public boolean hasEventListeners(ComponentConnector paintable,
String eventIdentifier) {
- return connectorMap.hasEventListeners(paintable, eventIdentifier);
+ return paintable.hasEventListener(eventIdentifier);
}
/**
*/
@Deprecated
public boolean isReadOnly();
+
+ public boolean hasEventListener(String eventIdentifier);
+
}
import java.util.HashMap;
-import com.google.gwt.core.client.JsArrayString;
import com.vaadin.terminal.gwt.client.RenderInformation.Size;
class ComponentDetail {
}
}
- private JsArrayString eventListeners;
-
- /**
- * Stores the event listeners registered on server-side and passed along in
- * the UIDL.
- *
- * @param componentUIDL
- * The UIDL for the component
- * @since 6.2
- */
- native void registerEventListenersFromUIDL(UIDL uidl)
- /*-{
- this.@com.vaadin.terminal.gwt.client.ComponentDetail::eventListeners = uidl[1].eventListeners;
- }-*/;
-
- /**
- * Checks if there is a registered server side listener for the event.
- *
- * @param eventIdentifier
- * The identifier for the event
- * @return true if at least one listener has been registered on server side
- * for the event identified by eventIdentifier.
- */
- public boolean hasEventListeners(String eventIdentifier) {
- if (eventListeners != null) {
- int l = eventListeners.length();
- for (int i = 0; i < l; i++) {
- if (eventListeners.get(i).equals(eventIdentifier)) {
- return true;
- }
- }
- }
- return false;
- }
}
package com.vaadin.terminal.gwt.client;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import com.vaadin.terminal.gwt.client.communication.SharedState;
import com.vaadin.terminal.gwt.client.communication.URLReference;
private URLReference icon = null;
private List<String> styles = null;
private String debugId = null;
+ /**
+ * A set of event identifiers with registered listeners.
+ */
+ private Set<String> registeredEventListeners = null;
/**
* Returns the component height as set by the server.
this.debugId = debugId;
}
+ /**
+ * Gets the identifiers for the event listeners that have been registered
+ * for the component (using an event id)
+ *
+ * @return A set of event identifiers or null if no identifiers have been
+ * registered
+ */
+ public Set<String> getRegisteredEventListeners() {
+ return registeredEventListeners;
+ }
+
+ /**
+ * Sets the identifiers for the event listeners that have been registered
+ * for the component (using an event id)
+ *
+ * @param registeredEventListeners
+ * The new set of identifiers or null if no identifiers have been
+ * registered
+ */
+ public void setRegisteredEventListeners(Set<String> registeredEventListeners) {
+ this.registeredEventListeners = registeredEventListeners;
+ }
+
+ /**
+ * Adds an event listener id.
+ *
+ * @param eventListenerId
+ * The event identifier to add
+ */
+ public void addRegisteredEventListener(String eventListenerId) {
+ if (registeredEventListeners == null) {
+ registeredEventListeners = new HashSet<String>();
+ }
+ registeredEventListeners.add(eventListenerId);
+
+ }
+
+ /**
+ * Removes an event listener id.
+ *
+ * @param eventListenerId
+ * The event identifier to remove
+ */
+ public void removeRegisteredEventListener(String eventIdentifier) {
+ if (registeredEventListeners == null) {
+ return;
+ }
+ registeredEventListeners.remove(eventIdentifier);
+ if (registeredEventListeners.size() == 0) {
+ registeredEventListeners = null;
+ }
+
+ }
+
}
return result.toArray(new ComponentConnector[result.size()]);
}
- /**
- * FIXME: Should not be here
- *
- * @param pid
- * @param uidl
- */
- @Deprecated
- public void registerEventListenersFromUIDL(String pid, UIDL uidl) {
- ComponentDetail cd = idToComponentDetail.get(pid);
- if (cd == null) {
- throw new IllegalArgumentException("Pid must not be null");
- }
-
- cd.registerEventListenersFromUIDL(uidl);
-
- }
-
/**
* FIXME: Should not be here
*
}
- /**
- * FIXME: Should not be here
- *
- * @param componentConnector
- * @return
- */
- @Deprecated
- public boolean hasEventListeners(ComponentConnector componentConnector,
- String eventIdentifier) {
- return getComponentDetail(componentConnector).hasEventListeners(
- eventIdentifier);
- }
-
/**
* Tests if the widget is the root widget of a {@link ComponentConnector}.
*
return;
}
- clickEventHandler.handleEventHandlerRegistration(client);
+ clickEventHandler.handleEventHandlerRegistration();
HashSet<String> unrenderedPids = new HashSet<String>(
getWidget().pidToComponentWrappper.keySet());
*/
package com.vaadin.terminal.gwt.client.ui;
+import java.util.Set;
+
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.Focusable;
}
ConnectorMap paintableMap = ConnectorMap.get(getConnection());
- // register the listened events by the server-side to the event-handler
- // of the component
- paintableMap.registerEventListenersFromUIDL(getConnectorId(), uidl);
-
// Visibility
setVisible(!uidl.getBooleanAttribute("invisible"), uidl);
this.parent = parent;
}
+ /**
+ * Checks if there is a registered server side listener for the given event
+ * identifier.
+ *
+ * @param eventIdentifier
+ * The identifier to check for
+ * @return true if an event listener has been registered with the given
+ * event identifier on the server side, false otherwise
+ */
+ public boolean hasEventListener(String eventIdentifier) {
+ Set<String> reg = getState().getRegisteredEventListeners();
+ return (reg != null && reg.contains(eventIdentifier));
+ }
+
}
}
getWidget().setEnabled(isEnabled());
- clickEventHandler.handleEventHandlerRegistration(client);
+ clickEventHandler.handleEventHandlerRegistration();
if (getState().hasStyles()) {
getWidget().componentStyleNames = getState().getStyles();
} else {
import com.google.gwt.user.client.Element;
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.MouseEventDetails;
import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder;
protected String clickEventIdentifier;
protected ComponentConnector paintable;
- private ApplicationConnection client;
public ClickEventHandler(ComponentConnector paintable,
String clickEventIdentifier) {
this.clickEventIdentifier = clickEventIdentifier;
}
- public void handleEventHandlerRegistration(ApplicationConnection client) {
- this.client = client;
+ public void handleEventHandlerRegistration() {
// Handle registering/unregistering of click handler depending on if
// server side listeners have been added or removed.
if (hasEventListener()) {
final H handler, DomEvent.Type<H> type);
protected ApplicationConnection getApplicationConnection() {
- return client;
+ return paintable.getConnection();
}
public boolean hasEventListener() {
- return getApplicationConnection().hasEventListeners(paintable,
- clickEventIdentifier);
+ return paintable.hasEventListener(clickEventIdentifier);
}
protected void fireClick(NativeEvent event) {
- ApplicationConnection client = getApplicationConnection();
- String pid = ConnectorMap.get(getApplicationConnection())
- .getConnectorId(paintable);
+ String pid = paintable.getConnectorId();
MouseEventDetails mouseDetails = MouseEventDetailsBuilder
.buildMouseEventDetails(event, getRelativeToElement());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("mouseDetails", mouseDetails.serialize());
- client.updateVariable(pid, clickEventIdentifier, parameters, true);
+ paintable.getConnection().updateVariable(pid, clickEventIdentifier,
+ parameters, true);
}
if (!isRealUpdate(uidl)) {
return;
}
- clickEventHandler.handleEventHandlerRegistration(client);
+ clickEventHandler.handleEventHandlerRegistration();
getWidget().setMarginAndSpacingStyles(
new VMarginInfo(uidl.getIntAttribute("margins")),
boolean clearBrowserElement = true;
- clickEventHandler.handleEventHandlerRegistration(client);
+ clickEventHandler.handleEventHandlerRegistration();
if (uidl.hasAttribute("type")) {
getWidget().type = uidl.getStringAttribute("type");
if (!isRealUpdate(uidl)) {
return;
}
- clickEventHandler.handleEventHandlerRegistration(client);
+ clickEventHandler.handleEventHandlerRegistration();
int cols = uidl.getIntAttribute("w");
int rows = uidl.getIntAttribute("h");
return;
}
- clickEventHandler.handleEventHandlerRegistration(client);
+ clickEventHandler.handleEventHandlerRegistration();
getWidget().client = client;
getWidget().id = uidl.getId();
@Override
public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) {
ConnectorMap paintableMap = ConnectorMap.get(getConnection());
- // register the listened events by the server-side to the event-handler
- // of the component
- paintableMap.registerEventListenersFromUIDL(getConnectorId(), uidl);
-
getWidget().rendering = true;
getWidget().id = getConnectorId();
boolean firstPaint = getWidget().connection == null;
}
getWidget().setStyleName(styles.trim());
- clickEventHandler.handleEventHandlerRegistration(client);
+ clickEventHandler.handleEventHandlerRegistration();
if (!getWidget().isEmbedded() && getState().getCaption() != null) {
// only change window title if we're in charge of the whole page
getWidget().immediate = getState().isImmediate();
- getWidget().listenTextChangeEvents = client.hasEventListeners(this,
- "ie");
+ getWidget().listenTextChangeEvents = hasEventListener("ie");
if (getWidget().listenTextChangeEvents) {
getWidget().textChangeEventMode = uidl
.getStringAttribute(VTextField.ATTR_TEXTCHANGE_EVENTMODE);
}
getWidget().visibilityChangesDisabled = false;
- clickEventHandler.handleEventHandlerRegistration(client);
+ clickEventHandler.handleEventHandlerRegistration();
getWidget().immediate = getState().isImmediate();
}
public static Iterable<Component> getChildComponents(HasComponents cc) {
+ // TODO This must be moved to Root/Panel
if (cc instanceof Root) {
Root root = (Root) cc;
List<Component> children = new ArrayList<Component>();
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
*/
private EventRouter eventRouter = null;
- /**
- * A set of event identifiers with registered listeners.
- */
- private Set<String> eventIdentifiers = null;
-
/**
* The internal error message of the component.
*/
// Only paint content of visible components.
if (isVisibleInContext()) {
- if (eventIdentifiers != null) {
- target.addAttribute("eventListeners",
- eventIdentifiers.toArray());
- }
-
paintContent(target);
final ErrorMessage error = getErrorMessage();
if (eventRouter == null) {
eventRouter = new EventRouter();
}
- if (eventIdentifiers == null) {
- eventIdentifiers = new HashSet<String>();
- }
boolean needRepaint = !eventRouter.hasListeners(eventType);
eventRouter.addListener(eventType, target, method);
if (needRepaint) {
- eventIdentifiers.add(eventIdentifier);
+ getState().addRegisteredEventListener(eventIdentifier);
requestRepaint();
}
}
if (eventRouter != null) {
eventRouter.removeListener(eventType, target);
if (!eventRouter.hasListeners(eventType)) {
- eventIdentifiers.remove(eventIdentifier);
+ getState().removeRegisteredEventListener(eventIdentifier);
requestRepaint();
}
}