]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed some component visibility bugs
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Thu, 14 Jun 2007 16:38:46 +0000 (16:38 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Thu, 14 Jun 2007 16:38:46 +0000 (16:38 +0000)
svn changeset:1736/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/CaptionWrapper.java
src/com/itmill/toolkit/terminal/gwt/client/Client.java

index dfe72bbf7da02e090458c6bb54db6c645aa4974e..e609798301800f4a06c26db9458a68f275f99890 100644 (file)
@@ -29,6 +29,7 @@ public class CaptionWrapper extends VerticalPanel {
                        else 
                                caption.setText(c);
                }               
+               setVisible(!uidl.getBooleanAttribute("invisible"));
        }
        
        public static boolean isNeeded(UIDL uidl) {
index e97c33ef088aa2af8ef06394948e594f74ff8c30..5b17f41bfab46e4ef30f6fd5750781466962cc8c 100755 (executable)
@@ -14,6 +14,7 @@ import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONParser;
 import com.google.gwt.json.client.JSONValue;
+import com.google.gwt.user.client.ui.FocusWidget;
 import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ui.IButton;
@@ -234,46 +235,76 @@ public class Client implements EntryPoint {
        }
 
        /**
-        * Ensure that correct implementation is used for the component.
+        * Update generic component features.
         * 
+        * <h2>Selecting correct implementation</h2>
+        * 
+        * <p>
         * The implementation of a component depends on many properties, including
         * styles, component features, etc. Sometimes the user changes those
         * properties after the component has been created. Calling this method in
         * the beginning of your updateFromUIDL -method automatically replaces your
         * component with more appropriate if the requested implementation changes.
+        * </p>
+        * 
+        * <h2>Caption, icon, error messages and description</h2>
+        * 
+        * <p>
+        * Component can delegate management of caption, icon, error messages and
+        * description to parent layout. This is optional an should be decided by
+        * component author
+        * </p>
+        * 
+        * <h2>Component visibility and disabling</h2>
+        * 
+        * This method will manage component visibility automatically and if
+        * component is an instanceof FocusWidget, also handle component disabling
+        * when needed.
         * 
         * @param currentWidget
         *            Current widget that might need replacement
         * @param uidl
         *            UIDL to be painted
-        * @return Returns true
+        * @param manageCaption
+        *            True if you want to delegate caption, icon, description and
+        *            error message management to parent.
+        * 
+        * @return Returns true iff no further painting is needed by caller
         */
        public boolean updateComponent(Widget component, UIDL uidl,
                        boolean manageCaption) {
 
+               // Switch to correct implementation if neede
+               if (!widgetFactory.isCorrectImplementation(component, uidl)) {
+                       Layout parent = getParentLayout(component);
+                       if (parent != null) {
+                               Widget w = widgetFactory.createWidget(uidl);
+                               registerPaintable(uidl.getId(), (Paintable) w);
+                               parent.replaceChildComponent(component, w);
+                               ((Paintable) w).updateFromUIDL(uidl, this);
+                               return true;
+                       }
+               }
+
+               // Set captions
+               // TODO Manage Error messages
                if (manageCaption) {
                        Layout parent = getParentLayout(component);
                        if (parent != null)
                                parent.updateCaption(component, uidl);
                }
-               
+
+               // Visibility, Disabling and read-only status
+               if (component instanceof FocusWidget)
+                       ((FocusWidget) component).setEnabled(!uidl
+                                       .getBooleanAttribute("disabled"));
                boolean visible = !uidl.getBooleanAttribute("invisible");
                component.setVisible(visible);
-               if (!visible) return true;
-               
-               if (widgetFactory.isCorrectImplementation(component, uidl))
-                       return false;
-               Layout parent = getParentLayout(component);
-               if (parent == null)
-                       return false;
-               Widget w = widgetFactory.createWidget(uidl);
-               registerPaintable(uidl.getId(), (Paintable) w);
-               parent.replaceChildComponent(component, w);
-               ((Paintable) w).updateFromUIDL(uidl, this);
-
-               return true;
-       }
+               if (!visible)
+                       return true;
 
+               return false;
+       }
 
        /**
         * Get either existing or new widget for given UIDL.