diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-02-15 16:28:07 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-02-18 12:20:27 +0000 |
commit | f759408c0fa75cc1610b6a598737bf4eec039104 (patch) | |
tree | 981a812ea95c312faa7e3039a3c56b6d872d0bd3 /client | |
parent | d4af8b07d51a1e7b1b4eaa828be596b780afd34f (diff) | |
download | vaadin-framework-f759408c0fa75cc1610b6a598737bf4eec039104.tar.gz vaadin-framework-f759408c0fa75cc1610b6a598737bf4eec039104.zip |
Only add tooltip listeners when needed (#11051)
Change-Id: I2b097ed67d59260390cd939b2f2d844548b5fced
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/metadata/TypeDataStore.java | 19 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/AbstractComponentConnector.java | 67 |
2 files changed, 71 insertions, 15 deletions
diff --git a/client/src/com/vaadin/client/metadata/TypeDataStore.java b/client/src/com/vaadin/client/metadata/TypeDataStore.java index 5b466146a3..c1eca0a168 100644 --- a/client/src/com/vaadin/client/metadata/TypeDataStore.java +++ b/client/src/com/vaadin/client/metadata/TypeDataStore.java @@ -38,6 +38,7 @@ public class TypeDataStore { private final FastStringSet delayedMethods = FastStringSet.create(); private final FastStringSet lastOnlyMethods = FastStringSet.create(); + private final FastStringSet hasGetTooltipInfo = FastStringSet.create(); private final FastStringMap<Type> returnTypes = FastStringMap.create(); private final FastStringMap<Invoker> invokers = FastStringMap.create(); @@ -276,4 +277,22 @@ public class TypeDataStore { public static boolean hasProperties(Type type) { return get().properties.containsKey(type.getSignature()); } + + /** + * @deprecated As of 7.0.1. This is just a hack to avoid breaking backwards + * compatibility and will be removed in Vaadin 7.1 + */ + @Deprecated + public void setHasGetTooltipInfo(Class<?> clazz) { + hasGetTooltipInfo.add(getType(clazz).getSignature()); + } + + /** + * @deprecated As of 7.0.1. This is just a hack to avoid breaking backwards + * compatibility and will be removed in Vaadin 7.1 + */ + @Deprecated + public static boolean getHasGetTooltipInfo(Class clazz) { + return get().hasGetTooltipInfo.contains(getType(clazz).getSignature()); + } } diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index e3bdc5a93f..51051644c0 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -15,9 +15,6 @@ */ package com.vaadin.client.ui; -import java.util.ArrayList; -import java.util.List; - import com.google.gwt.core.client.JsArrayString; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Focusable; @@ -38,6 +35,7 @@ import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.metadata.NoDataException; import com.vaadin.client.metadata.Type; import com.vaadin.client.metadata.TypeData; +import com.vaadin.client.metadata.TypeDataStore; import com.vaadin.client.ui.datefield.PopupDateFieldConnector; import com.vaadin.client.ui.ui.UIConnector; import com.vaadin.shared.AbstractComponentState; @@ -56,6 +54,8 @@ public abstract class AbstractComponentConnector extends AbstractConnector private boolean initialStateEvent = true; + private boolean tooltipListenersAttached = false; + /** * The style names from getState().getStyles() which are currently applied * to the widget. @@ -68,14 +68,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector public AbstractComponentConnector() { } - @Override - protected void init() { - super.init(); - - getConnection().getVTooltip().connectHandlersToWidget(getWidget()); - - } - /** * Creates and returns the widget for this VPaintableWidget. This method * should only be called once when initializing the paintable. @@ -164,6 +156,17 @@ public abstract class AbstractComponentConnector extends AbstractConnector updateComponentSize(); + Profiler.enter("AbstractComponentContainer.onStateChanged check tooltip"); + if (!tooltipListenersAttached && hasTooltip()) { + /* + * Add event handlers for tooltips if they are needed but have not + * yet been added. + */ + tooltipListenersAttached = true; + getConnection().getVTooltip().connectHandlersToWidget(getWidget()); + } + Profiler.leave("AbstractComponentContainer.onStateChanged check tooltip"); + initialStateEvent = false; Profiler.leave("AbstractComponentConnector.onStateChanged"); @@ -415,11 +418,16 @@ public abstract class AbstractComponentConnector extends AbstractConnector } } - /* - * (non-Javadoc) + /** + * {@inheritDoc} * - * @see com.vaadin.client.ComponentConnector#getTooltipInfo(com. - * google.gwt.dom.client.Element) + * <p> + * When overriding this method, {@link #hasTooltip()} should also be + * overridden to return true in all situations where this method might + * return a non-empty result. + * </p> + * + * @see ComponentConnector#getTooltipInfo(Element) */ @Override public TooltipInfo getTooltipInfo(Element element) { @@ -427,6 +435,35 @@ public abstract class AbstractComponentConnector extends AbstractConnector } /** + * Check whether there might be a tooltip for this component. The framework + * will only add event listeners for automatically handling tooltips (using + * {@link #getTooltipInfo(Element)}) if this method returns true. + * + * @return <code>true</code> if some part of the component might have a + * tooltip, otherwise <code>false</code> + */ + private boolean hasTooltip() { + /* + * Hack to avoid breaking backwards compatibility - use a generator to + * know whether there's a custom implementation of getTooltipInfo, and + * in that case always assume that there might be tooltip. + */ + if (TypeDataStore.getHasGetTooltipInfo(getClass())) { + return true; + } + + // Normally, there is a tooltip if description or errorMessage is set + AbstractComponentState state = getState(); + if (state.description != null && !state.description.equals("")) { + return true; + } else if (state.errorMessage != null && !state.errorMessage.equals("")) { + return true; + } else { + return false; + } + } + + /** * Gets the icon set for this component. * * @return the URL of the icon, or <code>null</code> if no icon has been |