diff options
author | Denis <denis@vaadin.com> | 2017-01-20 10:13:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-20 10:13:25 +0200 |
commit | 1fb40df8742791803e0a08328028bbbd67deb78b (patch) | |
tree | 0af44b046f5b76f775f5da4e65e5be69bb2764b0 /client | |
parent | f42b9657b818da483b839d3b43b4cf55552ef034 (diff) | |
download | vaadin-framework-1fb40df8742791803e0a08328028bbbd67deb78b.tar.gz vaadin-framework-1fb40df8742791803e0a08328028bbbd67deb78b.zip |
Overload AbstarctComponent.setDescription() with content mode parameter (#8252)
* Overload AbstarctComponent.setDescription() with content mode parameter
Fixes #8185
Diffstat (limited to 'client')
5 files changed, 93 insertions, 15 deletions
diff --git a/client/src/main/java/com/vaadin/client/TooltipInfo.java b/client/src/main/java/com/vaadin/client/TooltipInfo.java index 1f819438ef..a84e45e988 100644 --- a/client/src/main/java/com/vaadin/client/TooltipInfo.java +++ b/client/src/main/java/com/vaadin/client/TooltipInfo.java @@ -15,12 +15,15 @@ */ package com.vaadin.client; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.util.SharedUtil; public class TooltipInfo { private String title; + private ContentMode contentMode; + private String errorMessageHtml; // Contains the tooltip's identifier. If a tooltip's contents and this @@ -32,16 +35,57 @@ public class TooltipInfo { } public TooltipInfo(String tooltip) { - setTitle(tooltip); + this(tooltip, ContentMode.PREFORMATTED); } + /** + * Constructs a new instance using the {@code tooltip} for the title and + * {@code errorMessage} as a description. + * + * @param tooltip + * tooltip title + * @param errorMessage + * error description + * + * @deprecated use {@link #TooltipInfo(String, ContentMode, String)} instead + */ + @Deprecated public TooltipInfo(String tooltip, String errorMessage) { - this(tooltip, errorMessage, null); + this(tooltip, ContentMode.HTML, errorMessage, null); } + /** + * Constructs a new instance using the {@code tooltip} for the title, + * {@code errorMessage} as a description and {@code identifier} as its id. + * + * @param tooltip + * tooltip title + * @param errorMessage + * error description + * @param identifier + * + * @deprecated use {@link #TooltipInfo(String, ContentMode, String, Object)} + * instead + */ + @Deprecated public TooltipInfo(String tooltip, String errorMessage, Object identifier) { + this(tooltip, ContentMode.HTML, errorMessage, identifier); + } + + public TooltipInfo(String tooltip, ContentMode mode) { + setTitle(tooltip); + setContentMode(mode); + } + + public TooltipInfo(String tooltip, ContentMode mode, String errorMessage) { + this(tooltip, mode, errorMessage, null); + } + + public TooltipInfo(String tooltip, ContentMode mode, String errorMessage, + Object identifier) { setIdentifier(identifier); setTitle(tooltip); + setContentMode(mode); setErrorMessage(errorMessage); } @@ -69,6 +113,14 @@ public class TooltipInfo { errorMessageHtml = errorMessage; } + public ContentMode getContentMode() { + return contentMode; + } + + public void setContentMode(ContentMode contentMode) { + this.contentMode = contentMode; + } + /** * Checks is a message has been defined for the tooltip. * diff --git a/client/src/main/java/com/vaadin/client/VTooltip.java b/client/src/main/java/com/vaadin/client/VTooltip.java index 21a3287442..b9fbfa1470 100644 --- a/client/src/main/java/com/vaadin/client/VTooltip.java +++ b/client/src/main/java/com/vaadin/client/VTooltip.java @@ -18,7 +18,10 @@ package com.vaadin.client; import com.google.gwt.aria.client.LiveValue; import com.google.gwt.aria.client.RelevantValue; import com.google.gwt.aria.client.Roles; +import com.google.gwt.core.shared.GWT; +import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.PreElement; import com.google.gwt.dom.client.Style.Display; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; @@ -38,6 +41,7 @@ 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.HTML; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ui.VOverlay; @@ -51,7 +55,7 @@ public class VTooltip extends VOverlay { public static final int TOOLTIP_EVENTS = Event.ONKEYDOWN | Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONMOUSEMOVE | Event.ONCLICK; VErrorMessage em = new VErrorMessage(); - Element description = DOM.createDiv(); + HTML description = GWT.create(HTML.class); private TooltipInfo currentTooltipInfo = new TooltipInfo(" "); @@ -88,8 +92,8 @@ public class VTooltip extends VOverlay { FlowPanel layout = new FlowPanel(); setWidget(layout); layout.add(em); - DOM.setElementProperty(description, "className", CLASSNAME + "-text"); - DOM.appendChild(layout.getElement(), description); + description.setStyleName(CLASSNAME + "-text"); + layout.add(description); // When a tooltip is shown, the content of the tooltip changes. With a // tooltip being a live-area, this change is notified to a assistive @@ -128,7 +132,7 @@ public class VTooltip extends VOverlay { setTooltipText(new TooltipInfo(" ")); showTooltip(); hideTooltip(); - description.getParentElement().getStyle().clearWidth(); + description.getParent().getElement().getStyle().clearWidth(); } private void setTooltipText(TooltipInfo info) { @@ -140,7 +144,24 @@ public class VTooltip extends VOverlay { em.setVisible(false); } if (info.getTitle() != null && !info.getTitle().isEmpty()) { - description.setInnerHTML(info.getTitle()); + switch (info.getContentMode()) { + case HTML: + description.setHTML(info.getTitle()); + break; + case TEXT: + description.setText(info.getTitle()); + break; + case PREFORMATTED: + PreElement preElement = Document.get().createPreElement(); + preElement.setInnerText(info.getTitle()); + // clear existing content + description.setHTML(""); + // add preformatted text to dom + description.getElement().appendChild(preElement); + break; + default: + break; + } /* * Issue #11871: to correctly update the offsetWidth of description * element we need to clear style width of its parent DIV from old @@ -156,11 +177,11 @@ public class VTooltip extends VOverlay { * native GWT method getSubPixelOffsetWidth()) of description * element") */ - description.getParentElement().getStyle().clearWidth(); - description.getStyle().clearDisplay(); + description.getParent().getElement().getStyle().clearWidth(); + description.getElement().getStyle().clearDisplay(); } else { - description.setInnerHTML(""); - description.getStyle().setDisplay(Display.NONE); + description.setHTML(""); + description.getElement().getStyle().setDisplay(Display.NONE); } currentTooltipInfo = info; } @@ -439,7 +460,7 @@ public class VTooltip extends VOverlay { @Override public void hide() { em.updateMessage(""); - description.setInnerHTML(""); + description.setHTML(""); updatePosition(null, true); setPopupPosition(tooltipEventMouseX, tooltipEventMouseY); diff --git a/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java index d7b6d52f98..e35accb1b1 100644 --- a/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java @@ -761,7 +761,8 @@ public abstract class AbstractComponentConnector extends AbstractConnector @Override public TooltipInfo getTooltipInfo(Element element) { - return new TooltipInfo(getState().description, getState().errorMessage); + return new TooltipInfo(getState().description, + getState().descriptionContentMode, getState().errorMessage); } @Override diff --git a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java index 2f1b93994b..6527ac8c93 100644 --- a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java +++ b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java @@ -54,6 +54,7 @@ import com.vaadin.client.TooltipInfo; import com.vaadin.client.UIDL; import com.vaadin.client.Util; import com.vaadin.client.WidgetUtil; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.ui.menubar.MenuBarConstants; public class VMenuBar extends SimpleFocusablePanel @@ -1087,7 +1088,8 @@ public class VMenuBar extends SimpleFocusablePanel return null; } - return new TooltipInfo(description, null, this); + return new TooltipInfo(description, ContentMode.PREFORMATTED, null, + this); } /** diff --git a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java index 4b8c9b2602..8fbd3bcd74 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java @@ -73,6 +73,7 @@ import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.EventId; import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc; import com.vaadin.shared.ui.ComponentStateUtil; +import com.vaadin.shared.ui.ContentMode; import com.vaadin.shared.ui.tabsheet.TabState; import com.vaadin.shared.ui.tabsheet.TabsheetServerRpc; import com.vaadin.shared.ui.tabsheet.TabsheetState; @@ -339,7 +340,8 @@ public class VTabsheet extends VTabsheetBase if (tabState.description != null || tabState.componentError != null) { setTooltipInfo(new TooltipInfo(tabState.description, - tabState.componentError, this)); + ContentMode.PREFORMATTED, tabState.componentError, + this)); } else { setTooltipInfo(null); } |