From: Artur Signell Date: Thu, 22 Mar 2012 11:46:56 +0000 (+0200) Subject: #8437 Error indicators in tabs work again X-Git-Tag: 7.0.0.alpha2~246 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4f2909b2a568adfe7da4c0ae514fe41988fc9d0b;p=vaadin-framework.git #8437 Error indicators in tabs work again --- diff --git a/src/com/vaadin/terminal/gwt/client/VCaption.java b/src/com/vaadin/terminal/gwt/client/VCaption.java index b8a105f21b..cf4e5bdd17 100644 --- a/src/com/vaadin/terminal/gwt/client/VCaption.java +++ b/src/com/vaadin/terminal/gwt/client/VCaption.java @@ -10,7 +10,6 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.HTML; import com.vaadin.terminal.gwt.client.ui.AbstractFieldConnector; import com.vaadin.terminal.gwt.client.ui.Icon; -import com.vaadin.terminal.gwt.client.ui.TabsheetBaseConnector; public class VCaption extends HTML { @@ -249,7 +248,7 @@ public class VCaption extends HTML { @Deprecated public boolean updateCaptionWithoutOwner(String caption, boolean disabled, - boolean hasDescription, String iconURL) { + boolean hasDescription, boolean hasError, String iconURL) { boolean wasPlacedAfterComponent = placedAfterComponent; // Caption is placed after component unless there is some part which @@ -311,7 +310,7 @@ public class VCaption extends HTML { // browsers when it is set to the empty string. If there is an // icon, error indicator or required indicator they will ensure // that space is reserved. - if (!hasIcon) { + if (!hasIcon && !hasError) { captionText.setInnerHTML(" "); } } else { @@ -324,6 +323,22 @@ public class VCaption extends HTML { captionText = null; } + if (hasError) { + if (errorIndicatorElement == null) { + errorIndicatorElement = DOM.createDiv(); + DOM.setInnerHTML(errorIndicatorElement, " "); + DOM.setElementProperty(errorIndicatorElement, "className", + "v-errorindicator"); + + DOM.insertChild(getElement(), errorIndicatorElement, + getInsertPosition(InsertPosition.ERROR)); + } + } else if (errorIndicatorElement != null) { + // Remove existing + getElement().removeChild(errorIndicatorElement); + errorIndicatorElement = null; + } + return (wasPlacedAfterComponent != placedAfterComponent); } @@ -363,20 +378,6 @@ public class VCaption extends HTML { } } - @Deprecated - public static boolean isNeeded(UIDL uidl) { - // TODO fallback for cases where the caption has no owner (Tabsheet, - // Accordion) - if (uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_CAPTION) != null) { - return true; - } - if (uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ICON)) { - return true; - } - - return false; - } - public static boolean isNeeded(ComponentState state) { if (state.getCaption() != null) { return true; diff --git a/src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java b/src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java index bca4163185..9f023aba67 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java @@ -16,6 +16,7 @@ public abstract class TabsheetBaseConnector extends public static final String ATTRIBUTE_TAB_DISABLED = "disabled"; public static final String ATTRIBUTE_TAB_DESCRIPTION = "description"; + public static final String ATTRIBUTE_TAB_ERROR_MESSAGE = "error"; public static final String ATTRIBUTE_TAB_CAPTION = "caption"; public static final String ATTRIBUTE_TAB_ICON = "icon"; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java b/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java index cf07219516..019580751a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java @@ -443,6 +443,7 @@ public class VAccordion extends VTabsheetBase { uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_CAPTION), uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DISABLED), uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION), + uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ERROR_MESSAGE), uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ICON)); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java index 6e4f104b17..d2064c8d5e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java @@ -252,8 +252,9 @@ public class VTabsheet extends VTabsheetBase implements Focusable, tooltipInfo .setTitle(uidl .getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION)); - // TODO currently, there is no error indicator and message for a - // tab + tooltipInfo + .setErrorMessage(uidl + .getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ERROR_MESSAGE)); client.registerTooltip(getTabsheet(), getElement(), tooltipInfo); } else { client.registerTooltip(getTabsheet(), getElement(), null); @@ -265,6 +266,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_CAPTION), uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DISABLED), uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION), + uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ERROR_MESSAGE), uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ICON)); setClosable(uidl.hasAttribute("closable")); diff --git a/src/com/vaadin/ui/TabSheet.java b/src/com/vaadin/ui/TabSheet.java index 0caa55e969..7bafb7e75c 100644 --- a/src/com/vaadin/ui/TabSheet.java +++ b/src/com/vaadin/ui/TabSheet.java @@ -403,7 +403,12 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, target.addAttribute( TabsheetBaseConnector.ATTRIBUTE_TAB_CAPTION, caption); } - + ErrorMessage tabError = tab.getComponentError(); + if (tabError != null) { + target.addAttribute( + TabsheetBaseConnector.ATTRIBUTE_TAB_ERROR_MESSAGE, + tabError.getFormattedHtmlMessage()); + } final String description = tab.getDescription(); if (description != null) { target.addAttribute(