]> source.dussan.org Git - vaadin-framework.git/commitdiff
Require implementing hasTooltip if there's custom tooltip logic (#11052)
authorLeif Åstrand <leif@vaadin.com>
Fri, 5 Apr 2013 10:53:30 +0000 (13:53 +0300)
committerLeif Åstrand <leif@vaadin.com>
Mon, 8 Apr 2013 07:03:53 +0000 (10:03 +0300)
Change-Id: I3038b97d9a7c7e144a325ce87aa849309b9b31c4

15 files changed:
client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/WidgetInitVisitor.java
client/src/com/vaadin/client/ComponentConnector.java
client/src/com/vaadin/client/VTooltip.java
client/src/com/vaadin/client/metadata/TypeDataStore.java
client/src/com/vaadin/client/ui/AbstractComponentConnector.java
client/src/com/vaadin/client/ui/calendar/CalendarConnector.java
client/src/com/vaadin/client/ui/form/FormConnector.java
client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java
client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java
client/src/com/vaadin/client/ui/table/TableConnector.java
client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java
client/src/com/vaadin/client/ui/tree/TreeConnector.java
client/src/com/vaadin/client/ui/ui/UIConnector.java

index 2be3bf5a16f271c8eef6ea9790221b538d26150c..f8aa58606407a322507677fa1b69283131874773 100644 (file)
@@ -334,22 +334,6 @@ public class ConnectorBundleLoaderFactory extends Generator {
         writeGetters(logger, w, bundle);
         writeSerializers(logger, w, bundle);
         writeDelegateToWidget(logger, w, bundle);
-        writeHasGetTooltip(logger, w, bundle);
-    }
-
-    /**
-     * @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
-    private void writeHasGetTooltip(TreeLogger logger, SplittingSourceWriter w,
-            ConnectorBundle bundle) {
-        Set<JClassType> types = bundle.getHasGetTooltip();
-        for (JClassType type : types) {
-            w.println("store.setHasGetTooltipInfo(%s);",
-                    getClassLiteralString(type));
-            w.splitIfNeeded();
-        }
     }
 
     private void writeDelegateToWidget(TreeLogger logger,
index f6dc982f15e1615cd472eaa2ba1e23cb79880ff3..cbdd3e89aaf5343d0cffd178981c05baf541e998 100644 (file)
@@ -63,7 +63,6 @@ public class ConnectorBundle {
     private final Set<JClassType> needsGwtConstructor = new HashSet<JClassType>();
     private final Set<JClassType> visitedTypes = new HashSet<JClassType>();
     private final Set<JClassType> needsProxySupport = new HashSet<JClassType>();
-    private final Set<JClassType> hasGetTooltip = new HashSet<JClassType>();
 
     private final Map<JClassType, Set<String>> identifiers = new HashMap<JClassType, Set<String>>();
     private final Map<JClassType, Set<JMethod>> needsReturnType = new HashMap<JClassType, Set<JMethod>>();
@@ -620,37 +619,4 @@ public class ConnectorBundle {
         return Collections.unmodifiableSet(needsDelegateToWidget);
     }
 
-    /**
-     * @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 Set<JClassType> getHasGetTooltip() {
-        return Collections.unmodifiableSet(hasGetTooltip);
-    }
-
-    /**
-     * @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 setHasGetTooltip(JClassType type) {
-        if (!isHasGetTooltip(type)) {
-            hasGetTooltip.add(type);
-        }
-    }
-
-    /**
-     * @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
-    private boolean isHasGetTooltip(JClassType type) {
-        if (hasGetTooltip.contains(type)) {
-            return true;
-        } else {
-            return previousBundle != null
-                    && previousBundle.isHasGetTooltip(type);
-        }
-    }
 }
\ No newline at end of file
index 662ecf872bf8419fc03e789d92c9345fdf270a2e..4de9d2ae9976c2d2fff4b512ce0bb80c0546ea34 100644 (file)
@@ -47,25 +47,6 @@ public class WidgetInitVisitor extends TypeVisitor {
                 bundle.setNeedsReturnType(type, getWidget);
             }
 
-            // Hack to detect when getTooltipInfo has a custom implementation
-            // #11051
-            JClassType getTooltipParamType = type.getOracle().findType(
-                    "com.google.gwt.dom.client.Element");
-            JMethod getTooltipInfoMethod = findInheritedMethod(type,
-                    "getTooltipInfo", getTooltipParamType);
-            if (getTooltipInfoMethod == null) {
-                logger.log(Type.ERROR, "Could not find getTooltipInfo in "
-                        + type.getQualifiedSourceName());
-                throw new UnableToCompleteException();
-            }
-            JClassType enclosingType = getTooltipInfoMethod.getEnclosingType();
-            if (!enclosingType.getQualifiedSourceName().equals(
-                    AbstractComponentConnector.class.getCanonicalName())) {
-                logger.log(Type.WARN, type.getQualifiedSourceName()
-                        + " has overridden getTooltipInfo");
-                bundle.setHasGetTooltip(type);
-            }
-
             // Check state properties for @DelegateToWidget
             JMethod getState = findInheritedMethod(type, "getState");
             JClassType stateType = getState.getReturnType().isClass();
index eecc3fda0cfaad392a5cf84a601a02e1cd81d944..f923a9dade6b516cdec0454e0f00b5e52134b974 100644 (file)
@@ -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
@@ -127,6 +132,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
index 53770f42010ba14fa1152218726d0d0646aee649..61d155d668e3c2e4241c5127d0f2f8487ce05a74 100644 (file)
@@ -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;
             }
index dff02749f8ddb700e61cabceb40dac7e0a998b0c..aa37d75dc866468f82009363d21872910a360a17 100644 (file)
@@ -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());
-    }
 }
index 5475c128c1a47241718b2a0e862b016d7a75a2cb..13d1e6d56cc5636ab3df01e209db6f300fdb2f47 100644 (file)
@@ -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("")) {
index c36521b3ac38708052e406b6ebe8f5fbd8da3f47..285d15792ba1b75c70107c94fcd48ecea473dafb 100644 (file)
@@ -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();
index 22277b697496bd8a54d1edfc8f9cf65dd117635c..acd0e917fc7f4a84cdf6ef2a6a92c448fe186f92 100644 (file)
@@ -231,4 +231,9 @@ public class FormConnector extends AbstractComponentContainerConnector
         // as a part of the actual layout
         return null;
     }
+
+    @Override
+    public boolean hasTooltip() {
+        return false;
+    }
 }
index 1a952959f34e87143178c8755629b1a3384a9f76..c65f689f7a92c70b67e8aaf47a6a731a022d7d50 100644 (file)
@@ -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;
+    }
+
 }
index d8ca73a401e9fea81a9af196e695f4fb3d54ab0b..3e22ebb05bef484d29e9ea9c36f2650cf3622b96 100644 (file)
@@ -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;
+    }
 }
index fc31cdf8eae26521ba39f4c68d36950e3f5733c6..c8b4af83f2cd0d1dd2fc42f493e44f7eb628aa08 100644 (file)
@@ -395,6 +395,16 @@ public class TableConnector extends AbstractHasComponentsConnector implements
         return info;
     }
 
+    @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) {
index f1ad5e792af898d1cd0b608e61cb05dfacf0366e..04a514738dfb6cb5c714336d2875b17e36b17943 100644 (file)
@@ -137,6 +137,16 @@ public class TabsheetConnector extends TabsheetBaseConnector implements
         return info;
     }
 
+    @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) {
index d8ad7d6634410f16610625316415a4f3e492d3f8..ef016c31b783b64a5cfa820ea450eb982a484db5 100644 (file)
@@ -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;
+    }
+
 }
index 0843b3069d5011479c5c79766d00ac329dc9a2e3..07481063c3b967218a63b6868c464409a1232aca 100644 (file)
@@ -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;
     }
 
     /**