From ae3478bc2eb2abec316996b4fd54664ef0e4ad11 Mon Sep 17 00:00:00 2001
From: Artur Signell
Date: Fri, 9 Mar 2012 17:30:48 +0200
Subject: [PATCH] Updated Panel to no longer use child painted with the UIDL
---
src/com/vaadin/terminal/Scrollable.java | 60 +-----
.../gwt/client/ApplicationConnection.java | 24 +--
.../client/ComponentContainerConnector.java | 6 +-
.../ConnectorHierarchyChangedEvent.java | 8 +-
.../terminal/gwt/client/ConnectorMap.java | 16 +-
.../AbstractComponentContainerConnector.java | 10 +-
.../gwt/client/ui/PanelConnector.java | 108 ++++++++---
.../vaadin/terminal/gwt/client/ui/VPanel.java | 3 -
.../server/AbstractCommunicationManager.java | 26 ++-
src/com/vaadin/ui/Panel.java | 173 +++---------------
src/com/vaadin/ui/Window.java | 6 +-
.../components/panel/BasicPanelTest.java | 1 -
.../panel/PanelShouldNotScroll.java | 1 -
.../tree/TreeScrollingOnSelection.java | 1 -
.../WindowScrollingComponentIntoView.java | 1 -
.../com/vaadin/tests/tickets/Ticket1710.java | 16 +-
.../com/vaadin/tests/tickets/Ticket1804.java | 1 -
.../tickets/Ticket1834PanelScrolling.java | 1 -
.../com/vaadin/tests/tickets/Ticket1869.java | 2 -
.../com/vaadin/tests/tickets/Ticket1923.java | 1 -
.../validation/EmptyFieldErrorIndicators.java | 1 -
21 files changed, 184 insertions(+), 282 deletions(-)
diff --git a/src/com/vaadin/terminal/Scrollable.java b/src/com/vaadin/terminal/Scrollable.java
index dac35c7704..472954c556 100644
--- a/src/com/vaadin/terminal/Scrollable.java
+++ b/src/com/vaadin/terminal/Scrollable.java
@@ -9,8 +9,7 @@ import java.io.Serializable;
/**
*
* 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.
*
*
* @author Vaadin Ltd.
@@ -40,17 +39,10 @@ public interface Scrollable extends Serializable {
* scrolled right.
*
*
- *
- * 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.
- *
- *
- * @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 {
*
*
*
- * 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.
- *
- *
- *
* 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.
*
*
- * @param pixelsScrolled
+ * @param scrollTop
* the yOffset.
*/
- public void setScrollTop(int pixelsScrolled);
-
- /**
- * Is programmatic scrolling enabled.
- *
- *
- * Whether programmatic scrolling with {@link #setScrollLeft(int)} and
- * {@link #setScrollTop(int)} is enabled.
- *
- *
- * @return true
if the scrolling is enabled, otherwise
- * false
.
- */
- public boolean isScrollable();
-
- /**
- * Enables or disables programmatic scrolling.
- *
- *
- * 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.
- *
- *
- *
- * Notice that this does not 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.
- *
- *
- * @param isScrollingEnabled
- * true if the scrolling is allowed.
- */
- public void setScrollable(boolean isScrollingEnabled);
+ public void setScrollTop(int scrollTop);
}
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
index f956f56f92..c331ae4d6c 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
@@ -1103,26 +1103,22 @@ public class ApplicationConnection {
private void createConnectorsIfNeeded(ValueMap json) {
VConsole.log(" * Creating connectors (if needed)");
- JsArray 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 oldChildren = ccc
+ List 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);
diff --git a/src/com/vaadin/terminal/gwt/client/ComponentContainerConnector.java b/src/com/vaadin/terminal/gwt/client/ComponentContainerConnector.java
index 49e31e8690..f4855dfd40 100644
--- a/src/com/vaadin/terminal/gwt/client/ComponentContainerConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ComponentContainerConnector.java
@@ -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 getChildren();
+ public List 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 children);
+ public void setChildren(List children);
/**
* Called when the child connector hierarchy of this connector has changed.
diff --git a/src/com/vaadin/terminal/gwt/client/ConnectorHierarchyChangedEvent.java b/src/com/vaadin/terminal/gwt/client/ConnectorHierarchyChangedEvent.java
index 43b61337ec..849ec0788c 100644
--- a/src/com/vaadin/terminal/gwt/client/ConnectorHierarchyChangedEvent.java
+++ b/src/com/vaadin/terminal/gwt/client/ConnectorHierarchyChangedEvent.java
@@ -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 oldChildren;
+ List 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 getOldChildren() {
+ public List getOldChildren() {
return oldChildren;
}
@@ -36,7 +36,7 @@ public class ConnectorHierarchyChangedEvent {
* @param oldChildren
* The old child connectors. Must not be null.
*/
- public void setOldChildren(Collection oldChildren) {
+ public void setOldChildren(List oldChildren) {
this.oldChildren = oldChildren;
}
diff --git a/src/com/vaadin/terminal/gwt/client/ConnectorMap.java b/src/com/vaadin/terminal/gwt/client/ConnectorMap.java
index 3d250b2798..601d01c92c 100644
--- a/src/com/vaadin/terminal/gwt/client/ConnectorMap.java
+++ b/src/com/vaadin/terminal/gwt/client/ConnectorMap.java
@@ -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();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentContainerConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentContainerConnector.java
index db0cbc29a2..3113135b31 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentContainerConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentContainerConnector.java
@@ -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 children;
+ List children;
/**
* Default constructor
@@ -28,7 +28,7 @@ public abstract class AbstractComponentContainerConnector extends
* @see
* com.vaadin.terminal.gwt.client.ComponentContainerConnector#getChildren()
*/
- public Collection getChildren() {
+ public List getChildren() {
if (children == null) {
return new LinkedList();
}
@@ -43,7 +43,7 @@ public abstract class AbstractComponentContainerConnector extends
* com.vaadin.terminal.gwt.client.ComponentContainerConnector#setChildren
* (java.util.Collection)
*/
- public void setChildren(Collection children) {
+ public void setChildren(List 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());
diff --git a/src/com/vaadin/terminal/gwt/client/ui/PanelConnector.java b/src/com/vaadin/terminal/gwt/client/ui/PanelConnector.java
index 92c504da97..b48b0e8232 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/PanelConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/PanelConnector.java
@@ -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);
+ }
+ }
+ }
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java
index 7dcfa24d89..b9552493de 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VPanel.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VPanel.java
@@ -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 = "";
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
index 553c6fe572..66e692694f 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
@@ -814,6 +814,7 @@ public abstract class AbstractCommunicationManager implements
LinkedList stateQueue = new LinkedList();
LinkedList rpcPendingQueue = new LinkedList();
LinkedList hierarchyPendingQueue = new LinkedList();
+ LinkedList connectorTypeQueue = new LinkedList();
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
}
diff --git a/src/com/vaadin/ui/Panel.java b/src/com/vaadin/ui/Panel.java
index c3bca2a5bb..b6c08da86c 100644
--- a/src/com/vaadin/ui/Panel.java
+++ b/src/com/vaadin/ui/Panel.java
@@ -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.
- *
- *
- * 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.
- *
- *
- * @see com.vaadin.terminal.Scrollable#setScrollable(boolean)
- */
- public void setScrollable(boolean isScrollingEnabled) {
- if (scrollable != isScrollingEnabled) {
- scrollable = isScrollingEnabled;
- requestRepaint();
- }
- }
-
- /**
- * Sets the horizontal scroll position.
- *
- *
- * 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.
- *
- *
* @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.
- *
- *
- * 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.
- *
+ /*
+ * (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();
+ }
}
diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java
index 216a64e57e..57ed11f3ba 100644
--- a/src/com/vaadin/ui/Window.java
+++ b/src/com/vaadin/ui/Window.java
@@ -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 {
+
+ }
+
/**
* Sub window only. 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();
}
diff --git a/tests/testbench/com/vaadin/tests/components/panel/BasicPanelTest.java b/tests/testbench/com/vaadin/tests/components/panel/BasicPanelTest.java
index d23e317572..671b2c3fca 100644
--- a/tests/testbench/com/vaadin/tests/components/panel/BasicPanelTest.java
+++ b/tests/testbench/com/vaadin/tests/components/panel/BasicPanelTest.java
@@ -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);
diff --git a/tests/testbench/com/vaadin/tests/components/panel/PanelShouldNotScroll.java b/tests/testbench/com/vaadin/tests/components/panel/PanelShouldNotScroll.java
index b7047392e8..62b3007aba 100644
--- a/tests/testbench/com/vaadin/tests/components/panel/PanelShouldNotScroll.java
+++ b/tests/testbench/com/vaadin/tests/components/panel/PanelShouldNotScroll.java
@@ -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());
diff --git a/tests/testbench/com/vaadin/tests/components/tree/TreeScrollingOnSelection.java b/tests/testbench/com/vaadin/tests/components/tree/TreeScrollingOnSelection.java
index 42c9087fc3..a6079160ab 100644
--- a/tests/testbench/com/vaadin/tests/components/tree/TreeScrollingOnSelection.java
+++ b/tests/testbench/com/vaadin/tests/components/tree/TreeScrollingOnSelection.java
@@ -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");
diff --git a/tests/testbench/com/vaadin/tests/components/window/WindowScrollingComponentIntoView.java b/tests/testbench/com/vaadin/tests/components/window/WindowScrollingComponentIntoView.java
index c46f125192..9f3f27cf6a 100644
--- a/tests/testbench/com/vaadin/tests/components/window/WindowScrollingComponentIntoView.java
+++ b/tests/testbench/com/vaadin/tests/components/window/WindowScrollingComponentIntoView.java
@@ -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();
diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java
index 7c8e545c97..827879d3c6 100644
--- a/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java
+++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java
@@ -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());
}
}
diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1804.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1804.java
index 86eb3c429a..b659eff01e 100644
--- a/tests/testbench/com/vaadin/tests/tickets/Ticket1804.java
+++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1804.java
@@ -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);
diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1834PanelScrolling.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1834PanelScrolling.java
index afcdd2ed16..912f5ba02d 100644
--- a/tests/testbench/com/vaadin/tests/tickets/Ticket1834PanelScrolling.java
+++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1834PanelScrolling.java
@@ -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(
diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1869.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1869.java
index 6745acf583..d51c0990ae 100644
--- a/tests/testbench/com/vaadin/tests/tickets/Ticket1869.java
+++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1869.java
@@ -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);
}
}
diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1923.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1923.java
index 7252caf9d1..17a7dacf26 100644
--- a/tests/testbench/com/vaadin/tests/tickets/Ticket1923.java
+++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1923.java
@@ -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(
diff --git a/tests/testbench/com/vaadin/tests/validation/EmptyFieldErrorIndicators.java b/tests/testbench/com/vaadin/tests/validation/EmptyFieldErrorIndicators.java
index 0efd727a06..8fb0c3585d 100644
--- a/tests/testbench/com/vaadin/tests/validation/EmptyFieldErrorIndicators.java
+++ b/tests/testbench/com/vaadin/tests/validation/EmptyFieldErrorIndicators.java
@@ -45,7 +45,6 @@ public class EmptyFieldErrorIndicators extends TestBase {
panel.setSizeFull();
panel.setStyleName(Reindeer.PANEL_LIGHT);
panel.addComponent(hl);
- panel.setScrollable(true);
addComponent(panel);
}
--
2.39.5