]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #1112 (partially)
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 8 Nov 2007 11:49:28 +0000 (11:49 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 8 Nov 2007 11:49:28 +0000 (11:49 +0000)
svn changeset:2761/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/Caption.java
src/com/itmill/toolkit/terminal/gwt/client/ErrorMessage.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ICheckBox.java

index 7a5887cd93f83dcdcf81dcbe98990822a9a0e0e8..0669524de8d057ee5dc3ec9b68b78d45d4305d2b 100644 (file)
@@ -20,8 +20,6 @@ public class Caption extends HTML {
 
        private ErrorMessage errorMessage;
 
-       private PopupPanel errorContainer;
-
        /* Caption must be attached to a Paintable */
        private Caption() {
        };
@@ -106,27 +104,14 @@ public class Caption extends HTML {
        }
 
        private void hideErrorMessage() {
-               if (errorContainer != null) {
-                       errorContainer.hide();
+               if (errorMessage != null) {
+                       errorMessage.hide();
                }
        }
 
        private void showErrorMessage() {
                if (errorMessage != null) {
-                       if (errorContainer == null) {
-                               errorContainer = new PopupPanel();
-                               errorContainer.setWidget(errorMessage);
-                       }
-                       errorContainer.setPopupPosition(DOM
-                                       .getAbsoluteLeft(errorIndicatorElement)
-                                       + 2
-                                       * DOM.getElementPropertyInt(errorIndicatorElement,
-                                                       "offsetHeight"), DOM
-                                       .getAbsoluteTop(errorIndicatorElement)
-                                       + 2
-                                       * DOM.getElementPropertyInt(errorIndicatorElement,
-                                                       "offsetHeight"));
-                       errorContainer.show();
+                       errorMessage.showAt(errorIndicatorElement);
                }
        }
 
index fd46951fc1e1d7e36dc327913a8a5c3d6d4c812c..57ba0b254a9100d796f0fc0de275fb840a60cc98 100644 (file)
@@ -2,8 +2,11 @@ package com.itmill.toolkit.terminal.gwt.client;
 
 import java.util.Iterator;
 
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.ui.FlowPanel;
 import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.PopupPanel;
 
 public class ErrorMessage extends FlowPanel {
        public static final String CLASSNAME = "i-error";
@@ -30,4 +33,34 @@ public class ErrorMessage extends FlowPanel {
                        }
                }
        }
+       
+       /**
+        * Shows this error message next to given element.
+        * 
+        * @param indicatorElement
+        */
+       public void showAt(Element indicatorElement) {
+               PopupPanel errorContainer = (PopupPanel) this.getParent();
+               if (errorContainer == null) {
+                       errorContainer = new PopupPanel();
+                       errorContainer.setWidget(this);
+               }
+               errorContainer.setPopupPosition(DOM
+                               .getAbsoluteLeft(indicatorElement)
+                               + 2
+                               * DOM.getElementPropertyInt(indicatorElement,
+                                               "offsetHeight"), DOM
+                               .getAbsoluteTop(indicatorElement)
+                               + 2
+                               * DOM.getElementPropertyInt(indicatorElement,
+                                               "offsetHeight"));
+               errorContainer.show();
+               
+       }
+
+       public void hide() {
+               PopupPanel errorContainer = (PopupPanel) this.getParent();
+               if(errorContainer != null)
+                       errorContainer.hide();
+       }
 }
index 9998eda636d2a97fd706c265e26aff4c98e2d28f..50e1b76e6d63fe8b0b20776fca2cda62890a7ef6 100644 (file)
@@ -1,8 +1,12 @@
 package com.itmill.toolkit.terminal.gwt.client.ui;
 
+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.ClickListener;
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+import com.itmill.toolkit.terminal.gwt.client.ErrorMessage;
 import com.itmill.toolkit.terminal.gwt.client.Paintable;
 import com.itmill.toolkit.terminal.gwt.client.UIDL;
 
@@ -17,6 +21,10 @@ public class ICheckBox extends com.google.gwt.user.client.ui.CheckBox implements
 
        ApplicationConnection client;
 
+       private Element errorIndicatorElement;
+
+       private ErrorMessage errorMessage;
+
        public ICheckBox() {
                setStyleName(CLASSNAME);
                addClickListener(new ClickListener() {
@@ -28,22 +36,66 @@ public class ICheckBox extends com.google.gwt.user.client.ui.CheckBox implements
                        }
 
                });
+               
        }
 
        public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+               // Save details
+               this.client = client;
+               id = uidl.getId();
 
                // Ensure correct implementation
                if (client.updateComponent(this, uidl, false))
                        return;
+               
+               if (uidl.hasAttribute("error")) {
+                       UIDL errorUidl = uidl.getErrors();
+
+                       if (errorIndicatorElement == null) {
+                               errorIndicatorElement = DOM.createDiv();
+                               DOM.sinkEvents(errorIndicatorElement, Event.MOUSEEVENTS);
+                               DOM.setElementProperty(errorIndicatorElement, "className",
+                                               "i-errorindicator");
+                               DOM.appendChild(getElement(), errorIndicatorElement);
+                       }
+                       if (errorMessage == null)
+                               errorMessage = new ErrorMessage();
+                       errorMessage.updateFromUIDL(errorUidl);
+
+               } else if (errorIndicatorElement != null) {
+                       DOM.setStyleAttribute(errorIndicatorElement, "display", "none");
+               }
+               
+               if(uidl.hasAttribute("description")) {
+                       setTitle(uidl.getStringAttribute("description"));
+               }
 
-               // Save details
-               this.client = client;
-               id = uidl.getId();
 
                // Set text
                setText(uidl.getStringAttribute("caption"));
                setChecked(uidl.getBooleanVariable("state"));
                immediate = uidl.getBooleanAttribute("immediate");
        }
+       
+       public void onBrowserEvent(Event event) {
+               super.onBrowserEvent(event);
+               Element target = DOM.eventGetTarget(event);
+               if (errorIndicatorElement != null
+                               && DOM.compare(target, errorIndicatorElement)) {
+                       switch (DOM.eventGetType(event)) {
+                       case Event.ONMOUSEOVER:
+                               errorMessage.showAt(errorIndicatorElement);
+                               break;
+                       case Event.ONMOUSEOUT:
+                               errorMessage.hide();
+                               break;
+                       case Event.ONCLICK:
+                               ApplicationConnection.getConsole().log(
+                                               DOM.getInnerHTML(errorMessage.getElement()));
+                       default:
+                               break;
+                       }
+               }
 
+       }
 }