From 18ac8b25501e28cfcfc3271d2c6722a00fa01b98 Mon Sep 17 00:00:00 2001 From: Sami Viitanen Date: Thu, 28 Jun 2012 15:43:11 +0300 Subject: [PATCH] Tooltips are now handled by the connector and not the widget (#8425) --- .../gwt/client/ApplicationConnection.java | 99 +------- .../gwt/client/ComponentConnector.java | 11 + .../terminal/gwt/client/ConnectorMap.java | 38 ---- .../terminal/gwt/client/TooltipInfo.java | 19 ++ .../vaadin/terminal/gwt/client/VCaption.java | 27 ++- .../vaadin/terminal/gwt/client/VTooltip.java | 214 +++++++++++++----- .../client/ui/AbstractComponentConnector.java | 29 ++- .../gwt/client/ui/button/VButton.java | 5 - .../gwt/client/ui/checkbox/VCheckBox.java | 4 - .../gwt/client/ui/combobox/VFilterSelect.java | 22 +- .../gwt/client/ui/datefield/VDateField.java | 11 - .../VDragAndDropWrapper.java | 12 - .../gwt/client/ui/embedded/VEmbedded.java | 2 - .../ui/formlayout/FormLayoutConnector.java | 35 +++ .../gwt/client/ui/formlayout/VFormLayout.java | 21 +- .../terminal/gwt/client/ui/label/VLabel.java | 4 - .../terminal/gwt/client/ui/link/VLink.java | 5 - .../client/ui/listselect/TooltipListBox.java | 41 ---- .../gwt/client/ui/listselect/VListSelect.java | 15 +- .../gwt/client/ui/menubar/VMenuBar.java | 30 --- .../client/ui/nativebutton/VNativeButton.java | 6 - .../client/ui/nativeselect/VNativeSelect.java | 16 +- .../AbstractOrderedLayoutConnector.java | 1 + .../gwt/client/ui/panel/PanelConnector.java | 1 + .../terminal/gwt/client/ui/panel/VPanel.java | 4 - .../gwt/client/ui/popupview/VPopupView.java | 10 - .../gwt/client/ui/slider/VSlider.java | 6 - .../gwt/client/ui/table/TableConnector.java | 25 ++ .../gwt/client/ui/table/VScrollTable.java | 70 ++---- .../client/ui/tabsheet/TabsheetConnector.java | 30 ++- .../gwt/client/ui/tabsheet/VTabsheet.java | 16 +- .../gwt/client/ui/textfield/VTextField.java | 5 - .../gwt/client/ui/tree/TreeConnector.java | 47 +++- .../terminal/gwt/client/ui/tree/VTree.java | 21 +- .../gwt/client/ui/upload/VUpload.java | 11 - .../gwt/client/ui/window/VWindow.java | 5 - .../AllComponentTooltipTest.java | 50 ++++ .../abstractcomponent/TooltipTests.html | 77 +++++++ .../abstractcomponent/TooltipTests.java | 97 ++++++++ 39 files changed, 649 insertions(+), 493 deletions(-) delete mode 100644 src/com/vaadin/terminal/gwt/client/ui/listselect/TooltipListBox.java create mode 100644 tests/testbench/com/vaadin/tests/components/abstractcomponent/AllComponentTooltipTest.java create mode 100644 tests/testbench/com/vaadin/tests/components/abstractcomponent/TooltipTests.html create mode 100644 tests/testbench/com/vaadin/tests/components/abstractcomponent/TooltipTests.java diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 8484d4abea..da4dfa08dc 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -35,7 +35,6 @@ import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Widget; @@ -2323,57 +2322,8 @@ public class ApplicationConnection { /* Extended title handling */ - /** - * Data showed in tooltips are stored centrilized as it may be needed in - * varios place: caption, layouts, and in owner components themselves. - * - * Updating TooltipInfo is done in updateComponent method. - * - */ - public TooltipInfo getTooltipTitleInfo(ComponentConnector titleOwner, - Object key) { - if (null == titleOwner) { - return null; - } - return connectorMap.getTooltipInfo(titleOwner, key); - } - private final VTooltip tooltip = new VTooltip(this); - /** - * Component may want to delegate Tooltip handling to client. Layouts add - * Tooltip (description, errors) to caption, but some components may want - * them to appear one other elements too. - * - * Events wanted by this handler are same as in Tooltip.TOOLTIP_EVENTS - * - * @param event - * @param owner - */ - public void handleTooltipEvent(Event event, ComponentConnector owner) { - tooltip.handleTooltipEvent(event, owner, null); - - } - - /** - * Component may want to delegate Tooltip handling to client. Layouts add - * Tooltip (description, errors) to caption, but some components may want - * them to appear one other elements too. - * - * Events wanted by this handler are same as in Tooltip.TOOLTIP_EVENTS - * - * @param event - * @param owner - * @param key - * the key for tooltip if this is "additional" tooltip, null for - * components "main tooltip" - */ - public void handleTooltipEvent(Event event, ComponentConnector owner, - Object key) { - tooltip.handleTooltipEvent(event, owner, key); - - } - private ConnectorMap connectorMap = GWT.create(ConnectorMap.class); protected String getUidlSecurityKey() { @@ -2400,34 +2350,6 @@ public class ApplicationConnection { return rootConnector; } - /** - * If component has several tooltips in addition to the one provided by - * {@link com.vaadin.ui.AbstractComponent}, component can register them with - * this method. - *

- * Component must also pipe events to - * {@link #handleTooltipEvent(Event, ComponentConnector, Object)} method. - *

- * This method can also be used to deregister tooltips by using null as - * tooltip - * - * @param paintable - * Paintable "owning" this tooltip - * @param key - * key assosiated with given tooltip. Can be any object. For - * example a related dom element. Same key must be given for - * {@link #handleTooltipEvent(Event, ComponentConnector, Object)} - * method. - * - * @param tooltip - * the TooltipInfo object containing details shown in tooltip, - * null if deregistering tooltip - */ - public void registerTooltip(ComponentConnector paintable, Object key, - TooltipInfo tooltip) { - connectorMap.registerTooltip(paintable, key, tooltip); - } - /** * Gets the {@link ApplicationConfiguration} for the current application. * @@ -2510,15 +2432,15 @@ public class ApplicationConnection { // connectorMap.unregisterConnector(p); } + /** + * Get VTooltip instance related to application connection + * + * @return VTooltip instance + */ public VTooltip getVTooltip() { return tooltip; } - @Deprecated - public void handleTooltipEvent(Event event, Widget owner, Object key) { - handleTooltipEvent(event, getConnectorMap().getConnector(owner), key); - } - /** * Method provided for backwards compatibility. Duties previously done by * this method is now handled by the state change event handler in @@ -2546,17 +2468,6 @@ public class ApplicationConnection { return false; } - @Deprecated - public void handleTooltipEvent(Event event, Widget owner) { - handleTooltipEvent(event, getConnectorMap().getConnector(owner)); - - } - - @Deprecated - public void registerTooltip(Widget owner, Object key, TooltipInfo info) { - registerTooltip(getConnectorMap().getConnector(owner), key, info); - } - @Deprecated public boolean hasEventListeners(Widget widget, String eventIdentifier) { return hasEventListeners(getConnectorMap().getConnector(widget), diff --git a/src/com/vaadin/terminal/gwt/client/ComponentConnector.java b/src/com/vaadin/terminal/gwt/client/ComponentConnector.java index 4e6a690a3c..95e9a4cf78 100644 --- a/src/com/vaadin/terminal/gwt/client/ComponentConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ComponentConnector.java @@ -4,6 +4,7 @@ package com.vaadin.terminal.gwt.client; +import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; /** @@ -104,4 +105,14 @@ public interface ComponentConnector extends ServerConnector { */ public void setWidgetEnabled(boolean widgetEnabled); + /** + * Gets the tooltip info for the given element. + * + * @param element + * The element to lookup a tooltip for + * @return The tooltip for the element or null if no tooltip is defined for + * this element. + */ + public TooltipInfo getTooltipInfo(Element element); + } diff --git a/src/com/vaadin/terminal/gwt/client/ConnectorMap.java b/src/com/vaadin/terminal/gwt/client/ConnectorMap.java index efb50b5e00..8bc4a4aacf 100644 --- a/src/com/vaadin/terminal/gwt/client/ConnectorMap.java +++ b/src/com/vaadin/terminal/gwt/client/ConnectorMap.java @@ -200,48 +200,10 @@ public class ConnectorMap { return idToConnector.size(); } - /** - * FIXME: Should be moved to VAbstractPaintableWidget - * - * @param paintable - * @return - */ - @Deprecated - public TooltipInfo getTooltipInfo(ComponentConnector paintable, Object key) { - ComponentDetail componentDetail = getComponentDetail(paintable); - if (componentDetail == null) { - return null; - } - return componentDetail.getTooltipInfo(key); - } - - @Deprecated - public TooltipInfo getWidgetTooltipInfo(Widget widget, Object key) { - ComponentConnector connector = getConnector(widget); - if (connector == null) { - return null; - } - return getTooltipInfo(connector, key); - } - public Collection getConnectors() { return Collections.unmodifiableCollection(idToConnector.values()); } - /** - * FIXME: Should not be here - * - * @param componentConnector - * @return - */ - @Deprecated - public void registerTooltip(ComponentConnector componentConnector, - Object key, TooltipInfo tooltip) { - getComponentDetail(componentConnector).putAdditionalTooltip(key, - tooltip); - - } - /** * Tests if the widget is the root widget of a {@link ComponentConnector}. * diff --git a/src/com/vaadin/terminal/gwt/client/TooltipInfo.java b/src/com/vaadin/terminal/gwt/client/TooltipInfo.java index fb33a56c56..1ad1ea43cd 100644 --- a/src/com/vaadin/terminal/gwt/client/TooltipInfo.java +++ b/src/com/vaadin/terminal/gwt/client/TooltipInfo.java @@ -16,6 +16,11 @@ public class TooltipInfo { setTitle(tooltip); } + public TooltipInfo(String tooltip, String errorMessage) { + setTitle(tooltip); + setErrorMessage(errorMessage); + } + public String getTitle() { return title; } @@ -32,4 +37,18 @@ public class TooltipInfo { errorMessageHtml = errorMessage; } + /** + * Checks is a message has been defined for the tooltip. + * + * @return true if title or error message is present, false if both are + * empty + */ + public boolean hasMessage() { + return (title != null && !title.isEmpty()) + || (errorMessageHtml != null && errorMessageHtml.isEmpty()); + } + + public boolean equals(TooltipInfo other) { + return (other != null && other.title == title && other.errorMessageHtml == errorMessageHtml); + } } diff --git a/src/com/vaadin/terminal/gwt/client/VCaption.java b/src/com/vaadin/terminal/gwt/client/VCaption.java index 6f3fcf2c3a..2f7ba87870 100644 --- a/src/com/vaadin/terminal/gwt/client/VCaption.java +++ b/src/com/vaadin/terminal/gwt/client/VCaption.java @@ -35,6 +35,8 @@ public class VCaption extends HTML { ICON, CAPTION, REQUIRED, ERROR } + private TooltipInfo tooltipInfo = null; + /** * Creates a caption that is not linked to a {@link ComponentConnector}. * @@ -74,8 +76,6 @@ public class VCaption extends HTML { } setStyleName(CLASSNAME); - sinkEvents(VTooltip.TOOLTIP_EVENTS); - } /** @@ -345,9 +345,6 @@ public class VCaption extends HTML { public void onBrowserEvent(Event event) { super.onBrowserEvent(event); final Element target = DOM.eventGetTarget(event); - if (client != null && owner != null && target != getElement()) { - client.handleTooltipEvent(event, owner); - } if (DOM.eventGetType(event) == Event.ONLOAD && icon.getElement() == target) { @@ -555,6 +552,26 @@ public class VCaption extends HTML { } } + /** + * Sets the tooltip that should be shown for the caption + * + * @param tooltipInfo + * The tooltip that should be shown or null if no tooltip should + * be shown + */ + public void setTooltipInfo(TooltipInfo tooltipInfo) { + this.tooltipInfo = tooltipInfo; + } + + /** + * Returns the tooltip that should be shown for the caption + * + * @return The tooltip to show or null if no tooltip should be shown + */ + public TooltipInfo getTooltipInfo() { + return tooltipInfo; + } + protected Element getTextElement() { return captionText; } diff --git a/src/com/vaadin/terminal/gwt/client/VTooltip.java b/src/com/vaadin/terminal/gwt/client/VTooltip.java index 70f4a0de0a..7fd3a3238b 100644 --- a/src/com/vaadin/terminal/gwt/client/VTooltip.java +++ b/src/com/vaadin/terminal/gwt/client/VTooltip.java @@ -3,12 +3,19 @@ */ package com.vaadin.terminal.gwt.client; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.KeyDownEvent; +import com.google.gwt.event.dom.client.KeyDownHandler; +import com.google.gwt.event.dom.client.MouseMoveEvent; +import com.google.gwt.event.dom.client.MouseMoveHandler; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ui.VOverlay; /** @@ -27,15 +34,12 @@ public class VTooltip extends VOverlay { private static final int QUICK_OPEN_DELAY = 100; VErrorMessage em = new VErrorMessage(); Element description = DOM.createDiv(); - private ComponentConnector tooltipOwner; private boolean closing = false; private boolean opening = false; private ApplicationConnection ac; // Open next tooltip faster. Disabled after 2 sec of showTooltip-silence. private boolean justClosed = false; - // If this is "additional" tooltip, this field contains the key for it - private Object tooltipKey; public VTooltip(ApplicationConnection client) { super(false, false, true); @@ -115,51 +119,30 @@ public class VTooltip extends VOverlay { } } - public void showTooltip(ComponentConnector owner, Event event, Object key) { - if (closing && tooltipOwner == owner && tooltipKey == key) { - // return to same tooltip, cancel closing - closeTimer.cancel(); - closing = false; - justClosedTimer.cancel(); - justClosed = false; - return; - } + private void showTooltip() { - if (closing) { + // Close current tooltip + if (isShowing()) { closeNow(); } - updatePosition(event); - - if (opening) { - showTimer.cancel(); - } - tooltipOwner = owner; - tooltipKey = key; - // Schedule timer for showing the tooltip according to if it was // recently closed or not. - if (justClosed) { - showTimer.schedule(QUICK_OPEN_DELAY); - } else { - showTimer.schedule(OPEN_DELAY); - } + int timeout = justClosed ? QUICK_OPEN_DELAY : OPEN_DELAY; + showTimer.schedule(timeout); opening = true; } private void closeNow() { - if (closing) { - hide(); - tooltipOwner = null; - setWidth(""); - closing = false; - } + hide(); + setWidth(""); + closing = false; } private Timer showTimer = new Timer() { @Override public void run() { - TooltipInfo info = ac.getTooltipTitleInfo(tooltipOwner, tooltipKey); + TooltipInfo info = tooltipEventHandler.getTooltipInfo(); if (null != info) { show(info); } @@ -187,7 +170,6 @@ public class VTooltip extends VOverlay { if (opening) { showTimer.cancel(); opening = false; - tooltipOwner = null; } if (!isAttached()) { return; @@ -209,24 +191,6 @@ public class VTooltip extends VOverlay { public void updatePosition(Event event) { tooltipEventMouseX = DOM.eventGetClientX(event); tooltipEventMouseY = DOM.eventGetClientY(event); - - } - - public void handleTooltipEvent(Event event, ComponentConnector owner, - Object key) { - final int type = DOM.eventGetType(event); - if ((VTooltip.TOOLTIP_EVENTS & type) == type) { - if (type == Event.ONMOUSEOVER) { - showTooltip(owner, event, key); - } else if (type == Event.ONMOUSEMOVE) { - updatePosition(event); - } else { - hideTooltip(); - } - } else { - // non-tooltip event, hide tooltip - hideTooltip(); - } } @Override @@ -235,17 +199,149 @@ public class VTooltip extends VOverlay { // cancel closing event if tooltip is mouseovered; the user might want // to scroll of cut&paste - switch (type) { - case Event.ONMOUSEOVER: + if (type == Event.ONMOUSEOVER) { + // Cancel closing so tooltip stays open and user can copy paste the + // tooltip closeTimer.cancel(); closing = false; - break; - case Event.ONMOUSEOUT: + } + } + + /** + * Replace current open tooltip with new content + */ + public void replaceCurrentTooltip() { + if (closing) { + closeTimer.cancel(); + closeNow(); + } + + TooltipInfo info = tooltipEventHandler.getTooltipInfo(); + if (null != info) { + show(info); + } + opening = false; + } + + private class TooltipEventHandler implements MouseMoveHandler, + ClickHandler, KeyDownHandler { + + /** + * Current element hovered + */ + private com.google.gwt.dom.client.Element currentElement = null; + + /** + * Current tooltip active + */ + private TooltipInfo currentTooltipInfo = null; + + /** + * Get current active tooltip information + * + * @return Current active tooltip information or null + */ + public TooltipInfo getTooltipInfo() { + return currentTooltipInfo; + } + + /** + * Locate connector and it's tooltip for given element + * + * @param element + * Element used in search + * @return true if connector and tooltip found + */ + private boolean resolveConnector(Element element) { + + ComponentConnector connector = Util.getConnectorForElement(ac, ac + .getRootConnector().getWidget(), element); + + // Try to find first connector with proper tooltip info + TooltipInfo info = null; + while (connector != null) { + + info = connector.getTooltipInfo(element); + + if (info != null && info.hasMessage()) { + break; + } + + if (!(connector.getParent() instanceof ComponentConnector)) { + connector = null; + info = null; + break; + } + connector = (ComponentConnector) connector.getParent(); + } + + if (connector != null && info != null) { + currentTooltipInfo = info; + return true; + } + + return false; + } + + /** + * Handle hide event + * + * @param event + * Event causing hide + */ + private void handleHideEvent() { hideTooltip(); - break; - default: - // NOP + currentTooltipInfo = null; + } + + public void onMouseMove(MouseMoveEvent mme) { + Event event = Event.as(mme.getNativeEvent()); + com.google.gwt.dom.client.Element element = Element.as(event + .getEventTarget()); + + // We can ignore move event if it's handled by move or over already + if (currentElement == element) { + return; + } + currentElement = element; + + boolean connectorAndTooltipFound = resolveConnector((com.google.gwt.user.client.Element) element); + if (!connectorAndTooltipFound) { + if (isShowing()) { + handleHideEvent(); + } else { + currentTooltipInfo = null; + } + } else { + updatePosition(event); + if (isShowing()) { + replaceCurrentTooltip(); + } else { + showTooltip(); + } + } + } + + public void onClick(ClickEvent event) { + handleHideEvent(); + } + + public void onKeyDown(KeyDownEvent event) { + handleHideEvent(); } } + private final TooltipEventHandler tooltipEventHandler = new TooltipEventHandler(); + + /** + * Connects DOM handlers to widget that are needed for tooltip presentation. + * + * @param widget + * Widget which DOM handlers are connected + */ + public void connectHandlersToWidget(Widget widget) { + widget.addDomHandler(tooltipEventHandler, MouseMoveEvent.getType()); + widget.addDomHandler(tooltipEventHandler, ClickEvent.getType()); + widget.addDomHandler(tooltipEventHandler, KeyDownEvent.getType()); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java index f0b9d518ca..2f55cc4d16 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java @@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.Set; +import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Focusable; import com.google.gwt.user.client.ui.HasEnabled; import com.google.gwt.user.client.ui.Widget; @@ -37,6 +38,12 @@ 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. @@ -99,16 +106,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector String styleName = getStyleNames(getWidget().getStylePrimaryName()); getWidget().setStyleName(styleName); - // Update tooltip - TooltipInfo tooltipInfo = paintableMap.getTooltipInfo(this, null); - if (getState().hasDescription()) { - tooltipInfo.setTitle(getState().getDescription()); - } else { - tooltipInfo.setTitle(null); - } - // add error info to tooltip if present - tooltipInfo.setErrorMessage(getState().getErrorMessage()); - // Set captions if (delegateCaptionHandling()) { ServerConnector parent = getParent(); @@ -315,4 +312,16 @@ public abstract class AbstractComponentConnector extends AbstractConnector + ") has been unregistered. Widget was removed."); } } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.terminal.gwt.client.ComponentConnector#getTooltipInfo(com. + * google.gwt.dom.client.Element) + */ + public TooltipInfo getTooltipInfo(Element element) { + return new TooltipInfo(getState().getDescription(), getState() + .getErrorMessage()); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/button/VButton.java b/src/com/vaadin/terminal/gwt/client/ui/button/VButton.java index 0cd8bc54f4..bb3d8e2985 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/button/VButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/button/VButton.java @@ -18,7 +18,6 @@ import com.google.gwt.user.client.ui.FocusWidget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Icon; public class VButton extends FocusWidget implements ClickHandler { @@ -90,7 +89,6 @@ public class VButton extends FocusWidget implements ClickHandler { setTabIndex(0); sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS | Event.KEYEVENTS); - sinkEvents(VTooltip.TOOLTIP_EVENTS); setStyleName(CLASSNAME); @@ -128,9 +126,6 @@ public class VButton extends FocusWidget implements ClickHandler { * -onload event handler added (for icon handling) */ public void onBrowserEvent(Event event) { - if (client != null) { - client.handleTooltipEvent(event, this); - } if (DOM.eventGetType(event) == Event.ONLOAD) { Util.notifyParentOfSizeChange(this, true); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/checkbox/VCheckBox.java b/src/com/vaadin/terminal/gwt/client/ui/checkbox/VCheckBox.java index fd90796ea5..a6eec2de8a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/checkbox/VCheckBox.java +++ b/src/com/vaadin/terminal/gwt/client/ui/checkbox/VCheckBox.java @@ -31,7 +31,6 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements public VCheckBox() { setStyleName(CLASSNAME); - sinkEvents(VTooltip.TOOLTIP_EVENTS); Element el = DOM.getFirstChild(getElement()); while (el != null) { DOM.sinkEvents(el, @@ -53,9 +52,6 @@ public class VCheckBox extends com.google.gwt.user.client.ui.CheckBox implements if (event.getTypeInt() == Event.ONLOAD) { Util.notifyParentOfSizeChange(this, true); } - if (client != null) { - client.handleTooltipEvent(event, this); - } } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/combobox/VFilterSelect.java b/src/com/vaadin/terminal/gwt/client/ui/combobox/VFilterSelect.java index 8c5d521445..9831001024 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/combobox/VFilterSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/combobox/VFilterSelect.java @@ -54,7 +54,6 @@ import com.vaadin.terminal.gwt.client.Focusable; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Field; import com.vaadin.terminal.gwt.client.ui.SubPartAware; import com.vaadin.terminal.gwt.client.ui.VLazyExecutor; @@ -824,21 +823,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, * The text box where the filter is written */ protected final TextBox tb = new TextBox() { - /* - * (non-Javadoc) - * - * @see - * com.google.gwt.user.client.ui.TextBoxBase#onBrowserEvent(com.google - * .gwt.user.client.Event) - */ - - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - if (client != null) { - client.handleTooltipEvent(event, VFilterSelect.this); - } - } // Overridden to avoid selecting text when text input is disabled @Override @@ -869,9 +853,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); - if (client != null) { - client.handleTooltipEvent(event, VFilterSelect.this); - } /* * Prevent the keyboard focus from leaving the textfield by @@ -972,8 +953,7 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, } }); - tb.sinkEvents(VTooltip.TOOLTIP_EVENTS); - popupOpener.sinkEvents(VTooltip.TOOLTIP_EVENTS | Event.ONMOUSEDOWN); + popupOpener.sinkEvents(Event.ONMOUSEDOWN); panel.add(tb); panel.add(popupOpener); initWidget(panel); diff --git a/src/com/vaadin/terminal/gwt/client/ui/datefield/VDateField.java b/src/com/vaadin/terminal/gwt/client/ui/datefield/VDateField.java index d169b1b47e..614c4febdd 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/datefield/VDateField.java +++ b/src/com/vaadin/terminal/gwt/client/ui/datefield/VDateField.java @@ -6,11 +6,9 @@ package com.vaadin.terminal.gwt.client.ui.datefield; import java.util.Date; -import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.FlowPanel; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.DateTimeService; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Field; public class VDateField extends FlowPanel implements Field { @@ -66,15 +64,6 @@ public class VDateField extends FlowPanel implements Field { public VDateField() { setStyleName(CLASSNAME); dts = new DateTimeService(); - sinkEvents(VTooltip.TOOLTIP_EVENTS); - } - - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - if (client != null) { - client.handleTooltipEvent(event, this); - } } /* diff --git a/src/com/vaadin/terminal/gwt/client/ui/draganddropwrapper/VDragAndDropWrapper.java b/src/com/vaadin/terminal/gwt/client/ui/draganddropwrapper/VDragAndDropWrapper.java index 4c36e92bbb..b1fffc8355 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/draganddropwrapper/VDragAndDropWrapper.java +++ b/src/com/vaadin/terminal/gwt/client/ui/draganddropwrapper/VDragAndDropWrapper.java @@ -29,7 +29,6 @@ import com.vaadin.terminal.gwt.client.LayoutManager; import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ValueMap; import com.vaadin.terminal.gwt.client.ui.customcomponent.VCustomComponent; import com.vaadin.terminal.gwt.client.ui.dd.DDUtil; @@ -64,7 +63,6 @@ public class VDragAndDropWrapper extends VCustomComponent implements public VDragAndDropWrapper() { super(); - sinkEvents(VTooltip.TOOLTIP_EVENTS); hookHtml5Events(getElement()); setStyleName(CLASSNAME); @@ -92,16 +90,6 @@ public class VDragAndDropWrapper extends VCustomComponent implements sinkEvents(Event.TOUCHEVENTS); } - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - - if (hasTooltip && client != null) { - // Override child tooltips if the wrapper has a tooltip defined - client.handleTooltipEvent(event, this); - } - } - /** * Starts a drag and drop operation from mousedown or touchstart event if * required conditions are met. diff --git a/src/com/vaadin/terminal/gwt/client/ui/embedded/VEmbedded.java b/src/com/vaadin/terminal/gwt/client/ui/embedded/VEmbedded.java index 203e7362f3..5edd31174d 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/embedded/VEmbedded.java +++ b/src/com/vaadin/terminal/gwt/client/ui/embedded/VEmbedded.java @@ -232,8 +232,6 @@ public class VEmbedded extends HTML { VConsole.log("Embeddable onload"); Util.notifyParentOfSizeChange(this, true); } - - client.handleTooltipEvent(event, this); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java index ca21947a6c..c08651ded1 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java @@ -3,9 +3,12 @@ */ package com.vaadin.terminal.gwt.client.ui.formlayout; +import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent; +import com.vaadin.terminal.gwt.client.TooltipInfo; +import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.ui.AbstractFieldConnector; import com.vaadin.terminal.gwt.client.ui.AbstractLayoutConnector; @@ -96,4 +99,36 @@ public class FormLayoutConnector extends AbstractLayoutConnector { return (VFormLayout) super.getWidget(); } + @Override + public TooltipInfo getTooltipInfo(Element element) { + TooltipInfo info = null; + + if (element != getWidget().getElement()) { + Object node = Util.findWidget( + (com.google.gwt.user.client.Element) element, + VFormLayout.Caption.class); + + if (node != null) { + VFormLayout.Caption caption = (VFormLayout.Caption) node; + info = caption.getOwner().getTooltipInfo(element); + } else { + + node = Util.findWidget( + (com.google.gwt.user.client.Element) element, + VFormLayout.ErrorFlag.class); + + if (node != null) { + VFormLayout.ErrorFlag flag = (VFormLayout.ErrorFlag) node; + info = flag.getOwner().getTooltipInfo(element); + } + } + } + + if (info == null) { + info = super.getTooltipInfo(element); + } + + return info; + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java b/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java index 8a859c409c..1a161c529d 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java @@ -12,7 +12,6 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.SimplePanel; @@ -215,8 +214,6 @@ public class VFormLayout extends SimplePanel { public Caption(ComponentConnector component) { super(); owner = component; - - sinkEvents(VTooltip.TOOLTIP_EVENTS); } private void setStyles(String[] styles) { @@ -324,12 +321,6 @@ public class VFormLayout extends SimplePanel { public ComponentConnector getOwner() { return owner; } - - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - owner.getConnection().handleTooltipEvent(event, owner); - } } class ErrorFlag extends HTML { @@ -345,6 +336,10 @@ public class VFormLayout extends SimplePanel { this.owner = owner; } + public ComponentConnector getOwner() { + return owner; + } + public void updateError(String errorMessage, boolean hideErrors) { boolean showError = null != errorMessage; if (hideErrors) { @@ -366,13 +361,5 @@ public class VFormLayout extends SimplePanel { } } - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - if (owner != null) { - owner.getConnection().handleTooltipEvent(event, owner); - } - } - } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/label/VLabel.java b/src/com/vaadin/terminal/gwt/client/ui/label/VLabel.java index f47b8437b7..f0c170c6b0 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/label/VLabel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/label/VLabel.java @@ -28,7 +28,6 @@ public class VLabel extends HTML { public VLabel(String text) { super(text); setStyleName(CLASSNAME); - sinkEvents(VTooltip.TOOLTIP_EVENTS); } @Override @@ -39,9 +38,6 @@ public class VLabel extends HTML { event.stopPropagation(); return; } - if (connection != null) { - connection.handleTooltipEvent(event, this); - } } @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java b/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java index 68fe5d9292..bef7943e3f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java +++ b/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java @@ -13,7 +13,6 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.HTML; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Icon; public class VLink extends HTML implements ClickHandler { @@ -51,7 +50,6 @@ public class VLink extends HTML implements ClickHandler { getElement().appendChild(anchor); anchor.appendChild(captionElement); addClickHandler(this); - sinkEvents(VTooltip.TOOLTIP_EVENTS); setStyleName(CLASSNAME); } @@ -101,9 +99,6 @@ public class VLink extends HTML implements ClickHandler { if (event.getTypeInt() == Event.ONLOAD) { Util.notifyParentOfSizeChange(this, true); } - if (client != null) { - client.handleTooltipEvent(event, this); - } if (target == captionElement || target == anchor || (icon != null && target == icon.getElement())) { super.onBrowserEvent(event); diff --git a/src/com/vaadin/terminal/gwt/client/ui/listselect/TooltipListBox.java b/src/com/vaadin/terminal/gwt/client/ui/listselect/TooltipListBox.java deleted file mode 100644 index abecd844da..0000000000 --- a/src/com/vaadin/terminal/gwt/client/ui/listselect/TooltipListBox.java +++ /dev/null @@ -1,41 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.terminal.gwt.client.ui.listselect; - -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.ui.ListBox; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.VTooltip; - -/** - * Extended ListBox to listen tooltip events and forward them to generic - * handler. - */ -public class TooltipListBox extends ListBox { - private ApplicationConnection client; - private Widget widget; - - public TooltipListBox(boolean isMultiselect) { - super(isMultiselect); - sinkEvents(VTooltip.TOOLTIP_EVENTS); - } - - public void setClient(ApplicationConnection client) { - this.client = client; - } - - public void setSelect(Widget widget) { - this.widget = widget; - } - - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - if (client != null) { - client.handleTooltipEvent(event, widget); - } - } - -} \ No newline at end of file diff --git a/src/com/vaadin/terminal/gwt/client/ui/listselect/VListSelect.java b/src/com/vaadin/terminal/gwt/client/ui/listselect/VListSelect.java index e338897841..1b1c2c44e3 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/listselect/VListSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/listselect/VListSelect.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Iterator; import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.user.client.ui.ListBox; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.ui.optiongroup.VOptionGroupBase; @@ -17,23 +18,25 @@ public class VListSelect extends VOptionGroupBase { private static final int VISIBLE_COUNT = 10; - protected TooltipListBox select; + protected ListBox select; private int lastSelectedIndex = -1; public VListSelect() { - super(new TooltipListBox(true), CLASSNAME); - select = (TooltipListBox) optionsContainer; - select.setSelect(this); + super(new ListBox(true), CLASSNAME); + select = getOptionsContainer(); select.addChangeHandler(this); select.addClickHandler(this); select.setStyleName(CLASSNAME + "-select"); select.setVisibleItemCount(VISIBLE_COUNT); } + protected ListBox getOptionsContainer() { + return (ListBox) optionsContainer; + } + @Override protected void buildOptions(UIDL uidl) { - select.setClient(client); select.setMultipleSelect(isMultiselect()); select.setEnabled(!isDisabled() && !isReadonly()); select.clear(); @@ -99,7 +102,7 @@ public class VListSelect extends VOptionGroupBase { @Override protected void setTabIndex(int tabIndex) { - ((TooltipListBox) optionsContainer).setTabIndex(tabIndex); + getOptionsContainer().setTabIndex(tabIndex); } public void focus() { diff --git a/src/com/vaadin/terminal/gwt/client/ui/menubar/VMenuBar.java b/src/com/vaadin/terminal/gwt/client/ui/menubar/VMenuBar.java index e48483cb02..821fa5032c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/menubar/VMenuBar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/menubar/VMenuBar.java @@ -33,10 +33,8 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.LayoutManager; -import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Icon; import com.vaadin.terminal.gwt.client.ui.SimpleFocusablePanel; import com.vaadin.terminal.gwt.client.ui.SubPartAware; @@ -140,8 +138,6 @@ public class VMenuBar extends SimpleFocusablePanel implements sinkEvents(Event.ONCLICK | Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONLOAD); - - sinkEvents(VTooltip.TOOLTIP_EVENTS); } @Override @@ -340,15 +336,6 @@ public class VMenuBar extends SimpleFocusablePanel implements } } - // Handle tooltips - if (targetItem == null && client != null) { - // Handle root menubar tooltips - client.handleTooltipEvent(e, this); - } else if (targetItem != null) { - // Handle item tooltips - targetItem.onBrowserEvent(e); - } - if (targetItem != null) { switch (DOM.eventGetType(e)) { @@ -761,7 +748,6 @@ public class VMenuBar extends SimpleFocusablePanel implements setSelected(false); setStyleName(CLASSNAME + "-menuitem"); - sinkEvents(VTooltip.TOOLTIP_EVENTS); } public void setSelected(boolean selected) { @@ -917,22 +903,6 @@ public class VMenuBar extends SimpleFocusablePanel implements addStyleDependentName(itemStyle); } - if (uidl.hasAttribute(ATTRIBUTE_ITEM_DESCRIPTION)) { - String description = uidl - .getStringAttribute(ATTRIBUTE_ITEM_DESCRIPTION); - TooltipInfo info = new TooltipInfo(description); - - VMenuBar root = findRootMenu(); - client.registerTooltip(root, this, info); - } - } - - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - if (client != null) { - client.handleTooltipEvent(event, findRootMenu(), this); - } } private VMenuBar findRootMenu() { diff --git a/src/com/vaadin/terminal/gwt/client/ui/nativebutton/VNativeButton.java b/src/com/vaadin/terminal/gwt/client/ui/nativebutton/VNativeButton.java index dd6e741126..e5a2e1253c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/nativebutton/VNativeButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/nativebutton/VNativeButton.java @@ -15,7 +15,6 @@ import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Icon; import com.vaadin.terminal.gwt.client.ui.button.ButtonServerRpc; @@ -54,7 +53,6 @@ public class VNativeButton extends Button implements ClickHandler { addClickHandler(this); - sinkEvents(VTooltip.TOOLTIP_EVENTS); sinkEvents(Event.ONMOUSEDOWN); sinkEvents(Event.ONMOUSEUP); } @@ -87,10 +85,6 @@ public class VNativeButton extends Button implements ClickHandler { } clickPending = false; } - - if (client != null) { - client.handleTooltipEvent(event, this); - } } @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/nativeselect/VNativeSelect.java b/src/com/vaadin/terminal/gwt/client/ui/nativeselect/VNativeSelect.java index 54f5e9aff5..cab23b1bc2 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/nativeselect/VNativeSelect.java +++ b/src/com/vaadin/terminal/gwt/client/ui/nativeselect/VNativeSelect.java @@ -8,32 +8,34 @@ import java.util.ArrayList; import java.util.Iterator; import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.user.client.ui.ListBox; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.ui.Field; -import com.vaadin.terminal.gwt.client.ui.listselect.TooltipListBox; import com.vaadin.terminal.gwt.client.ui.optiongroup.VOptionGroupBase; public class VNativeSelect extends VOptionGroupBase implements Field { public static final String CLASSNAME = "v-select"; - protected TooltipListBox select; + protected ListBox select; private boolean firstValueIsTemporaryNullItem = false; public VNativeSelect() { - super(new TooltipListBox(false), CLASSNAME); - select = (TooltipListBox) optionsContainer; - select.setSelect(this); + super(new ListBox(false), CLASSNAME); + select = getOptionsContainer(); select.setVisibleItemCount(1); select.addChangeHandler(this); select.setStyleName(CLASSNAME + "-select"); } + protected ListBox getOptionsContainer() { + return (ListBox) optionsContainer; + } + @Override protected void buildOptions(UIDL uidl) { - select.setClient(client); select.setEnabled(!isDisabled() && !isReadonly()); select.clear(); firstValueIsTemporaryNullItem = false; @@ -103,7 +105,7 @@ public class VNativeSelect extends VOptionGroupBase implements Field { @Override protected void setTabIndex(int tabIndex) { - ((TooltipListBox) optionsContainer).setTabIndex(tabIndex); + getOptionsContainer().setTabIndex(tabIndex); } public void focus() { diff --git a/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index 9a89553fd2..7c748df29d 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -48,6 +48,7 @@ public abstract class AbstractOrderedLayoutConnector extends @Override public void init() { + super.init(); rpc = RpcProxy.create(AbstractOrderedLayoutServerRpc.class, this); getLayoutManager().registerDependency(this, getWidget().spacingMeasureElement); diff --git a/src/com/vaadin/terminal/gwt/client/ui/panel/PanelConnector.java b/src/com/vaadin/terminal/gwt/client/ui/panel/PanelConnector.java index d9096526f3..ea7ffda9db 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/panel/PanelConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/panel/PanelConnector.java @@ -46,6 +46,7 @@ public class PanelConnector extends AbstractComponentContainerConnector @Override public void init() { + super.init(); rpc = RpcProxy.create(PanelServerRpc.class, this); VPanel panel = getWidget(); LayoutManager layoutManager = getLayoutManager(); diff --git a/src/com/vaadin/terminal/gwt/client/ui/panel/VPanel.java b/src/com/vaadin/terminal/gwt/client/ui/panel/VPanel.java index 6a06367acd..d56a82c46b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/panel/VPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/panel/VPanel.java @@ -167,10 +167,6 @@ public class VPanel extends SimplePanel implements ShortcutActionHandlerOwner, client.updateVariable(id, "scrollTop", scrollTop, false); client.updateVariable(id, "scrollLeft", scrollLeft, false); } - } else if (captionNode.isOrHasChild(target)) { - if (client != null) { - client.handleTooltipEvent(event, this); - } } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/popupview/VPopupView.java b/src/com/vaadin/terminal/gwt/client/ui/popupview/VPopupView.java index da48975726..c8a0222ee2 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/popupview/VPopupView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/popupview/VPopupView.java @@ -26,7 +26,6 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VCaptionWrapper; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.VOverlay; import com.vaadin.terminal.gwt.client.ui.richtextarea.VRichTextArea; @@ -73,7 +72,6 @@ public class VPopupView extends HTML { }); popup.setAnimationEnabled(true); - sinkEvents(VTooltip.TOOLTIP_EVENTS); } /** @@ -337,12 +335,4 @@ public class VPopupView extends HTML { }// class CustomPopup - @Override - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - if (client != null) { - client.handleTooltipEvent(event, this); - } - } - }// class VPopupView diff --git a/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java b/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java index 5c7ee7a784..e5282dc45e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java +++ b/src/com/vaadin/terminal/gwt/client/ui/slider/VSlider.java @@ -18,7 +18,6 @@ import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ContainerResizedListener; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Field; import com.vaadin.terminal.gwt.client.ui.SimpleFocusablePanel; import com.vaadin.terminal.gwt.client.ui.VLazyExecutor; @@ -114,8 +113,6 @@ public class VSlider extends SimpleFocusablePanel implements Field, feedbackPopup.addStyleName(CLASSNAME + "-feedback"); feedbackPopup.setWidget(feedback); - - sinkEvents(VTooltip.TOOLTIP_EVENTS); } void setFeedbackValue(double value) { @@ -291,9 +288,6 @@ public class VSlider extends SimpleFocusablePanel implements Field, event.preventDefault(); // avoid simulated events event.stopPropagation(); } - if (client != null) { - client.handleTooltipEvent(event, this); - } } private void processMouseWheelEvent(final Event event) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/table/TableConnector.java b/src/com/vaadin/terminal/gwt/client/ui/table/TableConnector.java index ada0f2424f..ab867ea045 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/table/TableConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/table/TableConnector.java @@ -7,6 +7,7 @@ import java.util.Iterator; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Position; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.ui.Widget; @@ -17,6 +18,7 @@ import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.DirectionalManagedLayout; import com.vaadin.terminal.gwt.client.Paintable; import com.vaadin.terminal.gwt.client.ServerConnector; +import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.ui.AbstractComponentContainerConnector; @@ -328,4 +330,27 @@ public class TableConnector extends AbstractComponentContainerConnector } } + @Override + public TooltipInfo getTooltipInfo(Element element) { + + TooltipInfo info = null; + + if (element != getWidget().getElement()) { + Object node = Util.findWidget( + (com.google.gwt.user.client.Element) element, + VScrollTableRow.class); + + if (node != null) { + VScrollTableRow row = (VScrollTableRow) node; + info = row.getTooltip(element); + } + } + + if (info == null) { + info = super.getTooltipInfo(element); + } + + return info; + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/table/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/table/VScrollTable.java index c4a57f5c8b..b5f10e68ec 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/table/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/table/VScrollTable.java @@ -11,6 +11,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import com.google.gwt.core.client.JavaScriptObject; @@ -4194,14 +4195,6 @@ public class VScrollTable extends FlowPanel implements HasWidgets, private void unlinkRowAtActualIndex(int index) { final VScrollTableRow toBeRemoved = (VScrollTableRow) renderedRows .get(index); - // Unregister row tooltip - client.registerTooltip(VScrollTable.this, toBeRemoved.getElement(), - null); - for (int i = 0; i < toBeRemoved.getElement().getChildCount(); i++) { - // Unregister cell tooltips - Element td = toBeRemoved.getElement().getChild(i).cast(); - client.registerTooltip(VScrollTable.this, td, null); - } tBodyElement.removeChild(toBeRemoved.getElement()); orphan(toBeRemoved); renderedRows.remove(index); @@ -4423,6 +4416,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, private Timer dragTouchTimeout; private int touchStartY; private int touchStartX; + private TooltipInfo tooltipInfo = null; + private Map cellToolTips = new HashMap(); private boolean isDragging = false; private VScrollTableRow(int rowKey) { @@ -4450,11 +4445,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, String rowDescription = uidl.getStringAttribute("rowdescr"); if (rowDescription != null && !rowDescription.equals("")) { - TooltipInfo info = new TooltipInfo(rowDescription); - client.registerTooltip(VScrollTable.this, rowElement, info); + tooltipInfo = new TooltipInfo(rowDescription); } else { - // Remove possibly previously set tooltip - client.registerTooltip(VScrollTable.this, rowElement, null); + tooltipInfo = null; } tHead.getColumnAlignments(); @@ -4480,6 +4473,10 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } } + public TooltipInfo getTooltipInfo() { + return tooltipInfo; + } + /** * Add a dummy row, used for measurements if Table is empty. */ @@ -4665,10 +4662,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (description != null && !description.equals("")) { TooltipInfo info = new TooltipInfo(description); - client.registerTooltip(VScrollTable.this, td, info); + cellToolTips.put(td, info); } else { - // Remove possibly previously set tooltip - client.registerTooltip(VScrollTable.this, td, null); + cellToolTips.remove(td); } td.appendChild(container); @@ -4776,39 +4772,22 @@ public class VScrollTable extends FlowPanel implements HasWidgets, return true; } - private void handleTooltips(final Event event, Element target) { + public TooltipInfo getTooltip( + com.google.gwt.dom.client.Element target) { + + TooltipInfo info = null; + if (target.hasTagName("TD")) { - // Table cell (td) - Element container = target.getFirstChildElement().cast(); - Element widget = container.getFirstChildElement().cast(); - - boolean containsWidget = false; - for (Widget w : childWidgets) { - if (widget == w.getElement()) { - containsWidget = true; - break; - } - } - if (!containsWidget) { - // Only text nodes has tooltips - if (ConnectorMap.get(client).getWidgetTooltipInfo( - VScrollTable.this, target) != null) { - // Cell has description, use it - client.handleTooltipEvent(event, VScrollTable.this, - target); - } else { - // Cell might have row description, use row - // description - client.handleTooltipEvent(event, VScrollTable.this, - target.getParentElement()); - } - } + TableCellElement td = (TableCellElement) target.cast(); + info = cellToolTips.get(td); + } - } else { - // Table row (tr) - client.handleTooltipEvent(event, VScrollTable.this, target); + if (info == null) { + info = tooltipInfo; } + + return info; } /** @@ -4953,9 +4932,6 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } boolean targetCellOrRowFound = targetTdOrTr != null; - if (targetCellOrRowFound) { - handleTooltips(event, targetTdOrTr); - } switch (type) { case Event.ONDBLCLICK: diff --git a/src/com/vaadin/terminal/gwt/client/ui/tabsheet/TabsheetConnector.java b/src/com/vaadin/terminal/gwt/client/ui/tabsheet/TabsheetConnector.java index 08d4679dc5..51a7801f91 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/tabsheet/TabsheetConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/tabsheet/TabsheetConnector.java @@ -3,12 +3,13 @@ */ package com.vaadin.terminal.gwt.client.ui.tabsheet; -import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentConnector; +import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.ui.Connect; import com.vaadin.terminal.gwt.client.ui.SimpleManagedLayout; import com.vaadin.terminal.gwt.client.ui.layout.MayScrollChildren; @@ -97,4 +98,29 @@ public class TabsheetConnector extends TabsheetBaseConnector implements } + @Override + public TooltipInfo getTooltipInfo(Element element) { + + TooltipInfo info = null; + + // Find a tooltip for the tab, if the element is a tab + if (element != getWidget().getElement()) { + Object node = Util.findWidget( + (com.google.gwt.user.client.Element) element, + VTabsheet.TabCaption.class); + + if (node != null) { + VTabsheet.TabCaption caption = (VTabsheet.TabCaption) node; + info = caption.getTooltipInfo(); + } + } + + // If not tab tooltip was found, use the default + if (info == null) { + info = super.getTooltipInfo(element); + } + + return info; + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/tabsheet/VTabsheet.java b/src/com/vaadin/terminal/gwt/client/ui/tabsheet/VTabsheet.java index aba5a41f9a..24ea3b2d38 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/tabsheet/VTabsheet.java +++ b/src/com/vaadin/terminal/gwt/client/ui/tabsheet/VTabsheet.java @@ -233,7 +233,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, } } - private static class TabCaption extends VCaption { + public static class TabCaption extends VCaption { private boolean closable = false; private Element closeButton; @@ -248,16 +248,11 @@ public class VTabsheet extends VTabsheetBase implements Focusable, public boolean updateCaption(UIDL uidl) { if (uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION)) { - TooltipInfo tooltipInfo = new TooltipInfo(); - tooltipInfo - .setTitle(uidl - .getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION)); - tooltipInfo - .setErrorMessage(uidl - .getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ERROR_MESSAGE)); - client.registerTooltip(getTabsheet(), getElement(), tooltipInfo); + setTooltipInfo(new TooltipInfo( + uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION), + uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ERROR_MESSAGE))); } else { - client.registerTooltip(getTabsheet(), getElement(), null); + setTooltipInfo(null); } // TODO need to call this instead of super because the caption does @@ -292,7 +287,6 @@ public class VTabsheet extends VTabsheetBase implements Focusable, if (event.getTypeInt() == Event.ONLOAD) { getTabsheet().tabSizeMightHaveChanged(getTab()); } - client.handleTooltipEvent(event, getTabsheet(), getElement()); } public Tab getTab() { diff --git a/src/com/vaadin/terminal/gwt/client/ui/textfield/VTextField.java b/src/com/vaadin/terminal/gwt/client/ui/textfield/VTextField.java index aeae165f60..bd55c26a24 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/textfield/VTextField.java +++ b/src/com/vaadin/terminal/gwt/client/ui/textfield/VTextField.java @@ -22,7 +22,6 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Field; /** @@ -88,7 +87,6 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler, } addFocusHandler(this); addBlurHandler(this); - sinkEvents(VTooltip.TOOLTIP_EVENTS); } /* @@ -107,9 +105,6 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler, @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); - if (client != null) { - client.handleTooltipEvent(event, this); - } if (listenTextChangeEvents && (event.getTypeInt() & TEXTCHANGE_EVENTS) == event diff --git a/src/com/vaadin/terminal/gwt/client/ui/tree/TreeConnector.java b/src/com/vaadin/terminal/gwt/client/ui/tree/TreeConnector.java index e4afa32143..3f96a61bf3 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/tree/TreeConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/tree/TreeConnector.java @@ -3,14 +3,18 @@ */ package com.vaadin.terminal.gwt.client.ui.tree; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; +import com.google.gwt.dom.client.Element; import com.vaadin.terminal.gwt.client.AbstractFieldState; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.Paintable; import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; import com.vaadin.terminal.gwt.client.ui.Connect; import com.vaadin.terminal.gwt.client.ui.tree.VTree.TreeNode; @@ -27,6 +31,8 @@ public class TreeConnector extends AbstractComponentConnector implements public static final String ATTRIBUTE_ACTION_CAPTION = "caption"; public static final String ATTRIBUTE_ACTION_ICON = ATTRIBUTE_NODE_ICON; + protected final Map tooltipMap = new HashMap(); + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { if (!isRealUpdate(uidl)) { return; @@ -62,6 +68,8 @@ public class TreeConnector extends AbstractComponentConnector implements getWidget().body.clear(); // clear out any references to nodes that no longer are attached getWidget().clearNodeToKeyMap(); + tooltipMap.clear(); + TreeNode childTree = null; UIDL childUidl = null; for (final Iterator i = uidl.getChildIterator(); i.hasNext();) { @@ -74,6 +82,7 @@ public class TreeConnector extends AbstractComponentConnector implements continue; } childTree = getWidget().new TreeNode(); + getConnection().getVTooltip().connectHandlersToWidget(childTree); updateNodeFromUIDL(childTree, childUidl); getWidget().body.add(childTree); childTree.addStyleDependentName("root"); @@ -193,13 +202,8 @@ public class TreeConnector extends AbstractComponentConnector implements } String description = uidl.getStringAttribute("descr"); - if (description != null && getConnection() != null) { - // Set tooltip - TooltipInfo info = new TooltipInfo(description); - getConnection().registerTooltip(this, nodeKey, info); - } else { - // Remove possible previous tooltip - getConnection().registerTooltip(this, nodeKey, null); + if (description != null) { + tooltipMap.put(treeNode, new TooltipInfo(description)); } if (uidl.getBooleanAttribute("expanded") && !treeNode.getState()) { @@ -228,6 +232,7 @@ public class TreeConnector extends AbstractComponentConnector implements continue; } final TreeNode childTree = getWidget().new TreeNode(); + getConnection().getVTooltip().connectHandlersToWidget(childTree); updateNodeFromUIDL(childTree, childUidl); containerNode.childNodeContainer.add(childTree); if (!i.hasNext()) { @@ -250,4 +255,32 @@ public class TreeConnector extends AbstractComponentConnector implements return (AbstractFieldState) super.getState(); } + @Override + public TooltipInfo getTooltipInfo(Element element) { + + TooltipInfo info = null; + + // Try to find a tooltip for a node + if (element != getWidget().getElement()) { + Object node = Util.findWidget( + (com.google.gwt.user.client.Element) element, + TreeNode.class); + + if (node != null) { + TreeNode tnode = (TreeNode) node; + if (tnode.isCaptionElement(element)) { + info = tooltipMap.get(tnode); + } + } + } + + // If no tooltip found for the node or if the target was not a node, use + // the default tooltip + if (info == null) { + info = super.getTooltipInfo(element); + } + + return info; + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/tree/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/tree/VTree.java index 6f19cba957..7462160bad 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/tree/VTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/tree/VTree.java @@ -45,7 +45,6 @@ import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.Action; import com.vaadin.terminal.gwt.client.ui.ActionOwner; import com.vaadin.terminal.gwt.client.ui.FocusElementPanel; @@ -656,12 +655,7 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, return; } - if (target == nodeCaptionSpan) { - client.handleTooltipEvent(event, VTree.this, key); - } - - final boolean inCaption = target == nodeCaptionSpan - || (icon != null && target == icon.getElement()); + final boolean inCaption = isCaptionElement(target); if (inCaption && client .hasEventListeners(VTree.this, ITEM_CLICK_EVENT_ID) @@ -751,6 +745,18 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, } } + /** + * Checks if the given element is the caption or the icon. + * + * @param target + * The element to check + * @return true if the element is the caption or the icon + */ + public boolean isCaptionElement(com.google.gwt.dom.client.Element target) { + return (target == nodeCaptionSpan || (icon != null && target == icon + .getElement())); + } + private void fireClick(final Event evt) { /* * Ensure we have focus in tree before sending variables. Otherwise @@ -825,7 +831,6 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, + "-caption"); Element wrapper = DOM.createDiv(); nodeCaptionSpan = DOM.createSpan(); - DOM.sinkEvents(nodeCaptionSpan, VTooltip.TOOLTIP_EVENTS); DOM.appendChild(getElement(), nodeCaptionDiv); DOM.appendChild(nodeCaptionDiv, wrapper); DOM.appendChild(wrapper, nodeCaptionSpan); diff --git a/src/com/vaadin/terminal/gwt/client/ui/upload/VUpload.java b/src/com/vaadin/terminal/gwt/client/ui/upload/VUpload.java index 4fe53fb89c..ac475ce5a5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/upload/VUpload.java +++ b/src/com/vaadin/terminal/gwt/client/ui/upload/VUpload.java @@ -24,7 +24,6 @@ import com.google.gwt.user.client.ui.SimplePanel; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.VConsole; -import com.vaadin.terminal.gwt.client.VTooltip; import com.vaadin.terminal.gwt.client.ui.button.VButton; /** @@ -128,16 +127,6 @@ public class VUpload extends SimplePanel { panel.add(submitButton); setStyleName(CLASSNAME); - - sinkEvents(VTooltip.TOOLTIP_EVENTS); - } - - @Override - public void onBrowserEvent(Event event) { - if ((event.getTypeInt() & VTooltip.TOOLTIP_EVENTS) > 0) { - client.handleTooltipEvent(event, this); - } - super.onBrowserEvent(event); } private static native void setEncoding(Element form, String encoding) diff --git a/src/com/vaadin/terminal/gwt/client/ui/window/VWindow.java b/src/com/vaadin/terminal/gwt/client/ui/window/VWindow.java index 8fd84a9ea6..3946a026c6 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/window/VWindow.java +++ b/src/com/vaadin/terminal/gwt/client/ui/window/VWindow.java @@ -552,11 +552,6 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, final Element target = DOM.eventGetTarget(event); - if (client != null && header.isOrHasChild(target)) { - // Handle window caption tooltips - client.handleTooltipEvent(event, this); - } - if (resizing || resizeBox == target) { onResizeEvent(event); bubble = false; diff --git a/tests/testbench/com/vaadin/tests/components/abstractcomponent/AllComponentTooltipTest.java b/tests/testbench/com/vaadin/tests/components/abstractcomponent/AllComponentTooltipTest.java new file mode 100644 index 0000000000..17cc4270fb --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/abstractcomponent/AllComponentTooltipTest.java @@ -0,0 +1,50 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ +package com.vaadin.tests.components.abstractcomponent; + +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.tests.VaadinClasses; +import com.vaadin.tests.components.AbstractTestRoot; +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.Component; +import com.vaadin.ui.GridLayout; + +public class AllComponentTooltipTest extends AbstractTestRoot { + + @Override + protected void setup(WrappedRequest request) { + setContent(new GridLayout(5, 5)); + for (Class cls : VaadinClasses.getComponents()) { + try { + AbstractComponent c = (AbstractComponent) cls.newInstance(); + if (c instanceof LegacyWindow) { + continue; + } + + c.setDebugId(cls.getName()); + c.setCaption(cls.getName()); + c.setDescription(cls.getName()); + c.setWidth("100px"); + c.setHeight("100px"); + getContent().addComponent(c); + System.out.println("Added " + cls.getName()); + } catch (Exception e) { + System.err.println("Could not instatiate " + cls.getName()); + } + } + } + + @Override + protected String getTestDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/abstractcomponent/TooltipTests.html b/tests/testbench/com/vaadin/tests/components/abstractcomponent/TooltipTests.html new file mode 100644 index 0000000000..a1d4fc9b35 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/abstractcomponent/TooltipTests.html @@ -0,0 +1,77 @@ + + + + + + +TooltipTests + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TooltipTests
open/run/com.vaadin.tests.components.abstractcomponent.TooltipTests?restartApplication
showTooltip//div[@id='label']
screenCaptureno_tooltip
mouseClickvaadin=runcomvaadintestscomponentsabstractcomponentTooltipTests::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VCheckBox[0]/domChild[0]10,7
showTooltip//div[@id='label']
screenCapturepanel_tooltip
mouseClickvaadin=runcomvaadintestscomponentsabstractcomponentTooltipTests::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VCheckBox[1]/domChild[0]8,6
showTooltip//div[@id='label']
screenCapturelayout_tooltip
mouseClickvaadin=runcomvaadintestscomponentsabstractcomponentTooltipTests::/VVerticalLayout[0]/VVerticalLayout[0]/VHorizontalLayout[0]/VCheckBox[2]/domChild[0]5,5
showTooltip//div[@id='label']
screenCapturelabel_tooltip
+ + diff --git a/tests/testbench/com/vaadin/tests/components/abstractcomponent/TooltipTests.java b/tests/testbench/com/vaadin/tests/components/abstractcomponent/TooltipTests.java new file mode 100644 index 0000000000..c009e1d7bc --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/abstractcomponent/TooltipTests.java @@ -0,0 +1,97 @@ +package com.vaadin.tests.components.abstractcomponent; + +import com.vaadin.data.Property; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Panel; +import com.vaadin.ui.VerticalLayout; + +public class TooltipTests extends TestBase { + + private Panel panel; + private VerticalLayout layout; + private Label label; + + @Override + protected String getDescription() { + return "Generic tooltip handling tests"; + } + + @Override + protected Integer getTicketNumber() { + return 8425; + } + + @Override + protected void setup() { + HorizontalLayout topLayout = new HorizontalLayout(); + addComponent(topLayout); + CheckBox panelCbox = new CheckBox("Panel"); + panelCbox.addListener(panelListener); + topLayout.addComponent(panelCbox); + CheckBox layoutCbox = new CheckBox("Layout"); + layoutCbox.addListener(layoutListener); + topLayout.addComponent(layoutCbox); + CheckBox labelCbox = new CheckBox("Label"); + topLayout.addComponent(labelCbox); + labelCbox.addListener(labelListener); + + panel = new Panel(); + panel.setCaption("Panel caption"); + panel.setDebugId("panel"); + addComponent(panel); + + layout = new VerticalLayout(); + layout.setDebugId("layout"); + layout.setMargin(true); + layout.setSpacing(true); + panel.setContent(layout); + + label = new Label("Hover me!"); + label.setDebugId("label"); + layout.addComponent(label); + } + + private final Property.ValueChangeListener panelListener = new Property.ValueChangeListener() { + + public void valueChange(ValueChangeEvent event) { + boolean value = (Boolean) (event.getProperty().getValue()); + if (value) { + panel.setDescription("I'm panel!"); + } else { + panel.setDescription(""); + } + } + + }; + + private final Property.ValueChangeListener layoutListener = new Property.ValueChangeListener() { + + public void valueChange(ValueChangeEvent event) { + boolean value = (Boolean) (event.getProperty().getValue()); + if (value) { + layout.setDescription("I'm layout!"); + } else { + layout.setDescription(""); + } + } + + }; + + private final Property.ValueChangeListener labelListener = new Property.ValueChangeListener() { + + public void valueChange(ValueChangeEvent event) { + boolean value = (Boolean) (event.getProperty().getValue()); + if (value) { + label.setDescription("I'm label!"); + } else { + label.setDescription(""); + } + } + + }; + +} -- 2.39.5