]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8437 Error indicators in tabs work again
authorArtur Signell <artur@vaadin.com>
Thu, 22 Mar 2012 11:46:56 +0000 (13:46 +0200)
committerArtur Signell <artur@vaadin.com>
Thu, 22 Mar 2012 11:47:23 +0000 (13:47 +0200)
src/com/vaadin/terminal/gwt/client/VCaption.java
src/com/vaadin/terminal/gwt/client/ui/TabsheetBaseConnector.java
src/com/vaadin/terminal/gwt/client/ui/VAccordion.java
src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java
src/com/vaadin/ui/TabSheet.java

index b8a105f21be325d06265b455ac8e783d8f09cfaf..cf4e5bdd17f4d7476b8aa9e24b941a89e47adfb6 100644 (file)
@@ -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("&nbsp;");
                 }
             } else {
@@ -324,6 +323,22 @@ public class VCaption extends HTML {
             captionText = null;
         }
 
+        if (hasError) {
+            if (errorIndicatorElement == null) {
+                errorIndicatorElement = DOM.createDiv();
+                DOM.setInnerHTML(errorIndicatorElement, "&nbsp;");
+                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;
index bca4163185b2e0e764cf1a09124dbe1e6748c6e7..9f023aba675fa9510d59fcfc14b921777d741658 100644 (file)
@@ -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";
 
index cf07219516de655be0f697742fa79f5814809abb..019580751a1ff5de0e33d5604dce40a3faea53ae 100644 (file)
@@ -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));
         }
 
index 6e4f104b17da5518dfe9d8549f112e691d5ac3a2..d2064c8d5e6f352aac1611b43e028a2f96ef9863 100644 (file)
@@ -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"));
index 0caa55e96919eb9d58f8b231e183bace2caa5cff..7bafb7e75c5fdb3888cc8c79c54b057fce93231f 100644 (file)
@@ -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(