diff options
author | Leif Åstrand <leif@vaadin.com> | 2013-04-05 13:53:30 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2013-04-08 10:03:53 +0300 |
commit | 453099e29f5d6ca12f448eb9bb4264efd087ebf3 (patch) | |
tree | d34d261b08f314134e420ea1bf7acb04febe470f /client | |
parent | 708319b840380a9d96c510d5e24f2890071ec470 (diff) | |
download | vaadin-framework-453099e29f5d6ca12f448eb9bb4264efd087ebf3.tar.gz vaadin-framework-453099e29f5d6ca12f448eb9bb4264efd087ebf3.zip |
Require implementing hasTooltip if there's custom tooltip logic (#11052)
Change-Id: I3038b97d9a7c7e144a325ce87aa849309b9b31c4
Diffstat (limited to 'client')
12 files changed, 92 insertions, 55 deletions
diff --git a/client/src/com/vaadin/client/ComponentConnector.java b/client/src/com/vaadin/client/ComponentConnector.java index eecc3fda0c..f923a9dade 100644 --- a/client/src/com/vaadin/client/ComponentConnector.java +++ b/client/src/com/vaadin/client/ComponentConnector.java @@ -119,6 +119,11 @@ public interface ComponentConnector extends ServerConnector { /** * Gets the tooltip info for the given element. + * <p> + * When overriding this method, {@link #hasTooltip()} should also be + * overridden to return <code>true</code> in all situations where this + * method might return a non-empty result. + * </p> * * @param element * The element to lookup a tooltip for @@ -128,6 +133,20 @@ public interface ComponentConnector extends ServerConnector { public TooltipInfo getTooltipInfo(Element element); /** + * 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. + * <p> + * This is only done to optimize performance, so in cases where the status + * is not known, it's safer to return <code>true</code> so that there will + * be a tooltip handler even though it might not be needed in all cases. + * + * @return <code>true</code> if some part of the component might have a + * tooltip, otherwise <code>false</code> + */ + public boolean hasTooltip(); + + /** * Called for the active (focused) connector when a situation occurs that * the focused connector might have buffered changes which need to be * processed before other activity takes place. diff --git a/client/src/com/vaadin/client/VTooltip.java b/client/src/com/vaadin/client/VTooltip.java index 53770f4201..61d155d668 100644 --- a/client/src/com/vaadin/client/VTooltip.java +++ b/client/src/com/vaadin/client/VTooltip.java @@ -340,6 +340,9 @@ public class VTooltip extends VOverlay { } if (connector != null && info != null) { + assert connector.hasTooltip() : "getTooltipInfo for " + + Util.getConnectorString(connector) + + " returned a tooltip even though hasTooltip claims there are no tooltips for the connector."; currentTooltipInfo = info; return true; } diff --git a/client/src/com/vaadin/client/metadata/TypeDataStore.java b/client/src/com/vaadin/client/metadata/TypeDataStore.java index dff02749f8..aa37d75dc8 100644 --- a/client/src/com/vaadin/client/metadata/TypeDataStore.java +++ b/client/src/com/vaadin/client/metadata/TypeDataStore.java @@ -41,7 +41,6 @@ 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(); @@ -291,22 +290,4 @@ 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 5475c128c1..13d1e6d56c 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -35,7 +35,6 @@ 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; @@ -430,40 +429,13 @@ public abstract class AbstractComponentConnector extends AbstractConnector } } - /** - * {@inheritDoc} - * - * <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) { return new TooltipInfo(getState().description, getState().errorMessage); } - /** - * 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; - } - + @Override + public boolean hasTooltip() { // Normally, there is a tooltip if description or errorMessage is set AbstractComponentState state = getState(); if (state.description != null && !state.description.equals("")) { diff --git a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java index c36521b3ac..285d15792b 100644 --- a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java +++ b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java @@ -411,6 +411,15 @@ public class CalendarConnector extends AbstractComponentConnector implements return tooltipInfo; } + @Override + public boolean hasTooltip() { + /* + * Tooltips are not processed until updateFromUIDL, so we can't be sure + * that there are no tooltips during onStateChange when this is used. + */ + return true; + } + private void updateMonthView(List<CalendarState.Day> days, List<CalendarState.Event> events) { CalendarState state = getState(); diff --git a/client/src/com/vaadin/client/ui/form/FormConnector.java b/client/src/com/vaadin/client/ui/form/FormConnector.java index 22277b6974..acd0e917fc 100644 --- a/client/src/com/vaadin/client/ui/form/FormConnector.java +++ b/client/src/com/vaadin/client/ui/form/FormConnector.java @@ -231,4 +231,9 @@ public class FormConnector extends AbstractComponentContainerConnector // as a part of the actual layout return null; } + + @Override + public boolean hasTooltip() { + return false; + } } diff --git a/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java b/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java index 1a952959f3..c65f689f7a 100644 --- a/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java @@ -141,4 +141,13 @@ public class FormLayoutConnector extends AbstractLayoutConnector { return info; } + @Override + public boolean hasTooltip() { + /* + * Tooltips are fetched from child connectors -> there's no quick way of + * checking whether there might a tooltip hiding somewhere + */ + return true; + } + } diff --git a/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java b/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java index d8ca73a401..3e22ebb05b 100644 --- a/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java +++ b/client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java @@ -209,4 +209,14 @@ public class MenuBarConnector extends AbstractComponentConnector implements return info; } + + @Override + public boolean hasTooltip() { + /* + * Item tooltips are not processed until updateFromUIDL, so we can't be + * sure that there are no tooltips during onStateChange when this method + * is used. + */ + return true; + } } diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java index fc31cdf8ea..c8b4af83f2 100644 --- a/client/src/com/vaadin/client/ui/table/TableConnector.java +++ b/client/src/com/vaadin/client/ui/table/TableConnector.java @@ -396,6 +396,16 @@ public class TableConnector extends AbstractHasComponentsConnector implements } @Override + public boolean hasTooltip() { + /* + * Tooltips for individual rows and cells are not processed until + * updateFromUIDL, so we can't be sure that there are no tooltips during + * onStateChange when this method is used. + */ + return true; + } + + @Override public void onConnectorHierarchyChange( ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { // TODO Move code from updateFromUIDL to this method diff --git a/client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java b/client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java index f1ad5e792a..04a514738d 100644 --- a/client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java +++ b/client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java @@ -138,6 +138,16 @@ public class TabsheetConnector extends TabsheetBaseConnector implements } @Override + public boolean hasTooltip() { + /* + * Tab tooltips are not processed until updateFromUIDL, so we can't be + * sure that there are no tooltips during onStateChange when this method + * is used. + */ + return true; + } + + @Override public void onConnectorHierarchyChange( ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { // TODO Move code from updateFromUIDL to this method diff --git a/client/src/com/vaadin/client/ui/tree/TreeConnector.java b/client/src/com/vaadin/client/ui/tree/TreeConnector.java index d8ad7d6634..ef016c31b7 100644 --- a/client/src/com/vaadin/client/ui/tree/TreeConnector.java +++ b/client/src/com/vaadin/client/ui/tree/TreeConnector.java @@ -332,4 +332,14 @@ public class TreeConnector extends AbstractComponentConnector implements return info; } + @Override + public boolean hasTooltip() { + /* + * Item tooltips are not processed until updateFromUIDL, so we can't be + * sure that there are no tooltips during onStateChange when this method + * is used. + */ + return true; + } + } diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 0843b3069d..07481063c3 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -48,7 +48,6 @@ import com.vaadin.client.ConnectorHierarchyChangeEvent; import com.vaadin.client.ConnectorMap; import com.vaadin.client.Focusable; import com.vaadin.client.Paintable; -import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; import com.vaadin.client.VConsole; import com.vaadin.client.communication.StateChangeEvent; @@ -527,13 +526,13 @@ public class UIConnector extends AbstractSingleComponentContainerConnector } @Override - public TooltipInfo getTooltipInfo(com.google.gwt.dom.client.Element element) { + public boolean hasTooltip() { /* - * Override method to make AbstractComponentConnector.hasTooltip() - * return true so there's a top level handler that takes care of hiding - * tooltips whenever the mouse is moved somewhere else. + * Always return true so there's always top level tooltip handler that + * takes care of hiding tooltips whenever the mouse is moved somewhere + * else. */ - return super.getTooltipInfo(element); + return true; } /** |