]> source.dussan.org Git - vaadin-framework.git/commitdiff
Updated Panel to no longer use child painted with the UIDL
authorArtur Signell <artur@vaadin.com>
Fri, 9 Mar 2012 15:30:48 +0000 (17:30 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 14 Mar 2012 14:00:16 +0000 (16:00 +0200)
21 files changed:
src/com/vaadin/terminal/Scrollable.java
src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/client/ComponentContainerConnector.java
src/com/vaadin/terminal/gwt/client/ConnectorHierarchyChangedEvent.java
src/com/vaadin/terminal/gwt/client/ConnectorMap.java
src/com/vaadin/terminal/gwt/client/ui/AbstractComponentContainerConnector.java
src/com/vaadin/terminal/gwt/client/ui/PanelConnector.java
src/com/vaadin/terminal/gwt/client/ui/VPanel.java
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
src/com/vaadin/ui/Panel.java
src/com/vaadin/ui/Window.java
tests/testbench/com/vaadin/tests/components/panel/BasicPanelTest.java
tests/testbench/com/vaadin/tests/components/panel/PanelShouldNotScroll.java
tests/testbench/com/vaadin/tests/components/tree/TreeScrollingOnSelection.java
tests/testbench/com/vaadin/tests/components/window/WindowScrollingComponentIntoView.java
tests/testbench/com/vaadin/tests/tickets/Ticket1710.java
tests/testbench/com/vaadin/tests/tickets/Ticket1804.java
tests/testbench/com/vaadin/tests/tickets/Ticket1834PanelScrolling.java
tests/testbench/com/vaadin/tests/tickets/Ticket1869.java
tests/testbench/com/vaadin/tests/tickets/Ticket1923.java
tests/testbench/com/vaadin/tests/validation/EmptyFieldErrorIndicators.java

index dac35c7704e739d86d89125e69b0564a46f3a271..472954c556e16d4965a8b3d10cc3f3438341a241 100644 (file)
@@ -9,8 +9,7 @@ import java.io.Serializable;
 /**
  * <p>
  * This interface is implemented by all visual objects that can be scrolled
- * programmatically from the server-side, or for which it is possible to know
- * the scroll position on the server-side. The unit of scrolling is pixel.
+ * programmatically from the server-side. The unit of scrolling is pixel.
  * </p>
  * 
  * @author Vaadin Ltd.
@@ -40,17 +39,10 @@ public interface Scrollable extends Serializable {
      * scrolled right.
      * </p>
      * 
-     * <p>
-     * The method only has effect if programmatic scrolling is enabled for the
-     * scrollable. Some implementations may require enabling programmatic before
-     * this method can be used. See {@link #setScrollable(boolean)} for more
-     * information.
-     * </p>
-     * 
-     * @param pixelsScrolled
+     * @param scrollLeft
      *            the xOffset.
      */
-    public void setScrollLeft(int pixelsScrolled);
+    public void setScrollLeft(int scrollLeft);
 
     /**
      * Gets scroll top offset.
@@ -73,13 +65,6 @@ public interface Scrollable extends Serializable {
      * </p>
      * 
      * <p>
-     * The method only has effect if programmatic scrolling is enabled for the
-     * scrollable. Some implementations may require enabling programmatic before
-     * this method can be used. See {@link #setScrollable(boolean)} for more
-     * information.
-     * </p>
-     * 
-     * <p>
      * The scrolling position is limited by the current height of the content
      * area. If the position is below the height, it is scrolled to the bottom.
      * However, if the same response also adds height to the content area,
@@ -87,44 +72,9 @@ public interface Scrollable extends Serializable {
      * area.
      * </p>
      * 
-     * @param pixelsScrolled
+     * @param scrollTop
      *            the yOffset.
      */
-    public void setScrollTop(int pixelsScrolled);
-
-    /**
-     * Is programmatic scrolling enabled.
-     * 
-     * <p>
-     * Whether programmatic scrolling with {@link #setScrollLeft(int)} and
-     * {@link #setScrollTop(int)} is enabled.
-     * </p>
-     * 
-     * @return <code>true</code> if the scrolling is enabled, otherwise
-     *         <code>false</code>.
-     */
-    public boolean isScrollable();
-
-    /**
-     * Enables or disables programmatic scrolling.
-     * 
-     * <p>
-     * Enables setting the scroll position with {@link #setScrollLeft(int)} and
-     * {@link #setScrollTop(int)}. Implementations of the interface may have
-     * programmatic scrolling disabled by default, in which case you need to
-     * enable it to use the mentioned methods.
-     * </p>
-     * 
-     * <p>
-     * Notice that this does <i>not</i> control whether scroll bars are shown
-     * for a scrollable component. That normally happens automatically when the
-     * content grows too big for the component, relying on the "overflow: auto"
-     * property in CSS.
-     * </p>
-     * 
-     * @param isScrollingEnabled
-     *            true if the scrolling is allowed.
-     */
-    public void setScrollable(boolean isScrollingEnabled);
+    public void setScrollTop(int scrollTop);
 
 }
index f956f56f92456eeb88e498fa1557ffeab2fe5026..c331ae4d6c3f186613195da40a6cfd1a013031b0 100644 (file)
@@ -1103,26 +1103,22 @@ public class ApplicationConnection {
             private void createConnectorsIfNeeded(ValueMap json) {
                 VConsole.log(" * Creating connectors (if needed)");
 
-                JsArray<ValueMap> changes = json.getJSValueMapArray("changes");
-                // FIXME: This should be based on shared state, not the old
-                // "changes"
-                int length = changes.length();
-                for (int i = 0; i < length; i++) {
+                ValueMap types = json.getValueMap("types");
+                JsArrayString keyArray = types.getKeyArray();
+                for (int i = 0; i < keyArray.length(); i++) {
                     try {
-                        final UIDL change = changes.get(i).cast();
-                        final UIDL uidl = change.getChildUIDL(0);
-                        String connectorId = uidl.getId();
+                        String connectorId = keyArray.get(i);
+                        String connectorType = types.getString(connectorId);
                         Connector connector = connectorMap
                                 .getConnector(connectorId);
                         if (connector != null) {
                             continue;
                         }
-
                         // Connector does not exist so we must create it
-                        if (!uidl.getTag().equals(
-                                configuration.getEncodedWindowTag())) {
+                        if (!connectorType.equals(configuration
+                                .getEncodedWindowTag())) {
                             // create, initialize and register the paintable
-                            getConnector(uidl.getId(), uidl.getTag());
+                            getConnector(connectorId, connectorType);
                         } else {
                             // First RootConnector update. Before this the
                             // RootConnector has been created but not
@@ -1258,7 +1254,7 @@ public class ApplicationConnection {
                         // TODO This check should be done on the server side in
                         // the future so the hierarchy update is only sent when
                         // something actually has changed
-                        Collection<ComponentConnector> oldChildren = ccc
+                        List<ComponentConnector> oldChildren = ccc
                                 .getChildren();
                         boolean actuallyChanged = !Util.collectionsEquals(
                                 oldChildren, newChildren);
@@ -1272,7 +1268,7 @@ public class ApplicationConnection {
                                 .create(ConnectorHierarchyChangedEvent.class);
                         event.setOldChildren(oldChildren);
                         event.setParent(ccc);
-                        ccc.setChildren((Collection) newChildren);
+                        ccc.setChildren((List) newChildren);
                         events.add(event);
                     } catch (final Throwable e) {
                         VConsole.error(e);
index 49e31e86907779aaac0d9c9ae6e894473edf1d61..f4855dfd4044edbc4584b0f7962de05e2fb1000b 100644 (file)
@@ -4,7 +4,7 @@
 
 package com.vaadin.terminal.gwt.client;
 
-import java.util.Collection;
+import java.util.List;
 
 import com.google.gwt.user.client.ui.HasWidgets;
 
@@ -42,7 +42,7 @@ public interface ComponentContainerConnector extends ComponentConnector {
      * @return A collection of children for this connector. An empty collection
      *         if there are no children. Never returns null.
      */
-    public Collection<ComponentConnector> getChildren();
+    public List<ComponentConnector> getChildren();
 
     /**
      * Sets the children for this connector. This method should only be called
@@ -57,7 +57,7 @@ public interface ComponentContainerConnector extends ComponentConnector {
      * @param children
      *            The new child connectors
      */
-    public void setChildren(Collection<ComponentConnector> children);
+    public void setChildren(List<ComponentConnector> children);
 
     /**
      * Called when the child connector hierarchy of this connector has changed.
index 43b61337ecb2e3f088e7abf261efe8b18d1625e9..849ec0788c56f33a23a2ea5f783203b1460d381b 100644 (file)
@@ -1,6 +1,6 @@
 package com.vaadin.terminal.gwt.client;
 
-import java.util.Collection;
+import java.util.List;
 
 /**
  * Event for containing data related to a change in the {@link Connector}
@@ -14,7 +14,7 @@ import java.util.Collection;
  * 
  */
 public class ConnectorHierarchyChangedEvent {
-    Collection<ComponentConnector> oldChildren;
+    List<ComponentConnector> oldChildren;
     private ComponentContainerConnector parent;
 
     public ConnectorHierarchyChangedEvent() {
@@ -26,7 +26,7 @@ public class ConnectorHierarchyChangedEvent {
      * 
      * @return A collection of old child connectors. Never returns null.
      */
-    public Collection<ComponentConnector> getOldChildren() {
+    public List<ComponentConnector> getOldChildren() {
         return oldChildren;
     }
 
@@ -36,7 +36,7 @@ public class ConnectorHierarchyChangedEvent {
      * @param oldChildren
      *            The old child connectors. Must not be null.
      */
-    public void setOldChildren(Collection<ComponentConnector> oldChildren) {
+    public void setOldChildren(List<ComponentConnector> oldChildren) {
         this.oldChildren = oldChildren;
     }
 
index 3d250b2798438c260ba60083ba5b942a73aefc36..601d01c92c0f02a7e77cb2a427fbac6281b89b79 100644 (file)
@@ -188,15 +188,9 @@ public class ConnectorMap {
         }
 
         if (id == null) {
-            /*
-             * Uncomment the following to debug unregistring components. No
-             * paintables with null id should end here. At least one exception
-             * is our VScrollTableRow, that is hacked to fake it self as a
-             * Paintable to build support for sizing easier.
-             */
-            // if (!(p instanceof VScrollTableRow)) {
-            // VConsole.log("Trying to unregister Paintable not created by Application Connection.");
-            // }
+            VConsole.log("Tried to unregister a "
+                    + connector.getClass().getName() + " (" + id
+                    + ") which was not registered");
         } else {
             unregistryBag.add(id);
         }
@@ -212,7 +206,7 @@ public class ConnectorMap {
         for (Connector connector : getConnectors()) {
             if (connector instanceof ComponentConnector) {
                 ComponentConnector componentConnector = (ComponentConnector) connector;
-                if (!unregistryBag.contains(getConnectorId(connector))) {
+                if (!unregistryBag.contains(connector.getId())) {
                     result.add(componentConnector);
                 }
             }
@@ -237,6 +231,8 @@ public class ConnectorMap {
                             + ") that is never registered (or already unregistered)");
                     continue;
                 }
+                VConsole.log("Unregistering connector "
+                        + connector.getClass().getName() + " " + connectorId);
                 Widget widget = null;
                 if (connector instanceof ComponentConnector) {
                     widget = ((ComponentConnector) connector).getWidget();
index db0cbc29a29746f913dc9308ab6b0b59f5137022..3113135b3115d0491feddb714b3ef984edaaf795 100644 (file)
@@ -3,8 +3,8 @@
  */
 package com.vaadin.terminal.gwt.client.ui;
 
-import java.util.Collection;
 import java.util.LinkedList;
+import java.util.List;
 
 import com.vaadin.terminal.gwt.client.ComponentConnector;
 import com.vaadin.terminal.gwt.client.ComponentContainerConnector;
@@ -14,7 +14,7 @@ import com.vaadin.terminal.gwt.client.Util;
 public abstract class AbstractComponentContainerConnector extends
         AbstractComponentConnector implements ComponentContainerConnector {
 
-    Collection<ComponentConnector> children;
+    List<ComponentConnector> children;
 
     /**
      * Default constructor
@@ -28,7 +28,7 @@ public abstract class AbstractComponentContainerConnector extends
      * @see
      * com.vaadin.terminal.gwt.client.ComponentContainerConnector#getChildren()
      */
-    public Collection<ComponentConnector> getChildren() {
+    public List<ComponentConnector> getChildren() {
         if (children == null) {
             return new LinkedList<ComponentConnector>();
         }
@@ -43,7 +43,7 @@ public abstract class AbstractComponentContainerConnector extends
      * com.vaadin.terminal.gwt.client.ComponentContainerConnector#setChildren
      * (java.util.Collection)
      */
-    public void setChildren(Collection<ComponentConnector> children) {
+    public void setChildren(List<ComponentConnector> children) {
         this.children = children;
     }
 
@@ -55,7 +55,7 @@ public abstract class AbstractComponentContainerConnector extends
      * (com.vaadin.terminal.gwt.client.ConnectorHierarchyChangedEvent)
      */
     public void connectorHierarchyChanged(ConnectorHierarchyChangedEvent event) {
-        //TODO Remove debug info
+        // TODO Remove debug info
         System.out.println("Hierarchy changed for " + Util.getSimpleName(this));
         System.out.println("* Old children: " + event.getOldChildren());
         System.out.println("* New children: " + getChildren());
index 92c504da97d7cba7c251aea0bdb9eca8ae0f4dae..b48b0e823276386f498ccf9c253428a48388a294 100644 (file)
@@ -12,12 +12,44 @@ import com.google.gwt.event.shared.HandlerRegistration;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.ComponentConnector;
+import com.vaadin.terminal.gwt.client.ComponentState;
+import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangedEvent;
 import com.vaadin.terminal.gwt.client.LayoutManager;
 import com.vaadin.terminal.gwt.client.UIDL;
 
 public class PanelConnector extends AbstractComponentContainerConnector
         implements SimpleManagedLayout, PostLayoutListener {
 
+    public static class PanelState extends ComponentState {
+        private int tabIndex;
+        private int scrollLeft, scrollTop;
+
+        public int getTabIndex() {
+            return tabIndex;
+        }
+
+        public void setTabIndex(int tabIndex) {
+            this.tabIndex = tabIndex;
+        }
+
+        public int getScrollLeft() {
+            return scrollLeft;
+        }
+
+        public void setScrollLeft(int scrollLeft) {
+            this.scrollLeft = scrollLeft;
+        }
+
+        public int getScrollTop() {
+            return scrollTop;
+        }
+
+        public void setScrollTop(int scrollTop) {
+            this.scrollTop = scrollTop;
+        }
+
+    }
+
     public static final String CLICK_EVENT_IDENTIFIER = "click";
 
     private Integer uidlScrollTop;
@@ -113,21 +145,21 @@ public class PanelConnector extends AbstractComponentContainerConnector
         getWidget().handleError(uidl);
 
         // Render content
-        final UIDL layoutUidl = uidl.getChildUIDL(0);
-        final ComponentConnector newLayout = client.getPaintable(layoutUidl);
-        if (newLayout != getWidget().layout) {
-            if (getWidget().layout != null) {
-                client.unregisterPaintable(getWidget().layout);
-            }
-            getWidget().setWidget(newLayout.getWidget());
-            getWidget().layout = newLayout;
-        }
-        getWidget().layout.updateFromUIDL(layoutUidl, client);
+        // final UIDL layoutUidl = uidl.getChildUIDL(0);
+        // final ComponentConnector newLayout = client.getPaintable(layoutUidl);
+        // if (newLayout != getWidget().layout) {
+        // if (getWidget().layout != null) {
+        // client.unregisterPaintable(getWidget().layout);
+        // }
+        // getWidget().setWidget(newLayout.getWidget());
+        // getWidget().layout = newLayout;
+        // }
+        // getWidget().layout.updateFromUIDL(layoutUidl, client);
 
         // We may have actions attached to this panel
-        if (uidl.getChildCount() > 1) {
+        if (uidl.getChildCount() > 0) {
             final int cnt = uidl.getChildCount();
-            for (int i = 1; i < cnt; i++) {
+            for (int i = 0; i < cnt; i++) {
                 UIDL childUidl = uidl.getChildUIDL(i);
                 if (childUidl.getTag().equals("actions")) {
                     if (getWidget().shortcutHandler == null) {
@@ -139,25 +171,20 @@ public class PanelConnector extends AbstractComponentContainerConnector
             }
         }
 
-        if (uidl.hasVariable("scrollTop")
-                && uidl.getIntVariable("scrollTop") != getWidget().scrollTop) {
+        if (getState().getScrollTop() != getWidget().scrollTop) {
             // Sizes are not yet up to date, so changing the scroll position
             // is deferred to after the layout phase
-            uidlScrollTop = new Integer(uidl.getIntVariable("scrollTop"));
+            uidlScrollTop = getState().getScrollTop();
         }
 
-        if (uidl.hasVariable("scrollLeft")
-                && uidl.getIntVariable("scrollLeft") != getWidget().scrollLeft) {
+        if (getState().getScrollLeft() != getWidget().scrollLeft) {
             // Sizes are not yet up to date, so changing the scroll position
             // is deferred to after the layout phase
-            uidlScrollLeft = new Integer(uidl.getIntVariable("scrollLeft"));
+            uidlScrollLeft = getState().getScrollLeft();
         }
 
         // And apply tab index
-        if (uidl.hasVariable("tabindex")) {
-            getWidget().contentNode
-                    .setTabIndex(uidl.getIntVariable("tabindex"));
-        }
+        getWidget().contentNode.setTabIndex(getState().getTabIndex());
     }
 
     public void updateCaption(ComponentConnector component, UIDL uidl) {
@@ -231,4 +258,41 @@ public class PanelConnector extends AbstractComponentContainerConnector
         }
     }
 
+    @Override
+    public PanelState getState() {
+        return (PanelState) super.getState();
+    }
+
+    @Override
+    protected PanelState createState() {
+        return GWT.create(PanelState.class);
+    }
+
+    @Override
+    public void connectorHierarchyChanged(ConnectorHierarchyChangedEvent event) {
+        super.connectorHierarchyChanged(event);
+
+        possiblyUnregisterOldChild(event);
+
+        // We always have 0 or 1 child
+        ComponentConnector newChild = null;
+        if (getChildren().size() != 0) {
+            // We now have one child
+            newChild = getChildren().get(0);
+        }
+
+        getWidget().setWidget(newChild.getWidget());
+    }
+
+    private void possiblyUnregisterOldChild(ConnectorHierarchyChangedEvent event) {
+        // Did we have a child that needs to be unregistered?
+        if (event.getOldChildren().size() != 0) {
+            ComponentConnector oldChild = event.getOldChildren().get(0);
+            // We had a child, unregister it
+            // TODO Should be handled by the framework
+            if (oldChild.getParent() == null) {
+                getConnection().unregisterPaintable(oldChild);
+            }
+        }
+    }
 }
index 7dcfa24d89795afe30cf19c3719b68620c28b42b..b9552493ded2bf22a5e47596e3c1c60d3162f7d1 100644 (file)
@@ -13,7 +13,6 @@ import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.ui.SimplePanel;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.ComponentConnector;
 import com.vaadin.terminal.gwt.client.Focusable;
 import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner;
@@ -39,8 +38,6 @@ public class VPanel extends SimplePanel implements ShortcutActionHandlerOwner,
 
     private Element errorIndicatorElement;
 
-    ComponentConnector layout;
-
     ShortcutActionHandler shortcutHandler;
 
     private String width = "";
index 553c6fe5727106d1f1215b1d0bc4aa70a1cdc405..66e692694f821c99c5a49a4a80cda766d1697073 100644 (file)
@@ -814,6 +814,7 @@ public abstract class AbstractCommunicationManager implements
         LinkedList<Paintable> stateQueue = new LinkedList<Paintable>();
         LinkedList<Paintable> rpcPendingQueue = new LinkedList<Paintable>();
         LinkedList<Paintable> hierarchyPendingQueue = new LinkedList<Paintable>();
+        LinkedList<Paintable> connectorTypeQueue = new LinkedList<Paintable>();
 
         if (paintables != null) {
 
@@ -825,6 +826,9 @@ public abstract class AbstractCommunicationManager implements
                 final Paintable p = paintQueue.removeFirst();
                 // for now, all painted components may need a state refresh
                 stateQueue.push(p);
+                // TODO This should be optimized. The type only needs to be sent
+                // once for each connector id + on refresh
+                connectorTypeQueue.push(p);
                 // also a hierarchy update
                 hierarchyPendingQueue.push(p);
                 // ... and RPC calls to be sent
@@ -911,6 +915,24 @@ public abstract class AbstractCommunicationManager implements
             outWriter.append(sharedStates.toString());
             outWriter.print(", "); // close states
         }
+        if (!connectorTypeQueue.isEmpty()) {
+            JSONObject connectorTypes = new JSONObject();
+            while (!connectorTypeQueue.isEmpty()) {
+                final Paintable p = connectorTypeQueue.pop();
+                String paintableId = getPaintableId(p);
+                String connectorType = paintTarget.getTag(p);
+                try {
+                    connectorTypes.put(paintableId, connectorType);
+                } catch (JSONException e) {
+                    throw new PaintException(
+                            "Failed to send connector type for paintable "
+                                    + paintableId + ": " + e.getMessage());
+                }
+            }
+            outWriter.print("\"types\":");
+            outWriter.append(connectorTypes.toString());
+            outWriter.print(", "); // close states
+        }
         if (!hierarchyPendingQueue.isEmpty()) {
             // Send update hierarchy information to the client.
 
@@ -932,7 +954,7 @@ public abstract class AbstractCommunicationManager implements
                     while (iterator.hasNext()) {
                         Component child = iterator.next();
                         if (child.getState().isVisible()) {
-                            String childConnectorId = paintableIdMap.get(child);
+                            String childConnectorId = getPaintableId(child);
                             children.put(childConnectorId);
                         }
                     }
@@ -947,7 +969,7 @@ public abstract class AbstractCommunicationManager implements
                 }
             }
             outWriter.append(hierarchyInfo.toString());
-            outWriter.print(", "); // close states
+            outWriter.print(", "); // close hierarchy
 
         }
 
index c3bca2a5bb51626b90a4679d68a564b1285a4767..b6c08da86c25d15fb23ba7e851e0c48b90dd8a0e 100644 (file)
@@ -17,9 +17,8 @@ import com.vaadin.terminal.PaintTarget;
 import com.vaadin.terminal.Scrollable;
 import com.vaadin.terminal.gwt.client.MouseEventDetails;
 import com.vaadin.terminal.gwt.client.ui.PanelConnector;
+import com.vaadin.terminal.gwt.client.ui.PanelConnector.PanelState;
 import com.vaadin.ui.Component.Focusable;
-import com.vaadin.ui.themes.Reindeer;
-import com.vaadin.ui.themes.Runo;
 
 /**
  * Panel - a simple single component container.
@@ -37,51 +36,17 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
 
     private static final String CLICK_EVENT = PanelConnector.CLICK_EVENT_IDENTIFIER;
 
-    /**
-     * Removes extra decorations from the Panel.
-     * 
-     * @deprecated this style is no longer part of the core framework and this
-     *             component, even though most built-in themes implement this
-     *             style. Use the constant specified in the theme class file
-     *             that you're using, if it provides one, e.g.
-     *             {@link Reindeer#PANEL_LIGHT} or {@link Runo#PANEL_LIGHT} .
-     */
-    @Deprecated
-    public static final String STYLE_LIGHT = "light";
-
     /**
      * Content of the panel.
      */
     private ComponentContainer content;
 
-    /**
-     * Scroll X position.
-     */
-    private int scrollOffsetX = 0;
-
-    /**
-     * Scroll Y position.
-     */
-    private int scrollOffsetY = 0;
-
-    /**
-     * Scrolling mode.
-     */
-    private boolean scrollable = false;
-
     /**
      * Keeps track of the Actions added to this component, and manages the
      * painting and handling as well.
      */
     protected ActionManager actionManager;
 
-    /**
-     * By default the Panel is not in the normal document focus flow and can
-     * only be focused by using the focus()-method. Change this to 0 if you want
-     * to have the Panel in the normal focus flow.
-     */
-    private int tabIndex = -1;
-
     /**
      * Creates a new empty panel. A VerticalLayout is used as content.
      */
@@ -98,7 +63,8 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
      */
     public Panel(ComponentContainer content) {
         setContent(content);
-        setWidth(100, UNITS_PERCENTAGE);
+        setWidth(100, Unit.PERCENTAGE);
+        getState().setTabIndex(-1);
     }
 
     /**
@@ -254,15 +220,9 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
      */
     @Override
     public void paintContent(PaintTarget target) throws PaintException {
+        // This is needed for now for paint to be ever run for the child
         content.paint(target);
 
-        target.addVariable(this, "tabindex", getTabIndex());
-
-        if (isScrollable()) {
-            target.addVariable(this, "scrollLeft", getScrollLeft());
-            target.addVariable(this, "scrollTop", getScrollTop());
-        }
-
         if (actionManager != null) {
             actionManager.paintActions(null, target);
         }
@@ -346,11 +306,11 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
         final Integer newScrollY = (Integer) variables.get("scrollTop");
         if (newScrollX != null && newScrollX.intValue() != getScrollLeft()) {
             // set internally, not to fire request repaint
-            scrollOffsetX = newScrollX.intValue();
+            getState().setScrollLeft(newScrollX.intValue());
         }
         if (newScrollY != null && newScrollY.intValue() != getScrollTop()) {
             // set internally, not to fire request repaint
-            scrollOffsetY = newScrollY.intValue();
+            getState().setScrollTop(newScrollY.intValue());
         }
 
         // Actions
@@ -368,15 +328,7 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
      * @see com.vaadin.terminal.Scrollable#setScrollable(boolean)
      */
     public int getScrollLeft() {
-        return scrollOffsetX;
-    }
-
-    /**
-     * @deprecated use {@link #getScrollLeft()} instead
-     */
-    @Deprecated
-    public int getScrollOffsetX() {
-        return getScrollLeft();
+        return getState().getScrollLeft();
     }
 
     /*
@@ -385,110 +337,35 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
      * @see com.vaadin.terminal.Scrollable#setScrollable(boolean)
      */
     public int getScrollTop() {
-        return scrollOffsetY;
-    }
-
-    /**
-     * @deprecated use {@link #getScrollTop()} instead
-     */
-    @Deprecated
-    public int getScrollOffsetY() {
-        return getScrollTop();
+        return getState().getScrollTop();
     }
 
     /*
      * (non-Javadoc)
      * 
-     * @see com.vaadin.terminal.Scrollable#setScrollable(boolean)
-     */
-    public boolean isScrollable() {
-        return scrollable;
-    }
-
-    /**
-     * Sets the panel as programmatically scrollable.
-     * 
-     * <p>
-     * Panel is by default not scrollable programmatically with
-     * {@link #setScrollLeft(int)} and {@link #setScrollTop(int)}, so if you use
-     * those methods, you need to enable scrolling with this method. Components
-     * that extend Panel may have a different default for the programmatic
-     * scrollability.
-     * </p>
-     * 
-     * @see com.vaadin.terminal.Scrollable#setScrollable(boolean)
-     */
-    public void setScrollable(boolean isScrollingEnabled) {
-        if (scrollable != isScrollingEnabled) {
-            scrollable = isScrollingEnabled;
-            requestRepaint();
-        }
-    }
-
-    /**
-     * Sets the horizontal scroll position.
-     * 
-     * <p>
-     * Setting the horizontal scroll position with this method requires that
-     * programmatic scrolling of the component has been enabled. For Panel it is
-     * disabled by default, so you have to call {@link #setScrollable(boolean)}.
-     * Components extending Panel may have a different default for programmatic
-     * scrollability.
-     * </p>
-     * 
      * @see com.vaadin.terminal.Scrollable#setScrollLeft(int)
-     * @see #setScrollable(boolean)
      */
-    public void setScrollLeft(int pixelsScrolled) {
-        if (pixelsScrolled < 0) {
+    public void setScrollLeft(int scrollLeft) {
+        if (scrollLeft < 0) {
             throw new IllegalArgumentException(
                     "Scroll offset must be at least 0");
         }
-        if (scrollOffsetX != pixelsScrolled) {
-            scrollOffsetX = pixelsScrolled;
-            requestRepaint();
-        }
-    }
-
-    /**
-     * @deprecated use setScrollLeft() method instead
-     */
-    @Deprecated
-    public void setScrollOffsetX(int pixels) {
-        setScrollLeft(pixels);
+        getState().setScrollLeft(scrollLeft);
+        requestRepaint();
     }
 
-    /**
-     * Sets the vertical scroll position.
-     * 
-     * <p>
-     * Setting the vertical scroll position with this method requires that
-     * programmatic scrolling of the component has been enabled. For Panel it is
-     * disabled by default, so you have to call {@link #setScrollable(boolean)}.
-     * Components extending Panel may have a different default for programmatic
-     * scrollability.
-     * </p>
+    /*
+     * (non-Javadoc)
      * 
      * @see com.vaadin.terminal.Scrollable#setScrollTop(int)
-     * @see #setScrollable(boolean)
      */
-    public void setScrollTop(int pixelsScrolledDown) {
-        if (pixelsScrolledDown < 0) {
+    public void setScrollTop(int scrollTop) {
+        if (scrollTop < 0) {
             throw new IllegalArgumentException(
                     "Scroll offset must be at least 0");
         }
-        if (scrollOffsetY != pixelsScrolledDown) {
-            scrollOffsetY = pixelsScrolledDown;
-            requestRepaint();
-        }
-    }
-
-    /**
-     * @deprecated use setScrollTop() method instead
-     */
-    @Deprecated
-    public void setScrollOffsetY(int pixels) {
-        setScrollTop(pixels);
+        getState().setScrollTop(scrollTop);
+        requestRepaint();
     }
 
     /* Documented in superclass */
@@ -641,14 +518,14 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
      * {@inheritDoc}
      */
     public int getTabIndex() {
-        return tabIndex;
+        return getState().getTabIndex();
     }
 
     /**
      * {@inheritDoc}
      */
     public void setTabIndex(int tabIndex) {
-        this.tabIndex = tabIndex;
+        getState().setTabIndex(tabIndex);
         requestRepaint();
     }
 
@@ -670,4 +547,14 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
         // This is so wrong... (#2924)
         return content.getComponentCount();
     }
+
+    @Override
+    public PanelState getState() {
+        return (PanelState) super.getState();
+    }
+
+    @Override
+    protected PanelState createState() {
+        return new PanelState();
+    }
 }
index 216a64e57ea8ff504223b6c630b930f408c28844..57ed11f3bac6df6dc86a78bc278432dd8941129a 100644 (file)
@@ -21,6 +21,7 @@ import com.vaadin.event.ShortcutAction.ModifierKey;
 import com.vaadin.event.ShortcutListener;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.gwt.client.ui.PanelConnector.PanelState;
 import com.vaadin.terminal.gwt.client.ui.VView;
 import com.vaadin.terminal.gwt.client.ui.WindowConnector;
 
@@ -73,6 +74,10 @@ import com.vaadin.terminal.gwt.client.ui.WindowConnector;
 @ClientWidget(WindowConnector.class)
 public class Window extends Panel implements FocusNotifier, BlurNotifier {
 
+    public class WindowState extends PanelState {
+
+    }
+
     /**
      * <b>Sub window only</b>. Top offset in pixels for the sub window (relative
      * to the parent application window) or -1 if unspecified.
@@ -139,7 +144,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier {
      */
     public Window(String caption, ComponentContainer content) {
         super(caption, content);
-        setScrollable(true);
         setSizeUndefined();
     }
 
index d23e3175723cf346631be6cb616245a928584b0d..671b2c3fca392612d63fa828323adb3852b4ddfa 100644 (file)
@@ -62,7 +62,6 @@ public class BasicPanelTest extends TestBase {
         getLayout().addComponent(panel);
         getLayout().setExpandRatio(panel, 1);
 
-        panel.setScrollable(true);
         panel.setScrollTop(50);
         panel.setScrollLeft(50);
         panel.setImmediate(true);
index b7047392e8e837ed119d9f4b6e9504ab791fa009..62b3007abac98de87ecf79c16b82425d780aa3a0 100644 (file)
@@ -18,7 +18,6 @@ public class PanelShouldNotScroll extends TestBase {
     @Override
     protected void setup() {
         final Panel p = new Panel(new CssLayout());
-        p.setScrollable(true);
         p.setSizeFull();
         p.setHeight("600px");
         p.addComponent(foo());
index 42c9087fc3e553c7fd5491651cf4e2204957d69e..a6079160abf4c78d429e4da0d634ebd65bc827ce 100644 (file)
@@ -36,7 +36,6 @@ public class TreeScrollingOnSelection extends TestBase {
         tree.setImmediate(true);
 
         Panel panel = new Panel();
-        panel.setScrollable(true);
         panel.addComponent(tree);
         panel.setWidth("200px");
         panel.setHeight("300px");
index c46f125192bc996e5761f4b1438ee844ab3c6602..9f3f27cf6a6276beb80bc693379465d693ddce9a 100644 (file)
@@ -75,7 +75,6 @@ public class WindowScrollingComponentIntoView extends AbstractTestCase {
 
         Panel panel = new Panel("scrollable panel");
         panel.setHeight(400, Panel.UNITS_PIXELS);
-        panel.setScrollable(true);
         panel.setScrollLeft(50);
         panel.setScrollTop(50);
         panel.getContent().setSizeUndefined();
index 7c8e545c97fb9a6a465541329a14fb74201c75fb..827879d3c62d18a995a90f283c207add72d817c5 100644 (file)
@@ -99,7 +99,6 @@ public class Ticket1710 extends com.vaadin.Application.LegacyApplication {
         cb.setImmediate(true);
         hidingControls.addComponent(cb);
         elhp.setVisible(false);
-        elhp.setScrollable(true);
         elh.setWidth("2000px");
         elh.setHeight("100px");
         addFields(elh);
@@ -251,7 +250,6 @@ public class Ticket1710 extends com.vaadin.Application.LegacyApplication {
             Panel controlWrapper = new Panel();
             controlWrapper.addComponent(controls);
             controlWrapper.setWidth("100%");
-            controlWrapper.setScrollable(true);
             controlWrapper.setStyleName("controls");
             internalLayout.addComponent(controlWrapper);
             Panel testPanel = new Panel(testPanelLayout);
@@ -392,15 +390,13 @@ public class Ticket1710 extends com.vaadin.Application.LegacyApplication {
         }
 
         private void updateMarginsAndSpacing() {
-            testedLayout.setMargin(
-                    ((Boolean) marginTop.getValue()).booleanValue(),
-                    ((Boolean) marginRight.getValue()).booleanValue(),
-                    ((Boolean) marginBottom.getValue()).booleanValue(),
-                    ((Boolean) marginLeft.getValue()).booleanValue());
+            testedLayout.setMargin(marginTop.getValue().booleanValue(),
+                    marginRight.getValue().booleanValue(), marginBottom
+                            .getValue().booleanValue(), marginLeft.getValue()
+                            .booleanValue());
             if (testedLayout instanceof Layout.SpacingHandler) {
-                ((Layout.SpacingHandler) testedLayout)
-                        .setSpacing(((Boolean) spacing.getValue())
-                                .booleanValue());
+                ((Layout.SpacingHandler) testedLayout).setSpacing(spacing
+                        .getValue().booleanValue());
             }
         }
 
index 86eb3c429a19acc273334886a78436464f65ebba..b659eff01e6c85b3ce7bac2cbc60e61ab14d7248 100644 (file)
@@ -107,7 +107,6 @@ public class Ticket1804 extends com.vaadin.Application.LegacyApplication {
                 }
                 Window w = new Window("Status of the fields");
                 w.setModal(true);
-                w.setScrollable(true);
                 w.setHeight("80%");
                 w.addComponent(new Label(msg.toString(), ContentMode.XHTML));
                 main.addWindow(w);
index afcdd2ed162a8468ea92549e11ff91a56d85c243..912f5ba02d3d514dc62b95b4db3a80771ed065e9 100644 (file)
@@ -69,7 +69,6 @@ public class Ticket1834PanelScrolling extends
         main.addComponent(b);
 
         p = new Panel("TestPanel");
-        p.setScrollable(true);
 
         for (int i = 0; i < ROWS; i++) {
             p.addComponent(new Label(
index 6745acf583b189ff153078a296306b15ee64eb47..d51c0990aebf9418986e184b05085809d40d8e6b 100644 (file)
@@ -32,7 +32,6 @@ public class Ticket1869 extends com.vaadin.Application.LegacyApplication {
         lo.addComponent(elp);
         elp.setWidth("300px");
         elp.setHeight("300px");
-        elp.setScrollable(true);
 
         HorizontalLayout elh = new HorizontalLayout();
         Panel elph = new Panel(
@@ -49,7 +48,6 @@ public class Ticket1869 extends com.vaadin.Application.LegacyApplication {
         lo.addComponent(elph);
         elph.setWidth("300px");
         elph.setHeight("300px");
-        elph.setScrollable(true);
 
     }
 }
index 7252caf9d1e82f646961d0e4c57d6b7754068e5f..17a7dacf261978c8c7902d957432577d1fff1d02 100644 (file)
@@ -19,7 +19,6 @@ public class Ticket1923 extends com.vaadin.Application.LegacyApplication {
 
         p = new Panel("TestPanel 250x300");
         // p.getLayout().setWidth("100%");
-        p.setScrollable(true);
         // p.setContent(new GridLayout(1, 100));
         for (int i = 0; i < ROWS; i++) {
             p.addComponent(new Label(
index 0efd727a06bbead0ca5f8b2f01c1b752565b2ea6..8fb0c3585d5a8ea93d97ef81773f90e4c094b25c 100644 (file)
@@ -45,7 +45,6 @@ public class EmptyFieldErrorIndicators extends TestBase {
         panel.setSizeFull();
         panel.setStyleName(Reindeer.PANEL_LIGHT);
         panel.addComponent(hl);
-        panel.setScrollable(true);
         addComponent(panel);
     }