From 890356e6ab17661364a04d60ded9fe01628b0830 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 20 Aug 2012 08:53:33 +0300 Subject: Support @Delayable and change window size update to use it (#8421) --- server/src/com/vaadin/terminal/Page.java | 20 +++------ .../gwt/server/AbstractCommunicationManager.java | 1 + .../server/LegacyChangeVariablesInvocation.java | 50 ---------------------- server/src/com/vaadin/ui/Root.java | 13 +++--- server/src/com/vaadin/ui/Window.java | 19 -------- 5 files changed, 15 insertions(+), 88 deletions(-) delete mode 100644 server/src/com/vaadin/terminal/gwt/server/LegacyChangeVariablesInvocation.java (limited to 'server/src') diff --git a/server/src/com/vaadin/terminal/Page.java b/server/src/com/vaadin/terminal/Page.java index d5d474e2e3..933f9b39e6 100644 --- a/server/src/com/vaadin/terminal/Page.java +++ b/server/src/com/vaadin/terminal/Page.java @@ -376,23 +376,17 @@ public class Page implements Serializable { .getBrowser(); } - public void setBrowserWindowSize(Integer width, Integer height) { + public void setBrowserWindowSize(int width, int height) { boolean fireEvent = false; - if (width != null) { - int newWidth = width.intValue(); - if (newWidth != browserWindowWidth) { - browserWindowWidth = newWidth; - fireEvent = true; - } + if (width != browserWindowWidth) { + browserWindowWidth = width; + fireEvent = true; } - if (height != null) { - int newHeight = height.intValue(); - if (newHeight != browserWindowHeight) { - browserWindowHeight = newHeight; - fireEvent = true; - } + if (height != browserWindowHeight) { + browserWindowHeight = height; + fireEvent = true; } if (fireEvent) { diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 00e65382cd..96ae70f27c 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -69,6 +69,7 @@ import com.vaadin.external.json.JSONObject; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.Connector; import com.vaadin.shared.Version; +import com.vaadin.shared.communication.LegacyChangeVariablesInvocation; import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.communication.SharedState; import com.vaadin.shared.communication.UidlValue; diff --git a/server/src/com/vaadin/terminal/gwt/server/LegacyChangeVariablesInvocation.java b/server/src/com/vaadin/terminal/gwt/server/LegacyChangeVariablesInvocation.java deleted file mode 100644 index fc3fbd6c00..0000000000 --- a/server/src/com/vaadin/terminal/gwt/server/LegacyChangeVariablesInvocation.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.terminal.gwt.server; - -import java.util.HashMap; -import java.util.Map; - -import com.vaadin.shared.ApplicationConstants; -import com.vaadin.shared.communication.MethodInvocation; - -public class LegacyChangeVariablesInvocation extends MethodInvocation { - private Map variableChanges = new HashMap(); - - public LegacyChangeVariablesInvocation(String connectorId, - String variableName, Object value) { - super(connectorId, ApplicationConstants.UPDATE_VARIABLE_INTERFACE, - ApplicationConstants.UPDATE_VARIABLE_METHOD); - setVariableChange(variableName, value); - } - - public static boolean isLegacyVariableChange(String interfaceName, - String methodName) { - return ApplicationConstants.UPDATE_VARIABLE_METHOD - .equals(interfaceName) - && ApplicationConstants.UPDATE_VARIABLE_METHOD - .equals(methodName); - } - - public void setVariableChange(String name, Object value) { - variableChanges.put(name, value); - } - - public Map getVariableChanges() { - return variableChanges; - } - -} diff --git a/server/src/com/vaadin/ui/Root.java b/server/src/com/vaadin/ui/Root.java index 685296c55a..b37005a16e 100644 --- a/server/src/com/vaadin/ui/Root.java +++ b/server/src/com/vaadin/ui/Root.java @@ -434,6 +434,13 @@ public abstract class Root extends AbstractComponentContainer implements public void click(MouseEventDetails mouseDetails) { fireEvent(new ClickEvent(Root.this, mouseDetails)); } + + @Override + public void resize(int viewWidth, int viewHeight, int windowWidth, + int windowHeight) { + // TODO We're not doing anything with the view dimensions + getPage().setBrowserWindowSize(windowWidth, windowHeight); + } }; /** @@ -582,12 +589,6 @@ public abstract class Root extends AbstractComponentContainer implements .get(RootConstants.FRAGMENT_VARIABLE); getPage().setFragment(fragment, true); } - - if (variables.containsKey("height") || variables.containsKey("width")) { - getPage().setBrowserWindowSize((Integer) variables.get("width"), - (Integer) variables.get("height")); - } - } /* diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index 13ef7e5784..d1d2c25d8b 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -32,7 +32,6 @@ import com.vaadin.event.ShortcutAction.KeyCode; import com.vaadin.event.ShortcutAction.ModifierKey; import com.vaadin.event.ShortcutListener; import com.vaadin.shared.MouseEventDetails; -import com.vaadin.shared.ui.root.RootConstants; import com.vaadin.shared.ui.window.WindowServerRpc; import com.vaadin.shared.ui.window.WindowState; import com.vaadin.terminal.PaintException; @@ -76,10 +75,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, } }; - private int browserWindowWidth = -1; - - private int browserWindowHeight = -1; - /** * Creates a new unnamed window with a default layout. */ @@ -170,20 +165,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, .get("width") != getWidth())) { sizeHasChanged = true; } - Integer browserHeightVar = (Integer) variables - .get(RootConstants.BROWSER_HEIGHT_VAR); - if (browserHeightVar != null - && browserHeightVar.intValue() != browserWindowHeight) { - browserWindowHeight = browserHeightVar.intValue(); - sizeHasChanged = true; - } - Integer browserWidthVar = (Integer) variables - .get(RootConstants.BROWSER_WIDTH_VAR); - if (browserWidthVar != null - && browserWidthVar.intValue() != browserWindowWidth) { - browserWindowWidth = browserWidthVar.intValue(); - sizeHasChanged = true; - } super.changeVariables(source, variables); -- cgit v1.2.3 From a80335107906f1c41c1f42d2462dd838e8ea5b6c Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 15 Aug 2012 16:12:50 +0300 Subject: Introduce ClientConnector.beforeClientResponse(boolean initial) #9228 Remove Component.updateState() to use the new method instead. --- .../vaadin/terminal/AbstractClientConnector.java | 5 +++ .../gwt/server/AbstractCommunicationManager.java | 11 ++++-- .../terminal/gwt/server/ClientConnector.java | 20 ++++++++++ .../terminal/gwt/server/DragAndDropService.java | 5 +++ server/src/com/vaadin/ui/AbsoluteLayout.java | 4 +- server/src/com/vaadin/ui/AbstractComponent.java | 8 +--- server/src/com/vaadin/ui/AbstractField.java | 4 +- server/src/com/vaadin/ui/AbstractTextField.java | 4 +- server/src/com/vaadin/ui/Component.java | 12 ------ server/src/com/vaadin/ui/ConnectorTracker.java | 45 ++++++++++++++++++++++ server/src/com/vaadin/ui/CssLayout.java | 4 +- 11 files changed, 93 insertions(+), 29 deletions(-) (limited to 'server/src') diff --git a/server/src/com/vaadin/terminal/AbstractClientConnector.java b/server/src/com/vaadin/terminal/AbstractClientConnector.java index 0eb38a3d13..bc1cd2af1a 100644 --- a/server/src/com/vaadin/terminal/AbstractClientConnector.java +++ b/server/src/com/vaadin/terminal/AbstractClientConnector.java @@ -518,4 +518,9 @@ public abstract class AbstractClientConnector implements ClientConnector { return getParent().isConnectorEnabled(); } } + + @Override + public void beforeClientResponse(boolean initial) { + // Do nothing by default + } } diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 96ae70f27c..ffee517550 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -819,6 +819,7 @@ public abstract class AbstractCommunicationManager implements Serializable { if (repaintAll) { getClientCache(root).clear(); rootConnectorTracker.markAllConnectorsDirty(); + rootConnectorTracker.markAllClientSidesUninitialized(); // Reset sent locales locales = null; @@ -833,9 +834,9 @@ public abstract class AbstractCommunicationManager implements Serializable { "Found " + dirtyVisibleConnectors.size() + " dirty connectors to paint"); for (ClientConnector connector : dirtyVisibleConnectors) { - if (connector instanceof Component) { - ((Component) connector).updateState(); - } + boolean initialized = rootConnectorTracker + .isClientSideInitialized(connector); + connector.beforeClientResponse(!initialized); } rootConnectorTracker.markAllConnectorsClean(); @@ -1251,6 +1252,10 @@ public abstract class AbstractCommunicationManager implements Serializable { dragAndDropService.printJSONResponse(outWriter); } + for (ClientConnector connector : dirtyVisibleConnectors) { + rootConnectorTracker.markClientSideInitialized(connector); + } + writePerformanceData(outWriter); } diff --git a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java index eef4e240ec..c9fe2563f9 100644 --- a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java +++ b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java @@ -157,4 +157,24 @@ public interface ClientConnector extends Connector, RpcTarget { * attached to any Root */ public Root getRoot(); + + /** + * Called before the shared state and RPC invocations are sent to the + * client. Gives the connector an opportunity to set computed/dynamic state + * values or to invoke last minute RPC methods depending on other component + * features. + *

+ * This method must not alter the component hierarchy in any way. Calling + * requestRepaint() from this method will have no effect. + *

+ * + * @param initial + * true if the client-side connector will be created + * and initialized after this method has been invoked. + * false if there is already an initialized + * client-side connector. + * + * @since 7.0 + */ + public void beforeClientResponse(boolean initial); } diff --git a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java index bb96c6e53e..56d5ed1393 100644 --- a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java +++ b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java @@ -322,4 +322,9 @@ public class DragAndDropService implements VariableOwner, ClientConnector { public Root getRoot() { return null; } + + @Override + public void beforeClientResponse(boolean initial) { + // Nothing to do + } } diff --git a/server/src/com/vaadin/ui/AbsoluteLayout.java b/server/src/com/vaadin/ui/AbsoluteLayout.java index 9851a79bcd..a3bc577fe3 100644 --- a/server/src/com/vaadin/ui/AbsoluteLayout.java +++ b/server/src/com/vaadin/ui/AbsoluteLayout.java @@ -169,8 +169,8 @@ public class AbsoluteLayout extends AbstractLayout implements } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); // This could be in internalRemoveComponent and internalSetComponent if // Map was supported. We cannot get the child diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index fb3993d0cf..cde5217ca1 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -717,13 +717,9 @@ public abstract class AbstractComponent extends AbstractClientConnector return (ComponentState) super.getState(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Component#updateState() - */ @Override - public void updateState() { + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); // TODO This logic should be on the client side and the state should // simply be a data object with "width" and "height". if (getHeight() >= 0 diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 2d14acf442..67a1826100 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -1620,8 +1620,8 @@ public abstract class AbstractField extends AbstractComponent implements } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); // Hide the error indicator if needed getState().setHideErrors(shouldHideErrors()); diff --git a/server/src/com/vaadin/ui/AbstractTextField.java b/server/src/com/vaadin/ui/AbstractTextField.java index c8bbadd0ab..86315f801f 100644 --- a/server/src/com/vaadin/ui/AbstractTextField.java +++ b/server/src/com/vaadin/ui/AbstractTextField.java @@ -97,8 +97,8 @@ public abstract class AbstractTextField extends AbstractField implements } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); String value = getValue(); if (value == null) { diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java index ac668168f2..ff7ed47930 100644 --- a/server/src/com/vaadin/ui/Component.java +++ b/server/src/com/vaadin/ui/Component.java @@ -636,18 +636,6 @@ public interface Component extends ClientConnector, Sizeable, Serializable { @Override public ComponentState getState(); - /** - * Called before the shared state is sent to the client. Gives the component - * an opportunity to set computed/dynamic state values e.g. state values - * that depend on other component features. - *

- * This method must not alter the component hierarchy in any way. - *

- * - * @since 7.0 - */ - public void updateState(); - /** * Adds an unique id for component that get's transferred to terminal for * testing purposes. Keeping identifiers unique is the responsibility of the diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index 12ad377b62..27dfebd95e 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -25,6 +25,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.terminal.AbstractClientConnector; +import com.vaadin.terminal.gwt.client.ServerConnector; import com.vaadin.terminal.gwt.server.ClientConnector; /** @@ -50,6 +51,7 @@ public class ConnectorTracker implements Serializable { private final HashMap connectorIdToConnector = new HashMap(); private Set dirtyConnectors = new HashSet(); + private Set uninitializedConnectors = new HashSet(); private Root root; @@ -91,6 +93,7 @@ public class ConnectorTracker implements Serializable { .get(connectorId); if (previouslyRegistered == null) { connectorIdToConnector.put(connectorId, connector); + uninitializedConnectors.add(connector); getLogger().fine( "Registered " + connector.getClass().getSimpleName() + " (" + connectorId + ")"); @@ -136,6 +139,47 @@ public class ConnectorTracker implements Serializable { "Unregistered " + connector.getClass().getSimpleName() + " (" + connectorId + ")"); connectorIdToConnector.remove(connectorId); + uninitializedConnectors.remove(connector); + } + + /** + * Checks whether the given connector has already been initialized in the + * browser. The given connector should be registered with this connector + * tracker. + * + * @param connector + * the client connector to check + * @return true if the initial state has previously been sent + * to the browser, false if the client-side doesn't + * already know anything about the connector. + */ + public boolean isClientSideInitialized(ClientConnector connector) { + assert connectorIdToConnector.get(connector.getConnectorId()) == connector : "Connector should be registered with this ConnectorTracker"; + return !uninitializedConnectors.contains(connector); + } + + /** + * Marks the given connector as initialized, meaning that the client-side + * state has been initialized for the connector. + * + * @see #isClientSideInitialized(ClientConnector) + * + * @param connector + * the connector that should be marked as initialized + */ + public void markClientSideInitialized(ClientConnector connector) { + uninitializedConnectors.remove(connector); + } + + /** + * Marks all currently registered connectors as uninitialized. This should + * be done when the client-side has been reset but the server-side state is + * retained. + * + * @see #isClientSideInitialized(ClientConnector) + */ + public void markAllClientSidesUninitialized() { + uninitializedConnectors.addAll(connectorIdToConnector.values()); } /** @@ -175,6 +219,7 @@ public class ConnectorTracker implements Serializable { "cleanConnectorMap unregistered connector " + getConnectorAndParentInfo(connector) + "). This should have been done when the connector was detached."); + uninitializedConnectors.remove(connector); iterator.remove(); } } diff --git a/server/src/com/vaadin/ui/CssLayout.java b/server/src/com/vaadin/ui/CssLayout.java index c43f347e68..0192debc4a 100644 --- a/server/src/com/vaadin/ui/CssLayout.java +++ b/server/src/com/vaadin/ui/CssLayout.java @@ -197,8 +197,8 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); getState().getChildCss().clear(); for (Iterator ci = getComponentIterator(); ci.hasNext();) { Component child = ci.next(); -- cgit v1.2.3 From 44758a2791a568f97a11e7da918444e4fffec84e Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 16 Aug 2012 09:47:14 +0300 Subject: Don't decode enum as an object (#9333) --- .../com/vaadin/terminal/gwt/server/JsonCodec.java | 13 ++++--- .../vaadin/tests/serialization/SerializerTest.html | 40 ++++++++++++---------- .../vaadin/tests/serialization/SerializerTest.java | 12 +++++++ .../widgetset/client/SerializerTestConnector.java | 11 ++++++ .../tests/widgetset/client/SerializerTestRpc.java | 3 ++ 5 files changed, 54 insertions(+), 25 deletions(-) (limited to 'server/src') diff --git a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java index 60197b0b3a..94d860a200 100644 --- a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java +++ b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java @@ -165,6 +165,10 @@ public class JsonCodec implements Serializable { } else if (targetType == JSONObject.class || targetType == JSONArray.class) { return value; + } else if (Enum.class.isAssignableFrom(getClassForType(targetType))) { + Class classForType = getClassForType(targetType); + return decodeEnum(classForType.asSubclass(Enum.class), + (String) value); } else { return decodeObject(targetType, (JSONObject) value, connectorTracker); @@ -420,9 +424,8 @@ public class JsonCodec implements Serializable { } } - private static Object decodeEnum(Class cls, JSONObject value) { - String enumIdentifier = String.valueOf(value); - return Enum.valueOf(cls, enumIdentifier); + private static Object decodeEnum(Class cls, String value) { + return Enum.valueOf(cls, value); } private static String[] decodeStringArray(JSONArray jsonArray) @@ -491,10 +494,6 @@ public class JsonCodec implements Serializable { throws JSONException { Class targetClass = getClassForType(targetType); - if (Enum.class.isAssignableFrom(targetClass)) { - return decodeEnum(targetClass.asSubclass(Enum.class), - serializedObject); - } try { Object decodedObject = targetClass.newInstance(); diff --git a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html index 3d52356cab..4417fabf14 100644 --- a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html +++ b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html @@ -18,90 +18,94 @@ assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[16] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[17] 1. sendBoolean: false, false, [false, false, true, false, true, true] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[15] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[16] 2. sendByte: 5, -12, [3, 1, 2] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[14] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[15] 3. sendChar: Å, ∫, [a, b, c, d] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[13] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[14] 4. sendInt: 2, 5, [2147483647, 0] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[12] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[13] 5. sendLong: -57841235865, 577431841358, [57, 0] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[11] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[12] 6. sendFloat: 1.0000001, 3.14159, [-12.0, 0.0, 57.0] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[10] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[11] 7. sendDouble: 0.423310825130748, 5.859874482048838, [2.0, 1.7976931348623157E308, 4.9E-324] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[9] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[10] 8. sendString: Taegghiiiinnrsssstt‡ assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[8] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[9] 9. sendConnector: com.vaadin.tests.widgetset.server.SerializerTestExtension assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[7] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[8] 10. sendBean: ComplexTestBean [innerBean1=SimpleTestBean(1), innerBean2=SimpleTestBean(3), innerBeanCollection=[SimpleTestBean(6), SimpleTestBean(0)], privimite=6], SimpleTestBean(0), [SimpleTestBean(7)] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[6] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[7] 11. sendNull: null, Not null assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[5] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[6] 12. sendNestedArray: [[7, 5]], [[SimpleTestBean(2)], [SimpleTestBean(4)]] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[4] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[5] 13. sendList: [-234, 5, 8], class com.vaadin.tests.widgetset.server.SerializerTestExtension, class com.vaadin.tests.serialization.SerializerTest, [SimpleTestBean(-568), SimpleTestBean(234)] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[3] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[4] 14. sendArrayList: [[2], [2]], [[2, 1], [2, 3]], [[SimpleTestBean(7)]] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[2] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[3] 15. sendSet: [-12, -7, -4], class com.vaadin.tests.serialization.SerializerTest, [SimpleTestBean(2), SimpleTestBean(3)] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[2] 16. sendMap: {a=null}, [com.vaadin.tests.widgetset.server.SerializerTestExtension=false], [2=com.vaadin.tests.widgetset.server.SerializerTestExtension], {SimpleTestBean(4)=SimpleTestBean(-4), SimpleTestBean(-5)=SimpleTestBean(5)} assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1] 17. sendWrappedGenerics: {[SimpleTestBean(1)]={1=[SimpleTestBean(42)]}} - + + assertText + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0] + 18. sendEnum: PREFORMATTED, [XHTML, RAW], [PREFORMATTED, XML] + diff --git a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java index da4b5dd7d9..a301ecf828 100644 --- a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java +++ b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java @@ -28,6 +28,7 @@ import java.util.Set; import com.vaadin.annotations.Widgetset; import com.vaadin.shared.Connector; +import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestRoot; import com.vaadin.tests.util.Log; @@ -122,6 +123,10 @@ public class SerializerTest extends AbstractTestRoot { } }); + rpc.sendEnum(ContentMode.TEXT, new ContentMode[] { + ContentMode.PREFORMATTED, ContentMode.XML }, + Arrays.asList(ContentMode.XHTML, ContentMode.RAW)); + testExtension.registerRpc(new SerializerTestRpc() { @Override public void sendBoolean(boolean value, Boolean boxedValue, @@ -288,6 +293,13 @@ public class SerializerTest extends AbstractTestRoot { log.log("sendWrappedGenerics: " + generics.toString()); } + @Override + public void sendEnum(ContentMode contentMode, ContentMode[] array, + List list) { + log.log("sendEnum: " + contentMode + ", " + + Arrays.toString(array) + ", " + list); + } + }); } diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java index 3977ff7f71..9fb6807bb7 100644 --- a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java +++ b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java @@ -28,6 +28,7 @@ import java.util.Set; import com.vaadin.shared.Connector; import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.terminal.gwt.client.communication.RpcProxy; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.extensions.AbstractExtensionConnector; @@ -231,6 +232,16 @@ public class SerializerTestConnector extends AbstractExtensionConnector { objectListArray[0] }, new List[] { Collections .singletonList(beanListArray[0].get(0)) }); } + + @Override + public void sendEnum(ContentMode contentMode, ContentMode[] array, + List list) { + ContentMode nextContentMode = ContentMode.values()[contentMode + .ordinal() + 1]; + rpc.sendEnum(nextContentMode, + list.toArray(new ContentMode[list.size()]), + Arrays.asList(array)); + } }); } diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java index 47a26b7408..eb3a20e90e 100644 --- a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java +++ b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java @@ -23,6 +23,7 @@ import java.util.Set; import com.vaadin.shared.Connector; import com.vaadin.shared.communication.ClientRpc; import com.vaadin.shared.communication.ServerRpc; +import com.vaadin.shared.ui.label.ContentMode; @SuppressWarnings("javadoc") public interface SerializerTestRpc extends ServerRpc, ClientRpc { @@ -73,4 +74,6 @@ public interface SerializerTestRpc extends ServerRpc, ClientRpc { public void sendWrappedGenerics( Map, Map>> generics); + public void sendEnum(ContentMode contentMode, ContentMode[] array, List list); + } -- cgit v1.2.3 From 4863e078780a3d0ca94c4edcc153d1bdfe5a7f92 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 16 Aug 2012 13:42:07 +0300 Subject: Add crude support for only sending state changes (#9026) --- .../gwt/server/AbstractCommunicationManager.java | 38 +++++++++++++++------- .../com/vaadin/terminal/gwt/server/JsonCodec.java | 27 +++++++++------ server/src/com/vaadin/ui/ConnectorTracker.java | 13 ++++++++ 3 files changed, 56 insertions(+), 22 deletions(-) (limited to 'server/src') diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index ffee517550..99376ffd1f 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -68,6 +68,7 @@ import com.vaadin.external.json.JSONException; import com.vaadin.external.json.JSONObject; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.Connector; +import com.vaadin.shared.JavaScriptConnectorState; import com.vaadin.shared.Version; import com.vaadin.shared.communication.LegacyChangeVariablesInvocation; import com.vaadin.shared.communication.MethodInvocation; @@ -885,23 +886,36 @@ public abstract class AbstractCommunicationManager implements Serializable { try { Class stateType = connector .getStateType(); - SharedState referenceState = null; - if (repaintAll) { + Object diffState = rootConnectorTracker + .getDiffState(connector); + if (diffState == null) { + diffState = new JSONObject(); // Use an empty state object as reference for full // repaints - try { - referenceState = stateType.newInstance(); - } catch (Exception e) { - getLogger().log( - Level.WARNING, - "Error creating reference object for state of type " - + stateType.getName()); + boolean emptyInitialState = JavaScriptConnectorState.class + .isAssignableFrom(stateType); + if (!emptyInitialState) { + try { + SharedState referenceState = stateType + .newInstance(); + diffState = JsonCodec.encode(referenceState, + null, stateType, + root.getConnectorTracker()); + } catch (Exception e) { + getLogger().log( + Level.WARNING, + "Error creating reference object for state of type " + + stateType.getName()); + } } + rootConnectorTracker.setDiffState(connector, diffState); } - Object stateJson = JsonCodec.encode(state, referenceState, - stateType, root.getConnectorTracker()); + JSONObject stateJson = (JSONObject) JsonCodec.encode(state, + diffState, stateType, root.getConnectorTracker()); - sharedStates.put(connector.getConnectorId(), stateJson); + if (stateJson.length() != 0) { + sharedStates.put(connector.getConnectorId(), stateJson); + } } catch (JSONException e) { throw new PaintException( "Failed to serialize shared state for connector " diff --git a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java index 94d860a200..884e01f9a5 100644 --- a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java +++ b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java @@ -526,9 +526,8 @@ public class JsonCodec implements Serializable { } } - public static Object encode(Object value, Object referenceValue, - Type valueType, ConnectorTracker connectorTracker) - throws JSONException { + public static Object encode(Object value, Object diffState, Type valueType, + ConnectorTracker connectorTracker) throws JSONException { if (valueType == null) { throw new IllegalArgumentException("type must be defined"); @@ -595,7 +594,7 @@ public class JsonCodec implements Serializable { } else { // Any object that we do not know how to encode we encode by looping // through fields - return encodeObject(value, referenceValue, connectorTracker); + return encodeObject(value, (JSONObject) diffState, connectorTracker); } } @@ -603,7 +602,7 @@ public class JsonCodec implements Serializable { return JSONObject.NULL; } - private static Object encodeObject(Object value, Object referenceValue, + private static Object encodeObject(Object value, JSONObject diffState, ConnectorTracker connectorTracker) throws JSONException { JSONObject jsonMap = new JSONObject(); @@ -620,10 +619,11 @@ public class JsonCodec implements Serializable { Type fieldType = getterMethod.getGenericReturnType(); Object fieldValue = getterMethod.invoke(value, (Object[]) null); boolean equals = false; - Object referenceFieldValue = null; - if (referenceValue != null) { - referenceFieldValue = getterMethod.invoke(referenceValue, - (Object[]) null); + Object diffStateValue = null; + if (diffState != null) { + diffStateValue = diffState.get(fieldName); + Object referenceFieldValue = decodeInternalOrCustomType( + fieldType, diffStateValue, connectorTracker); equals = equals(fieldValue, referenceFieldValue); } if (!equals) { @@ -637,8 +637,15 @@ public class JsonCodec implements Serializable { } jsonMap.put( fieldName, - encode(fieldValue, referenceFieldValue, fieldType, + encode(fieldValue, diffStateValue, fieldType, connectorTracker)); + if (diffState != null) { + diffState.put( + fieldName, + encode(fieldValue, null, fieldType, + connectorTracker)); + } + // } else { // System.out.println("Skipping field " + fieldName // + " of type " + fieldType.getName() diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index 27dfebd95e..f16642d91b 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -54,6 +55,7 @@ public class ConnectorTracker implements Serializable { private Set uninitializedConnectors = new HashSet(); private Root root; + private Map diffStates = new HashMap(); /** * Gets a logger for this class @@ -140,6 +142,7 @@ public class ConnectorTracker implements Serializable { + connectorId + ")"); connectorIdToConnector.remove(connectorId); uninitializedConnectors.remove(connector); + diffStates.remove(connector); } /** @@ -180,6 +183,7 @@ public class ConnectorTracker implements Serializable { */ public void markAllClientSidesUninitialized() { uninitializedConnectors.addAll(connectorIdToConnector.values()); + diffStates.clear(); } /** @@ -220,6 +224,7 @@ public class ConnectorTracker implements Serializable { + getConnectorAndParentInfo(connector) + "). This should have been done when the connector was detached."); uninitializedConnectors.remove(connector); + diffStates.remove(connector); iterator.remove(); } } @@ -372,4 +377,12 @@ public class ConnectorTracker implements Serializable { return dirtyConnectors; } + public Object getDiffState(ClientConnector connector) { + return diffStates.get(connector); + } + + public void setDiffState(ClientConnector connector, Object diffState) { + diffStates.put(connector, diffState); + } + } -- cgit v1.2.3 From c9689846a8ba1254fb51c164cee6c3c157740eac Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 20 Aug 2012 11:49:48 +0300 Subject: Don't import from client even for javadoc (#9026) --- server/src/com/vaadin/ui/ConnectorTracker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'server/src') diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index f16642d91b..2afe7f9025 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -26,7 +26,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.terminal.AbstractClientConnector; -import com.vaadin.terminal.gwt.client.ServerConnector; import com.vaadin.terminal.gwt.server.ClientConnector; /** @@ -41,7 +40,8 @@ import com.vaadin.terminal.gwt.server.ClientConnector; * Tracks which {@link ClientConnector}s are dirty so they can be updated to the * client when the following response is sent. A connector is dirty when an * operation has been performed on it on the server and as a result of this - * operation new information needs to be sent to its {@link ServerConnector}. + * operation new information needs to be sent to its + * {@link com.vaadin.terminal.gwt.client.ServerConnector}. *

* * @author Vaadin Ltd -- cgit v1.2.3 From 72d9cc9ec098952dfdb03708f808da555307e78d Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 20 Aug 2012 19:19:47 +0300 Subject: Add RootProvider for Root selection without custom Application (#8159) --- server/src/com/vaadin/Application.java | 70 ++++++++-------------- .../com/vaadin/terminal/AbstractRootProvider.java | 35 +++++++++++ .../com/vaadin/terminal/DefaultRootProvider.java | 51 ++++++++++++++++ server/src/com/vaadin/terminal/RootProvider.java | 29 +++++++++ .../terminal/gwt/server/ApplicationServlet.java | 2 + .../component/root/CustomRootClassLoader.java | 18 ++++-- .../vaadin/launcher/ApplicationRunnerServlet.java | 33 +++++----- .../tests/application/RefreshStatePreserve.java | 16 +++-- .../tests/components/root/RootsInMultipleTabs.java | 15 ++++- 9 files changed, 191 insertions(+), 78 deletions(-) create mode 100644 server/src/com/vaadin/terminal/AbstractRootProvider.java create mode 100644 server/src/com/vaadin/terminal/DefaultRootProvider.java create mode 100644 server/src/com/vaadin/terminal/RootProvider.java (limited to 'server/src') diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index b120c8455a..d2924eb716 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.LinkedList; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -56,6 +57,7 @@ import com.vaadin.terminal.ApplicationResource; import com.vaadin.terminal.CombinedRequest; import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.RequestHandler; +import com.vaadin.terminal.RootProvider; import com.vaadin.terminal.Terminal; import com.vaadin.terminal.VariableOwner; import com.vaadin.terminal.WrappedRequest; @@ -503,6 +505,8 @@ public class Application implements Terminal.ErrorListener, Serializable { */ private Set initedRoots = new HashSet(); + private List rootProviders = new LinkedList(); + /** * Gets the user of the application. * @@ -1873,55 +1877,21 @@ public class Application implements Terminal.ErrorListener, Serializable { */ protected Root getRoot(WrappedRequest request) throws RootRequiresMoreInformationException { - String rootClassName = getRootClassName(request); - try { - ClassLoader classLoader = request.getDeploymentConfiguration() - .getClassLoader(); - if (classLoader == null) { - classLoader = getClass().getClassLoader(); - } - Class rootClass = Class.forName(rootClassName, - true, classLoader).asSubclass(Root.class); - try { - Root root = rootClass.newInstance(); - return root; - } catch (Exception e) { - throw new RuntimeException("Could not instantiate root class " - + rootClassName, e); + + // Iterate in reverse order - test check newest provider first + for (int i = rootProviders.size() - 1; i >= 0; i--) { + RootProvider provider = rootProviders.get(i); + + Class rootClass = provider.getRootClass(this, + request); + + if (rootClass != null) { + return provider.instantiateRoot(this, rootClass, request); } - } catch (ClassNotFoundException e) { - throw new RuntimeException("Could not load root class " - + rootClassName, e); } - } - /** - * Provides the name of the Root class that should be used for - * a request. The class must have an accessible no-args constructor. - *

- * The default implementation uses the {@value #ROOT_PARAMETER} parameter - * from web.xml. - *

- *

- * This method is mainly used by the default implementation of - * {@link #getRoot(WrappedRequest)}. If you override that method with your - * own functionality, the results of this method might not be used. - *

- * - * @param request - * the request for which a new root is required - * @return the name of the root class to use - * - * @since 7.0 - */ - protected String getRootClassName(WrappedRequest request) { - Object rootClassNameObj = getProperties().get(ROOT_PARAMETER); - if (rootClassNameObj instanceof String) { - return (String) rootClassNameObj; - } else { - throw new RuntimeException("No " + ROOT_PARAMETER - + " defined in web.xml"); - } + throw new RuntimeException( + "No root providers available or providers are not able to find root instance"); } /** @@ -2169,6 +2139,14 @@ public class Application implements Terminal.ErrorListener, Serializable { return configuration.isProductionMode(); } + public void addRootProvider(RootProvider rootProvider) { + rootProviders.add(rootProvider); + } + + public void removeRootProvider(RootProvider rootProvider) { + rootProviders.remove(rootProvider); + } + /** * Finds the {@link Root} to which a particular request belongs. If the * request originates from an existing Root, that root is returned. In other diff --git a/server/src/com/vaadin/terminal/AbstractRootProvider.java b/server/src/com/vaadin/terminal/AbstractRootProvider.java new file mode 100644 index 0000000000..0b63003440 --- /dev/null +++ b/server/src/com/vaadin/terminal/AbstractRootProvider.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.terminal; + +import com.vaadin.Application; +import com.vaadin.ui.Root; + +public abstract class AbstractRootProvider implements RootProvider { + + @Override + public Root instantiateRoot(Application application, + Class type, WrappedRequest request) { + try { + return type.newInstance(); + } catch (InstantiationException e) { + throw new RuntimeException("Could not instantiate root class", e); + } catch (IllegalAccessException e) { + throw new RuntimeException("Could not access root class", e); + } + } +} diff --git a/server/src/com/vaadin/terminal/DefaultRootProvider.java b/server/src/com/vaadin/terminal/DefaultRootProvider.java new file mode 100644 index 0000000000..cbf8c98828 --- /dev/null +++ b/server/src/com/vaadin/terminal/DefaultRootProvider.java @@ -0,0 +1,51 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.terminal; + +import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.ui.Root; + +public class DefaultRootProvider extends AbstractRootProvider { + + @Override + public Class getRootClass(Application application, + WrappedRequest request) throws RootRequiresMoreInformationException { + Object rootClassNameObj = application + .getProperty(Application.ROOT_PARAMETER); + + if (rootClassNameObj instanceof String) { + String rootClassName = rootClassNameObj.toString(); + + ClassLoader classLoader = request.getDeploymentConfiguration() + .getClassLoader(); + if (classLoader == null) { + classLoader = getClass().getClassLoader(); + } + try { + Class rootClass = Class.forName(rootClassName, + true, classLoader).asSubclass(Root.class); + + return rootClass; + } catch (ClassNotFoundException e) { + throw new RuntimeException("Could not find root class", e); + } + } + + return null; + } +} diff --git a/server/src/com/vaadin/terminal/RootProvider.java b/server/src/com/vaadin/terminal/RootProvider.java new file mode 100644 index 0000000000..476cf1bd78 --- /dev/null +++ b/server/src/com/vaadin/terminal/RootProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.terminal; + +import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.ui.Root; + +public interface RootProvider { + public Class getRootClass(Application application, + WrappedRequest request) throws RootRequiresMoreInformationException; + + public Root instantiateRoot(Application application, + Class type, WrappedRequest request); +} diff --git a/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java b/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java index 06bc70872d..52885f3fbb 100644 --- a/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java +++ b/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java @@ -20,6 +20,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import com.vaadin.Application; +import com.vaadin.terminal.DefaultRootProvider; import com.vaadin.terminal.gwt.server.ServletPortletHelper.ApplicationClassException; /** @@ -69,6 +70,7 @@ public class ApplicationServlet extends AbstractApplicationServlet { // Creates a new application instance try { final Application application = getApplicationClass().newInstance(); + application.addRootProvider(new DefaultRootProvider()); return application; } catch (final IllegalAccessException e) { diff --git a/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java index fa730515a2..74770f8652 100644 --- a/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java +++ b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java @@ -6,15 +6,16 @@ import java.util.Properties; import junit.framework.TestCase; +import org.easymock.EasyMock; + import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.terminal.DefaultRootProvider; import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.WrappedRequest; import com.vaadin.ui.Root; -import org.easymock.EasyMock; - public class CustomRootClassLoader extends TestCase { /** @@ -111,10 +112,17 @@ public class CustomRootClassLoader extends TestCase { private Application createStubApplication() { return new Application() { + { + addRootProvider(new DefaultRootProvider()); + } + @Override - protected String getRootClassName(WrappedRequest request) { - // Always use the same root class - return MyRoot.class.getName(); + public String getProperty(String name) { + if (name.equals(ROOT_PARAMETER)) { + return MyRoot.class.getName(); + } else { + return super.getProperty(name); + } } @Override diff --git a/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java b/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java index 6b7b36c3f3..bb37082d30 100644 --- a/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -30,6 +30,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.terminal.AbstractRootProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.gwt.server.AbstractApplicationServlet; import com.vaadin.terminal.gwt.server.WrappedHttpServletRequest; @@ -39,23 +41,6 @@ import com.vaadin.ui.Root; @SuppressWarnings("serial") public class ApplicationRunnerServlet extends AbstractApplicationServlet { - /** - * Internal implementation of an application with a dynamically selected - * Root implementation; - */ - private static class RootRunnerApplication extends Application { - private final Class runnableClass; - - private RootRunnerApplication(Class runnableClass) { - this.runnableClass = runnableClass; - } - - @Override - protected String getRootClassName(WrappedRequest request) { - return runnableClass.getCanonicalName(); - } - } - /** * The name of the application class currently used. Only valid within one * request. @@ -126,7 +111,17 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { try { final Class classToRun = getClassToRun(); if (Root.class.isAssignableFrom(classToRun)) { - return new RootRunnerApplication(classToRun); + Application application = new Application(); + application.addRootProvider(new AbstractRootProvider() { + + @Override + public Class getRootClass( + Application application, WrappedRequest request) + throws RootRequiresMoreInformationException { + return (Class) classToRun; + } + }); + return application; } else if (Application.class.isAssignableFrom(classToRun)) { return (Application) classToRun.newInstance(); } else { @@ -221,7 +216,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { throws ClassNotFoundException { Class classToRun = getClassToRun(); if (Root.class.isAssignableFrom(classToRun)) { - return RootRunnerApplication.class; + return Application.class; } else if (Application.class.isAssignableFrom(classToRun)) { return classToRun.asSubclass(Application.class); } else { diff --git a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java index 36a793bd6d..bd2aea3756 100644 --- a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java +++ b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java @@ -1,5 +1,8 @@ package com.vaadin.tests.application; +import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.terminal.AbstractRootProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.ui.Label; @@ -20,11 +23,14 @@ public class RefreshStatePreserve extends AbstractTestApplication { public void init() { super.init(); setRootPreserved(true); - } - - @Override - protected String getRootClassName(WrappedRequest request) { - return RefreshStateRoot.class.getName(); + addRootProvider(new AbstractRootProvider() { + @Override + public Class getRootClass(Application application, + WrappedRequest request) + throws RootRequiresMoreInformationException { + return RefreshStateRoot.class; + } + }); } @Override diff --git a/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java b/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java index c3b20c5e7c..ae3182401d 100644 --- a/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java +++ b/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java @@ -1,5 +1,8 @@ package com.vaadin.tests.components.root; +import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.terminal.AbstractRootProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.ui.Label; @@ -19,9 +22,15 @@ public class RootsInMultipleTabs extends AbstractTestApplication { } } - @Override - protected String getRootClassName(WrappedRequest request) { - return TabRoot.class.getName(); + public RootsInMultipleTabs() { + addRootProvider(new AbstractRootProvider() { + @Override + public Class getRootClass(Application application, + WrappedRequest request) + throws RootRequiresMoreInformationException { + return TabRoot.class; + } + }); } @Override -- cgit v1.2.3 From 7bfa8f43d14d1823b27cfd84f925e23853fbf4c7 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 21 Aug 2012 13:12:17 +0300 Subject: Don't pass JSONObject.Null as diffstate value (#9026) --- server/src/com/vaadin/terminal/gwt/server/JsonCodec.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'server/src') diff --git a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java index 884e01f9a5..cb0a604b89 100644 --- a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java +++ b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java @@ -624,6 +624,9 @@ public class JsonCodec implements Serializable { diffStateValue = diffState.get(fieldName); Object referenceFieldValue = decodeInternalOrCustomType( fieldType, diffStateValue, connectorTracker); + if (JSONObject.NULL.equals(diffStateValue)) { + diffStateValue = null; + } equals = equals(fieldValue, referenceFieldValue); } if (!equals) { -- cgit v1.2.3 From b02028c90b9143ad16864ad371b4b9429e20573a Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Tue, 21 Aug 2012 17:57:51 +0300 Subject: Add "As of 7.0" to relevant @deprecated tags --- server/src/com/vaadin/data/Buffered.java | 16 ++++++++-------- server/src/com/vaadin/ui/AbstractField.java | 8 ++++---- server/src/com/vaadin/ui/DateField.java | 12 ++++++------ server/src/com/vaadin/ui/Table.java | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'server/src') diff --git a/server/src/com/vaadin/data/Buffered.java b/server/src/com/vaadin/data/Buffered.java index 5461d34fbd..2472524bbc 100644 --- a/server/src/com/vaadin/data/Buffered.java +++ b/server/src/com/vaadin/data/Buffered.java @@ -83,8 +83,8 @@ public interface Buffered extends Serializable { * * @return true if the object is in write-through mode, * false if it's not. - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Deprecated @@ -105,8 +105,8 @@ public interface Buffered extends Serializable { * If the implicit commit operation fails because of a * validation error. * - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Deprecated @@ -126,8 +126,8 @@ public interface Buffered extends Serializable { * * @return true if the object is in read-through mode, * false if it's not. - * @deprecated Use {@link #isBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #isBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Deprecated @@ -145,8 +145,8 @@ public interface Buffered extends Serializable { * @throws SourceException * If the operation fails because of an exception is thrown by * the data source. The cause is included in the exception. - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Deprecated diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 67a1826100..b914fb4c46 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -394,8 +394,8 @@ public abstract class AbstractField extends AbstractComponent implements * @throws InvalidValueException * If the implicit commit operation fails because of a * validation error. - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Override @@ -435,8 +435,8 @@ public abstract class AbstractField extends AbstractComponent implements * @throws SourceException * If the operation fails because of an exception is thrown by * the data source. The cause is included in the exception. - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Override diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java index 5130d665eb..790f3568d5 100644 --- a/server/src/com/vaadin/ui/DateField.java +++ b/server/src/com/vaadin/ui/DateField.java @@ -131,7 +131,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: seconds. * - * @deprecated Use {@link Resolution#SECOND} + * @deprecated As of 7.0, use {@link Resolution#SECOND} */ @Deprecated public static final Resolution RESOLUTION_SEC = Resolution.SECOND; @@ -139,7 +139,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: minutes. * - * @deprecated Use {@link Resolution#MINUTE} + * @deprecated As of 7.0, use {@link Resolution#MINUTE} */ @Deprecated public static final Resolution RESOLUTION_MIN = Resolution.MINUTE; @@ -147,7 +147,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: hours. * - * @deprecated Use {@link Resolution#HOUR} + * @deprecated As of 7.0, use {@link Resolution#HOUR} */ @Deprecated public static final Resolution RESOLUTION_HOUR = Resolution.HOUR; @@ -155,7 +155,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: days. * - * @deprecated Use {@link Resolution#DAY} + * @deprecated As of 7.0, use {@link Resolution#DAY} */ @Deprecated public static final Resolution RESOLUTION_DAY = Resolution.DAY; @@ -163,7 +163,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: months. * - * @deprecated Use {@link Resolution#MONTH} + * @deprecated As of 7.0, use {@link Resolution#MONTH} */ @Deprecated public static final Resolution RESOLUTION_MONTH = Resolution.MONTH; @@ -171,7 +171,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: years. * - * @deprecated Use {@link Resolution#YEAR} + * @deprecated As of 7.0, use {@link Resolution#YEAR} */ @Deprecated public static final Resolution RESOLUTION_YEAR = Resolution.YEAR; diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 6f7f88f883..2bbb69beaf 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -4470,7 +4470,7 @@ public class Table extends AbstractSelect implements Action.Container, * would support this. * * @return True iff sorting is disabled. - * @deprecated Use {@link #isSortEnabled()} instead + * @deprecated As of 7.0, use {@link #isSortEnabled()} instead */ @Deprecated public boolean isSortDisabled() { @@ -4491,7 +4491,7 @@ public class Table extends AbstractSelect implements Action.Container, * * @param sortDisabled * True iff sorting is disabled. - * @deprecated Use {@link #setSortEnabled(boolean)} instead + * @deprecated As of 7.0, use {@link #setSortEnabled(boolean)} instead */ @Deprecated public void setSortDisabled(boolean sortDisabled) { -- cgit v1.2.3 From c680e97bc0a879041f3c24a5c6acdfa1829a8506 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 21 Aug 2012 18:45:27 +0300 Subject: Don't use diffstate value if it isn't there (#9026) --- server/src/com/vaadin/terminal/gwt/server/JsonCodec.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/src') diff --git a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java index cb0a604b89..892f7ec526 100644 --- a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java +++ b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java @@ -620,7 +620,7 @@ public class JsonCodec implements Serializable { Object fieldValue = getterMethod.invoke(value, (Object[]) null); boolean equals = false; Object diffStateValue = null; - if (diffState != null) { + if (diffState != null && diffState.has(fieldName)) { diffStateValue = diffState.get(fieldName); Object referenceFieldValue = decodeInternalOrCustomType( fieldType, diffStateValue, connectorTracker); -- cgit v1.2.3 From 514bffe7a6aa2c599ab9f4ba239295d63f229125 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 20 Aug 2012 16:03:21 +0300 Subject: Removed remaining methods from Terminal (#4355, #8027) --- server/src/com/vaadin/terminal/Terminal.java | 36 ++-------------------- .../com/vaadin/terminal/gwt/server/WebBrowser.java | 30 +++++------------- 2 files changed, 10 insertions(+), 56 deletions(-) (limited to 'server/src') diff --git a/server/src/com/vaadin/terminal/Terminal.java b/server/src/com/vaadin/terminal/Terminal.java index 29cb649d54..a02bcb50bb 100644 --- a/server/src/com/vaadin/terminal/Terminal.java +++ b/server/src/com/vaadin/terminal/Terminal.java @@ -25,43 +25,11 @@ import java.io.Serializable; * * @author Vaadin Ltd. * @since 3.0 + * @deprecated Currently only a container for ErrorEvent and ErrorListener */ +@Deprecated public interface Terminal extends Serializable { - /** - * Gets the name of the default theme for this terminal. - * - * @return the name of the theme that is used by default by this terminal. - */ - public String getDefaultTheme(); - - /** - * Gets the width of the terminal screen in pixels. This is the width of the - * screen and not the width available for the application. - *

- * Note that the screen width is typically not available in the - * {@link com.vaadin.Application#init()} method as this is called before the - * browser has a chance to report the screen size to the server. - *

- * - * @return the width of the terminal screen. - */ - public int getScreenWidth(); - - /** - * Gets the height of the terminal screen in pixels. This is the height of - * the screen and not the height available for the application. - * - *

- * Note that the screen height is typically not available in the - * {@link com.vaadin.Application#init()} method as this is called before the - * browser has a chance to report the screen size to the server. - *

- * - * @return the height of the terminal screen. - */ - public int getScreenHeight(); - /** * An error event implementation for Terminal. */ diff --git a/server/src/com/vaadin/terminal/gwt/server/WebBrowser.java b/server/src/com/vaadin/terminal/gwt/server/WebBrowser.java index 90aef4283d..37bc81cfcf 100644 --- a/server/src/com/vaadin/terminal/gwt/server/WebBrowser.java +++ b/server/src/com/vaadin/terminal/gwt/server/WebBrowser.java @@ -20,7 +20,6 @@ import java.util.Date; import java.util.Locale; import com.vaadin.shared.VBrowserDetails; -import com.vaadin.terminal.Terminal; import com.vaadin.terminal.WrappedRequest; /** @@ -30,7 +29,7 @@ import com.vaadin.terminal.WrappedRequest; * * @author Vaadin Ltd. */ -public class WebBrowser implements Terminal { +public class WebBrowser { private int screenHeight = 0; private int screenWidth = 0; @@ -48,34 +47,21 @@ public class WebBrowser implements Terminal { private long clientServerTimeDelta; /** - * There is no default-theme for this terminal type. + * Gets the height of the screen in pixels. This is the full screen + * resolution and not the height available for the application. * - * @return Always returns null. + * @return the height of the screen in pixels. */ - - @Override - public String getDefaultTheme() { - return null; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.terminal.Terminal#getScreenHeight() - */ - - @Override public int getScreenHeight() { return screenHeight; } - /* - * (non-Javadoc) + /** + * Gets the width of the screen in pixels. This is the full screen + * resolution and not the width available for the application. * - * @see com.vaadin.terminal.Terminal#getScreenWidth() + * @return the width of the screen in pixels. */ - - @Override public int getScreenWidth() { return screenWidth; } -- cgit v1.2.3 From 667ef9c144bf3522100e5c8eac4d76a3c4faf65b Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 20 Aug 2012 19:29:04 +0300 Subject: Refactored margin handlers (#8292) Only layouts actually supporting margins now implement MarginHandler CssLayout should be simplified before 7.0.0 so margin support was removed. GridLayout, VerticalLayout and HorizontalLayout were the only other layouts which actually supported margin. MarginInfo is now passed directly in the state. --- .../client/ui/csslayout/CssLayoutConnector.java | 4 - .../gwt/client/ui/csslayout/VCssLayout.java | 19 ----- .../client/ui/formlayout/FormLayoutConnector.java | 4 +- .../gwt/client/ui/formlayout/VFormLayout.java | 4 +- .../client/ui/gridlayout/GridLayoutConnector.java | 4 +- .../gwt/client/ui/gridlayout/VGridLayout.java | 4 +- .../AbstractOrderedLayoutConnector.java | 5 +- .../ui/orderedlayout/VMeasuringOrderedLayout.java | 4 +- server/src/com/vaadin/ui/AbstractLayout.java | 53 +----------- .../src/com/vaadin/ui/AbstractOrderedLayout.java | 26 +++++- server/src/com/vaadin/ui/CustomLayout.java | 27 ------ server/src/com/vaadin/ui/FormLayout.java | 4 +- server/src/com/vaadin/ui/GridLayout.java | 38 ++++++++- server/src/com/vaadin/ui/Layout.java | 51 ++++-------- .../com/vaadin/shared/ui/AbstractLayoutState.java | 9 -- shared/src/com/vaadin/shared/ui/MarginInfo.java | 96 ++++++++++++++++++++++ shared/src/com/vaadin/shared/ui/VMarginInfo.java | 93 --------------------- .../shared/ui/gridlayout/GridLayoutState.java | 9 ++ .../orderedlayout/AbstractOrderedLayoutState.java | 10 +++ tests/testbench/com/vaadin/tests/Parameters.java | 4 +- .../tests/components/AbstractLayoutTest.java | 9 +- .../components/customfield/NestedPersonForm.java | 5 +- .../vaadin/tests/integration/LiferayThemeDemo.java | 6 +- .../vaadin/tests/layouts/CssLayoutCustomCss.java | 3 +- .../tests/layouts/GridLayoutInsidePanel.java | 6 +- .../com/vaadin/tests/tickets/Ticket1435.java | 3 +- .../com/vaadin/tests/tickets/Ticket1572.java | 9 +- .../com/vaadin/tests/tickets/Ticket1710.java | 12 ++- .../com/vaadin/tests/tickets/Ticket1805.java | 4 +- .../com/vaadin/tests/tickets/Ticket2021.java | 3 +- .../com/vaadin/tests/tickets/Ticket2040.java | 4 +- .../com/vaadin/tests/tickets/Ticket2405.java | 4 +- .../com/vaadin/tests/tickets/Ticket2998.java | 3 +- 33 files changed, 251 insertions(+), 288 deletions(-) create mode 100644 shared/src/com/vaadin/shared/ui/MarginInfo.java delete mode 100644 shared/src/com/vaadin/shared/ui/VMarginInfo.java (limited to 'server/src') diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java index 47c2049a67..2e51d717a4 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java @@ -23,7 +23,6 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.LayoutClickRpc; -import com.vaadin.shared.ui.VMarginInfo; import com.vaadin.shared.ui.csslayout.CssLayoutServerRpc; import com.vaadin.shared.ui.csslayout.CssLayoutState; import com.vaadin.terminal.gwt.client.BrowserInfo; @@ -75,9 +74,6 @@ public class CssLayoutConnector extends AbstractLayoutConnector { public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - getWidget().setMarginStyles( - new VMarginInfo(getState().getMarginsBitmask())); - for (ComponentConnector child : getChildComponents()) { if (!getState().getChildCss().containsKey(child)) { continue; diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java index 813e95e3ed..e66b1c4208 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java @@ -21,8 +21,6 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.shared.ui.VMarginInfo; -import com.vaadin.terminal.gwt.client.StyleConstants; public class VCssLayout extends SimplePanel { public static final String TAGNAME = "csslayout"; @@ -64,21 +62,4 @@ public class VCssLayout extends SimplePanel { } - /** - * Sets CSS classes for margin based on the given parameters. - * - * @param margins - * A {@link VMarginInfo} object that provides info on - * top/left/bottom/right margins - */ - protected void setMarginStyles(VMarginInfo margins) { - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_TOP, margins.hasTop()); - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_RIGHT, margins.hasRight()); - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_BOTTOM, margins.hasBottom()); - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_LEFT, margins.hasLeft()); - } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java index 7d5edfadf5..cbe06244af 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java @@ -18,7 +18,7 @@ package com.vaadin.terminal.gwt.client.ui.formlayout; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent; @@ -46,7 +46,7 @@ public class FormLayoutConnector extends AbstractLayoutConnector { VFormLayoutTable formLayoutTable = getWidget().table; - formLayoutTable.setMargins(new VMarginInfo(getState() + formLayoutTable.setMargins(new MarginInfo(getState() .getMarginsBitmask())); formLayoutTable.setSpacing(getState().isSpacing()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java index d3ce6f3d3f..7f211aaf9c 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java @@ -29,7 +29,7 @@ import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ComponentState; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ComponentConnector; @@ -112,7 +112,7 @@ public class VFormLayout extends SimplePanel { } } - public void setMargins(VMarginInfo margins) { + public void setMargins(MarginInfo margins) { Element margin = getElement(); setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP, margins.hasTop()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java index 520afb778d..9a2732e408 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java @@ -22,7 +22,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.AlignmentInfo; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.LayoutClickRpc; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.gridlayout.GridLayoutServerRpc; import com.vaadin.shared.ui.gridlayout.GridLayoutState; import com.vaadin.terminal.gwt.client.ApplicationConnection; @@ -163,7 +163,7 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector layout.colExpandRatioArray = uidl.getIntArrayAttribute("colExpand"); layout.rowExpandRatioArray = uidl.getIntArrayAttribute("rowExpand"); - layout.updateMarginStyleNames(new VMarginInfo(getState() + layout.updateMarginStyleNames(new MarginInfo(getState() .getMarginsBitmask())); layout.updateSpacingStyleName(getState().isSpacing()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java index 25d7de6ee6..ef44964da7 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java @@ -29,7 +29,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.AlignmentInfo; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.ConnectorMap; @@ -677,7 +677,7 @@ public class VGridLayout extends ComplexPanel { } } - void updateMarginStyleNames(VMarginInfo marginInfo) { + void updateMarginStyleNames(MarginInfo marginInfo) { togglePrefixedStyleName("margin-top", marginInfo.hasTop()); togglePrefixedStyleName("margin-right", marginInfo.hasRight()); togglePrefixedStyleName("margin-bottom", marginInfo.hasBottom()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index 5da01bf127..122547ddb4 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -23,7 +23,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.AlignmentInfo; import com.vaadin.shared.ui.LayoutClickRpc; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutServerRpc; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; import com.vaadin.terminal.gwt.client.ComponentConnector; @@ -133,9 +133,8 @@ public abstract class AbstractOrderedLayoutConnector extends slot.setExpandRatio(expandRatio); } - layout.updateMarginStyleNames(new VMarginInfo(getState() + layout.updateMarginStyleNames(new MarginInfo(getState() .getMarginsBitmask())); - layout.updateSpacingStyleName(getState().isSpacing()); getLayoutManager().setNeedsLayout(this); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java index ec2c4afa97..ee55bc07ba 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java @@ -27,7 +27,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.WidgetCollection; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.gwt.client.VCaption; import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot; @@ -75,7 +75,7 @@ public class VMeasuringOrderedLayout extends ComplexPanel { } } - void updateMarginStyleNames(VMarginInfo marginInfo) { + void updateMarginStyleNames(MarginInfo marginInfo) { togglePrefixedStyleName("margin-top", marginInfo.hasTop()); togglePrefixedStyleName("margin-right", marginInfo.hasRight()); togglePrefixedStyleName("margin-bottom", marginInfo.hasBottom()); diff --git a/server/src/com/vaadin/ui/AbstractLayout.java b/server/src/com/vaadin/ui/AbstractLayout.java index c26812f3fc..dd1d5eab12 100644 --- a/server/src/com/vaadin/ui/AbstractLayout.java +++ b/server/src/com/vaadin/ui/AbstractLayout.java @@ -17,7 +17,6 @@ package com.vaadin.ui; import com.vaadin.shared.ui.AbstractLayoutState; -import com.vaadin.ui.Layout.MarginHandler; /** * An abstract class that defines default implementation for the {@link Layout} @@ -26,62 +25,12 @@ import com.vaadin.ui.Layout.MarginHandler; * @author Vaadin Ltd. * @since 5.0 */ -@SuppressWarnings("serial") public abstract class AbstractLayout extends AbstractComponentContainer - implements Layout, MarginHandler { - - protected MarginInfo margins = new MarginInfo(false); + implements Layout { @Override public AbstractLayoutState getState() { return (AbstractLayoutState) super.getState(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout#setMargin(boolean) - */ - @Override - public void setMargin(boolean enabled) { - margins.setMargins(enabled); - getState().setMarginsBitmask(margins.getBitMask()); - requestRepaint(); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout.MarginHandler#getMargin() - */ - @Override - public MarginInfo getMargin() { - return margins; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout.MarginHandler#setMargin(MarginInfo) - */ - @Override - public void setMargin(MarginInfo marginInfo) { - margins.setMargins(marginInfo); - getState().setMarginsBitmask(margins.getBitMask()); - requestRepaint(); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout#setMargin(boolean, boolean, boolean, boolean) - */ - @Override - public void setMargin(boolean topEnabled, boolean rightEnabled, - boolean bottomEnabled, boolean leftEnabled) { - margins.setMargins(topEnabled, rightEnabled, bottomEnabled, leftEnabled); - getState().setMarginsBitmask(margins.getBitMask()); - requestRepaint(); - } - } diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java index a7cc780414..3ac4e76bdb 100644 --- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -25,6 +25,7 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutServerRpc; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState.ChildComponentData; @@ -32,7 +33,8 @@ import com.vaadin.terminal.Sizeable; @SuppressWarnings("serial") public abstract class AbstractOrderedLayout extends AbstractLayout implements - Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier { + Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier, + Layout.MarginHandler { private AbstractOrderedLayoutServerRpc rpc = new AbstractOrderedLayoutServerRpc() { @@ -392,4 +394,26 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements return components.get(index); } + public void setMargin(boolean enabled) { + setMargin(new MarginInfo(enabled)); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#getMargin() + */ + public MarginInfo getMargin() { + return new MarginInfo(getState().getMarginsBitmask()); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#setMargin(MarginInfo) + */ + public void setMargin(MarginInfo marginInfo) { + getState().setMarginsBitmask(marginInfo.getBitMask()); + requestRepaint(); + } } diff --git a/server/src/com/vaadin/ui/CustomLayout.java b/server/src/com/vaadin/ui/CustomLayout.java index 2da443bfa5..d47b2f92b3 100644 --- a/server/src/com/vaadin/ui/CustomLayout.java +++ b/server/src/com/vaadin/ui/CustomLayout.java @@ -291,33 +291,6 @@ public class CustomLayout extends AbstractLayout implements Vaadin6Component { requestRepaint(); } - /** - * Although most layouts support margins, CustomLayout does not. The - * behaviour of this layout is determined almost completely by the actual - * template. - * - * @throws UnsupportedOperationException - */ - @Override - public void setMargin(boolean enabled) { - throw new UnsupportedOperationException( - "CustomLayout does not support margins."); - } - - /** - * Although most layouts support margins, CustomLayout does not. The - * behaviour of this layout is determined almost completely by the actual - * template. - * - * @throws UnsupportedOperationException - */ - @Override - public void setMargin(boolean topEnabled, boolean rightEnabled, - boolean bottomEnabled, boolean leftEnabled) { - throw new UnsupportedOperationException( - "CustomLayout does not support margins."); - } - @Override public void changeVariables(Object source, Map variables) { // Nothing to see here diff --git a/server/src/com/vaadin/ui/FormLayout.java b/server/src/com/vaadin/ui/FormLayout.java index c4ba4665ea..15ea478597 100644 --- a/server/src/com/vaadin/ui/FormLayout.java +++ b/server/src/com/vaadin/ui/FormLayout.java @@ -16,6 +16,8 @@ package com.vaadin.ui; +import com.vaadin.shared.ui.MarginInfo; + /** * FormLayout is used by {@link Form} to layout fields. It may also be used * separately without {@link Form}. @@ -36,7 +38,7 @@ public class FormLayout extends AbstractOrderedLayout { public FormLayout() { super(); setSpacing(true); - setMargin(true, false, true, false); + setMargin(new MarginInfo(true, false, true, false)); setWidth(100, UNITS_PERCENTAGE); } diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index 5a748c04f6..b31ab82741 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -30,6 +30,7 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.gridlayout.GridLayoutServerRpc; import com.vaadin.shared.ui.gridlayout.GridLayoutState; import com.vaadin.terminal.LegacyPaint; @@ -63,8 +64,8 @@ import com.vaadin.terminal.Vaadin6Component; */ @SuppressWarnings("serial") public class GridLayout extends AbstractLayout implements - Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier, - Vaadin6Component { + Layout.AlignmentHandler, Layout.SpacingHandler, Layout.MarginHandler, + LayoutClickNotifier, Vaadin6Component { private GridLayoutServerRpc rpc = new GridLayoutServerRpc() { @@ -1416,4 +1417,37 @@ public class GridLayout extends AbstractLayout implements LayoutClickEvent.class, listener); } + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#setMargin(boolean) + */ + @Override + public void setMargin(boolean enabled) { + setMargin(new MarginInfo(enabled)); + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.Layout.MarginHandler#setMargin(com.vaadin.shared.ui.MarginInfo + * ) + */ + @Override + public void setMargin(MarginInfo marginInfo) { + getState().setMarginsBitmask(marginInfo.getBitMask()); + requestRepaint(); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#getMargin() + */ + @Override + public MarginInfo getMargin() { + return new MarginInfo(getState().getMarginsBitmask()); + } + } diff --git a/server/src/com/vaadin/ui/Layout.java b/server/src/com/vaadin/ui/Layout.java index 6a95d23f8c..9c7cd2b477 100644 --- a/server/src/com/vaadin/ui/Layout.java +++ b/server/src/com/vaadin/ui/Layout.java @@ -18,8 +18,8 @@ package com.vaadin.ui; import java.io.Serializable; -import com.vaadin.shared.ui.VMarginInfo; import com.vaadin.shared.ui.AlignmentInfo.Bits; +import com.vaadin.shared.ui.MarginInfo; /** * Extension to the {@link ComponentContainer} interface which adds the @@ -32,30 +32,6 @@ import com.vaadin.shared.ui.AlignmentInfo.Bits; */ public interface Layout extends ComponentContainer, Serializable { - /** - * Enable layout margins. Affects all four sides of the layout. This will - * tell the client-side implementation to leave extra space around the - * layout. The client-side implementation decides the actual amount, and it - * can vary between themes. - * - * @param enabled - */ - public void setMargin(boolean enabled); - - /** - * Enable specific layout margins. This will tell the client-side - * implementation to leave extra space around the layout in specified edges, - * clockwise from top (top, right, bottom, left). The client-side - * implementation decides the actual amount, and it can vary between themes. - * - * @param top - * @param right - * @param bottom - * @param left - */ - public void setMargin(boolean top, boolean right, boolean bottom, - boolean left); - /** * AlignmentHandler is most commonly an advanced {@link Layout} that can * align its components. @@ -197,6 +173,19 @@ public interface Layout extends ComponentContainer, Serializable { * its components). */ public interface MarginHandler extends Serializable { + + /** + * Enable layout margins. Affects all four sides of the layout. This + * will tell the client-side implementation to leave extra space around + * the layout. The client-side implementation decides the actual amount, + * and it can vary between themes. + * + * @param enabled + * true if margins should be enabled on all sides, false to + * disable all margins + */ + public void setMargin(boolean enabled); + /** * Enable margins for this layout. * @@ -224,16 +213,4 @@ public interface Layout extends ComponentContainer, Serializable { public MarginInfo getMargin(); } - @SuppressWarnings("serial") - public static class MarginInfo extends VMarginInfo implements Serializable { - - public MarginInfo(boolean enabled) { - super(enabled, enabled, enabled, enabled); - } - - public MarginInfo(boolean top, boolean right, boolean bottom, - boolean left) { - super(top, right, bottom, left); - } - } } diff --git a/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java b/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java index 675d11d0b7..4fc865626c 100644 --- a/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java @@ -18,14 +18,5 @@ package com.vaadin.shared.ui; import com.vaadin.shared.ComponentState; public class AbstractLayoutState extends ComponentState { - private int marginsBitmask; - - public int getMarginsBitmask() { - return marginsBitmask; - } - - public void setMarginsBitmask(int marginsBitmask) { - this.marginsBitmask = marginsBitmask; - } } \ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/MarginInfo.java b/shared/src/com/vaadin/shared/ui/MarginInfo.java new file mode 100644 index 0000000000..21e52f258a --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/MarginInfo.java @@ -0,0 +1,96 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.shared.ui; + +import java.io.Serializable; + +public class MarginInfo implements Serializable { + + private static final int TOP = 1; + private static final int RIGHT = 2; + private static final int BOTTOM = 4; + private static final int LEFT = 8; + + private int bitMask; + + public MarginInfo(boolean enabled) { + this(enabled, enabled, enabled, enabled); + } + + public MarginInfo(int bitMask) { + this.bitMask = bitMask; + } + + public MarginInfo(boolean top, boolean right, boolean bottom, boolean left) { + setMargins(top, right, bottom, left); + } + + public void setMargins(boolean top, boolean right, boolean bottom, + boolean left) { + bitMask = top ? TOP : 0; + bitMask += right ? RIGHT : 0; + bitMask += bottom ? BOTTOM : 0; + bitMask += left ? LEFT : 0; + } + + public void setMargins(MarginInfo marginInfo) { + bitMask = marginInfo.bitMask; + } + + public boolean hasLeft() { + return (bitMask & LEFT) == LEFT; + } + + public boolean hasRight() { + return (bitMask & RIGHT) == RIGHT; + } + + public boolean hasTop() { + return (bitMask & TOP) == TOP; + } + + public boolean hasBottom() { + return (bitMask & BOTTOM) == BOTTOM; + } + + public int getBitMask() { + return bitMask; + } + + public void setMargins(boolean enabled) { + if (enabled) { + bitMask = TOP + RIGHT + BOTTOM + LEFT; + } else { + bitMask = 0; + } + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MarginInfo)) { + return false; + } + + return ((MarginInfo) obj).bitMask == bitMask; + } + + @Override + public int hashCode() { + return bitMask; + } + +} diff --git a/shared/src/com/vaadin/shared/ui/VMarginInfo.java b/shared/src/com/vaadin/shared/ui/VMarginInfo.java deleted file mode 100644 index 9e9e0a4bb4..0000000000 --- a/shared/src/com/vaadin/shared/ui/VMarginInfo.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.shared.ui; - -import java.io.Serializable; - -@SuppressWarnings("serial") -public class VMarginInfo implements Serializable { - - private static final int TOP = 1; - private static final int RIGHT = 2; - private static final int BOTTOM = 4; - private static final int LEFT = 8; - - private int bitMask; - - public VMarginInfo(int bitMask) { - this.bitMask = bitMask; - } - - public VMarginInfo(boolean top, boolean right, boolean bottom, boolean left) { - setMargins(top, right, bottom, left); - } - - public void setMargins(boolean top, boolean right, boolean bottom, - boolean left) { - bitMask = top ? TOP : 0; - bitMask += right ? RIGHT : 0; - bitMask += bottom ? BOTTOM : 0; - bitMask += left ? LEFT : 0; - } - - public void setMargins(VMarginInfo marginInfo) { - bitMask = marginInfo.bitMask; - } - - public boolean hasLeft() { - return (bitMask & LEFT) == LEFT; - } - - public boolean hasRight() { - return (bitMask & RIGHT) == RIGHT; - } - - public boolean hasTop() { - return (bitMask & TOP) == TOP; - } - - public boolean hasBottom() { - return (bitMask & BOTTOM) == BOTTOM; - } - - public int getBitMask() { - return bitMask; - } - - public void setMargins(boolean enabled) { - if (enabled) { - bitMask = TOP + RIGHT + BOTTOM + LEFT; - } else { - bitMask = 0; - } - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof VMarginInfo)) { - return false; - } - - return ((VMarginInfo) obj).bitMask == bitMask; - } - - @Override - public int hashCode() { - return bitMask; - } - -} diff --git a/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java b/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java index d2e685d8cb..381a6a7f85 100644 --- a/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java @@ -21,6 +21,7 @@ public class GridLayoutState extends AbstractLayoutState { private boolean spacing = false; private int rows = 0; private int columns = 0; + private int marginsBitmask = 0; public boolean isSpacing() { return spacing; @@ -30,6 +31,14 @@ public class GridLayoutState extends AbstractLayoutState { this.spacing = spacing; } + public int getMarginsBitmask() { + return marginsBitmask; + } + + public void setMarginsBitmask(int marginsBitmask) { + this.marginsBitmask = marginsBitmask; + } + public int getRows() { return rows; } diff --git a/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java b/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java index 235c9eab13..3fa2ad771c 100644 --- a/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java @@ -27,6 +27,8 @@ public class AbstractOrderedLayoutState extends AbstractLayoutState { public HashMap childData = new HashMap(); + private int marginsBitmask = 0; + public static class ChildComponentData implements Serializable { private int alignmentBitmask = AlignmentInfo.TOP_LEFT.getBitMask(); private float expandRatio = 0.0f; @@ -65,4 +67,12 @@ public class AbstractOrderedLayoutState extends AbstractLayoutState { this.spacing = spacing; } + public int getMarginsBitmask() { + return marginsBitmask; + } + + public void setMarginsBitmask(int marginsBitmask) { + this.marginsBitmask = marginsBitmask; + } + } \ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/Parameters.java b/tests/testbench/com/vaadin/tests/Parameters.java index 4fb224eb19..e9824d9c40 100644 --- a/tests/testbench/com/vaadin/tests/Parameters.java +++ b/tests/testbench/com/vaadin/tests/Parameters.java @@ -27,7 +27,7 @@ import com.vaadin.terminal.RequestHandler; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.WrappedResponse; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Link; import com.vaadin.ui.Panel; import com.vaadin.ui.Root.LegacyWindow; @@ -90,7 +90,7 @@ public class Parameters extends com.vaadin.Application.LegacyApplication final Panel panel2 = new Panel("Parameter Handler"); params.setSizeFull(); panel2.setContent(new VerticalLayout()); - ((Layout) panel2.getContent()).setMargin(true); + ((MarginHandler) panel2.getContent()).setMargin(true); params.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID); panel2.addComponent(params); diff --git a/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java b/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java index af62e5e4a4..c04be3d724 100644 --- a/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java +++ b/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java @@ -2,11 +2,12 @@ package com.vaadin.tests.components; import java.util.LinkedHashMap; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.AbstractLayout; import com.vaadin.ui.Alignment; import com.vaadin.ui.Component; import com.vaadin.ui.Layout.AlignmentHandler; -import com.vaadin.ui.Layout.MarginInfo; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Layout.SpacingHandler; public abstract class AbstractLayoutTest extends @@ -17,7 +18,7 @@ public abstract class AbstractLayoutTest extends @Override public void execute(T c, MarginInfo value, Object data) { - c.setMargin(value); + ((MarginHandler) c).setMargin(value); } }; @@ -42,7 +43,9 @@ public abstract class AbstractLayoutTest extends @Override protected void createActions() { super.createActions(); - createMarginsSelect(CATEGORY_LAYOUT_FEATURES); + if (MarginHandler.class.isAssignableFrom(getTestClass())) { + createMarginsSelect(CATEGORY_LAYOUT_FEATURES); + } if (SpacingHandler.class.isAssignableFrom(getTestClass())) { createSpacingSelect(CATEGORY_LAYOUT_FEATURES); } diff --git a/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java b/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java index 0bc4f45545..0655c09102 100644 --- a/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java +++ b/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java @@ -4,6 +4,7 @@ import java.util.Arrays; import com.vaadin.data.Item; import com.vaadin.data.util.BeanItem; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.tests.util.Person; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; @@ -13,6 +14,7 @@ import com.vaadin.ui.DefaultFieldFactory; import com.vaadin.ui.Field; import com.vaadin.ui.Form; import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Layout.MarginHandler; /** * Example of nested forms @@ -37,7 +39,8 @@ public class NestedPersonForm extends Form { setItemDataSource(beanItem, Arrays.asList("firstName", "lastName", "address", "email", "phoneNumber")); getFooter().addComponent(getButtonsLayout()); - getFooter().setMargin(false, false, true, true); + ((MarginHandler) getFooter()).setMargin(new MarginInfo(false, false, + true, true)); } /** diff --git a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java index 1ea800821b..a35b78c219 100644 --- a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java +++ b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java @@ -8,6 +8,7 @@ import com.vaadin.Application; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.event.Action; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.terminal.ExternalResource; import com.vaadin.terminal.Page; @@ -103,7 +104,6 @@ public class LiferayThemeDemo extends Application.LegacyApplication { mainLayout.addComponent(getTopMenu()); CssLayout margin = new CssLayout(); - margin.setMargin(false, true, true, true); margin.setSizeFull(); tabs = new TabSheet(); tabs.setSizeFull(); @@ -239,7 +239,7 @@ public class LiferayThemeDemo extends Application.LegacyApplication { HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); - hl.setMargin(true, false, false, false); + hl.setMargin(new MarginInfo(true, false, false, false)); l.addComponent(hl); AbstractSelect cb = new ComboBox(); @@ -270,7 +270,7 @@ public class LiferayThemeDemo extends Application.LegacyApplication { HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); - hl.setMargin(true, false, false, false); + hl.setMargin(new MarginInfo(true, false, false, false)); l.addComponent(hl); DateField df = new DateField(); diff --git a/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java b/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java index 792bcb1aab..ed35d39ef7 100644 --- a/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java +++ b/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java @@ -12,6 +12,7 @@ import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.NativeButton; public class CssLayoutCustomCss extends TestBase implements ClickListener { @@ -48,7 +49,7 @@ public class CssLayoutCustomCss extends TestBase implements ClickListener { @Override public void valueChange(ValueChangeEvent event) { - layout.setMargin(cb.getValue()); + ((MarginHandler) layout).setMargin(cb.getValue()); } }); diff --git a/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java b/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java index 1c864fdb47..e200c40744 100644 --- a/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java +++ b/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java @@ -3,7 +3,7 @@ package com.vaadin.tests.layouts; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Panel; public class GridLayoutInsidePanel extends TestBase { @@ -27,7 +27,7 @@ public class GridLayoutInsidePanel extends TestBase { "A label which defines the size of the GL")); Panel p = new Panel("Panel 1"); - ((Layout) p.getContent()).setMargin(false); + ((MarginHandler) p.getContent()).setMargin(false); p.setSizeUndefined(); p.getContent().setSizeUndefined(); @@ -41,7 +41,7 @@ public class GridLayoutInsidePanel extends TestBase { "A label which defines the size of the GL")); Panel p = new Panel("Panel 2", gl); - ((Layout) p.getContent()).setMargin(false); + ((MarginHandler) p.getContent()).setMargin(false); p.setSizeUndefined(); p.getContent().setSizeUndefined(); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java index 438f7e2d5f..d6d3b132c3 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java @@ -10,6 +10,7 @@ import com.vaadin.ui.CustomComponent; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Panel; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.Table; @@ -159,7 +160,7 @@ public class Ticket1435 extends Application.LegacyApplication { private void initContainer() { container.setStyleName("custompanel"); container.setSizeFull(); - ((Layout) container.getContent()).setMargin(false); + ((MarginHandler) container.getContent()).setMargin(false); container.getContent().setSizeFull(); root.addComponent(container); root.setExpandRatio(container, 1); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java index b9fd2debd5..87ea7e86a8 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java @@ -1,5 +1,6 @@ package com.vaadin.tests.tickets; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.GridLayout; @@ -82,19 +83,19 @@ public class Ticket1572 extends com.vaadin.Application.LegacyApplication { state.setValue("Margin on"); break; case 2: - gl.setMargin(true, false, false, false); + gl.setMargin(new MarginInfo(true, false, false, false)); state.setValue("Margin top"); break; case 3: - gl.setMargin(false, true, false, false); + gl.setMargin(new MarginInfo(false, true, false, false)); state.setValue("Margin right"); break; case 4: - gl.setMargin(false, false, true, false); + gl.setMargin(new MarginInfo(false, false, true, false)); state.setValue("Margin bottom"); break; case 5: - gl.setMargin(false, false, false, true); + gl.setMargin(new MarginInfo(false, false, false, true)); state.setValue("Margin left"); break; default: diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java index 01792aeb89..1f2c9624c3 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java @@ -5,6 +5,7 @@ import java.util.Iterator; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.util.MethodProperty; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.SystemError; import com.vaadin.terminal.ThemeResource; import com.vaadin.ui.AbstractComponent; @@ -393,10 +394,13 @@ public class Ticket1710 extends com.vaadin.Application.LegacyApplication { } private void updateMarginsAndSpacing() { - testedLayout.setMargin(marginTop.getValue().booleanValue(), - marginRight.getValue().booleanValue(), marginBottom - .getValue().booleanValue(), marginLeft.getValue() - .booleanValue()); + if (testedLayout instanceof Layout.MarginHandler) { + ((Layout.MarginHandler) testedLayout).setMargin(new MarginInfo( + marginTop.getValue().booleanValue(), marginRight + .getValue().booleanValue(), marginBottom + .getValue().booleanValue(), marginLeft + .getValue().booleanValue())); + } if (testedLayout instanceof Layout.SpacingHandler) { ((Layout.SpacingHandler) testedLayout).setSpacing(spacing .getValue().booleanValue()); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java index a40f5b25b9..e5fcf59db8 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java @@ -6,7 +6,7 @@ import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextField; @@ -17,7 +17,7 @@ public class Ticket1805 extends com.vaadin.Application.LegacyApplication { final LegacyWindow main = new LegacyWindow(getClass().getName() .substring(getClass().getName().lastIndexOf(".") + 1)); setMainWindow(main); - ((Layout) main.getContent()).setMargin(false); + ((MarginHandler) main.getContent()).setMargin(false); Label description = new Label( "GridLayout with 100% (no height), is wanted to " diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java index c36bb5c25e..f6d8ce5e01 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java @@ -9,6 +9,7 @@ import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Panel; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextArea; @@ -78,7 +79,7 @@ public class Ticket2021 extends Application.LegacyApplication { p3.setHeight("500px"); // p3.setContent(new GridLayout()); p3.getContent().setSizeFull(); - ((Layout) p3.getContent()).setMargin(false); + ((MarginHandler) p3.getContent()).setMargin(false); GridLayout gl = new GridLayout(); gl.setSizeFull(); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java index ac8928d110..d98656b9ca 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java @@ -2,7 +2,7 @@ package com.vaadin.tests.tickets; import com.vaadin.ui.Accordion; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; @@ -17,7 +17,7 @@ public class Ticket2040 extends com.vaadin.Application.LegacyApplication { setMainWindow(main); main.getContent().setSizeFull(); - ((Layout) main.getContent()).setMargin(true); + ((MarginHandler) main.getContent()).setMargin(true); setTheme("tests-tickets"); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java index 16a552e37a..c5ef9ec0b0 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java @@ -8,7 +8,7 @@ import com.vaadin.ui.Embedded; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; @@ -31,7 +31,7 @@ public class Ticket2405 extends Application.LegacyApplication { setMainWindow(root); root.getContent().setSizeFull(); - ((Layout) root.getContent()).setMargin(false); + ((MarginHandler) root.getContent()).setMargin(false); // Top area, containing playback and volume controls, play status, view // modes and search diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java index ee60c0ce7e..2d2970d36e 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java @@ -19,6 +19,7 @@ import com.vaadin.ui.DefaultFieldFactory; import com.vaadin.ui.Field; import com.vaadin.ui.FormLayout; import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.ListSelect; import com.vaadin.ui.Notification; import com.vaadin.ui.Panel; @@ -252,7 +253,7 @@ public class Ticket2998 extends Application.LegacyApplication { // set theme and some layout stuff setMainWindow(w); w.getContent().setSizeFull(); - ((Layout) w.getContent()).setMargin(false); + ((MarginHandler) w.getContent()).setMargin(false); Panel p = new Panel("Workout Log"); p.setStyleName(Reindeer.PANEL_LIGHT); -- cgit v1.2.3 From 88776600733901f3f9891aa90a11a5aeb2b97ef4 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 22 Aug 2012 08:53:23 +0300 Subject: Changed border style to enum (#9072) --- .../terminal/gwt/client/ui/link/LinkConnector.java | 7 ++--- .../vaadin/terminal/gwt/client/ui/link/VLink.java | 18 ++++++++----- server/src/com/vaadin/terminal/Page.java | 21 ++++++++------- server/src/com/vaadin/ui/Link.java | 31 +++++++++++----------- server/src/com/vaadin/ui/Root.java | 6 ++--- shared/src/com/vaadin/shared/ui/BorderStyle.java | 20 ++++++++++++++ 6 files changed, 65 insertions(+), 38 deletions(-) create mode 100755 shared/src/com/vaadin/shared/ui/BorderStyle.java (limited to 'server/src') diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/link/LinkConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/link/LinkConnector.java index c4bbcd34f7..f2b8361f2b 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/link/LinkConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/link/LinkConnector.java @@ -17,6 +17,7 @@ package com.vaadin.terminal.gwt.client.ui.link; import com.google.gwt.user.client.DOM; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.Connect; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Paintable; @@ -57,12 +58,12 @@ public class LinkConnector extends AbstractComponentConnector implements if (uidl.hasAttribute("border")) { if ("none".equals(uidl.getStringAttribute("border"))) { - getWidget().borderStyle = VLink.BORDER_STYLE_NONE; + getWidget().borderStyle = BorderStyle.NONE; } else { - getWidget().borderStyle = VLink.BORDER_STYLE_MINIMAL; + getWidget().borderStyle = BorderStyle.MINIMAL; } } else { - getWidget().borderStyle = VLink.BORDER_STYLE_DEFAULT; + getWidget().borderStyle = BorderStyle.DEFAULT; } getWidget().targetHeight = uidl.hasAttribute("targetHeight") ? uidl diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java b/client/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java index e312d4d489..b0e44c9d13 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java @@ -23,6 +23,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.HTML; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.ui.Icon; @@ -31,15 +32,20 @@ public class VLink extends HTML implements ClickHandler { public static final String CLASSNAME = "v-link"; - protected static final int BORDER_STYLE_DEFAULT = 0; - protected static final int BORDER_STYLE_MINIMAL = 1; - protected static final int BORDER_STYLE_NONE = 2; + @Deprecated + protected static final BorderStyle BORDER_STYLE_DEFAULT = BorderStyle.DEFAULT; + + @Deprecated + protected static final BorderStyle BORDER_STYLE_MINIMAL = BorderStyle.MINIMAL; + + @Deprecated + protected static final BorderStyle BORDER_STYLE_NONE = BorderStyle.NONE; protected String src; protected String target; - protected int borderStyle = BORDER_STYLE_DEFAULT; + protected BorderStyle borderStyle = BorderStyle.DEFAULT; protected boolean enabled; @@ -73,10 +79,10 @@ public class VLink extends HTML implements ClickHandler { } String features; switch (borderStyle) { - case BORDER_STYLE_NONE: + case NONE: features = "menubar=no,location=no,status=no"; break; - case BORDER_STYLE_MINIMAL: + case MINIMAL: features = "menubar=yes,location=no,status=no"; break; default: diff --git a/server/src/com/vaadin/terminal/Page.java b/server/src/com/vaadin/terminal/Page.java index 933f9b39e6..8eb77b7d0d 100644 --- a/server/src/com/vaadin/terminal/Page.java +++ b/server/src/com/vaadin/terminal/Page.java @@ -24,6 +24,7 @@ import java.util.LinkedList; import java.util.List; import com.vaadin.event.EventRouter; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.root.PageClientRpc; import com.vaadin.shared.ui.root.RootConstants; import com.vaadin.terminal.WrappedRequest.BrowserDetails; @@ -128,7 +129,7 @@ public class Page implements Serializable { /** * The border style of the target window */ - private final int border; + private final BorderStyle border; /** * Creates a new open resource. @@ -145,7 +146,7 @@ public class Page implements Serializable { * The border style of the target window */ private OpenResource(Resource resource, String name, int width, - int height, int border) { + int height, BorderStyle border) { this.resource = resource; this.name = name; this.width = width; @@ -174,10 +175,10 @@ public class Page implements Serializable { target.addAttribute("height", height); } switch (border) { - case BORDER_MINIMAL: + case MINIMAL: target.addAttribute("border", "minimal"); break; - case BORDER_NONE: + case NONE: target.addAttribute("border", "none"); break; } @@ -193,19 +194,20 @@ public class Page implements Serializable { /** * A border style used for opening resources in a window without a border. */ - public static final int BORDER_NONE = 0; + @Deprecated + public static final BorderStyle BORDER_NONE = BorderStyle.NONE; /** * A border style used for opening resources in a window with a minimal * border. */ - public static final int BORDER_MINIMAL = 1; + public static final BorderStyle BORDER_MINIMAL = BorderStyle.MINIMAL; /** * A border style that indicates that the default border style should be * used when opening resources. */ - public static final int BORDER_DEFAULT = 2; + public static final BorderStyle BORDER_DEFAULT = BorderStyle.DEFAULT; /** * Listener that listens changes in URI fragment. @@ -581,11 +583,10 @@ public class Page implements Serializable { * @param height * the height of the window in pixels * @param border - * the border style of the window. See {@link #BORDER_NONE - * Window.BORDER_* constants} + * the border style of the window. */ public void open(Resource resource, String windowName, int width, - int height, int border) { + int height, BorderStyle border) { openList.add(new OpenResource(resource, windowName, width, height, border)); root.requestRepaint(); diff --git a/server/src/com/vaadin/ui/Link.java b/server/src/com/vaadin/ui/Link.java index 57f2088054..ae2934f878 100644 --- a/server/src/com/vaadin/ui/Link.java +++ b/server/src/com/vaadin/ui/Link.java @@ -18,7 +18,7 @@ package com.vaadin.ui; import java.util.Map; -import com.vaadin.terminal.Page; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; @@ -34,19 +34,22 @@ import com.vaadin.terminal.Vaadin6Component; public class Link extends AbstractComponent implements Vaadin6Component { /* Target window border type constant: No window border */ - public static final int TARGET_BORDER_NONE = Page.BORDER_NONE; + @Deprecated + public static final BorderStyle TARGET_BORDER_NONE = BorderStyle.NONE; /* Target window border type constant: Minimal window border */ - public static final int TARGET_BORDER_MINIMAL = Page.BORDER_MINIMAL; + @Deprecated + public static final BorderStyle TARGET_BORDER_MINIMAL = BorderStyle.MINIMAL; /* Target window border type constant: Default window border */ - public static final int TARGET_BORDER_DEFAULT = Page.BORDER_DEFAULT; + @Deprecated + public static final BorderStyle TARGET_BORDER_DEFAULT = BorderStyle.DEFAULT; private Resource resource = null; private String targetName; - private int targetBorder = TARGET_BORDER_DEFAULT; + private BorderStyle targetBorder = BorderStyle.DEFAULT; private int targetWidth = -1; @@ -89,7 +92,7 @@ public class Link extends AbstractComponent implements Vaadin6Component { * */ public Link(String caption, Resource resource, String targetName, - int width, int height, int border) { + int width, int height, BorderStyle border) { setCaption(caption); this.resource = resource; setTargetName(targetName); @@ -131,10 +134,10 @@ public class Link extends AbstractComponent implements Vaadin6Component { // Target window border switch (getTargetBorder()) { - case TARGET_BORDER_MINIMAL: + case MINIMAL: target.addAttribute("border", "minimal"); break; - case TARGET_BORDER_NONE: + case NONE: target.addAttribute("border", "none"); break; } @@ -145,7 +148,7 @@ public class Link extends AbstractComponent implements Vaadin6Component { * * @return the target window border. */ - public int getTargetBorder() { + public BorderStyle getTargetBorder() { return targetBorder; } @@ -183,13 +186,9 @@ public class Link extends AbstractComponent implements Vaadin6Component { * @param targetBorder * the targetBorder to set. */ - public void setTargetBorder(int targetBorder) { - if (targetBorder == TARGET_BORDER_DEFAULT - || targetBorder == TARGET_BORDER_MINIMAL - || targetBorder == TARGET_BORDER_NONE) { - this.targetBorder = targetBorder; - requestRepaint(); - } + public void setTargetBorder(BorderStyle targetBorder) { + this.targetBorder = targetBorder; + requestRepaint(); } /** diff --git a/server/src/com/vaadin/ui/Root.java b/server/src/com/vaadin/ui/Root.java index b37005a16e..020ff869fa 100644 --- a/server/src/com/vaadin/ui/Root.java +++ b/server/src/com/vaadin/ui/Root.java @@ -34,6 +34,7 @@ import com.vaadin.event.MouseEvents.ClickEvent; import com.vaadin.event.MouseEvents.ClickListener; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.root.RootConstants; import com.vaadin.shared.ui.root.RootServerRpc; import com.vaadin.shared.ui.root.RootState; @@ -283,13 +284,12 @@ public abstract class Root extends AbstractComponentContainer implements * @param height * the height of the window in pixels * @param border - * the border style of the window. See {@link #BORDER_NONE - * Window.BORDER_* constants} + * the border style of the window. * @deprecated As of 7.0, use getPage().open instead */ @Deprecated public void open(Resource resource, String windowName, int width, - int height, int border) { + int height, BorderStyle border) { getPage().open(resource, windowName, width, height, border); } diff --git a/shared/src/com/vaadin/shared/ui/BorderStyle.java b/shared/src/com/vaadin/shared/ui/BorderStyle.java new file mode 100755 index 0000000000..786d340f1c --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/BorderStyle.java @@ -0,0 +1,20 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui; + +public enum BorderStyle { + NONE, MINIMAL, DEFAULT; +} -- cgit v1.2.3