]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8324 Split Panel into widget and paintable
authorArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 11:59:29 +0000 (13:59 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 13:08:42 +0000 (15:08 +0200)
src/com/vaadin/terminal/gwt/client/ui/VPanel.java
src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java [new file with mode: 0644]
src/com/vaadin/ui/Panel.java

index 9eec275b592bf38f1d30bd486e3a13125cd01b46..354a42c4d566c1a4e6391eb7bcbbafc6f5193815 100644 (file)
@@ -8,11 +8,8 @@ import java.util.Set;
 
 import com.google.gwt.dom.client.DivElement;
 import com.google.gwt.dom.client.Document;
-import com.google.gwt.event.dom.client.DomEvent.Type;
 import com.google.gwt.event.dom.client.TouchStartEvent;
 import com.google.gwt.event.dom.client.TouchStartHandler;
-import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
@@ -33,28 +30,27 @@ import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHan
 public class VPanel extends SimplePanel implements Container,
         ShortcutActionHandlerOwner, Focusable {
 
-    public static final String CLICK_EVENT_IDENTIFIER = "click";
     public static final String CLASSNAME = "v-panel";
 
     ApplicationConnection client;
 
     String id;
 
-    private final Element captionNode = DOM.createDiv();
+    final Element captionNode = DOM.createDiv();
 
     private final Element captionText = DOM.createSpan();
 
     private Icon icon;
 
-    private final Element bottomDecoration = DOM.createDiv();
+    final Element bottomDecoration = DOM.createDiv();
 
-    private final Element contentNode = DOM.createDiv();
+    final Element contentNode = DOM.createDiv();
 
     private Element errorIndicatorElement;
 
     private String height;
 
-    private VPaintableWidget layout;
+    VPaintableWidget layout;
 
     ShortcutActionHandler shortcutHandler;
 
@@ -62,9 +58,9 @@ public class VPanel extends SimplePanel implements Container,
 
     private Element geckoCaptionMeter;
 
-    private int scrollTop;
+    int scrollTop;
 
-    private int scrollLeft;
+    int scrollLeft;
 
     private RenderInformation renderInformation = new RenderInformation();
 
@@ -76,21 +72,12 @@ public class VPanel extends SimplePanel implements Container,
 
     private int captionMarginLeft = -1;
 
-    private boolean rendering;
+    boolean rendering;
 
     private int contentMarginLeft = -1;
 
     private String previousStyleName;
 
-    private ClickEventHandler clickEventHandler = new ClickEventHandler(this,
-            CLICK_EVENT_IDENTIFIER) {
-
-        @Override
-        protected <H extends EventHandler> HandlerRegistration registerHandler(
-                H handler, Type<H> type) {
-            return addDomHandler(handler, type);
-        }
-    };
     private TouchScrollDelegate touchScrollDelegate;
 
     public VPanel() {
@@ -157,129 +144,10 @@ public class VPanel extends SimplePanel implements Container,
         return contentNode;
     }
 
-    private void setCaption(String text) {
+    void setCaption(String text) {
         DOM.setInnerHTML(captionText, text);
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        rendering = true;
-        if (!uidl.hasAttribute("cached")) {
-
-            // Handle caption displaying and style names, prior generics.
-            // Affects size
-            // calculations
-
-            // Restore default stylenames
-            contentNode.setClassName(CLASSNAME + "-content");
-            bottomDecoration.setClassName(CLASSNAME + "-deco");
-            captionNode.setClassName(CLASSNAME + "-caption");
-            boolean hasCaption = false;
-            if (uidl.hasAttribute("caption")
-                    && !uidl.getStringAttribute("caption").equals("")) {
-                setCaption(uidl.getStringAttribute("caption"));
-                hasCaption = true;
-            } else {
-                setCaption("");
-                captionNode.setClassName(CLASSNAME + "-nocaption");
-            }
-
-            // Add proper stylenames for all elements. This way we can prevent
-            // unwanted CSS selector inheritance.
-            if (uidl.hasAttribute("style")) {
-                final String[] styles = uidl.getStringAttribute("style").split(
-                        " ");
-                final String captionBaseClass = CLASSNAME
-                        + (hasCaption ? "-caption" : "-nocaption");
-                final String contentBaseClass = CLASSNAME + "-content";
-                final String decoBaseClass = CLASSNAME + "-deco";
-                String captionClass = captionBaseClass;
-                String contentClass = contentBaseClass;
-                String decoClass = decoBaseClass;
-                for (int i = 0; i < styles.length; i++) {
-                    captionClass += " " + captionBaseClass + "-" + styles[i];
-                    contentClass += " " + contentBaseClass + "-" + styles[i];
-                    decoClass += " " + decoBaseClass + "-" + styles[i];
-                }
-                captionNode.setClassName(captionClass);
-                contentNode.setClassName(contentClass);
-                bottomDecoration.setClassName(decoClass);
-
-            }
-        }
-        // Ensure correct implementation
-        if (client.updateComponent(this, uidl, false)) {
-            rendering = false;
-            return;
-        }
-
-        clickEventHandler.handleEventHandlerRegistration(client);
-
-        this.client = client;
-        id = uidl.getId();
-
-        setIconUri(uidl, client);
-
-        handleError(uidl);
-
-        // Render content
-        final UIDL layoutUidl = uidl.getChildUIDL(0);
-        final VPaintableWidget newLayout = client.getPaintable(layoutUidl);
-        if (newLayout != layout) {
-            if (layout != null) {
-                client.unregisterPaintable(layout);
-            }
-            setWidget(newLayout.getWidgetForPaintable());
-            layout = newLayout;
-        }
-        layout.updateFromUIDL(layoutUidl, client);
-
-        // We may have actions attached to this panel
-        if (uidl.getChildCount() > 1) {
-            final int cnt = uidl.getChildCount();
-            for (int i = 1; i < cnt; i++) {
-                UIDL childUidl = uidl.getChildUIDL(i);
-                if (childUidl.getTag().equals("actions")) {
-                    if (shortcutHandler == null) {
-                        shortcutHandler = new ShortcutActionHandler(id, client);
-                    }
-                    shortcutHandler.updateActionMap(childUidl);
-                }
-            }
-        }
-
-        if (uidl.hasVariable("scrollTop")
-                && uidl.getIntVariable("scrollTop") != scrollTop) {
-            scrollTop = uidl.getIntVariable("scrollTop");
-            contentNode.setScrollTop(scrollTop);
-            // re-read the actual scrollTop in case invalid value was set
-            // (scrollTop != 0 when no scrollbar exists, other values would be
-            // caught by scroll listener), see #3784
-            scrollTop = contentNode.getScrollTop();
-        }
-
-        if (uidl.hasVariable("scrollLeft")
-                && uidl.getIntVariable("scrollLeft") != scrollLeft) {
-            scrollLeft = uidl.getIntVariable("scrollLeft");
-            contentNode.setScrollLeft(scrollLeft);
-            // re-read the actual scrollTop in case invalid value was set
-            // (scrollTop != 0 when no scrollbar exists, other values would be
-            // caught by scroll listener), see #3784
-            scrollLeft = contentNode.getScrollLeft();
-        }
-
-        // Must be run after scrollTop is set as Webkit overflow fix re-sets the
-        // scrollTop
-        runHacks(false);
-
-        // And apply tab index
-        if (uidl.hasVariable("tabindex")) {
-            contentNode.setTabIndex(uidl.getIntVariable("tabindex"));
-        }
-
-        rendering = false;
-
-    }
-
     @Override
     public void setStyleName(String style) {
         if (!style.equals(previousStyleName)) {
@@ -289,7 +157,7 @@ public class VPanel extends SimplePanel implements Container,
         }
     }
 
-    private void handleError(UIDL uidl) {
+    void handleError(UIDL uidl) {
         if (uidl.hasAttribute("error")) {
             if (errorIndicatorElement == null) {
                 errorIndicatorElement = DOM.createSpan();
@@ -305,7 +173,7 @@ public class VPanel extends SimplePanel implements Container,
         }
     }
 
-    private void setIconUri(UIDL uidl, ApplicationConnection client) {
+    void setIconUri(UIDL uidl, ApplicationConnection client) {
         final String iconUri = uidl.hasAttribute("icon") ? uidl
                 .getStringAttribute("icon") : null;
         if (iconUri == null) {
@@ -394,7 +262,7 @@ public class VPanel extends SimplePanel implements Container,
             }
         } else if (captionNode.isOrHasChild(target)) {
             if (client != null) {
-                client.handleTooltipEvent(event, this);
+                client.handleWidgetTooltipEvent(event, this);
             }
         }
     }
@@ -554,10 +422,6 @@ public class VPanel extends SimplePanel implements Container,
         return !renderInformation.updateSize(getElement());
     }
 
-    public void updateCaption(VPaintableWidget component, UIDL uidl) {
-        // NOP: layouts caption, errors etc not rendered in Panel
-    }
-
     @Override
     protected void onAttach() {
         super.onAttach();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java
new file mode 100644 (file)
index 0000000..198d7f4
--- /dev/null
@@ -0,0 +1,175 @@
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.event.dom.client.DomEvent.Type;\r
+import com.google.gwt.event.shared.EventHandler;\r
+import com.google.gwt.event.shared.HandlerRegistration;\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 VPanelPaintable extends VAbstractPaintableWidgetContainer {\r
+\r
+    public static final String CLICK_EVENT_IDENTIFIER = "click";\r
+\r
+    private ClickEventHandler clickEventHandler = new ClickEventHandler(this,\r
+            CLICK_EVENT_IDENTIFIER) {\r
+\r
+        @Override\r
+        protected <H extends EventHandler> HandlerRegistration registerHandler(\r
+                H handler, Type<H> type) {\r
+            return getWidgetForPaintable().addDomHandler(handler, type);\r
+        }\r
+    };\r
+\r
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+        getWidgetForPaintable().rendering = true;\r
+        if (!uidl.hasAttribute("cached")) {\r
+\r
+            // Handle caption displaying and style names, prior generics.\r
+            // Affects size\r
+            // calculations\r
+\r
+            // Restore default stylenames\r
+            getWidgetForPaintable().contentNode.setClassName(VPanel.CLASSNAME\r
+                    + "-content");\r
+            getWidgetForPaintable().bottomDecoration\r
+                    .setClassName(VPanel.CLASSNAME + "-deco");\r
+            getWidgetForPaintable().captionNode.setClassName(VPanel.CLASSNAME\r
+                    + "-caption");\r
+            boolean hasCaption = false;\r
+            if (uidl.hasAttribute("caption")\r
+                    && !uidl.getStringAttribute("caption").equals("")) {\r
+                getWidgetForPaintable().setCaption(\r
+                        uidl.getStringAttribute("caption"));\r
+                hasCaption = true;\r
+            } else {\r
+                getWidgetForPaintable().setCaption("");\r
+                getWidgetForPaintable().captionNode\r
+                        .setClassName(VPanel.CLASSNAME + "-nocaption");\r
+            }\r
+\r
+            // Add proper stylenames for all elements. This way we can prevent\r
+            // unwanted CSS selector inheritance.\r
+            if (uidl.hasAttribute("style")) {\r
+                final String[] styles = uidl.getStringAttribute("style").split(\r
+                        " ");\r
+                final String captionBaseClass = VPanel.CLASSNAME\r
+                        + (hasCaption ? "-caption" : "-nocaption");\r
+                final String contentBaseClass = VPanel.CLASSNAME + "-content";\r
+                final String decoBaseClass = VPanel.CLASSNAME + "-deco";\r
+                String captionClass = captionBaseClass;\r
+                String contentClass = contentBaseClass;\r
+                String decoClass = decoBaseClass;\r
+                for (int i = 0; i < styles.length; i++) {\r
+                    captionClass += " " + captionBaseClass + "-" + styles[i];\r
+                    contentClass += " " + contentBaseClass + "-" + styles[i];\r
+                    decoClass += " " + decoBaseClass + "-" + styles[i];\r
+                }\r
+                getWidgetForPaintable().captionNode.setClassName(captionClass);\r
+                getWidgetForPaintable().contentNode.setClassName(contentClass);\r
+                getWidgetForPaintable().bottomDecoration\r
+                        .setClassName(decoClass);\r
+\r
+            }\r
+        }\r
+        // Ensure correct implementation\r
+        if (client.updateComponent(this, uidl, false)) {\r
+            getWidgetForPaintable().rendering = false;\r
+            return;\r
+        }\r
+\r
+        clickEventHandler.handleEventHandlerRegistration(client);\r
+\r
+        getWidgetForPaintable().client = client;\r
+        getWidgetForPaintable().id = uidl.getId();\r
+\r
+        getWidgetForPaintable().setIconUri(uidl, client);\r
+\r
+        getWidgetForPaintable().handleError(uidl);\r
+\r
+        // Render content\r
+        final UIDL layoutUidl = uidl.getChildUIDL(0);\r
+        final VPaintableWidget newLayout = client.getPaintable(layoutUidl);\r
+        if (newLayout != getWidgetForPaintable().layout) {\r
+            if (getWidgetForPaintable().layout != null) {\r
+                client.unregisterPaintable(getWidgetForPaintable().layout);\r
+            }\r
+            getWidgetForPaintable()\r
+                    .setWidget(newLayout.getWidgetForPaintable());\r
+            getWidgetForPaintable().layout = newLayout;\r
+        }\r
+        getWidgetForPaintable().layout.updateFromUIDL(layoutUidl, client);\r
+\r
+        // We may have actions attached to this panel\r
+        if (uidl.getChildCount() > 1) {\r
+            final int cnt = uidl.getChildCount();\r
+            for (int i = 1; i < cnt; i++) {\r
+                UIDL childUidl = uidl.getChildUIDL(i);\r
+                if (childUidl.getTag().equals("actions")) {\r
+                    if (getWidgetForPaintable().shortcutHandler == null) {\r
+                        getWidgetForPaintable().shortcutHandler = new ShortcutActionHandler(\r
+                                getId(), client);\r
+                    }\r
+                    getWidgetForPaintable().shortcutHandler\r
+                            .updateActionMap(childUidl);\r
+                }\r
+            }\r
+        }\r
+\r
+        if (uidl.hasVariable("scrollTop")\r
+                && uidl.getIntVariable("scrollTop") != getWidgetForPaintable().scrollTop) {\r
+            getWidgetForPaintable().scrollTop = uidl\r
+                    .getIntVariable("scrollTop");\r
+            getWidgetForPaintable().contentNode\r
+                    .setScrollTop(getWidgetForPaintable().scrollTop);\r
+            // re-read the actual scrollTop in case invalid value was set\r
+            // (scrollTop != 0 when no scrollbar exists, other values would be\r
+            // caught by scroll listener), see #3784\r
+            getWidgetForPaintable().scrollTop = getWidgetForPaintable().contentNode\r
+                    .getScrollTop();\r
+        }\r
+\r
+        if (uidl.hasVariable("scrollLeft")\r
+                && uidl.getIntVariable("scrollLeft") != getWidgetForPaintable().scrollLeft) {\r
+            getWidgetForPaintable().scrollLeft = uidl\r
+                    .getIntVariable("scrollLeft");\r
+            getWidgetForPaintable().contentNode\r
+                    .setScrollLeft(getWidgetForPaintable().scrollLeft);\r
+            // re-read the actual scrollTop in case invalid value was set\r
+            // (scrollTop != 0 when no scrollbar exists, other values would be\r
+            // caught by scroll listener), see #3784\r
+            getWidgetForPaintable().scrollLeft = getWidgetForPaintable().contentNode\r
+                    .getScrollLeft();\r
+        }\r
+\r
+        // Must be run after scrollTop is set as Webkit overflow fix re-sets the\r
+        // scrollTop\r
+        getWidgetForPaintable().runHacks(false);\r
+\r
+        // And apply tab index\r
+        if (uidl.hasVariable("tabindex")) {\r
+            getWidgetForPaintable().contentNode.setTabIndex(uidl\r
+                    .getIntVariable("tabindex"));\r
+        }\r
+\r
+        getWidgetForPaintable().rendering = false;\r
+\r
+    }\r
+\r
+    public void updateCaption(VPaintableWidget component, UIDL uidl) {\r
+        // NOP: layouts caption, errors etc not rendered in Panel\r
+    }\r
+\r
+    @Override\r
+    public VPanel getWidgetForPaintable() {\r
+        return (VPanel) super.getWidgetForPaintable();\r
+    }\r
+\r
+    @Override\r
+    protected Widget createWidget() {\r
+        return GWT.create(VPanel.class);\r
+    }\r
+\r
+}\r
index a69413c28b201e15a3d3360cb5dc31a194088fa3..390279a62f74e1dac5d54d3d8eaf971971171829 100644 (file)
@@ -16,7 +16,7 @@ import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
 import com.vaadin.terminal.Scrollable;
 import com.vaadin.terminal.gwt.client.MouseEventDetails;
-import com.vaadin.terminal.gwt.client.ui.VPanel;
+import com.vaadin.terminal.gwt.client.ui.VPanelPaintable;
 import com.vaadin.ui.Component.Focusable;
 import com.vaadin.ui.themes.Reindeer;
 import com.vaadin.ui.themes.Runo;
@@ -30,12 +30,12 @@ import com.vaadin.ui.themes.Runo;
  * @since 3.0
  */
 @SuppressWarnings("serial")
-@ClientWidget(VPanel.class)
+@ClientWidget(VPanelPaintable.class)
 public class Panel extends AbstractComponentContainer implements Scrollable,
         ComponentContainer.ComponentAttachListener,
         ComponentContainer.ComponentDetachListener, Action.Notifier, Focusable {
 
-    private static final String CLICK_EVENT = VPanel.CLICK_EVENT_IDENTIFIER;
+    private static final String CLICK_EVENT = VPanelPaintable.CLICK_EVENT_IDENTIFIER;
 
     /**
      * Removes extra decorations from the Panel.
@@ -559,6 +559,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
     /*
      * ACTIONS
      */
+    @Override
     protected ActionManager getActionManager() {
         if (actionManager == null) {
             actionManager = new ActionManager(this);