]> source.dussan.org Git - vaadin-framework.git/commitdiff
svn changeset:2012/svn branch:trunk
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 15 Aug 2007 08:19:07 +0000 (08:19 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 15 Aug 2007 08:19:07 +0000 (08:19 +0000)
src/com/itmill/toolkit/terminal/gwt/client/Caption.java
src/com/itmill/toolkit/terminal/gwt/client/UIDL.java
src/com/itmill/toolkit/terminal/gwt/public/component-themes/caption/css/caption.css [new file with mode: 0644]
src/com/itmill/toolkit/terminal/gwt/public/component-themes/collection.css
src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java

index 3e1936638b098a9f3217c9526c34e1e1a493d620..873433ba67d7e79b1a5d2f74c976e490484e5241 100644 (file)
@@ -1,15 +1,29 @@
 package com.itmill.toolkit.terminal.gwt.client;
 
+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.HTML;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.VerticalPanel;
-import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.PopupPanel;
+import com.google.gwt.user.client.ui.SimplePanel;
 
 public class Caption extends HTML {
        
        private Paintable owner;
 
+       private Element errorIndicatorElement;
+       
+       private Element captionText;
+
+       private ErrorMessage errorMessage;
+       
+       private PopupPanel errorContainer;
+       
+       /* Caption must be attached to a Paintable */
+       private Caption(){};
+       
        public Caption(Paintable component)  {
+               super();
                owner = component;
                setStyleName("i-caption");
        }
@@ -17,21 +31,78 @@ public class Caption extends HTML {
        public void updateCaption(UIDL uidl) {
                setVisible(!uidl.getBooleanAttribute("invisible"));
                
-               String c = uidl.getStringAttribute("caption");
-               if (c == null) {
-               } else {
-                       setText(c);
+               if(uidl.hasAttribute("error")) {
+                       UIDL errorUidl = uidl.getErrors();
+                       
+                       if(errorIndicatorElement == null) {
+                               errorIndicatorElement = DOM.createDiv();
+                               DOM.setAttribute(errorIndicatorElement, "className", "i-errorindicator");
+                               DOM.insertChild(getElement(), errorIndicatorElement, 0);
+                       }
+                       
+                       errorMessage = new ErrorMessage();
+                       errorMessage.updateFromUIDL(errorUidl);
+                       
+               } else if( errorIndicatorElement != null) {
+                       DOM.setStyleAttribute(errorIndicatorElement, "display", "none");
                }
                
-               if(uidl.hasAttribute("description")) {
-                       setTitle(uidl.getStringAttribute("description"));
+               
+               if(uidl.hasAttribute("caption")) {
+                       if(captionText == null) {
+                               captionText = DOM.createSpan();
+                               DOM.appendChild(getElement(), captionText);
+                       }
+                       DOM.setInnerText(captionText, uidl.getStringAttribute("caption"));
                }
                
-               if(uidl.hasAttribute("error")) {
-                       // TODO error messages
+               if(uidl.hasAttribute("description")) {
+                       if(captionText != null) {
+                               DOM.setAttribute(captionText, "title", uidl.getStringAttribute("description"));
+                       } else {
+                               setTitle(uidl.getStringAttribute("description"));
+                       }
                }
+               
        }
        
+       public void onBrowserEvent(Event event) {
+               Element target= DOM.eventGetTarget(event);
+               if(errorIndicatorElement != null && DOM.compare(target, errorIndicatorElement)) {
+                       switch (DOM.eventGetType(event)) {
+                       case Event.ONMOUSEOVER:
+                               showErrorMessage();
+                               break;
+                       case Event.ONMOUSEOUT:
+                               hideErrorMessage();
+                               break;
+                       default:
+                               break;
+                       }
+               }
+       }
+
+       private void hideErrorMessage() {
+               if(errorContainer != null) {
+                       errorContainer.hide();
+               }
+       }
+
+       private void showErrorMessage() {
+               if(errorMessage != null) {
+                       if(errorContainer == null) {
+                               errorContainer = new PopupPanel();
+                               errorContainer.setWidget(errorMessage);
+                       }
+                       errorContainer.setPopupPosition(
+                                       DOM.getAbsoluteLeft(errorIndicatorElement) +
+                                               2*DOM.getIntAttribute(errorIndicatorElement, "offsetHeight"),
+                                       DOM.getAbsoluteTop(errorIndicatorElement) + 
+                                               2*DOM.getIntAttribute(errorIndicatorElement, "offsetHeight"));
+                       errorContainer.show();
+               }
+       }
+
        public static boolean isNeeded(UIDL uidl) {
                if (uidl.getStringAttribute("caption") != null) return true;
                // TODO Description and error messages
index 3dc4997e0b75e3aebb72006da08581f95aa0e898..4cffdbcd35dd5c3f8f2d97e45e77369612396377 100644 (file)
@@ -397,4 +397,10 @@ public class UIDL {
        public int getChidlCount() {
                return json.size()-2;
        }
+
+       public UIDL getErrors() {
+               JSONArray a = (JSONArray) ((JSONObject) json.get(1)).get("error");
+               return new UIDL(a);
+       }
+
 }
diff --git a/src/com/itmill/toolkit/terminal/gwt/public/component-themes/caption/css/caption.css b/src/com/itmill/toolkit/terminal/gwt/public/component-themes/caption/css/caption.css
new file mode 100644 (file)
index 0000000..af4a30e
--- /dev/null
@@ -0,0 +1,13 @@
+.i-errorindicator {
+       width: 10px;
+       height: 10px;
+       display: block;
+       float:left;
+       background: #f00;
+}
+
+.i-error {
+       padding-left: 15px;
+       background: #fff;
+       border: 1px solid red;
+}
\ No newline at end of file
index ee80367724ab13ebdd7753d10e99dee4a5f3ebf0..df2efe8c1dd8e446113f66953b91011996a6f0ff 100644 (file)
@@ -7,3 +7,4 @@
 @import "table/css/table.css";\r
 @import "slider/css/slider.css";
 @import "window/css/window.css";
+@import "caption/css/caption.css";
index a755ca9c651e8fa566d9970ddd22113b8133fd45..a4e0fa5db92f7e7ee4bf93f618160aba1bfc77af 100644 (file)
@@ -87,6 +87,8 @@ public class JsonPaintTarget implements PaintTarget {
 
        private JsonTag tag;
 
+       private int errorsOpen;
+
        /**
         * Creates a new XMLPrintWriter, without automatic line flushing.
         * 
@@ -162,6 +164,10 @@ public class JsonPaintTarget implements PaintTarget {
                mTagArgumentListOpen = true;
 
                customLayoutArgumentsOpen = "customlayout".equals(tagName);
+               
+               if("error".equals(tagName)) {
+                       errorsOpen++;
+               }
        }
 
        /**
@@ -195,7 +201,17 @@ public class JsonPaintTarget implements PaintTarget {
                                throw new PaintException("Invalid UIDL: wrong ending tag: '"
                                                + tagName + "' expected: '" + lastTag + "'.");
 
-                       parent.addData(tag.getJSON());
+                       // simple hack which writes error uidl structure into attribute
+                       if("error".equals(lastTag)) {
+                               if(errorsOpen == 1) // ending error section
+                                       parent.addAttribute("\"error\":[\"error\",{}"+tag.getData() + "]");
+                               else // sub error
+                                       parent.addData(tag.getJSON());
+                               errorsOpen--;
+                       } else {
+                               parent.addData(tag.getJSON());
+                       }
+                       
 
                        tag = parent;
                } else {