]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8324 Split Form and FormLayout into widget and paintable
authorArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 11:58:36 +0000 (13:58 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 13:08:39 +0000 (15:08 +0200)
src/com/vaadin/terminal/gwt/client/ui/VForm.java
src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java
src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java [new file with mode: 0644]
src/com/vaadin/ui/Form.java
src/com/vaadin/ui/FormLayout.java

index a329e1eaefe0dcf025539c44b715c53bb0f22fb2..d70d7ed0d8fdf4cd873eaa45c4d67a91eb28e1ec 100644 (file)
@@ -19,12 +19,9 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.Container;
 import com.vaadin.terminal.gwt.client.RenderInformation;
 import com.vaadin.terminal.gwt.client.RenderSpace;
-import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.VConsole;
 import com.vaadin.terminal.gwt.client.VErrorMessage;
-import com.vaadin.terminal.gwt.client.VPaintableMap;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
 
 public class VForm extends ComplexPanel implements Container, KeyDownHandler {
 
@@ -36,33 +33,33 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
 
     public static final String CLASSNAME = "v-form";
 
-    private Container lo;
-    private Element legend = DOM.createLegend();
-    private Element caption = DOM.createSpan();
+    Widget lo;
+    Element legend = DOM.createLegend();
+    Element caption = DOM.createSpan();
     private Element errorIndicatorElement = DOM.createDiv();
-    private Element desc = DOM.createDiv();
-    private Icon icon;
-    private VErrorMessage errorMessage = new VErrorMessage();
+    Element desc = DOM.createDiv();
+    Icon icon;
+    VErrorMessage errorMessage = new VErrorMessage();
 
-    private Element fieldContainer = DOM.createDiv();
+    Element fieldContainer = DOM.createDiv();
 
-    private Element footerContainer = DOM.createDiv();
+    Element footerContainer = DOM.createDiv();
 
-    private Element fieldSet = DOM.createFieldSet();
+    Element fieldSet = DOM.createFieldSet();
 
-    private Container footer;
+    Widget footer;
 
-    private ApplicationConnection client;
+    ApplicationConnection client;
 
     private RenderInformation renderInformation = new RenderInformation();
 
     private int borderPaddingHorizontal = -1;
 
-    private boolean rendering = false;
+    boolean rendering = false;
 
     ShortcutActionHandler shortcutHandler;
 
-    private HandlerRegistration keyDownRegistration;
+    HandlerRegistration keyDownRegistration;
 
     public VForm() {
         setElement(DOM.createDiv());
@@ -84,130 +81,6 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
         fieldSet.appendChild(footerContainer);
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        rendering = true;
-        this.client = client;
-        id = uidl.getId();
-
-        if (client.updateComponent(this, uidl, false)) {
-            rendering = false;
-            return;
-        }
-
-        boolean legendEmpty = true;
-        if (uidl.hasAttribute("caption")) {
-            caption.setInnerText(uidl.getStringAttribute("caption"));
-            legendEmpty = false;
-        } else {
-            caption.setInnerText("");
-        }
-        if (uidl.hasAttribute("icon")) {
-            if (icon == null) {
-                icon = new Icon(client);
-                legend.insertFirst(icon.getElement());
-            }
-            icon.setUri(uidl.getStringAttribute("icon"));
-            legendEmpty = false;
-        } else {
-            if (icon != null) {
-                legend.removeChild(icon.getElement());
-            }
-        }
-        if (legendEmpty) {
-            addStyleDependentName("nocaption");
-        } else {
-            removeStyleDependentName("nocaption");
-        }
-
-        if (uidl.hasAttribute("error")) {
-            final UIDL errorUidl = uidl.getErrors();
-            errorMessage.updateFromUIDL(errorUidl);
-            errorMessage.setVisible(true);
-
-        } else {
-            errorMessage.setVisible(false);
-        }
-
-        if (uidl.hasAttribute("description")) {
-            desc.setInnerHTML(uidl.getStringAttribute("description"));
-            if (desc.getParentElement() == null) {
-                fieldSet.insertAfter(desc, legend);
-            }
-        } else {
-            desc.setInnerHTML("");
-            if (desc.getParentElement() != null) {
-                fieldSet.removeChild(desc);
-            }
-        }
-
-        updateSize();
-
-        // first render footer so it will be easier to handle relative height of
-        // main layout
-        if (uidl.getChildCount() > 1
-                && !uidl.getChildUIDL(1).getTag().equals("actions")) {
-            // render footer
-            Container newFooter = (Container) client.getPaintable(uidl
-                    .getChildUIDL(1));
-            if (footer == null) {
-                add(newFooter.getWidgetForPaintable(), footerContainer);
-                footer = newFooter;
-            } else if (newFooter != footer) {
-                remove(footer.getWidgetForPaintable());
-                client.unregisterPaintable(footer);
-                add(newFooter.getWidgetForPaintable(), footerContainer);
-            }
-            footer = newFooter;
-            footer.updateFromUIDL(uidl.getChildUIDL(1), client);
-            // needed for the main layout to know the space it has available
-            updateSize();
-        } else {
-            if (footer != null) {
-                remove(footer.getWidgetForPaintable());
-                client.unregisterPaintable(footer);
-                // needed for the main layout to know the space it has available
-                updateSize();
-            }
-        }
-
-        final UIDL layoutUidl = uidl.getChildUIDL(0);
-        Container newLo = (Container) client.getPaintable(layoutUidl);
-        if (lo == null) {
-            lo = newLo;
-            add(lo.getWidgetForPaintable(), fieldContainer);
-        } else if (lo != newLo) {
-            client.unregisterPaintable(lo);
-            remove(lo.getWidgetForPaintable());
-            lo = newLo;
-            add(lo.getWidgetForPaintable(), fieldContainer);
-        }
-        lo.updateFromUIDL(layoutUidl, client);
-
-        // also recalculates size of the footer if undefined size form - see
-        // #3710
-        updateSize();
-        client.runDescendentsLayout(this);
-
-        // We may have actions attached
-        if (uidl.getChildCount() > 1) {
-            UIDL childUidl = uidl.getChildByTagName("actions");
-            if (childUidl != null) {
-                if (shortcutHandler == null) {
-                    shortcutHandler = new ShortcutActionHandler(id, client);
-                    keyDownRegistration = addDomHandler(this,
-                            KeyDownEvent.getType());
-                }
-                shortcutHandler.updateActionMap(childUidl);
-            }
-        } else if (shortcutHandler != null) {
-            keyDownRegistration.removeHandler();
-            shortcutHandler = null;
-            keyDownRegistration = null;
-        }
-
-        rendering = false;
-    }
-
     public void updateSize() {
 
         renderInformation.updateSize(getElement());
@@ -241,12 +114,10 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
         }
         remove(oldComponent);
         if (oldComponent == lo) {
-            lo = (Container) VPaintableMap.get(client).getPaintable(
-                    newComponent);
+            lo = newComponent;
             add(newComponent, fieldContainer);
         } else {
-            footer = (Container) VPaintableMap.get(client).getPaintable(
-                    newComponent);
+            footer = newComponent;
             add(newComponent, footerContainer);
         }
 
@@ -272,11 +143,6 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
 
     }
 
-    public void updateCaption(VPaintableWidget component, UIDL uidl) {
-        // NOP form don't render caption for neither field layout nor footer
-        // layout
-    }
-
     @Override
     public void setHeight(String height) {
         if (this.height.equals(height)) {
@@ -332,4 +198,11 @@ public class VForm extends ComplexPanel implements Container, KeyDownHandler {
     public Widget getWidgetForPaintable() {
         return this;
     }
+
+    @Override
+    protected void add(Widget child, Element container) {
+        // Overridden to allow VFormPaintable to call this. Should be removed
+        // once functionality from VFormPaintable is moved to VForm.
+        super.add(child, container);
+    }
 }
index e6305b3c42f830c7d663ca906cb09e71cdcd0fa9..b2357f11e169f78a7c37d0d5e9bd8182a4500f80 100644 (file)
@@ -38,13 +38,13 @@ public class VFormLayout extends SimplePanel implements Container {
 
     private final static String CLASSNAME = "v-formlayout";
 
-    private ApplicationConnection client;
-    private VFormLayoutTable table;
+    ApplicationConnection client;
+    VFormLayoutTable table;
 
     private String width = "";
     private String height = "";
 
-    private boolean rendering = false;
+    boolean rendering = false;
 
     public VFormLayout() {
         super();
@@ -279,21 +279,6 @@ public class VFormLayout extends SimplePanel implements Container {
         }
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        rendering = true;
-
-        this.client = client;
-
-        if (client.updateComponent(this, uidl, true)) {
-            rendering = false;
-            return;
-        }
-
-        table.updateFromUIDL(uidl, client);
-
-        rendering = false;
-    }
-
     public boolean isDynamicWidth() {
         return width.equals("");
     }
@@ -306,10 +291,6 @@ public class VFormLayout extends SimplePanel implements Container {
         table.replaceChildComponent(oldComponent, newComponent);
     }
 
-    public void updateCaption(VPaintableWidget component, UIDL uidl) {
-        table.updateCaption(component, uidl);
-    }
-
     public class Caption extends HTML {
 
         public static final String CLASSNAME = "v-caption";
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java
new file mode 100644 (file)
index 0000000..c4590a7
--- /dev/null
@@ -0,0 +1,39 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+\r
+public class VFormLayoutPaintable extends VAbstractPaintableWidgetContainer {\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        getWidgetForPaintable().rendering = true;\r
+\r
+        getWidgetForPaintable().client = client;\r
+\r
+        if (client.updateComponent(this, uidl, true)) {\r
+            getWidgetForPaintable().rendering = false;\r
+            return;\r
+        }\r
+\r
+        getWidgetForPaintable().table.updateFromUIDL(uidl, client);\r
+\r
+        getWidgetForPaintable().rendering = false;\r
+    }\r
+\r
+    public void updateCaption(VPaintableWidget component, UIDL uidl) {\r
+        getWidgetForPaintable().table.updateCaption(component, uidl);\r
+    }\r
+\r
+    @Override\r
+    public VFormLayout getWidgetForPaintable() {\r
+        return (VFormLayout) super.getWidgetForPaintable();\r
+    }\r
+\r
+    @Override\r
+    protected Widget createWidget() {\r
+        return GWT.create(VFormLayout.class);\r
+    }\r
+\r
+}\r
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java
new file mode 100644 (file)
index 0000000..5f519c0
--- /dev/null
@@ -0,0 +1,173 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.event.dom.client.KeyDownEvent;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.VPaintableMap;\r
+import com.vaadin.terminal.gwt.client.VPaintableWidget;\r
+\r
+public class VFormPaintable extends VAbstractPaintableWidgetContainer {\r
+\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        getWidgetForPaintable().rendering = true;\r
+        getWidgetForPaintable().client = client;\r
+        getWidgetForPaintable().id = uidl.getId();\r
+\r
+        if (client.updateComponent(this, uidl, false)) {\r
+            getWidgetForPaintable().rendering = false;\r
+            return;\r
+        }\r
+\r
+        boolean legendEmpty = true;\r
+        if (uidl.hasAttribute("caption")) {\r
+            getWidgetForPaintable().caption.setInnerText(uidl\r
+                    .getStringAttribute("caption"));\r
+            legendEmpty = false;\r
+        } else {\r
+            getWidgetForPaintable().caption.setInnerText("");\r
+        }\r
+        if (uidl.hasAttribute("icon")) {\r
+            if (getWidgetForPaintable().icon == null) {\r
+                getWidgetForPaintable().icon = new Icon(client);\r
+                getWidgetForPaintable().legend\r
+                        .insertFirst(getWidgetForPaintable().icon.getElement());\r
+            }\r
+            getWidgetForPaintable().icon\r
+                    .setUri(uidl.getStringAttribute("icon"));\r
+            legendEmpty = false;\r
+        } else {\r
+            if (getWidgetForPaintable().icon != null) {\r
+                getWidgetForPaintable().legend\r
+                        .removeChild(getWidgetForPaintable().icon.getElement());\r
+            }\r
+        }\r
+        if (legendEmpty) {\r
+            getWidgetForPaintable().addStyleDependentName("nocaption");\r
+        } else {\r
+            getWidgetForPaintable().removeStyleDependentName("nocaption");\r
+        }\r
+\r
+        if (uidl.hasAttribute("error")) {\r
+            final UIDL errorUidl = uidl.getErrors();\r
+            getWidgetForPaintable().errorMessage.updateFromUIDL(errorUidl);\r
+            getWidgetForPaintable().errorMessage.setVisible(true);\r
+        } else {\r
+            getWidgetForPaintable().errorMessage.setVisible(false);\r
+        }\r
+\r
+        if (uidl.hasAttribute("description")) {\r
+            getWidgetForPaintable().desc.setInnerHTML(uidl\r
+                    .getStringAttribute("description"));\r
+            if (getWidgetForPaintable().desc.getParentElement() == null) {\r
+                getWidgetForPaintable().fieldSet.insertAfter(\r
+                        getWidgetForPaintable().desc,\r
+                        getWidgetForPaintable().legend);\r
+            }\r
+        } else {\r
+            getWidgetForPaintable().desc.setInnerHTML("");\r
+            if (getWidgetForPaintable().desc.getParentElement() != null) {\r
+                getWidgetForPaintable().fieldSet\r
+                        .removeChild(getWidgetForPaintable().desc);\r
+            }\r
+        }\r
+\r
+        getWidgetForPaintable().updateSize();\r
+\r
+        // first render footer so it will be easier to handle relative height of\r
+        // main layout\r
+        if (uidl.getChildCount() > 1\r
+                && !uidl.getChildUIDL(1).getTag().equals("actions")) {\r
+            // render footer\r
+            VPaintableWidget newFooter = client.getPaintable(uidl\r
+                    .getChildUIDL(1));\r
+            Widget newFooterWidget = newFooter.getWidgetForPaintable();\r
+            if (getWidgetForPaintable().footer == null) {\r
+                getWidgetForPaintable().add(newFooter.getWidgetForPaintable(),\r
+                        getWidgetForPaintable().footerContainer);\r
+                getWidgetForPaintable().footer = newFooterWidget;\r
+            } else if (newFooter != getWidgetForPaintable().footer) {\r
+                getWidgetForPaintable().remove(getWidgetForPaintable().footer);\r
+                client.unregisterPaintable(VPaintableMap.get(getConnection())\r
+                        .getPaintable(getWidgetForPaintable().footer));\r
+                getWidgetForPaintable().add(newFooter.getWidgetForPaintable(),\r
+                        getWidgetForPaintable().footerContainer);\r
+            }\r
+            getWidgetForPaintable().footer = newFooterWidget;\r
+            newFooter.updateFromUIDL(uidl.getChildUIDL(1), client);\r
+            // needed for the main layout to know the space it has available\r
+            getWidgetForPaintable().updateSize();\r
+        } else {\r
+            if (getWidgetForPaintable().footer != null) {\r
+                getWidgetForPaintable().remove(getWidgetForPaintable().footer);\r
+                client.unregisterPaintable(VPaintableMap.get(getConnection())\r
+                        .getPaintable(getWidgetForPaintable().footer));\r
+                // needed for the main layout to know the space it has available\r
+                getWidgetForPaintable().updateSize();\r
+            }\r
+        }\r
+\r
+        final UIDL layoutUidl = uidl.getChildUIDL(0);\r
+        VPaintableWidget newLayout = client.getPaintable(layoutUidl);\r
+        Widget newLayoutWidget = newLayout.getWidgetForPaintable();\r
+        if (getWidgetForPaintable().lo == null) {\r
+            // Layout not rendered before\r
+            getWidgetForPaintable().lo = newLayoutWidget;\r
+            getWidgetForPaintable().add(newLayoutWidget,\r
+                    getWidgetForPaintable().fieldContainer);\r
+        } else if (getWidgetForPaintable().lo != newLayoutWidget) {\r
+            // Layout has changed\r
+            client.unregisterPaintable(VPaintableMap.get(getConnection())\r
+                    .getPaintable(getWidgetForPaintable().lo));\r
+            getWidgetForPaintable().remove(getWidgetForPaintable().lo);\r
+            getWidgetForPaintable().lo = newLayoutWidget;\r
+            getWidgetForPaintable().add(newLayoutWidget,\r
+                    getWidgetForPaintable().fieldContainer);\r
+        }\r
+        newLayout.updateFromUIDL(layoutUidl, client);\r
+\r
+        // also recalculates size of the footer if undefined size form - see\r
+        // #3710\r
+        getWidgetForPaintable().updateSize();\r
+        client.runDescendentsLayout(getWidgetForPaintable());\r
+\r
+        // We may have actions attached\r
+        if (uidl.getChildCount() > 1) {\r
+            UIDL childUidl = uidl.getChildByTagName("actions");\r
+            if (childUidl != null) {\r
+                if (getWidgetForPaintable().shortcutHandler == null) {\r
+                    getWidgetForPaintable().shortcutHandler = new ShortcutActionHandler(\r
+                            getId(), client);\r
+                    getWidgetForPaintable().keyDownRegistration = getWidgetForPaintable()\r
+                            .addDomHandler(getWidgetForPaintable(),\r
+                                    KeyDownEvent.getType());\r
+                }\r
+                getWidgetForPaintable().shortcutHandler\r
+                        .updateActionMap(childUidl);\r
+            }\r
+        } else if (getWidgetForPaintable().shortcutHandler != null) {\r
+            getWidgetForPaintable().keyDownRegistration.removeHandler();\r
+            getWidgetForPaintable().shortcutHandler = null;\r
+            getWidgetForPaintable().keyDownRegistration = null;\r
+        }\r
+\r
+        getWidgetForPaintable().rendering = false;\r
+    }\r
+\r
+    public void updateCaption(VPaintableWidget component, UIDL uidl) {\r
+        // NOP form don't render caption for neither field layout nor footer\r
+        // layout\r
+    }\r
+\r
+    @Override\r
+    public VForm getWidgetForPaintable() {\r
+        return (VForm) super.getWidgetForPaintable();\r
+    }\r
+\r
+    @Override\r
+    protected Widget createWidget() {\r
+        return GWT.create(VForm.class);\r
+    }\r
+\r
+}\r
index 47210e1aed5327aadde636d5f88ad46295d55cac..c79804c7e7735c1601b67c3df36245bf16ad195c 100644 (file)
@@ -27,7 +27,7 @@ import com.vaadin.terminal.CompositeErrorMessage;
 import com.vaadin.terminal.ErrorMessage;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VForm;
+import com.vaadin.terminal.gwt.client.ui.VFormPaintable;
 
 /**
  * Form component provides easy way of creating and managing sets fields.
@@ -62,8 +62,7 @@ import com.vaadin.terminal.gwt.client.ui.VForm;
  * @deprecated Use {@link FieldGroup} instead of {@link Form} for more
  *             flexibility.
  */
-@SuppressWarnings("serial")
-@ClientWidget(VForm.class)
+@ClientWidget(VFormPaintable.class)
 @Deprecated
 public class Form extends AbstractField<Object> implements Item.Editor,
         Buffered, Item, Validatable, Action.Notifier {
index eecf3372bbebf52e19c731446255815e710b67d8..c5c211924e845b6ab4abe7933970a7f321dd6512 100644 (file)
@@ -4,7 +4,7 @@
 
 package com.vaadin.ui;
 
-import com.vaadin.terminal.gwt.client.ui.VFormLayout;
+import com.vaadin.terminal.gwt.client.ui.VFormLayoutPaintable;
 
 /**
  * FormLayout is used by {@link Form} to layout fields. It may also be used
@@ -21,7 +21,7 @@ import com.vaadin.terminal.gwt.client.ui.VFormLayout;
  * bottom are by default on.
  * 
  */
-@ClientWidget(VFormLayout.class)
+@ClientWidget(VFormLayoutPaintable.class)
 public class FormLayout extends AbstractOrderedLayout {
 
     public FormLayout() {