]> source.dussan.org Git - vaadin-framework.git/commitdiff
Support for invisibility
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Thu, 14 Jun 2007 14:44:57 +0000 (14:44 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Thu, 14 Jun 2007 14:44:57 +0000 (14:44 +0000)
svn changeset:1728/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/Client.java
src/com/itmill/toolkit/terminal/gwt/client/ui/TkButton.java
src/com/itmill/toolkit/terminal/gwt/client/ui/TkCheckBox.java
src/com/itmill/toolkit/terminal/gwt/client/ui/TkHorizontalLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/TkLabel.java
src/com/itmill/toolkit/terminal/gwt/client/ui/TkPanel.java
src/com/itmill/toolkit/terminal/gwt/client/ui/TkTextField.java
src/com/itmill/toolkit/terminal/gwt/client/ui/TkVerticalLayout.java

index 5c805b923ab7d286227d56c7fe12cdda6c46f459..51575630300a1e95a9c5e924c2d76c2a0e36ccb9 100755 (executable)
@@ -38,15 +38,13 @@ public class Client implements EntryPoint {
 
        private HashMap paintables = new HashMap();
 
-       private int requestCount = 0;
-
        private WidgetFactory widgetFactory = new DefaultWidgetFactory();
 
        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {
-               
+
                appUri = getAppUri();
 
                console = new Console(RootPanel.get("itmtk-loki"));
@@ -74,10 +72,10 @@ public class Client implements EntryPoint {
                }
 
        }
-       
+
        private native String getAppUri()/*-{
-               return $wnd.itmtk.appUri;
-       }-*/;
+        return $wnd.itmtk.appUri;
+        }-*/;
 
        private void makeUidlRequest(String requestData) {
                console.log("Making UIDL Request with params: " + requestData);
@@ -114,7 +112,8 @@ public class Client implements EntryPoint {
                                        console.dirUIDL(change);
                                } catch (Exception e) {
                                        console.log(e.getMessage());
-                                       // TODO: dir doesn't work in any browser although it should work (works in hosted mode)
+                                       // TODO: dir doesn't work in any browser although it should
+                                       // work (works in hosted mode)
                                        // it partially did at some part but now broken.
                                }
                                UIDL uidl = change.getChildUIDL(0);
@@ -129,10 +128,9 @@ public class Client implements EntryPoint {
                                                                + uidl.getId() + ") registered yet.");
                                        Widget window = widgetFactory.createWidget(uidl);
                                        registerPaintable(uidl.getId(), (Paintable) window);
-                                       ((Paintable)window).updateFromUIDL(uidl, this);
+                                       ((Paintable) window).updateFromUIDL(uidl, this);
 
-                                       
-                                       // TODO We should also handle other windows 
+                                       // TODO We should also handle other windows
                                        RootPanel.get("itmtk-ajax-window").add(window);
                                }
 
@@ -142,7 +140,8 @@ public class Client implements EntryPoint {
 
                }
                long prosessingTime = (new Date().getTime()) - start.getTime();
-               console.log(" Processing time was " + String.valueOf(prosessingTime) + "ms for "+jsonText.length()+" characters of JSON");
+               console.log(" Processing time was " + String.valueOf(prosessingTime)
+                               + "ms for " + jsonText.length() + " characters of JSON");
 
        }
 
@@ -153,14 +152,6 @@ public class Client implements EntryPoint {
        public Paintable getPaintable(String id) {
                return (Paintable) paintables.get(id);
        }
-/*
-       public Widget createWidgetFromUIDL(UIDL uidlForChild) {
-               Widget w = widgetFactory.createWidget(uidlForChild);
-                       registerPaintable(uidlForChild.getId(), (Paintable) w);
-                       ((Paintable)w).updateFromUIDL(uidlForChild, this);
-               return w;
-       }
-*/
 
        private void addVariableToQueue(String paintableId, String variableName,
                        String encodedValue, boolean immediate) {
@@ -212,17 +203,19 @@ public class Client implements EntryPoint {
                addVariableToQueue(paintableId, variableName, newValue ? "true"
                                : "false", immediate);
        }
-       public void updateVariable(String paintableId, String variableName, Object[] values, boolean immediate) {
+
+       public void updateVariable(String paintableId, String variableName,
+                       Object[] values, boolean immediate) {
                StringBuffer buf = new StringBuffer();
                for (int i = 0; i < values.length; i++) {
-                       if(i > 0)
+                       if (i > 0)
                                buf.append(",");
                        buf.append(escapeString(values[i].toString()));
                }
-               addVariableToQueue("array:" + paintableId, variableName, buf.toString(), immediate);
+               addVariableToQueue("array:" + paintableId, variableName,
+                               buf.toString(), immediate);
        }
 
-
        public WidgetFactory getWidgetFactory() {
                return widgetFactory;
        }
@@ -230,38 +223,76 @@ public class Client implements EntryPoint {
        public void setWidgetFactory(WidgetFactory widgetFactory) {
                this.widgetFactory = widgetFactory;
        }
-       
+
        public static Layout getParentLayout(Widget component) {
                Widget parent = component.getParent();
-               while (parent != null && !(parent instanceof Layout)) parent = parent.getParent();
-               if (parent != null && ((Layout)parent).hasChildComponent(component))
+               while (parent != null && !(parent instanceof Layout))
+                       parent = parent.getParent();
+               if (parent != null && ((Layout) parent).hasChildComponent(component))
                        return (Layout) parent;
                return null;
        }
 
-       public boolean replaceComponentWithCorrectImplementation(Widget currentWidget, UIDL uidl) {
-               if (widgetFactory.isCorrectImplementation(currentWidget, uidl)) return false;
-               Layout parent = getParentLayout(currentWidget);
-               if (parent == null) return false;
+       /**
+        * Ensure that correct implementation is used for the component.
+        * 
+        * 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.
+        * 
+        * @param currentWidget
+        *            Current widget that might need replacement
+        * @param uidl
+        *            UIDL to be painted
+        * @return Returns true
+        */
+       public boolean updateComponent(Widget component, UIDL uidl,
+                       boolean manageCaption) {
+
+               if (manageCaption) {
+                       Layout parent = getParentLayout(component);
+                       if (parent != null)
+                               parent.updateCaption(component, uidl);
+               }
+               
+               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(currentWidget, w);
-               ((Paintable)w).updateFromUIDL(uidl, this);
+               parent.replaceChildComponent(component, w);
+               ((Paintable) w).updateFromUIDL(uidl, this);
 
                return true;
        }
 
-       public void delegateCaptionToParent(Widget component, UIDL uidl) {
-               Layout parent = getParentLayout(component);
-               if (parent != null) parent.updateCaption(component, uidl);
-       }
-       
+
+       /**
+        * Get either existing or new widget for given UIDL.
+        * 
+        * If corresponding paintable has been previously painted, return it.
+        * Otherwise create and register a new widget from UIDL. Caller must update
+        * the returned widget from UIDL after it has been connected to parent.
+        * 
+        * @param uidl
+        *            UIDL to create widget from.
+        * @return Either existing or new widget corresponding to UIDL.
+        */
        public Widget getWidget(UIDL uidl) {
                String id = uidl.getId();
                Widget w = (Widget) getPaintable(id);
-               if (w != null) return w;
+               if (w != null)
+                       return w;
                w = widgetFactory.createWidget(uidl);
-               registerPaintable(id, (Paintable)w);
+               registerPaintable(id, (Paintable) w);
                return w;
        }
 
index 45d0f6864f38ea95d6a97e3cac597d89f511b1d4..00fc65076c01ef9712e11529e510a779ff051274 100644 (file)
@@ -27,7 +27,7 @@ public class TkButton extends com.google.gwt.user.client.ui.Button implements
        public void updateFromUIDL(UIDL uidl, Client client) {
 
                // Ensure correct implementation
-               if (client.replaceComponentWithCorrectImplementation(this, uidl))
+               if (client.updateComponent(this, uidl, false))
                        return;
 
                // Save details
index 1e91dbc0505c3d8996a225bc30b983136b1feba0..0241a8f6dd6fa3bc1c96e5eee4a05e9dfc3fb199 100644 (file)
@@ -30,7 +30,7 @@ public class TkCheckBox extends com.google.gwt.user.client.ui.CheckBox
        public void updateFromUIDL(UIDL uidl, Client client) {
                
                // Ensure correct implementation
-               if (client.replaceComponentWithCorrectImplementation(this, uidl))
+               if (client.updateComponent(this, uidl, false))
                        return;
 
                // Save details
index d5d5c6067c7f758c5ff932ec8a84614d3c86dcf3..dc0c839e4e5b53cfffc9ec78f93ad3df196f51a3 100644 (file)
@@ -18,7 +18,7 @@ public class TkHorizontalLayout extends HorizontalPanel implements Paintable, La
        public void updateFromUIDL(UIDL uidl, Client client) {
                
                // Ensure correct implementation
-               if (client.replaceComponentWithCorrectImplementation(this, uidl))
+               if (client.updateComponent(this, uidl, false))
                        return;
 
                // TODO Should update instead of just redraw
index af89f6eff4744f2f518cf52c0d5e0f6e3e7f03df..1d105dbb44a048b4eb4ac3a3d5b3ec9d22a7a111 100644 (file)
@@ -10,9 +10,8 @@ public class TkLabel extends HTML implements Paintable {
 
        public void updateFromUIDL(UIDL uidl, Client client) {
 
-               if (client.replaceComponentWithCorrectImplementation(this, uidl))
+               if (client.updateComponent(this, uidl, true))
                        return;
-               client.delegateCaptionToParent(this, uidl);
 
                String mode = uidl.getStringAttribute("mode");
                if (mode == null || "text".equals(mode))
index 910dea65c765174b59a018829bf9931f798d5173..2ef901009b056b462a75eedd41a3ba072d9cd03e 100644 (file)
@@ -8,7 +8,6 @@ public class TkPanel extends TkVerticalLayout implements Paintable {
 
        public void updateFromUIDL(UIDL uidl, Client client) {
                super.updateFromUIDL(uidl, client);
-               client.delegateCaptionToParent(this, uidl);
        }
        
 }
index 82fcbae2f4e58462cfe315e2d9d2c9441e073896..d8d7101a2181577c7268ae429d02b287ae31da21 100644 (file)
@@ -50,9 +50,8 @@ public class TkTextField extends TextBoxBase implements
                this.client = client;
                id = uidl.getId();
                
-               if(client.replaceComponentWithCorrectImplementation(this, uidl))
+               if(client.updateComponent(this, uidl, true))
                        return;
-               client.delegateCaptionToParent(this, uidl);
                
                immediate  = uidl.getBooleanAttribute("immediate");
 
index 89e17db0daf427a48e57f49c819e694a2f653ffe..e773878d20feb713e34e94b303937391fc9227a7 100644 (file)
@@ -18,7 +18,7 @@ public class TkVerticalLayout extends VerticalPanel implements Paintable, Layout
        public void updateFromUIDL(UIDL uidl, Client client) {
                
                // Ensure correct implementation
-               if (client.replaceComponentWithCorrectImplementation(this, uidl))
+               if (client.updateComponent(this, uidl, false))
                        return;
 
                // TODO Should update instead of just redraw