]> source.dussan.org Git - vaadin-framework.git/commitdiff
Split CustomComponent, CustomField and CustomLayout into widget +
authorArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 07:58:15 +0000 (09:58 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 08:00:13 +0000 (10:00 +0200)
paintable

src/com/vaadin/terminal/gwt/client/ui/VCustomComponent.java
src/com/vaadin/terminal/gwt/client/ui/VCustomComponentPaintable.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java
src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java [new file with mode: 0644]
src/com/vaadin/ui/CustomComponent.java
src/com/vaadin/ui/CustomField.java
src/com/vaadin/ui/CustomLayout.java

index 39d1ee462c432a28d28a7a1f0a1d959cc22d9e7e..5ecd50baff34daf458fa8a1d8a87dd13be81c0c0 100644 (file)
@@ -6,81 +6,27 @@ package com.vaadin.terminal.gwt.client.ui;
 
 import java.util.Set;
 
-import com.google.gwt.core.client.Scheduler;
-import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.ui.SimplePanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.Container;
 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.VPaintableMap;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
 
-public class VCustomComponent extends SimplePanel implements Container {
+public class VCustomComponent extends SimplePanel {
 
     private static final String CLASSNAME = "v-customcomponent";
     private String height;
-    private ApplicationConnection client;
-    private boolean rendering;
+    ApplicationConnection client;
+    boolean rendering;
     private String width;
-    private RenderSpace renderSpace = new RenderSpace();
+    RenderSpace renderSpace = new RenderSpace();
 
     public VCustomComponent() {
         super();
         setStyleName(CLASSNAME);
     }
 
-    public void updateFromUIDL(UIDL uidl, final ApplicationConnection client) {
-        rendering = true;
-        if (client.updateComponent(this, uidl, true)) {
-            rendering = false;
-            return;
-        }
-        this.client = client;
-
-        final UIDL child = uidl.getChildUIDL(0);
-        if (child != null) {
-            final VPaintableWidget paintable = client.getPaintable(child);
-            Widget widget = paintable.getWidgetForPaintable();
-            if (widget != getWidget()) {
-                if (getWidget() != null) {
-                    client.unregisterPaintable(VPaintableMap.get(client)
-                            .getPaintable(getWidget()));
-                    clear();
-                }
-                setWidget(widget);
-            }
-            paintable.updateFromUIDL(child, client);
-        }
-
-        boolean updateDynamicSize = updateDynamicSize();
-        if (updateDynamicSize) {
-            Scheduler.get().scheduleDeferred(new Command() {
-                public void execute() {
-                    // FIXME deferred relative size update needed to fix some
-                    // scrollbar issues in sampler. This must be the wrong way
-                    // to do it. Might be that some other component is broken.
-                    client.handleComponentRelativeSize(VCustomComponent.this);
-
-                }
-            });
-        }
-
-        renderSpace.setWidth(getElement().getOffsetWidth());
-        renderSpace.setHeight(getElement().getOffsetHeight());
-
-        /*
-         * Needed to update client size if the size of this component has
-         * changed and the child uses relative size(s).
-         */
-        client.runDescendentsLayout(this);
-
-        rendering = false;
-    }
-
-    private boolean updateDynamicSize() {
+    boolean updateDynamicSize() {
         boolean updated = false;
         if (isDynamicWidth()) {
             int childWidth = Util.getRequiredWidth(getWidget());
@@ -121,10 +67,6 @@ public class VCustomComponent extends SimplePanel implements Container {
         }
     }
 
-    public void updateCaption(VPaintableWidget component, UIDL uidl) {
-        // NOP, custom component dont render composition roots caption
-    }
-
     public boolean requestLayout(Set<Widget> children) {
         // If a child grows in size, it will not necessarily be calculated
         // correctly unless we remove previous size definitions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCustomComponentPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VCustomComponentPaintable.java
new file mode 100644 (file)
index 0000000..3abcd9c
--- /dev/null
@@ -0,0 +1,79 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.core.client.Scheduler;\r
+import com.google.gwt.user.client.Command;\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 VCustomComponentPaintable extends\r
+        VAbstractPaintableWidgetContainer {\r
+\r
+    public void updateFromUIDL(UIDL uidl, final ApplicationConnection client) {\r
+        getWidgetForPaintable().rendering = true;\r
+        if (client.updateComponent(this, uidl, true)) {\r
+            getWidgetForPaintable().rendering = false;\r
+            return;\r
+        }\r
+        getWidgetForPaintable().client = client;\r
+\r
+        final UIDL child = uidl.getChildUIDL(0);\r
+        if (child != null) {\r
+            final VPaintableWidget paintable = client.getPaintable(child);\r
+            Widget widget = paintable.getWidgetForPaintable();\r
+            if (widget != getWidgetForPaintable().getWidget()) {\r
+                if (getWidgetForPaintable().getWidget() != null) {\r
+                    client.unregisterPaintable(VPaintableMap.get(client)\r
+                            .getPaintable(getWidgetForPaintable().getWidget()));\r
+                    getWidgetForPaintable().clear();\r
+                }\r
+                getWidgetForPaintable().setWidget(widget);\r
+            }\r
+            paintable.updateFromUIDL(child, client);\r
+        }\r
+\r
+        boolean updateDynamicSize = getWidgetForPaintable().updateDynamicSize();\r
+        if (updateDynamicSize) {\r
+            Scheduler.get().scheduleDeferred(new Command() {\r
+                public void execute() {\r
+                    // FIXME deferred relative size update needed to fix some\r
+                    // scrollbar issues in sampler. This must be the wrong way\r
+                    // to do it. Might be that some other component is broken.\r
+                    client.handleComponentRelativeSize(getWidgetForPaintable());\r
+\r
+                }\r
+            });\r
+        }\r
+\r
+        getWidgetForPaintable().renderSpace.setWidth(getWidgetForPaintable()\r
+                .getElement().getOffsetWidth());\r
+        getWidgetForPaintable().renderSpace.setHeight(getWidgetForPaintable()\r
+                .getElement().getOffsetHeight());\r
+\r
+        /*\r
+         * Needed to update client size if the size of this component has\r
+         * changed and the child uses relative size(s).\r
+         */\r
+        client.runDescendentsLayout(getWidgetForPaintable());\r
+\r
+        getWidgetForPaintable().rendering = false;\r
+    }\r
+\r
+    @Override\r
+    protected Widget createWidget() {\r
+        return GWT.create(VCustomComponent.class);\r
+    }\r
+\r
+    @Override\r
+    public VCustomComponent getWidgetForPaintable() {\r
+        return (VCustomComponent) super.getWidgetForPaintable();\r
+    }\r
+\r
+    public void updateCaption(VPaintableWidget component, UIDL uidl) {\r
+        // NOP, custom component dont render composition roots caption\r
+    }\r
+\r
+}\r
index 787be254f6108491e636f1d85562fc1a81d7d486..9b067267ffefb79c80e6afe4b3d911b32761debc 100644 (file)
@@ -18,7 +18,6 @@ import com.google.gwt.user.client.ui.ComplexPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.Container;
 import com.vaadin.terminal.gwt.client.ContainerResizedListener;
 import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
 import com.vaadin.terminal.gwt.client.RenderSpace;
@@ -35,8 +34,8 @@ import com.vaadin.terminal.gwt.client.VPaintableWidget;
  * @author Vaadin Ltd
  * 
  */
-public class VCustomLayout extends ComplexPanel implements VPaintableWidget,
-        Container, ContainerResizedListener {
+public class VCustomLayout extends ComplexPanel implements
+        ContainerResizedListener {
 
     public static final String CLASSNAME = "v-customlayout";
 
@@ -44,7 +43,7 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget,
     private final HashMap<String, Element> locationToElement = new HashMap<String, Element>();
 
     /** Location-name to contained widget map */
-    private final HashMap<String, Widget> locationToWidget = new HashMap<String, Widget>();
+    final HashMap<String, Widget> locationToWidget = new HashMap<String, Widget>();
 
     /** Widget to captionwrapper map */
     private final HashMap<VPaintableWidget, VCaptionWrapper> paintableToCaptionWrapper = new HashMap<VPaintableWidget, VCaptionWrapper>();
@@ -53,12 +52,12 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget,
     String currentTemplateName;
 
     /** Unexecuted scripts loaded from the template */
-    private String scripts = "";
+    String scripts = "";
 
     /** Paintable ID of this paintable */
-    private String pid;
+    String pid;
 
-    private ApplicationConnection client;
+    ApplicationConnection client;
 
     /** Has the template been loaded from contents passed in UIDL **/
     private boolean hasTemplateContents = false;
@@ -132,66 +131,8 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget,
         locationToWidget.put(location, widget);
     }
 
-    /** Update the layout from UIDL */
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        this.client = client;
-        // ApplicationConnection manages generic component features
-        if (client.updateComponent(this, uidl, true)) {
-            return;
-        }
-
-        pid = uidl.getId();
-        if (!hasTemplate()) {
-            // Update HTML template only once
-            initializeHTML(uidl, client);
-        }
-
-        // Evaluate scripts
-        eval(scripts);
-        scripts = null;
-
-        iLayout();
-        // TODO Check if this is needed
-        client.runDescendentsLayout(this);
-
-        Set<Widget> oldWidgets = new HashSet<Widget>();
-        oldWidgets.addAll(locationToWidget.values());
-
-        // For all contained widgets
-        for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
-            final UIDL uidlForChild = (UIDL) i.next();
-            if (uidlForChild.getTag().equals("location")) {
-                final String location = uidlForChild.getStringAttribute("name");
-                UIDL childUIDL = uidlForChild.getChildUIDL(0);
-                final VPaintableWidget childPaintable = client
-                        .getPaintable(childUIDL);
-                Widget childWidget = childPaintable.getWidgetForPaintable();
-                try {
-                    setWidget(childWidget, location);
-                    childPaintable.updateFromUIDL(childUIDL, client);
-                } catch (final IllegalArgumentException e) {
-                    // If no location is found, this component is not visible
-                }
-                oldWidgets.remove(childWidget);
-            }
-        }
-        for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator
-                .hasNext();) {
-            Widget oldWidget = iterator.next();
-            if (oldWidget.isAttached()) {
-                // slot of this widget is emptied, remove it
-                remove(oldWidget);
-            }
-        }
-
-        iLayout();
-        // TODO Check if this is needed
-        client.runDescendentsLayout(this);
-
-    }
-
     /** Initialize HTML-layout. */
-    private void initializeHTML(UIDL uidl, ApplicationConnection client) {
+    void initializeHTML(UIDL uidl, ApplicationConnection client) {
 
         final String newTemplateContents = uidl
                 .getStringAttribute("templateContents");
@@ -264,7 +205,7 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget,
         return false;
     }-*/;
 
-    private boolean hasTemplate() {
+    boolean hasTemplate() {
         if (currentTemplateName == null && !hasTemplateContents) {
             return false;
         } else {
@@ -295,7 +236,7 @@ public class VCustomLayout extends ComplexPanel implements VPaintableWidget,
     }
 
     /** Evaluate given script in browser document */
-    private static native void eval(String script)
+    static native void eval(String script)
     /*-{
       try {
         if (script != null) 
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java
new file mode 100644 (file)
index 0000000..7997355
--- /dev/null
@@ -0,0 +1,87 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.Set;\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 VCustomLayoutPaintable extends VAbstractPaintableWidgetContainer {\r
+\r
+    /** Update the layout from UIDL */\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        getWidgetForPaintable().client = client;\r
+        // ApplicationConnection manages generic component features\r
+        if (client.updateComponent(this, uidl, true)) {\r
+            return;\r
+        }\r
+\r
+        getWidgetForPaintable().pid = uidl.getId();\r
+        if (!getWidgetForPaintable().hasTemplate()) {\r
+            // Update HTML template only once\r
+            getWidgetForPaintable().initializeHTML(uidl, client);\r
+        }\r
+\r
+        // Evaluate scripts\r
+        VCustomLayout.eval(getWidgetForPaintable().scripts);\r
+        getWidgetForPaintable().scripts = null;\r
+\r
+        getWidgetForPaintable().iLayout();\r
+        // TODO Check if this is needed\r
+        client.runDescendentsLayout(getWidgetForPaintable());\r
+\r
+        Set<Widget> oldWidgets = new HashSet<Widget>();\r
+        oldWidgets.addAll(getWidgetForPaintable().locationToWidget.values());\r
+\r
+        // For all contained widgets\r
+        for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {\r
+            final UIDL uidlForChild = (UIDL) i.next();\r
+            if (uidlForChild.getTag().equals("location")) {\r
+                final String location = uidlForChild.getStringAttribute("name");\r
+                UIDL childUIDL = uidlForChild.getChildUIDL(0);\r
+                final VPaintableWidget childPaintable = client\r
+                        .getPaintable(childUIDL);\r
+                Widget childWidget = childPaintable.getWidgetForPaintable();\r
+                try {\r
+                    getWidgetForPaintable().setWidget(childWidget, location);\r
+                    childPaintable.updateFromUIDL(childUIDL, client);\r
+                } catch (final IllegalArgumentException e) {\r
+                    // If no location is found, this component is not visible\r
+                }\r
+                oldWidgets.remove(childWidget);\r
+            }\r
+        }\r
+        for (Iterator<Widget> iterator = oldWidgets.iterator(); iterator\r
+                .hasNext();) {\r
+            Widget oldWidget = iterator.next();\r
+            if (oldWidget.isAttached()) {\r
+                // slot of this widget is emptied, remove it\r
+                getWidgetForPaintable().remove(oldWidget);\r
+            }\r
+        }\r
+\r
+        getWidgetForPaintable().iLayout();\r
+        // TODO Check if this is needed\r
+        client.runDescendentsLayout(getWidgetForPaintable());\r
+\r
+    }\r
+\r
+    @Override\r
+    public VCustomLayout getWidgetForPaintable() {\r
+        return (VCustomLayout) super.getWidgetForPaintable();\r
+    }\r
+\r
+    @Override\r
+    protected Widget createWidget() {\r
+        return GWT.create(VCustomLayout.class);\r
+    }\r
+\r
+    public void updateCaption(VPaintableWidget paintable, UIDL uidl) {\r
+        getWidgetForPaintable().updateCaption(paintable, uidl);\r
+\r
+    }\r
+}\r
index 0f891ac0fab4f233b7a9c052ddae8c45fd90f513..7aba34b6bb9ee54ebbd72c4a87ade18795ca52c2 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Iterator;
 
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VCustomComponent;
+import com.vaadin.terminal.gwt.client.ui.VCustomComponentPaintable;
 import com.vaadin.ui.ClientWidget.LoadStyle;
 
 /**
@@ -27,7 +27,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle;
  * @since 3.0
  */
 @SuppressWarnings("serial")
-@ClientWidget(value = VCustomComponent.class, loadStyle = LoadStyle.EAGER)
+@ClientWidget(value = VCustomComponentPaintable.class, loadStyle = LoadStyle.EAGER)
 public class CustomComponent extends AbstractComponentContainer {
 
     /**
index 72f863ca8b5ddb914daf361f081e780a825c9516..73f9050363669ec81158407ee154389a3450f5ba 100644 (file)
@@ -11,7 +11,7 @@ import java.util.Iterator;
 import com.vaadin.data.Property;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VCustomComponent;
+import com.vaadin.terminal.gwt.client.ui.VCustomComponentPaintable;
 
 /**
  * A {@link Field} whose UI content can be constructed by the user, enabling the
@@ -35,7 +35,7 @@ import com.vaadin.terminal.gwt.client.ui.VCustomComponent;
  * 
  * @since 7.0
  */
-@ClientWidget(VCustomComponent.class)
+@ClientWidget(VCustomComponentPaintable.class)
 public abstract class CustomField<T> extends AbstractField<T> implements
         ComponentContainer {
 
index dc473fb549ff2ccd67005b05bcd76363d2a18e7f..fb0c3699694de89be019570465748223466430f4 100644 (file)
@@ -12,7 +12,7 @@ import java.util.Iterator;
 
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VCustomLayout;
+import com.vaadin.terminal.gwt.client.ui.VCustomLayoutPaintable;
 
 /**
  * <p>
@@ -44,7 +44,7 @@ import com.vaadin.terminal.gwt.client.ui.VCustomLayout;
  * @since 3.0
  */
 @SuppressWarnings("serial")
-@ClientWidget(VCustomLayout.class)
+@ClientWidget(VCustomLayoutPaintable.class)
 public class CustomLayout extends AbstractLayout {
 
     private static final int BUFFER_SIZE = 10000;