From 391884746fda1781c55b13bc200dd75373f69141 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Tue, 13 Nov 2012 18:08:29 +0200 Subject: [PATCH] UI based on AbstractBasicComponentContainer (#2924) Change-Id: I1614a3464b8e7a0e9ecdd8c3a76335cdb85bdf87 --- .../com/vaadin/client/ui/ui/UIConnector.java | 26 +- .../vaadin/ui/AbstractComponentContainer.java | 75 ++--- .../ui/AbstractSingleComponentContainer.java | 281 ++++++++++++++++++ .../src/com/vaadin/ui/ComponentContainer.java | 147 +-------- server/src/com/vaadin/ui/HasComponents.java | 161 ++++++++++ server/src/com/vaadin/ui/LegacyWindow.java | 214 ++++++++----- .../vaadin/ui/SingleComponentContainer.java | 63 ++++ server/src/com/vaadin/ui/UI.java | 117 +------- ...stAbstractComponentContainerListeners.java | 8 +- ....java => LegacyUIAddRemoveComponents.java} | 12 +- .../ComponentAttachDetachListenerTest.java | 34 +-- .../src/com/vaadin/ui/LabelDataSource.java | 2 +- .../src/com/vaadin/shared/ui/ui/UIState.java | 2 - uitest/src/com/vaadin/tests/Components.java | 3 +- .../com/vaadin/tests/ScrollbarStressTest.java | 2 +- .../DeploymentConfigurationTest.java | 7 +- .../AbstractComponentContainerTest.java | 8 +- .../tests/components/AbstractTestUI.java | 11 +- .../components/LayoutAttachListenerInfo.java | 12 +- .../com/vaadin/tests/components/TestBase.java | 4 +- .../AllComponentTooltipTest.java | 5 +- .../menubar/MenuBarRunsOutOfBrowser.java | 2 +- .../components/table/TableInTabsheet.java | 1 - .../tests/components/ui/LazyInitUIs.java | 23 +- .../components/ui/UIsInMultipleTabs.java | 7 +- .../SubWindowFocusAndBlurListeners.java | 5 +- .../tests/integration/IntegrationTestUI.java | 9 +- .../v7a1/AutoGeneratingForm.java | 7 +- .../v7a1/CreatingPreserveState.java | 2 +- .../DifferentFeaturesForDifferentClients.java | 8 +- .../minitutorials/v7a1/DynamicImageUI.java | 2 +- .../minitutorials/v7a1/FindCurrentUI.java | 2 +- .../v7a1/UsingBeanValidation.java | 2 +- .../minitutorials/v7a1/UsingUriFragments.java | 13 +- .../v7a1/UsingXyzWhenInitializing.java | 11 +- .../v7a2/ComponentInStateUI.java | 9 +- .../minitutorials/v7a2/MyComponentUI.java | 2 +- .../minitutorials/v7a2/ResourceInStateUI.java | 2 +- .../minitutorials/v7a2/WidgetcontainerUI.java | 11 +- .../tests/minitutorials/v7a3/AnalyticsUI.java | 2 +- .../minitutorials/v7a3/ComplexTypesUI.java | 2 +- .../minitutorials/v7a3/FlotJavaScriptUI.java | 22 +- .../tests/minitutorials/v7a3/JSAPIUI.java | 2 +- .../tests/minitutorials/v7a3/RedButtonUI.java | 2 +- .../SettingReadingSessionAttributesUI.java | 36 ++- ...File.java => LettingUserDownloadFile.java} | 4 +- .../tests/minitutorials/v7b6/MyPopupUI.java | 2 +- .../minitutorials/v7b6/OpeningUIInPopup.java | 2 +- .../vaadin/tests/navigator/NavigatorTest.java | 16 +- .../com/vaadin/tests/tickets/Ticket2021.java | 6 +- .../com/vaadin/tests/tickets/Ticket2024.java | 4 +- .../com/vaadin/tests/tickets/Ticket2029.java | 4 +- .../com/vaadin/tests/tickets/Ticket2048.java | 3 +- .../com/vaadin/tests/tickets/Ticket2101.java | 2 +- .../vaadin/tests/util/SampleDirectory.java | 9 +- 55 files changed, 907 insertions(+), 523 deletions(-) create mode 100644 server/src/com/vaadin/ui/AbstractSingleComponentContainer.java create mode 100644 server/src/com/vaadin/ui/SingleComponentContainer.java rename server/tests/src/com/vaadin/tests/server/component/ui/{UIAddRemoveComponents.java => LegacyUIAddRemoveComponents.java} (86%) rename uitest/src/com/vaadin/tests/minitutorials/v7b6/{LettingUserDownladFile.java => LettingUserDownloadFile.java} (96%) diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index c1083a2bb4..a0898b3281 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -337,11 +337,19 @@ public class UIConnector extends AbstractComponentContainerConnector implements } protected ComponentConnector getContent() { - return (ComponentConnector) getState().content; + List children = getChildComponents(); + if (children.isEmpty()) { + return null; + } else { + return children.get(0); + } } protected void onChildSizeChange() { ComponentConnector child = getContent(); + if (child == null) { + return; + } Style childStyle = child.getWidget().getElement().getStyle(); /* * Must set absolute position if the child has relative height and @@ -408,12 +416,16 @@ public class UIConnector extends AbstractComponentContainerConnector implements childStateChangeHandlerRegistration.removeHandler(); childStateChangeHandlerRegistration = null; } - getWidget().setWidget(newChild.getWidget()); - childStateChangeHandlerRegistration = newChild - .addStateChangeHandler(childStateChangeHandler); - // Must handle new child here as state change events are already - // fired - onChildSizeChange(); + if (newChild != null) { + getWidget().setWidget(newChild.getWidget()); + childStateChangeHandlerRegistration = newChild + .addStateChangeHandler(childStateChangeHandler); + // Must handle new child here as state change events are already + // fired + onChildSizeChange(); + } else { + getWidget().setWidget(null); + } } for (ComponentConnector c : getChildComponents()) { diff --git a/server/src/com/vaadin/ui/AbstractComponentContainer.java b/server/src/com/vaadin/ui/AbstractComponentContainer.java index fdc753b57c..c60f312293 100644 --- a/server/src/com/vaadin/ui/AbstractComponentContainer.java +++ b/server/src/com/vaadin/ui/AbstractComponentContainer.java @@ -16,7 +16,6 @@ package com.vaadin.ui; -import java.lang.reflect.Method; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -83,32 +82,11 @@ public abstract class AbstractComponentContainer extends AbstractComponent } } - /* Events */ - - private static final Method COMPONENT_ATTACHED_METHOD; - - private static final Method COMPONENT_DETACHED_METHOD; - - static { - try { - COMPONENT_ATTACHED_METHOD = ComponentAttachListener.class - .getDeclaredMethod("componentAttachedToContainer", - new Class[] { ComponentAttachEvent.class }); - COMPONENT_DETACHED_METHOD = ComponentDetachListener.class - .getDeclaredMethod("componentDetachedFromContainer", - new Class[] { ComponentDetachEvent.class }); - } catch (final java.lang.NoSuchMethodException e) { - // This should never happen - throw new java.lang.RuntimeException( - "Internal error finding methods in AbstractComponentContainer"); - } - } - /* documented in interface */ @Override public void addComponentAttachListener(ComponentAttachListener listener) { - addListener(ComponentContainer.ComponentAttachEvent.class, listener, - COMPONENT_ATTACHED_METHOD); + addListener(ComponentAttachEvent.class, listener, + ComponentAttachListener.attachMethod); } /** @@ -123,9 +101,9 @@ public abstract class AbstractComponentContainer extends AbstractComponent /* documented in interface */ @Override - public void addComponentDetachListener(ComponentDetachListener listener) { - addListener(ComponentContainer.ComponentDetachEvent.class, listener, - COMPONENT_DETACHED_METHOD); + public void removeComponentAttachListener(ComponentAttachListener listener) { + removeListener(ComponentAttachEvent.class, listener, + ComponentAttachListener.attachMethod); } /** @@ -140,9 +118,9 @@ public abstract class AbstractComponentContainer extends AbstractComponent /* documented in interface */ @Override - public void removeComponentAttachListener(ComponentAttachListener listener) { - removeListener(ComponentContainer.ComponentAttachEvent.class, listener, - COMPONENT_ATTACHED_METHOD); + public void addComponentDetachListener(ComponentDetachListener listener) { + addListener(ComponentDetachEvent.class, listener, + ComponentDetachListener.detachMethod); } /** @@ -158,8 +136,8 @@ public abstract class AbstractComponentContainer extends AbstractComponent /* documented in interface */ @Override public void removeComponentDetachListener(ComponentDetachListener listener) { - removeListener(ComponentContainer.ComponentDetachEvent.class, listener, - COMPONENT_DETACHED_METHOD); + removeListener(ComponentDetachEvent.class, listener, + ComponentDetachListener.detachMethod); } /** @@ -218,9 +196,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent if (c.getParent() != null) { // If the component already has a parent, try to remove it - ComponentContainer oldParent = (ComponentContainer) c.getParent(); - oldParent.removeComponent(c); - + AbstractSingleComponentContainer.removeFromParent(c); } c.setParent(this); @@ -250,7 +226,7 @@ public abstract class AbstractComponentContainer extends AbstractComponent super.setVisible(visible); // If the visibility state is toggled it might affect all children - // aswell, e.g. make container visible should make children visible if + // as well, e.g. make container visible should make children visible if // they were only hidden because the container was hidden. markAsDirtyRecursive(); } @@ -315,30 +291,15 @@ public abstract class AbstractComponentContainer extends AbstractComponent private Collection getInvalidSizedChildren(final boolean vertical) { HashSet components = null; - if (this instanceof Panel) { - Panel p = (Panel) this; - ComponentContainer content = p.getContent(); + for (Component component : this) { boolean valid = vertical ? ComponentSizeValidator - .checkHeights(content) : ComponentSizeValidator - .checkWidths(content); - + .checkHeights(component) : ComponentSizeValidator + .checkWidths(component); if (!valid) { - components = new HashSet(1); - components.add(content); - } - } else { - for (Iterator componentIterator = getComponentIterator(); componentIterator - .hasNext();) { - Component component = componentIterator.next(); - boolean valid = vertical ? ComponentSizeValidator - .checkHeights(component) : ComponentSizeValidator - .checkWidths(component); - if (!valid) { - if (components == null) { - components = new HashSet(); - } - components.add(component); + if (components == null) { + components = new HashSet(); } + components.add(component); } } return components; diff --git a/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java new file mode 100644 index 0000000000..20660ce955 --- /dev/null +++ b/server/src/com/vaadin/ui/AbstractSingleComponentContainer.java @@ -0,0 +1,281 @@ +/* + * Copyright 2011-2012 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.ui; + +import java.util.Collections; +import java.util.Iterator; + +import com.vaadin.server.ComponentSizeValidator; + +/** + * Abstract base class for component containers that have only one child + * component. + * + * For component containers that support multiple children, inherit + * {@link AbstractComponentContainer} instead of this class. + * + * @since 7.0 + */ +public abstract class AbstractSingleComponentContainer extends + AbstractComponent implements SingleComponentContainer { + + private Component content; + + @Override + public int getComponentCount() { + return (content != null) ? 1 : 0; + } + + @Override + public Iterator iterator() { + if (content != null) { + return Collections.singletonList(content).iterator(); + } else { + return Collections. emptyList().iterator(); + } + } + + /* documented in interface */ + @Override + public void addComponentAttachListener(ComponentAttachListener listener) { + addListener(ComponentAttachEvent.class, listener, + ComponentAttachListener.attachMethod); + + } + + /* documented in interface */ + @Override + public void removeComponentAttachListener(ComponentAttachListener listener) { + removeListener(ComponentAttachEvent.class, listener, + ComponentAttachListener.attachMethod); + } + + /* documented in interface */ + @Override + public void addComponentDetachListener(ComponentDetachListener listener) { + addListener(ComponentDetachEvent.class, listener, + ComponentDetachListener.detachMethod); + } + + /* documented in interface */ + @Override + public void removeComponentDetachListener(ComponentDetachListener listener) { + removeListener(ComponentDetachEvent.class, listener, + ComponentDetachListener.detachMethod); + } + + /** + * Fires the component attached event. This is called by the + * {@link #setContent(Component)} method after the component has been set as + * the content. + * + * @param component + * the component that has been added to this container. + */ + protected void fireComponentAttachEvent(Component component) { + fireEvent(new ComponentAttachEvent(this, component)); + } + + /** + * Fires the component detached event. This is called by the + * {@link #setContent(Component)} method after the content component has + * been replaced by other content. + * + * @param component + * the component that has been removed from this container. + */ + protected void fireComponentDetachEvent(Component component) { + fireEvent(new ComponentDetachEvent(this, component)); + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.HasComponents#isComponentVisible(com.vaadin.ui.Component) + */ + @Override + public boolean isComponentVisible(Component childComponent) { + return true; + } + + @Override + public void setVisible(boolean visible) { + if (isVisible() == visible) { + return; + } + + super.setVisible(visible); + // If the visibility state is toggled it might affect all children + // aswell, e.g. make container visible should make children visible if + // they were only hidden because the container was hidden. + markAsDirtyRecursive(); + } + + @Override + public Component getContent() { + return content; + } + + /** + * Sets the content of this container. The content is a component that + * serves as the outermost item of the visual contents. + * + * The content must always be set, either with a constructor parameter or by + * calling this method. + * + * Previous versions of Vaadin used a {@link VerticalLayout} with margins + * enabled as the default content but that is no longer the case. + * + * @param content + * a component (typically a layout) to use as content + */ + @Override + public void setContent(Component content) { + Component oldContent = getContent(); + if (oldContent == content) { + // do not set the same content twice + return; + } + if (oldContent != null && oldContent.getParent() == this) { + oldContent.setParent(null); + fireComponentDetachEvent(oldContent); + } + this.content = content; + if (content != null) { + removeFromParent(content); + + content.setParent(this); + fireComponentAttachEvent(content); + } + + markAsDirty(); + } + + /** + * Utility method for removing a component from its parent (if possible). + * + * @param content + * component to remove + */ + // TODO move utility method elsewhere? + public static void removeFromParent(Component content) + throws IllegalArgumentException { + HasComponents parent = content.getParent(); + if (parent instanceof ComponentContainer) { + // If the component already has a parent, try to remove it + ComponentContainer oldParent = (ComponentContainer) parent; + oldParent.removeComponent(content); + } else if (parent instanceof SingleComponentContainer) { + SingleComponentContainer oldParent = (SingleComponentContainer) parent; + if (oldParent.getContent() == content) { + oldParent.setContent(null); + } + } else if (parent != null) { + throw new IllegalArgumentException( + "Content is already attached to another parent"); + } + } + + // the setHeight()/setWidth() methods duplicated and simplified from + // AbstractComponentContainer + + @Override + public void setWidth(float width, Unit unit) { + /* + * child tree repaints may be needed, due to our fall back support for + * invalid relative sizes + */ + boolean dirtyChild = false; + boolean childrenMayBecomeUndefined = false; + if (getWidth() == SIZE_UNDEFINED && width != SIZE_UNDEFINED) { + // children currently in invalid state may need repaint + dirtyChild = getInvalidSizedChild(false); + } else if ((width == SIZE_UNDEFINED && getWidth() != SIZE_UNDEFINED) + || (unit == Unit.PERCENTAGE + && getWidthUnits() != Unit.PERCENTAGE && !ComponentSizeValidator + .parentCanDefineWidth(this))) { + /* + * relative width children may get to invalid state if width becomes + * invalid. Width may also become invalid if units become percentage + * due to the fallback support + */ + childrenMayBecomeUndefined = true; + dirtyChild = getInvalidSizedChild(false); + } + super.setWidth(width, unit); + repaintChangedChildTree(dirtyChild, childrenMayBecomeUndefined, false); + } + + private void repaintChangedChildTree(boolean invalidChild, + boolean childrenMayBecomeUndefined, boolean vertical) { + if (getContent() == null) { + return; + } + boolean needRepaint = false; + if (childrenMayBecomeUndefined) { + // if became invalid now + needRepaint = !invalidChild && getInvalidSizedChild(vertical); + } else if (invalidChild) { + // if not still invalid + needRepaint = !getInvalidSizedChild(vertical); + } + if (needRepaint) { + getContent().markAsDirtyRecursive(); + } + } + + private boolean getInvalidSizedChild(final boolean vertical) { + Component content = getContent(); + if (content == null) { + return false; + } + if (vertical) { + return !ComponentSizeValidator.checkHeights(content); + } else { + return !ComponentSizeValidator.checkWidths(content); + } + } + + @Override + public void setHeight(float height, Unit unit) { + /* + * child tree repaints may be needed, due to our fall back support for + * invalid relative sizes + */ + boolean dirtyChild = false; + boolean childrenMayBecomeUndefined = false; + if (getHeight() == SIZE_UNDEFINED && height != SIZE_UNDEFINED) { + // children currently in invalid state may need repaint + dirtyChild = getInvalidSizedChild(true); + } else if ((height == SIZE_UNDEFINED && getHeight() != SIZE_UNDEFINED) + || (unit == Unit.PERCENTAGE + && getHeightUnits() != Unit.PERCENTAGE && !ComponentSizeValidator + .parentCanDefineHeight(this))) { + /* + * relative height children may get to invalid state if height + * becomes invalid. Height may also become invalid if units become + * percentage due to the fallback support. + */ + childrenMayBecomeUndefined = true; + dirtyChild = getInvalidSizedChild(true); + } + super.setHeight(height, unit); + repaintChangedChildTree(dirtyChild, childrenMayBecomeUndefined, true); + } + +} diff --git a/server/src/com/vaadin/ui/ComponentContainer.java b/server/src/com/vaadin/ui/ComponentContainer.java index 3663134520..5ef41d7cbf 100644 --- a/server/src/com/vaadin/ui/ComponentContainer.java +++ b/server/src/com/vaadin/ui/ComponentContainer.java @@ -16,9 +16,10 @@ package com.vaadin.ui; -import java.io.Serializable; import java.util.Iterator; +import com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier; + /** * Extension to the {@link Component} interface which adds to it the capacity to * contain other components. All UI elements that can have child elements @@ -27,7 +28,8 @@ import java.util.Iterator; * @author Vaadin Ltd. * @since 3.0 */ -public interface ComponentContainer extends HasComponents { +public interface ComponentContainer extends HasComponents, + ComponentAttachDetachNotifier { /** * Adds the component into this container. @@ -101,14 +103,6 @@ public interface ComponentContainer extends HasComponents { */ public void moveComponentsFrom(ComponentContainer source); - /** - * Listens the component attach events. - * - * @param listener - * the listener to add. - */ - public void addComponentAttachListener(ComponentAttachListener listener); - /** * @deprecated Since 7.0, replaced by * {@link #addComponentAttachListener(ComponentAttachListener)} @@ -116,14 +110,6 @@ public interface ComponentContainer extends HasComponents { @Deprecated public void addListener(ComponentAttachListener listener); - /** - * Stops the listening component attach events. - * - * @param listener - * the listener to removed. - */ - public void removeComponentAttachListener(ComponentAttachListener listener); - /** * @deprecated Since 7.0, replaced by * {@link #removeComponentAttachListener(ComponentAttachListener)} @@ -131,11 +117,6 @@ public interface ComponentContainer extends HasComponents { @Deprecated public void removeListener(ComponentAttachListener listener); - /** - * Listens the component detach events. - */ - public void addComponentDetachListener(ComponentDetachListener listener); - /** * @deprecated Since 7.0, replaced by * {@link #addComponentDetachListener(ComponentDetachListener)} @@ -143,11 +124,6 @@ public interface ComponentContainer extends HasComponents { @Deprecated public void addListener(ComponentDetachListener listener); - /** - * Stops the listening component detach events. - */ - public void removeComponentDetachListener(ComponentDetachListener listener); - /** * @deprecated Since 7.0, replaced by * {@link #removeComponentDetachListener(ComponentDetachListener)} @@ -155,119 +131,4 @@ public interface ComponentContainer extends HasComponents { @Deprecated public void removeListener(ComponentDetachListener listener); - /** - * Component attach listener interface. - */ - public interface ComponentAttachListener extends Serializable { - - /** - * A new component is attached to container. - * - * @param event - * the component attach event. - */ - public void componentAttachedToContainer(ComponentAttachEvent event); - } - - /** - * Component detach listener interface. - */ - public interface ComponentDetachListener extends Serializable { - - /** - * A component has been detached from container. - * - * @param event - * the component detach event. - */ - public void componentDetachedFromContainer(ComponentDetachEvent event); - } - - /** - * Component attach event sent when a component is attached to container. - */ - @SuppressWarnings("serial") - public static class ComponentAttachEvent extends Component.Event { - - private final Component component; - - /** - * Creates a new attach event. - * - * @param container - * the component container the component has been detached - * to. - * @param attachedComponent - * the component that has been attached. - */ - public ComponentAttachEvent(ComponentContainer container, - Component attachedComponent) { - super(container); - component = attachedComponent; - } - - /** - * Gets the component container. - * - * @param the - * component container. - */ - public ComponentContainer getContainer() { - return (ComponentContainer) getSource(); - } - - /** - * Gets the attached component. - * - * @param the - * attach component. - */ - public Component getAttachedComponent() { - return component; - } - } - - /** - * Component detach event sent when a component is detached from container. - */ - @SuppressWarnings("serial") - public static class ComponentDetachEvent extends Component.Event { - - private final Component component; - - /** - * Creates a new detach event. - * - * @param container - * the component container the component has been detached - * from. - * @param detachedComponent - * the component that has been detached. - */ - public ComponentDetachEvent(ComponentContainer container, - Component detachedComponent) { - super(container); - component = detachedComponent; - } - - /** - * Gets the component container. - * - * @param the - * component container. - */ - public ComponentContainer getContainer() { - return (ComponentContainer) getSource(); - } - - /** - * Gets the detached component. - * - * @return the detached component. - */ - public Component getDetachedComponent() { - return component; - } - } - } diff --git a/server/src/com/vaadin/ui/HasComponents.java b/server/src/com/vaadin/ui/HasComponents.java index db0aa1ca8e..4f6320f6b2 100644 --- a/server/src/com/vaadin/ui/HasComponents.java +++ b/server/src/com/vaadin/ui/HasComponents.java @@ -15,8 +15,12 @@ */ package com.vaadin.ui; +import java.io.Serializable; +import java.lang.reflect.Method; import java.util.Iterator; +import com.vaadin.util.ReflectTools; + /** * Interface that must be implemented by all {@link Component}s that contain * other {@link Component}s. @@ -55,4 +59,161 @@ public interface HasComponents extends Component, Iterable { */ public boolean isComponentVisible(Component childComponent); + /** + * Interface for {@link HasComponents} implementations that support sending + * attach and detach events for components. + * + * @since 7.0 + */ + public interface ComponentAttachDetachNotifier extends Serializable { + /** + * Listens the component attach events. + * + * @param listener + * the listener to add. + */ + public void addComponentAttachListener(ComponentAttachListener listener); + + /** + * Stops the listening component attach events. + * + * @param listener + * the listener to removed. + */ + public void removeComponentAttachListener( + ComponentAttachListener listener); + + /** + * Listens the component detach events. + */ + public void addComponentDetachListener(ComponentDetachListener listener); + + /** + * Stops the listening component detach events. + */ + public void removeComponentDetachListener( + ComponentDetachListener listener); + } + + /** + * Component attach listener interface. + */ + public interface ComponentAttachListener extends Serializable { + + public static final Method attachMethod = ReflectTools.findMethod( + ComponentAttachListener.class, "componentAttachedToContainer", + ComponentAttachEvent.class); + + /** + * A new component is attached to container. + * + * @param event + * the component attach event. + */ + public void componentAttachedToContainer(ComponentAttachEvent event); + } + + /** + * Component detach listener interface. + */ + public interface ComponentDetachListener extends Serializable { + + public static final Method detachMethod = ReflectTools.findMethod( + ComponentDetachListener.class, + "componentDetachedFromContainer", ComponentDetachEvent.class); + + /** + * A component has been detached from container. + * + * @param event + * the component detach event. + */ + public void componentDetachedFromContainer(ComponentDetachEvent event); + } + + /** + * Component attach event sent when a component is attached to container. + */ + @SuppressWarnings("serial") + public static class ComponentAttachEvent extends Component.Event { + + private final Component component; + + /** + * Creates a new attach event. + * + * @param container + * the container the component has been detached to. + * @param attachedComponent + * the component that has been attached. + */ + public ComponentAttachEvent(HasComponents container, + Component attachedComponent) { + super(container); + component = attachedComponent; + } + + /** + * Gets the component container. + * + * @param the + * component container. + */ + public HasComponents getContainer() { + return (HasComponents) getSource(); + } + + /** + * Gets the attached component. + * + * @param the + * attach component. + */ + public Component getAttachedComponent() { + return component; + } + } + + /** + * Component detach event sent when a component is detached from container. + */ + @SuppressWarnings("serial") + public static class ComponentDetachEvent extends Component.Event { + + private final Component component; + + /** + * Creates a new detach event. + * + * @param container + * the container the component has been detached from. + * @param detachedComponent + * the component that has been detached. + */ + public ComponentDetachEvent(HasComponents container, + Component detachedComponent) { + super(container); + component = detachedComponent; + } + + /** + * Gets the component container. + * + * @param the + * component container. + */ + public HasComponents getContainer() { + return (HasComponents) getSource(); + } + + /** + * Gets the detached component. + * + * @return the detached component. + */ + public Component getDetachedComponent() { + return component; + } + } + } diff --git a/server/src/com/vaadin/ui/LegacyWindow.java b/server/src/com/vaadin/ui/LegacyWindow.java index 88559af0b5..79d4d0aedb 100644 --- a/server/src/com/vaadin/ui/LegacyWindow.java +++ b/server/src/com/vaadin/ui/LegacyWindow.java @@ -1,6 +1,6 @@ /* @VaadinApache2LicenseForJavaFiles@ -*/ + */ package com.vaadin.ui; @@ -9,16 +9,16 @@ import java.net.URL; import com.vaadin.server.LegacyApplication; import com.vaadin.server.Page; -import com.vaadin.server.Resource; -import com.vaadin.server.VaadinRequest; import com.vaadin.server.Page.BrowserWindowResizeEvent; import com.vaadin.server.Page.BrowserWindowResizeListener; +import com.vaadin.server.Resource; +import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.BorderStyle; /** - * Helper class to emulate the main window from Vaadin 6 using UIs. This - * class should be used in the same way as Window used as a browser level - * window in Vaadin 6 with {@link com.vaadin.server.LegacyApplication} + * Helper class to emulate the main window from Vaadin 6 using UIs. This class + * should be used in the same way as Window used as a browser level window in + * Vaadin 6 with {@link com.vaadin.server.LegacyApplication} */ @Deprecated public class LegacyWindow extends UI { @@ -29,7 +29,8 @@ public class LegacyWindow extends UI { * Create a new legacy window */ public LegacyWindow() { - super(); + super(new VerticalLayout()); + ((VerticalLayout) getContent()).setMargin(true); } /** @@ -39,7 +40,8 @@ public class LegacyWindow extends UI { * the caption of the window */ public LegacyWindow(String caption) { - super(); + super(new VerticalLayout()); + ((VerticalLayout) getContent()).setMargin(true); setCaption(caption); } @@ -71,12 +73,11 @@ public class LegacyWindow extends UI { * Gets the unique name of the window. The name of the window is used to * uniquely identify it. *

- * The name also determines the URL that can be used for direct access - * to a window. All windows can be accessed through - * {@code http://host:port/app/win} where {@code http://host:port/app} - * is the application URL (as returned by - * {@link LegacyApplication#getURL()} and {@code win} is the window - * name. + * The name also determines the URL that can be used for direct access to a + * window. All windows can be accessed through + * {@code http://host:port/app/win} where {@code http://host:port/app} is + * the application URL (as returned by {@link LegacyApplication#getURL()} + * and {@code win} is the window name. *

*

* Note! Portlets do not support direct window access through URLs. @@ -92,12 +93,11 @@ public class LegacyWindow extends UI { * Sets the unique name of the window. The name of the window is used to * uniquely identify it inside the application. *

- * The name also determines the URL that can be used for direct access - * to a window. All windows can be accessed through - * {@code http://host:port/app/win} where {@code http://host:port/app} - * is the application URL (as returned by - * {@link LegacyApplication#getURL()} and {@code win} is the window - * name. + * The name also determines the URL that can be used for direct access to a + * window. All windows can be accessed through + * {@code http://host:port/app/win} where {@code http://host:port/app} is + * the application URL (as returned by {@link LegacyApplication#getURL()} + * and {@code win} is the window name. *

*

* This method can only be called before the window is added to an @@ -107,8 +107,8 @@ public class LegacyWindow extends UI { *

* * @param name - * the new name for the window or null if the application - * should automatically assign a name to it + * the new name for the window or null if the application should + * automatically assign a name to it * @throws IllegalStateException * if the window is attached to an application */ @@ -124,14 +124,14 @@ public class LegacyWindow extends UI { } /** - * Gets the full URL of the window. The returned URL is window specific - * and can be used to directly refer to the window. + * Gets the full URL of the window. The returned URL is window specific and + * can be used to directly refer to the window. *

* Note! This method can not be used for portlets. *

* - * @return the URL of the window or null if the window is not attached - * to an application + * @return the URL of the window or null if the window is not attached to an + * application */ public URL getURL() { LegacyApplication application = getApplication(); @@ -148,8 +148,8 @@ public class LegacyWindow extends UI { } /** - * Opens the given resource in this UI. The contents of this UI is - * replaced by the {@code Resource}. + * Opens the given resource in this UI. The contents of this UI is replaced + * by the {@code Resource}. * * @param resource * the resource to show in this UI @@ -167,41 +167,39 @@ public class LegacyWindow extends UI { * Opens the given resource in a window with the given name. *

* The supplied {@code windowName} is used as the target name in a - * window.open call in the client. This means that special values such - * as "_blank", "_self", "_top", "_parent" have special meaning. An - * empty or null window name is also a special case. + * window.open call in the client. This means that special values such as + * "_blank", "_self", "_top", "_parent" have special meaning. An empty or + * null window name is also a special case. *

*

- * "", null and "_self" as {@code windowName} all causes the resource to - * be opened in the current window, replacing any old contents. For + * "", null and "_self" as {@code windowName} all causes the resource to be + * opened in the current window, replacing any old contents. For * downloadable content you should avoid "_self" as "_self" causes the * client to skip rendering of any other changes as it considers them - * irrelevant (the page will be replaced by the resource). This can - * speed up the opening of a resource, but it might also put the client - * side into an inconsistent state if the window content is not - * completely replaced e.g., if the resource is downloaded instead of - * displayed in the browser. + * irrelevant (the page will be replaced by the resource). This can speed up + * the opening of a resource, but it might also put the client side into an + * inconsistent state if the window content is not completely replaced e.g., + * if the resource is downloaded instead of displayed in the browser. *

*

- * "_blank" as {@code windowName} causes the resource to always be - * opened in a new window or tab (depends on the browser and browser - * settings). + * "_blank" as {@code windowName} causes the resource to always be opened in + * a new window or tab (depends on the browser and browser settings). *

*

- * "_top" and "_parent" as {@code windowName} works as specified by the - * HTML standard. + * "_top" and "_parent" as {@code windowName} works as specified by the HTML + * standard. *

*

- * Any other {@code windowName} will open the resource in a window with - * that name, either by opening a new window/tab in the browser or by - * replacing the contents of an existing window with that name. + * Any other {@code windowName} will open the resource in a window with that + * name, either by opening a new window/tab in the browser or by replacing + * the contents of an existing window with that name. *

*

- * As of Vaadin 7.0.0, the functionality for opening a Resource in a - * Page has been replaced with similar methods based on a String URL. - * This is because the usage of Resource is problematic with memory - * management and with security features in some browsers. Is is - * recommended to instead use {@link Link} for starting downloads. + * As of Vaadin 7.0.0, the functionality for opening a Resource in a Page + * has been replaced with similar methods based on a String URL. This is + * because the usage of Resource is problematic with memory management and + * with security features in some browsers. Is is recommended to instead use + * {@link Link} for starting downloads. *

* * @param resource @@ -220,11 +218,11 @@ public class LegacyWindow extends UI { * name. For more information on the meaning of {@code windowName}, see * {@link #open(Resource, String)}. *

- * As of Vaadin 7.0.0, the functionality for opening a Resource in a - * Page has been replaced with similar methods based on a String URL. - * This is because the usage of Resource is problematic with memory - * management and with security features in some browsers. Is is - * recommended to instead use {@link Link} for starting downloads. + * As of Vaadin 7.0.0, the functionality for opening a Resource in a Page + * has been replaced with similar methods based on a String URL. This is + * because the usage of Resource is problematic with memory management and + * with security features in some browsers. Is is recommended to instead use + * {@link Link} for starting downloads. *

* * @param resource @@ -246,9 +244,9 @@ public class LegacyWindow extends UI { } /** - * Adds a new {@link BrowserWindowResizeListener} to this UI. The - * listener will be notified whenever the browser window within which - * this UI resides is resized. + * Adds a new {@link BrowserWindowResizeListener} to this UI. The listener + * will be notified whenever the browser window within which this UI resides + * is resized. * * @param resizeListener * the listener to add @@ -264,9 +262,8 @@ public class LegacyWindow extends UI { } /** - * Removes a {@link BrowserWindowResizeListener} from this UI. The - * listener will no longer be notified when the browser window is - * resized. + * Removes a {@link BrowserWindowResizeListener} from this UI. The listener + * will no longer be notified when the browser window is resized. * * @param resizeListener * the listener to remove @@ -290,8 +287,7 @@ public class LegacyWindow extends UI { } /** - * Gets the last known width of the browser window in which this UI - * resides. + * Gets the last known width of the browser window in which this UI resides. * * @return the browser window width in pixels * @@ -306,18 +302,17 @@ public class LegacyWindow extends UI { * Executes JavaScript in this window. * *

- * This method allows one to inject javascript from the server to - * client. A client implementation is not required to implement this - * functionality, but currently all web-based clients do implement this. + * This method allows one to inject javascript from the server to client. A + * client implementation is not required to implement this functionality, + * but currently all web-based clients do implement this. *

* *

- * Executing javascript this way often leads to cross-browser - * compatibility issues and regressions that are hard to resolve. Use of - * this method should be avoided and instead it is recommended to create - * new widgets with GWT. For more info on creating own, reusable - * client-side widgets in Java, read the corresponding chapter in Book - * of Vaadin. + * Executing javascript this way often leads to cross-browser compatibility + * issues and regressions that are hard to resolve. Use of this method + * should be avoided and instead it is recommended to create new widgets + * with GWT. For more info on creating own, reusable client-side widgets in + * Java, read the corresponding chapter in Book of Vaadin. *

* * @param script @@ -338,4 +333,77 @@ public class LegacyWindow extends UI { getPage().setTitle(caption); } + @Override + public ComponentContainer getContent() { + return (ComponentContainer) super.getContent(); + } + + /** + * Set the content of the window. For a {@link LegacyWindow}, the content + * must be a {@link ComponentContainer}. + * + * @param content + */ + @Override + public void setContent(Component content) { + if (!(content instanceof ComponentContainer)) { + throw new IllegalArgumentException( + "The content of a LegacyWindow must be a ComponentContainer"); + } + super.setContent(content); + } + + /** + * This implementation replaces a component in the content container ( + * {@link #getContent()}) instead of in the actual UI. + * + * This method should only be called when the content is a + * {@link ComponentContainer} (default {@link VerticalLayout} or explicitly + * set). + */ + public void replaceComponent(Component oldComponent, Component newComponent) { + getContent().replaceComponent(oldComponent, newComponent); + } + + /** + * Adds a component to this UI. The component is not added directly to the + * UI, but instead to the content container ({@link #getContent()}). + * + * This method should only be called when the content is a + * {@link ComponentContainer} (default {@link VerticalLayout} or explicitly + * set). + * + * @param component + * the component to add to this UI + * + * @see #getContent() + */ + public void addComponent(Component component) { + getContent().addComponent(component); + } + + /** + * This implementation removes the component from the content container ( + * {@link #getContent()}) instead of from the actual UI. + * + * This method should only be called when the content is a + * {@link ComponentContainer} (default {@link VerticalLayout} or explicitly + * set). + */ + public void removeComponent(Component component) { + getContent().removeComponent(component); + } + + /** + * This implementation removes the components from the content container ( + * {@link #getContent()}) instead of from the actual UI. + * + * This method should only be called when the content is a + * {@link ComponentContainer} (default {@link VerticalLayout} or explicitly + * set). + */ + public void removeAllComponents() { + getContent().removeAllComponents(); + } + } \ No newline at end of file diff --git a/server/src/com/vaadin/ui/SingleComponentContainer.java b/server/src/com/vaadin/ui/SingleComponentContainer.java new file mode 100644 index 0000000000..deb647e5eb --- /dev/null +++ b/server/src/com/vaadin/ui/SingleComponentContainer.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012 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.ui; + +import com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier; + +/** + * Interface for component containers that have one child component and do not + * support adding or removing components. + * + * For component containers that support multiple children, see + * {@link ComponentContainer} instead. + * + * @since 7.0 + */ +public interface SingleComponentContainer extends HasComponents, + ComponentAttachDetachNotifier { + + /** + * Gets the number of children this {@link SingleComponentContainer} has. + * This must be symmetric with what {@link #iterator()} returns and thus + * typically return 1 if the content is set, 0 otherwise. + * + * @return The number of child components this container has. + */ + public int getComponentCount(); + + /** + * Gets the content of this container. The content is a component that + * serves as the outermost item of the visual contents. + * + * @return a component to use as content + * + * @see #setContent(Component) + */ + public Component getContent(); + + /** + * Sets the content of this container. The content is a component that + * serves as the outermost item of the visual contents. + * + * The content should always be set, either as a constructor parameter or by + * calling this method. + * + * @return a component (typically a layout) to use as content + */ + public void setContent(Component content); + +} diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index d2f323e5fe..e4cee9386a 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -69,9 +69,9 @@ import com.vaadin.util.ReflectTools; * After a UI has been created by the application, it is initialized using * {@link #init(VaadinRequest)}. This method is intended to be overridden by the * developer to add components to the user interface and initialize - * non-component functionality. The component hierarchy is initialized by - * passing a {@link ComponentContainer} with the main layout of the view to - * {@link #setContent(ComponentContainer)}. + * non-component functionality. The component hierarchy must be initialized by + * passing a {@link Component} with the main layout or other content of the view + * to {@link #setContent(Component)} or to the constructor of the UI. *

* * @see #init(VaadinRequest) @@ -79,7 +79,7 @@ import com.vaadin.util.ReflectTools; * * @since 7.0 */ -public abstract class UI extends AbstractComponentContainer implements +public abstract class UI extends AbstractSingleComponentContainer implements Action.Container, Action.Notifier, LegacyComponent { /** @@ -178,22 +178,23 @@ public abstract class UI extends AbstractComponentContainer implements private long lastUidlRequest = System.currentTimeMillis(); /** - * Creates a new empty UI without a caption. This UI will have a - * {@link VerticalLayout} with margins enabled as its content. + * Creates a new empty UI without a caption. The content of the UI must be + * set by calling {@link #setContent(Component)} before using the UI. */ public UI() { - this((ComponentContainer) null); + this(null); } /** - * Creates a new UI with the given component container as its content. + * Creates a new UI with the given component (often a layout) as its + * content. * * @param content - * the content container to use as this UIs content. + * the component to use as this UIs content. * - * @see #setContent(ComponentContainer) + * @see #setContent(Component) */ - public UI(ComponentContainer content) { + public UI(Component content) { registerRpc(rpc); setSizeFull(); setContent(content); @@ -223,15 +224,6 @@ public abstract class UI extends AbstractComponentContainer implements return this; } - /** - * This implementation replaces a component in the content container ( - * {@link #getContent()}) instead of in the actual UI. - */ - @Override - public void replaceComponent(Component oldComponent, Component newComponent) { - getContent().replaceComponent(oldComponent, newComponent); - } - /** * Gets the application object to which the component is attached. * @@ -330,7 +322,7 @@ public abstract class UI extends AbstractComponentContainer implements /* * (non-Javadoc) * - * @see com.vaadin.ui.ComponentContainer#getComponentIterator() + * @see com.vaadin.ui.HasComponents#iterator() */ @Override public Iterator iterator() { @@ -540,89 +532,6 @@ public abstract class UI extends AbstractComponentContainer implements markAsDirty(); } - /** - * Gets the content of this UI. The content is a component container that - * serves as the outermost item of the visual contents of this UI. - * - * @return a component container to use as content - * - * @see #setContent(ComponentContainer) - * @see #createDefaultLayout() - */ - public ComponentContainer getContent() { - return (ComponentContainer) getState().content; - } - - /** - * Helper method to create the default content layout that is used if no - * content has not been explicitly defined. - * - * @return a newly created layout - */ - private static VerticalLayout createDefaultLayout() { - VerticalLayout layout = new VerticalLayout(); - layout.setMargin(true); - return layout; - } - - /** - * Sets the content of this UI. The content is a component container that - * serves as the outermost item of the visual contents of this UI. If no - * content has been set, a {@link VerticalLayout} with margins enabled will - * be used by default - see {@link #createDefaultLayout()}. The content can - * also be set in a constructor. - * - * @return a component container to use as content - * - * @see #UI(ComponentContainer) - * @see #createDefaultLayout() - */ - public void setContent(ComponentContainer content) { - if (content == null) { - content = createDefaultLayout(); - } - - if (getState().content != null) { - super.removeComponent((Component) getState().content); - } - getState().content = content; - if (content != null) { - super.addComponent(content); - } - } - - /** - * Adds a component to this UI. The component is not added directly to the - * UI, but instead to the content container ({@link #getContent()}). - * - * @param component - * the component to add to this UI - * - * @see #getContent() - */ - @Override - public void addComponent(Component component) { - getContent().addComponent(component); - } - - /** - * This implementation removes the component from the content container ( - * {@link #getContent()}) instead of from the actual UI. - */ - @Override - public void removeComponent(Component component) { - getContent().removeComponent(component); - } - - /** - * This implementation removes the components from the content container ( - * {@link #getContent()}) instead of from the actual UI. - */ - @Override - public void removeAllComponents() { - getContent().removeAllComponents(); - } - /** * Internal initialization method, should not be overridden. This method is * not declared as final because that would break compatibility with e.g. diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractcomponentcontainer/TestAbstractComponentContainerListeners.java b/server/tests/src/com/vaadin/tests/server/component/abstractcomponentcontainer/TestAbstractComponentContainerListeners.java index f9f170eb2a..9763354b57 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractcomponentcontainer/TestAbstractComponentContainerListeners.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractcomponentcontainer/TestAbstractComponentContainerListeners.java @@ -1,10 +1,10 @@ package com.vaadin.tests.server.component.abstractcomponentcontainer; import com.vaadin.tests.server.component.AbstractListenerMethodsTest; -import com.vaadin.ui.ComponentContainer.ComponentAttachEvent; -import com.vaadin.ui.ComponentContainer.ComponentAttachListener; -import com.vaadin.ui.ComponentContainer.ComponentDetachEvent; -import com.vaadin.ui.ComponentContainer.ComponentDetachListener; +import com.vaadin.ui.HasComponents.ComponentAttachEvent; +import com.vaadin.ui.HasComponents.ComponentAttachListener; +import com.vaadin.ui.HasComponents.ComponentDetachEvent; +import com.vaadin.ui.HasComponents.ComponentDetachListener; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.VerticalLayout; diff --git a/server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java b/server/tests/src/com/vaadin/tests/server/component/ui/LegacyUIAddRemoveComponents.java similarity index 86% rename from server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java rename to server/tests/src/com/vaadin/tests/server/component/ui/LegacyUIAddRemoveComponents.java index 1b07321605..1a5e19e0da 100644 --- a/server/tests/src/com/vaadin/tests/server/component/ui/UIAddRemoveComponents.java +++ b/server/tests/src/com/vaadin/tests/server/component/ui/LegacyUIAddRemoveComponents.java @@ -9,11 +9,11 @@ import org.junit.Test; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Component; import com.vaadin.ui.Label; -import com.vaadin.ui.UI; +import com.vaadin.ui.LegacyWindow; -public class UIAddRemoveComponents { +public class LegacyUIAddRemoveComponents { - private static class TestUI extends UI { + private static class TestUI extends LegacyWindow { @Override protected void init(VaadinRequest request) { } @@ -21,7 +21,7 @@ public class UIAddRemoveComponents { @Test public void addComponent() { - UI ui = new TestUI(); + TestUI ui = new TestUI(); Component c = new Label("abc"); ui.addComponent(c); @@ -34,7 +34,7 @@ public class UIAddRemoveComponents { @Test public void removeComponent() { - UI ui = new TestUI(); + TestUI ui = new TestUI(); Component c = new Label("abc"); ui.addComponent(c); @@ -49,7 +49,7 @@ public class UIAddRemoveComponents { @Test public void replaceComponent() { - UI ui = new TestUI(); + TestUI ui = new TestUI(); Component c = new Label("abc"); Component d = new Label("def"); diff --git a/server/tests/src/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java b/server/tests/src/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java index 3ba1c4c7f1..df515795eb 100644 --- a/server/tests/src/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java +++ b/server/tests/src/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java @@ -8,14 +8,14 @@ import com.vaadin.ui.AbsoluteLayout; import com.vaadin.ui.AbsoluteLayout.ComponentPosition; import com.vaadin.ui.AbstractOrderedLayout; import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer; -import com.vaadin.ui.ComponentContainer.ComponentAttachEvent; -import com.vaadin.ui.ComponentContainer.ComponentAttachListener; -import com.vaadin.ui.ComponentContainer.ComponentDetachEvent; -import com.vaadin.ui.ComponentContainer.ComponentDetachListener; import com.vaadin.ui.CssLayout; import com.vaadin.ui.GridLayout; import com.vaadin.ui.GridLayout.Area; +import com.vaadin.ui.HasComponents; +import com.vaadin.ui.HasComponents.ComponentAttachEvent; +import com.vaadin.ui.HasComponents.ComponentAttachListener; +import com.vaadin.ui.HasComponents.ComponentDetachEvent; +import com.vaadin.ui.HasComponents.ComponentDetachListener; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; @@ -29,12 +29,12 @@ public class ComponentAttachDetachListenerTest extends TestCase { // General variables private int attachCounter = 0; private Component attachedComponent = null; - private ComponentContainer attachTarget = null; + private HasComponents attachTarget = null; private boolean foundInContainer = false; private int detachCounter = 0; private Component detachedComponent = null; - private ComponentContainer detachedTarget = null; + private HasComponents detachedTarget = null; // Ordered layout specific variables private int indexOfComponent = -1; @@ -53,7 +53,7 @@ public class ComponentAttachDetachListenerTest extends TestCase { attachTarget = event.getContainer(); // Search for component in container (should be found) - Iterator iter = attachTarget.getComponentIterator(); + Iterator iter = attachTarget.iterator(); while (iter.hasNext()) { if (iter.next() == attachedComponent) { foundInContainer = true; @@ -83,7 +83,7 @@ public class ComponentAttachDetachListenerTest extends TestCase { detachedTarget = event.getContainer(); // Search for component in container (should NOT be found) - Iterator iter = detachedTarget.getComponentIterator(); + Iterator iter = detachedTarget.iterator(); while (iter.hasNext()) { if (iter.next() == detachedComponent) { foundInContainer = true; @@ -129,20 +129,20 @@ public class ComponentAttachDetachListenerTest extends TestCase { super.setUp(); olayout = new HorizontalLayout(); - olayout.addListener(new MyAttachListener()); - olayout.addListener(new MyDetachListener()); + olayout.addComponentAttachListener(new MyAttachListener()); + olayout.addComponentDetachListener(new MyDetachListener()); gridlayout = new GridLayout(); - gridlayout.addListener(new MyAttachListener()); - gridlayout.addListener(new MyDetachListener()); + gridlayout.addComponentAttachListener(new MyAttachListener()); + gridlayout.addComponentDetachListener(new MyDetachListener()); absolutelayout = new AbsoluteLayout(); - absolutelayout.addListener(new MyAttachListener()); - absolutelayout.addListener(new MyDetachListener()); + absolutelayout.addComponentAttachListener(new MyAttachListener()); + absolutelayout.addComponentDetachListener(new MyDetachListener()); csslayout = new CssLayout(); - csslayout.addListener(new MyAttachListener()); - csslayout.addListener(new MyDetachListener()); + csslayout.addComponentAttachListener(new MyAttachListener()); + csslayout.addComponentDetachListener(new MyDetachListener()); } public void testOrderedLayoutAttachListener() { diff --git a/server/tests/src/com/vaadin/ui/LabelDataSource.java b/server/tests/src/com/vaadin/ui/LabelDataSource.java index 506a635814..7ef8d67c2a 100644 --- a/server/tests/src/com/vaadin/ui/LabelDataSource.java +++ b/server/tests/src/com/vaadin/ui/LabelDataSource.java @@ -122,7 +122,7 @@ public class LabelDataSource { label.setPropertyDataSource(integerDataSource); UI ui = new MockUI(); ui.setLocale(Locale.GERMANY); - ui.addComponent(label); + ui.setContent(label); Assert.assertEquals(INTEGER_STRING_VALUE_DE, label.getState().text); } } diff --git a/shared/src/com/vaadin/shared/ui/ui/UIState.java b/shared/src/com/vaadin/shared/ui/ui/UIState.java index 6bbfeb18e1..c734ee5d0b 100644 --- a/shared/src/com/vaadin/shared/ui/ui/UIState.java +++ b/shared/src/com/vaadin/shared/ui/ui/UIState.java @@ -16,8 +16,6 @@ package com.vaadin.shared.ui.ui; import com.vaadin.shared.ComponentState; -import com.vaadin.shared.Connector; public class UIState extends ComponentState { - public Connector content; } \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/Components.java b/uitest/src/com/vaadin/tests/Components.java index de408104ae..7f024e774a 100644 --- a/uitest/src/com/vaadin/tests/Components.java +++ b/uitest/src/com/vaadin/tests/Components.java @@ -22,7 +22,6 @@ import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.components.AbstractComponentTest; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.Embedded; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Label; @@ -256,7 +255,7 @@ public class Components extends LegacyApplication { try { AbstractComponentTest t = cls.newInstance(); t.init(); - ComponentContainer c = t.getMainWindow().getContent(); + Component c = t.getMainWindow().getContent(); t.getMainWindow().setContent(null); return c; } catch (InstantiationException e) { diff --git a/uitest/src/com/vaadin/tests/ScrollbarStressTest.java b/uitest/src/com/vaadin/tests/ScrollbarStressTest.java index c671c5aa71..c72817ac41 100644 --- a/uitest/src/com/vaadin/tests/ScrollbarStressTest.java +++ b/uitest/src/com/vaadin/tests/ScrollbarStressTest.java @@ -126,7 +126,7 @@ public class ScrollbarStressTest extends LegacyApplication { el.addComponent(ol); - main.getContent().addComponent(el); + main.addComponent(el); main.removeWindow(subwindow); } diff --git a/uitest/src/com/vaadin/tests/application/DeploymentConfigurationTest.java b/uitest/src/com/vaadin/tests/application/DeploymentConfigurationTest.java index 9c89254bd7..799622b31d 100644 --- a/uitest/src/com/vaadin/tests/application/DeploymentConfigurationTest.java +++ b/uitest/src/com/vaadin/tests/application/DeploymentConfigurationTest.java @@ -5,15 +5,20 @@ import java.util.Properties; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Label; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; public class DeploymentConfigurationTest extends UI { @Override protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + Properties params = getSession().getConfiguration().getInitParameters(); for (Object key : params.keySet()) { - addComponent(new Label(key + ": " + layout.addComponent(new Label(key + ": " + params.getProperty((String) key))); } } diff --git a/uitest/src/com/vaadin/tests/components/AbstractComponentContainerTest.java b/uitest/src/com/vaadin/tests/components/AbstractComponentContainerTest.java index be3b7760f2..146e996eaf 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractComponentContainerTest.java +++ b/uitest/src/com/vaadin/tests/components/AbstractComponentContainerTest.java @@ -7,10 +7,10 @@ import java.util.LinkedHashMap; import com.vaadin.ui.AbstractComponentContainer; import com.vaadin.ui.Button; import com.vaadin.ui.Component; -import com.vaadin.ui.ComponentContainer.ComponentAttachEvent; -import com.vaadin.ui.ComponentContainer.ComponentAttachListener; -import com.vaadin.ui.ComponentContainer.ComponentDetachEvent; -import com.vaadin.ui.ComponentContainer.ComponentDetachListener; +import com.vaadin.ui.HasComponents.ComponentAttachEvent; +import com.vaadin.ui.HasComponents.ComponentAttachListener; +import com.vaadin.ui.HasComponents.ComponentDetachEvent; +import com.vaadin.ui.HasComponents.ComponentDetachListener; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.InlineDateField; import com.vaadin.ui.NativeButton; diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java index 480fd2df57..a044b52f18 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java @@ -17,10 +17,14 @@ public abstract class AbstractTestUI extends UI { Label label = new Label(getTestDescription(), ContentMode.HTML); label.setWidth("100%"); + VerticalLayout rootLayout = new VerticalLayout(); + rootLayout.setMargin(true); + setContent(rootLayout); + layout = new VerticalLayout(); - getContent().addComponent(label); - getContent().addComponent(layout); + rootLayout.addComponent(label); + rootLayout.addComponent(layout); ((VerticalLayout) getContent()).setExpandRatio(layout, 1); setup(request); @@ -34,17 +38,14 @@ public abstract class AbstractTestUI extends UI { protected abstract void setup(VaadinRequest request); - @Override public void addComponent(Component c) { getLayout().addComponent(c); } - @Override public void removeComponent(Component c) { getLayout().removeComponent(c); } - @Override public void replaceComponent(Component oldComponent, Component newComponent) { getLayout().replaceComponent(oldComponent, newComponent); } diff --git a/uitest/src/com/vaadin/tests/components/LayoutAttachListenerInfo.java b/uitest/src/com/vaadin/tests/components/LayoutAttachListenerInfo.java index 6e54c0d9f4..b815705883 100644 --- a/uitest/src/com/vaadin/tests/components/LayoutAttachListenerInfo.java +++ b/uitest/src/com/vaadin/tests/components/LayoutAttachListenerInfo.java @@ -7,9 +7,9 @@ import com.vaadin.data.Property.ValueChangeListener; import com.vaadin.ui.AbsoluteLayout; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.ComponentContainer; -import com.vaadin.ui.ComponentContainer.ComponentAttachEvent; import com.vaadin.ui.GridLayout; +import com.vaadin.ui.HasComponents.ComponentAttachEvent; +import com.vaadin.ui.HasComponents.ComponentAttachListener; import com.vaadin.ui.Label; import com.vaadin.ui.Notification; import com.vaadin.ui.OptionGroup; @@ -26,7 +26,7 @@ public class LayoutAttachListenerInfo extends TestBase { "AbsoluteLayout", "OrderedLayout", "GridLayout")); layouts.select("AbsoluteLayout"); layouts.setImmediate(true); - layouts.addListener(new ValueChangeListener() { + layouts.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { if (event.getProperty().getValue().equals("AbsoluteLayout")) { @@ -64,7 +64,7 @@ public class LayoutAttachListenerInfo extends TestBase { final AbsoluteLayout a = new AbsoluteLayout(); a.setWidth("300px"); a.setHeight("300px"); - a.addListener(new ComponentContainer.ComponentAttachListener() { + a.addComponentAttachListener(new ComponentAttachListener() { @Override public void componentAttachedToContainer(ComponentAttachEvent event) { AbsoluteLayout layout = (AbsoluteLayout) event.getContainer(); @@ -93,7 +93,7 @@ public class LayoutAttachListenerInfo extends TestBase { final VerticalLayout v = new VerticalLayout(); v.setWidth("300px"); v.setHeight("300px"); - v.addListener(new ComponentContainer.ComponentAttachListener() { + v.addComponentAttachListener(new ComponentAttachListener() { @Override public void componentAttachedToContainer(ComponentAttachEvent event) { VerticalLayout layout = (VerticalLayout) event.getContainer(); @@ -122,7 +122,7 @@ public class LayoutAttachListenerInfo extends TestBase { final GridLayout g = new GridLayout(4, 4); g.setWidth("300px"); g.setHeight("300px"); - g.addListener(new ComponentContainer.ComponentAttachListener() { + g.addComponentAttachListener(new ComponentAttachListener() { @Override public void componentAttachedToContainer(ComponentAttachEvent event) { GridLayout layout = (GridLayout) event.getContainer(); diff --git a/uitest/src/com/vaadin/tests/components/TestBase.java b/uitest/src/com/vaadin/tests/components/TestBase.java index 08e39f7e6f..b500a1144b 100644 --- a/uitest/src/com/vaadin/tests/components/TestBase.java +++ b/uitest/src/com/vaadin/tests/components/TestBase.java @@ -16,10 +16,10 @@ public abstract class TestBase extends AbstractTestCase { Label label = new Label(getDescription(), ContentMode.HTML); label.setWidth("100%"); - window.getContent().addComponent(label); + window.addComponent(label); layout = new VerticalLayout(); - window.getContent().addComponent(layout); + window.addComponent(layout); ((VerticalLayout) window.getContent()).setExpandRatio(layout, 1); setup(); diff --git a/uitest/src/com/vaadin/tests/components/abstractcomponent/AllComponentTooltipTest.java b/uitest/src/com/vaadin/tests/components/abstractcomponent/AllComponentTooltipTest.java index 3473f50ee5..4b2b1f81ce 100644 --- a/uitest/src/com/vaadin/tests/components/abstractcomponent/AllComponentTooltipTest.java +++ b/uitest/src/com/vaadin/tests/components/abstractcomponent/AllComponentTooltipTest.java @@ -27,7 +27,8 @@ public class AllComponentTooltipTest extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { - setContent(new GridLayout(5, 5)); + GridLayout layout = new GridLayout(5, 5); + setContent(layout); for (Class cls : VaadinClasses.getComponents()) { try { AbstractComponent c = (AbstractComponent) cls.newInstance(); @@ -40,7 +41,7 @@ public class AllComponentTooltipTest extends AbstractTestUI { c.setDescription(cls.getName()); c.setWidth("100px"); c.setHeight("100px"); - getContent().addComponent(c); + layout.addComponent(c); System.out.println("Added " + cls.getName()); } catch (Exception e) { System.err.println("Could not instatiate " + cls.getName()); diff --git a/uitest/src/com/vaadin/tests/components/menubar/MenuBarRunsOutOfBrowser.java b/uitest/src/com/vaadin/tests/components/menubar/MenuBarRunsOutOfBrowser.java index 78c6d92ee2..0d9c3d8bba 100644 --- a/uitest/src/com/vaadin/tests/components/menubar/MenuBarRunsOutOfBrowser.java +++ b/uitest/src/com/vaadin/tests/components/menubar/MenuBarRunsOutOfBrowser.java @@ -23,7 +23,7 @@ public class MenuBarRunsOutOfBrowser extends AbstractTestCase { menuBar.addItem("ABC", new ThemeResource("icons/16/document.png"), null); menuBar.addItem("123", new ThemeResource("icons/16/help.png"), null); - main.getContent().addComponent(menuBar); + main.addComponent(menuBar); ((VerticalLayout) main.getContent()).setComponentAlignment(menuBar, Alignment.TOP_RIGHT); diff --git a/uitest/src/com/vaadin/tests/components/table/TableInTabsheet.java b/uitest/src/com/vaadin/tests/components/table/TableInTabsheet.java index a9cecfd6b5..ee9609bb96 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableInTabsheet.java +++ b/uitest/src/com/vaadin/tests/components/table/TableInTabsheet.java @@ -18,7 +18,6 @@ public class TableInTabsheet extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { - getUI().setCaption("test"); VerticalLayout vPrinc = new VerticalLayout(); vPrinc.setStyleName(Reindeer.LAYOUT_BLUE); diff --git a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java index 1064f2e766..57fc9f3e62 100644 --- a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java +++ b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java @@ -11,6 +11,7 @@ import com.vaadin.tests.components.AbstractTestUIProvider; import com.vaadin.ui.Label; import com.vaadin.ui.Link; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; public class LazyInitUIs extends AbstractTestUIProvider { @@ -18,7 +19,11 @@ public class LazyInitUIs extends AbstractTestUIProvider { private static class EagerInitUI extends UI { @Override public void init(VaadinRequest request) { - addComponent(getRequestInfo("EagerInitUI", request)); + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + + layout.addComponent(getRequestInfo("EagerInitUI", request)); } } @@ -39,7 +44,11 @@ public class LazyInitUIs extends AbstractTestUIProvider { UI uI = new UI() { @Override protected void init(VaadinRequest request) { - addComponent(getRequestInfo("LazyCreateUI", request)); + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + + layout.addComponent(getRequestInfo("LazyCreateUI", request)); } }; return uI; @@ -51,20 +60,24 @@ public class LazyInitUIs extends AbstractTestUIProvider { UI uI = new UI() { @Override protected void init(VaadinRequest request) { - addComponent(getRequestInfo("NormalUI", request)); + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + + layout.addComponent(getRequestInfo("NormalUI", request)); String location = getPage().getLocation().toString(); Link lazyCreateLink = new Link("Open lazyCreate UI", new ExternalResource(location.replaceFirst( "(\\?|#|$).*", "?lazyCreate#lazyCreate"))); lazyCreateLink.setTargetName("_blank"); - addComponent(lazyCreateLink); + layout.addComponent(lazyCreateLink); Link lazyInitLink = new Link("Open eagerInit UI", new ExternalResource(location.replaceFirst( "(\\?|#|$).*", "?eagerInit#eagerInit"))); lazyInitLink.setTargetName("_blank"); - addComponent(lazyInitLink); + layout.addComponent(lazyInitLink); } }; diff --git a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java index 8c4ba3980d..53df69f028 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java +++ b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java @@ -9,6 +9,7 @@ import com.vaadin.server.VaadinServiceSession; import com.vaadin.tests.components.AbstractTestUIProvider; import com.vaadin.ui.Label; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; public class UIsInMultipleTabs extends AbstractTestUIProvider { // No cleanup -> will leak, but shouldn't matter for tests @@ -29,7 +30,11 @@ public class UIsInMultipleTabs extends AbstractTestUIProvider { int currentCount = count.incrementAndGet(); String message = "This is UI number " + currentCount; - addComponent(new Label(message)); + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + + layout.addComponent(new Label(message)); } } diff --git a/uitest/src/com/vaadin/tests/components/window/SubWindowFocusAndBlurListeners.java b/uitest/src/com/vaadin/tests/components/window/SubWindowFocusAndBlurListeners.java index bb247ee065..bb5a817362 100644 --- a/uitest/src/com/vaadin/tests/components/window/SubWindowFocusAndBlurListeners.java +++ b/uitest/src/com/vaadin/tests/components/window/SubWindowFocusAndBlurListeners.java @@ -10,6 +10,7 @@ import com.vaadin.event.ShortcutAction; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.ComponentContainer; import com.vaadin.ui.Notification; import com.vaadin.ui.TextField; import com.vaadin.ui.UI; @@ -68,7 +69,7 @@ public class SubWindowFocusAndBlurListeners extends TestBase { main.addWindow(window); - main.addComponent(new TextField()); + ((ComponentContainer) main.getContent()).addComponent(new TextField()); Button button = new Button("Bring to front (should focus too)", new Button.ClickListener() { @@ -77,7 +78,7 @@ public class SubWindowFocusAndBlurListeners extends TestBase { window.bringToFront(); } }); - main.addComponent(button); + ((ComponentContainer) main.getContent()).addComponent(button); Window window2 = new Window("Another window for testing"); main.addWindow(window2); diff --git a/uitest/src/com/vaadin/tests/integration/IntegrationTestUI.java b/uitest/src/com/vaadin/tests/integration/IntegrationTestUI.java index 61214ede8c..0e6cb19b30 100755 --- a/uitest/src/com/vaadin/tests/integration/IntegrationTestUI.java +++ b/uitest/src/com/vaadin/tests/integration/IntegrationTestUI.java @@ -9,10 +9,15 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Label; import com.vaadin.ui.Table; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; public class IntegrationTestUI extends UI { @Override protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + final Table table = new Table(); table.addContainerProperty("icon", Resource.class, null); table.setItemIconPropertyId("icon"); @@ -21,7 +26,7 @@ public class IntegrationTestUI extends UI { table.setImmediate(true); table.setSelectable(true); table.setVisibleColumns(new Object[] { "country" }); - addComponent(table); + layout.addComponent(table); Item item = table.addItem("FI"); item.getItemProperty("icon").setValue(new ClassResource("fi.gif")); @@ -37,6 +42,6 @@ public class IntegrationTestUI extends UI { selectedLabel.setValue(String.valueOf(table.getValue())); } }); - addComponent(selectedLabel); + layout.addComponent(selectedLabel); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java index 4111f6c07a..53d76a251f 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java @@ -21,6 +21,7 @@ import com.vaadin.data.fieldgroup.FieldGroup; import com.vaadin.data.util.BeanItem; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; /** * Mini tutorial code for @@ -34,6 +35,10 @@ public class AutoGeneratingForm extends UI { @Override protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + FieldGroup fieldGroup = new BeanFieldGroup(Person.class); // We need an item data source before we create the fields to be able to @@ -44,7 +49,7 @@ public class AutoGeneratingForm extends UI { // Loop through the properties, build fields for them and add the fields // to this root for (Object propertyId : fieldGroup.getUnboundPropertyIds()) { - addComponent(fieldGroup.buildAndBind(propertyId)); + layout.addComponent(fieldGroup.buildAndBind(propertyId)); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java index ffe1f09216..66de5af27e 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java @@ -37,7 +37,7 @@ public class CreatingPreserveState extends UI { public void init(VaadinRequest request) { TextField tf = new TextField("Window #" + (++windowCounter)); tf.setImmediate(true); - getContent().addComponent(tf); + setContent(tf); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java index 737de10894..6a713c4f64 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java @@ -59,8 +59,7 @@ public class DifferentFeaturesForDifferentClients extends UIProvider { class DefaultRoot extends UI { @Override protected void init(VaadinRequest request) { - getContent().addComponent( - new Label("This browser does not support touch events")); + setContent(new Label("This browser does not support touch events")); } } @@ -70,8 +69,7 @@ class TouchRoot extends UI { WebBrowser webBrowser = getSession().getBrowser(); String screenSize = "" + webBrowser.getScreenWidth() + "x" + webBrowser.getScreenHeight(); - getContent().addComponent( - new Label("Using a touch enabled device with screen size" - + screenSize)); + setContent(new Label("Using a touch enabled device with screen size" + + screenSize)); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java index 61cbd94f3a..a84a2206ef 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java @@ -25,7 +25,7 @@ public class DynamicImageUI extends AbstractTestUI { // Add an image using the resource Image image = new Image("A dynamically generated image", resource); - getContent().addComponent(image); + addComponent(image); } @Override diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java index ebacb2f672..ba7ef78ec1 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java @@ -55,7 +55,7 @@ public class FindCurrentUI extends UI { } }); - addComponent(helloButton); + setContent(helloButton); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingBeanValidation.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingBeanValidation.java index 51c7cbbe60..fa0a8e8c31 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingBeanValidation.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingBeanValidation.java @@ -77,7 +77,7 @@ public class UsingBeanValidation extends UI { TextField firstName = new TextField("First name", item.getItemProperty("name")); firstName.setImmediate(true); - addComponent(firstName); + setContent(firstName); firstName.addValidator(new BeanValidator(Person.class, "name")); } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingUriFragments.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingUriFragments.java index 15c4fa838e..f3bef99e65 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingUriFragments.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingUriFragments.java @@ -23,6 +23,7 @@ import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Label; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; /** * Mini tutorial code for @@ -33,11 +34,17 @@ import com.vaadin.ui.UI; */ public class UsingUriFragments extends UI { + private VerticalLayout layout; + @Override protected void init(VaadinRequest request) { + layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + Label label = new Label("Hello, your fragment is " + getPage().getUriFragment()); - getContent().addComponent(label); + layout.addComponent(label); // React to fragment changes getPage().addListener(new UriFragmentChangedListener() { @@ -50,7 +57,7 @@ public class UsingUriFragments extends UI { // Handle the fragment received in the initial request handleFragment(getPage().getUriFragment()); - addComponent(new Button("Show and set fragment", + layout.addComponent(new Button("Show and set fragment", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { @@ -61,7 +68,7 @@ public class UsingUriFragments extends UI { } private void handleFragment(String uriFragment) { - addComponent(new Label("Got new fragment: " + uriFragment)); + layout.addComponent(new Label("Got new fragment: " + uriFragment)); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java index 52499ffbe5..c4d496641d 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java @@ -19,6 +19,7 @@ package com.vaadin.tests.minitutorials.v7a1; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Label; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; /** * Mini tutorial code for @@ -32,18 +33,22 @@ public class UsingXyzWhenInitializing extends UI { @Override protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + String name = request.getParameter("name"); if (name == null) { name = "Unknown"; } - getContent().addComponent(new Label("Hello " + name)); + layout.addComponent(new Label("Hello " + name)); String pathInfo = request.getRequestPathInfo(); if ("/viewSource".equals(pathInfo)) { - getContent().addComponent(new Label("This is the source")); + layout.addComponent(new Label("This is the source")); } else { - getContent().addComponent(new Label("Welcome to my application")); + layout.addComponent(new Label("Welcome to my application")); } // WebBrowser browser = request.getBrowserDetails().getWebBrowser(); diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a2/ComponentInStateUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a2/ComponentInStateUI.java index da178167ed..986811e0f4 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a2/ComponentInStateUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a2/ComponentInStateUI.java @@ -4,6 +4,7 @@ import com.vaadin.annotations.Widgetset; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Label; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; /** * Mini tutorial code for @@ -17,10 +18,14 @@ import com.vaadin.ui.UI; public class ComponentInStateUI extends UI { @Override protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + ComponentInStateComponent component = new ComponentInStateComponent(); component.setOtherComponent(this); - addComponent(component); - addComponent(new Label("Server-side type of other component: " + layout.addComponent(component); + layout.addComponent(new Label("Server-side type of other component: " + component.getOtherComponent().getClass().getName())); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a2/MyComponentUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a2/MyComponentUI.java index caf38077bf..80aeecfa79 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a2/MyComponentUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a2/MyComponentUI.java @@ -41,7 +41,7 @@ public class MyComponentUI extends UI { component.setText("My component text"); - addComponent(component); + setContent(component); } } \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateUI.java index 155c1d9ded..4ddf86c345 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateUI.java @@ -37,7 +37,7 @@ public class ResourceInStateUI extends UI { ResourceInStateComponent component = new ResourceInStateComponent(); component.setMyIcon(new ThemeResource("../runo/icons/32/calendar.png")); - addComponent(component); + setContent(component); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a2/WidgetcontainerUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a2/WidgetcontainerUI.java index f7cf6b4270..d81e6b4c59 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a2/WidgetcontainerUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a2/WidgetcontainerUI.java @@ -11,15 +11,20 @@ import com.vaadin.ui.CheckBox; import com.vaadin.ui.Component; import com.vaadin.ui.Label; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; @Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet") public class WidgetcontainerUI extends UI { @Override public void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + Label label = new Label("Hello Vaadin user"); - addComponent(label); + layout.addComponent(label); final WidgetContainer widgetContainer = new WidgetContainer(); - addComponent(widgetContainer); + layout.addComponent(widgetContainer); widgetContainer.addComponent(new Label( "Click the button to add components to the WidgetContainer.")); Button button = new Button("Add more components", new ClickListener() { @@ -39,7 +44,7 @@ public class WidgetcontainerUI extends UI { widgetContainer.addComponent(component); } }); - addComponent(button); + layout.addComponent(button); } } \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a3/AnalyticsUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a3/AnalyticsUI.java index 980d0b90b2..8bc9619902 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a3/AnalyticsUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a3/AnalyticsUI.java @@ -28,7 +28,7 @@ public class AnalyticsUI extends UI { final Analytics analytics = new Analytics("UA-33036133-12"); analytics.extend(this); - addComponent(new Button("Track pageview", new Button.ClickListener() { + setContent(new Button("Track pageview", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { analytics.trackPageview("/fake/url"); diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a3/ComplexTypesUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a3/ComplexTypesUI.java index 792be69410..fd271db7e6 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a3/ComplexTypesUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a3/ComplexTypesUI.java @@ -25,7 +25,7 @@ public class ComplexTypesUI extends UI { protected void init(VaadinRequest request) { ComplexTypesComponent complexTypesComponent = new ComplexTypesComponent(); complexTypesComponent.sendComplexTypes(); - addComponent(complexTypesComponent); + setContent(complexTypesComponent); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a3/FlotJavaScriptUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a3/FlotJavaScriptUI.java index a3ed5fe11e..d1d9879a31 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a3/FlotJavaScriptUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a3/FlotJavaScriptUI.java @@ -20,24 +20,30 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; public class FlotJavaScriptUI extends UI { @Override protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + final Flot flot = new Flot(); flot.setHeight("300px"); flot.setWidth("400px"); flot.addSeries(1, 2, 4, 8, 16); - addComponent(flot); - - addComponent(new Button("Highlight point", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - flot.highlight(0, 3); - } - })); + layout.addComponent(flot); + + layout.addComponent(new Button("Highlight point", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + flot.highlight(0, 3); + } + })); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a3/JSAPIUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a3/JSAPIUI.java index ad4139d883..f9d79a518e 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a3/JSAPIUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a3/JSAPIUI.java @@ -39,7 +39,7 @@ public class JSAPIUI extends UI { } }); - addComponent(new Link( + setContent(new Link( "Send message", new ExternalResource( "javascript:(function(){com.example.api.notify(prompt('Message'),2);})();"))); diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a3/RedButtonUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a3/RedButtonUI.java index 18b4b1430e..a4d4031d5f 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a3/RedButtonUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a3/RedButtonUI.java @@ -22,6 +22,6 @@ import com.vaadin.ui.UI; public class RedButtonUI extends UI { @Override protected void init(VaadinRequest request) { - addComponent(new RedButton("My red button")); + setContent(new RedButton("My red button")); } } \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java index bc96152880..99b5973661 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b5/SettingReadingSessionAttributesUI.java @@ -36,22 +36,28 @@ public class SettingReadingSessionAttributesUI extends UI { @Override protected void init(VaadinRequest request) { - addComponent(statusHolder); - addComponent(textField); - addComponent(new Button("Set new values", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - String value = textField.getValue(); + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); - saveValue(SettingReadingSessionAttributesUI.this, value); - } - })); - addComponent(new Button("Reload page", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - getPage().setLocation(getPage().getLocation()); - } - })); + layout.addComponent(statusHolder); + layout.addComponent(textField); + layout.addComponent(new Button("Set new values", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + String value = textField.getValue(); + + saveValue(SettingReadingSessionAttributesUI.this, value); + } + })); + layout.addComponent(new Button("Reload page", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + getPage().setLocation(getPage().getLocation()); + } + })); showValue(this); } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b6/LettingUserDownladFile.java b/uitest/src/com/vaadin/tests/minitutorials/v7b6/LettingUserDownloadFile.java similarity index 96% rename from uitest/src/com/vaadin/tests/minitutorials/v7b6/LettingUserDownladFile.java rename to uitest/src/com/vaadin/tests/minitutorials/v7b6/LettingUserDownloadFile.java index e6a6e267a9..d5c99c931b 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7b6/LettingUserDownladFile.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b6/LettingUserDownloadFile.java @@ -31,7 +31,7 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Button; import com.vaadin.ui.UI; -public class LettingUserDownladFile extends UI { +public class LettingUserDownloadFile extends UI { @Override protected void init(VaadinRequest request) { @@ -41,7 +41,7 @@ public class LettingUserDownladFile extends UI { FileDownloader fileDownloader = new FileDownloader(myResource); fileDownloader.extend(downloadButton); - addComponent(downloadButton); + setContent(downloadButton); } private StreamResource createResource() { diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b6/MyPopupUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7b6/MyPopupUI.java index 2c50b62d0d..59f5831468 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7b6/MyPopupUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b6/MyPopupUI.java @@ -24,7 +24,7 @@ public class MyPopupUI extends UI { @Override protected void init(VaadinRequest request) { - addComponent(new Label("This is MyPopupUI")); + setContent(new Label("This is MyPopupUI")); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b6/OpeningUIInPopup.java b/uitest/src/com/vaadin/tests/minitutorials/v7b6/OpeningUIInPopup.java index f1db0fc478..7fd8373bbd 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7b6/OpeningUIInPopup.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b6/OpeningUIInPopup.java @@ -31,7 +31,7 @@ public class OpeningUIInPopup extends UI { popupOpener.setFeatures("height=300,width=300"); popupOpener.extend(popupButton); - addComponent(popupButton); + setContent(popupButton); } } diff --git a/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java index 97c4e9fd4f..08832e5e82 100644 --- a/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java +++ b/uitest/src/com/vaadin/tests/navigator/NavigatorTest.java @@ -113,6 +113,10 @@ public class NavigatorTest extends UI { @Override protected void init(VaadinRequest req) { try { + VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + setContent(layout); + navi = new Navigator(this, naviLayout); navi.addView("", new DefaultView()); @@ -127,13 +131,13 @@ public class NavigatorTest extends UI { navi.navigate(); - addComponent(new NaviButton("list")); - addComponent(new NaviButton("edit")); - addComponent(new NaviButton("forbidden")); + layout.addComponent(new NaviButton("list")); + layout.addComponent(new NaviButton("edit")); + layout.addComponent(new NaviButton("forbidden")); - addComponent(params); - addComponent(log); - addComponent(naviLayout); + layout.addComponent(params); + layout.addComponent(log); + layout.addComponent(naviLayout); } catch (Exception e) { e.printStackTrace(); log.log("Exception: " + e); diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2021.java b/uitest/src/com/vaadin/tests/tickets/Ticket2021.java index 3f798a3e19..938df7befc 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket2021.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket2021.java @@ -38,7 +38,7 @@ public class Ticket2021 extends LegacyApplication { p.setContent(new VerticalLayout()); p.getContent().setSizeFull(); - w.getContent().addComponent(p); + w.addComponent(p); tf1 = new TextArea(); tf1.setRows(5); @@ -59,7 +59,7 @@ public class Ticket2021 extends LegacyApplication { p2.setContent(new VerticalLayout()); p2.getContent().setSizeFull(); - w.getContent().addComponent(p2); + w.addComponent(p2); tf2 = new TextArea(); tf2.setRows(5); @@ -85,7 +85,7 @@ public class Ticket2021 extends LegacyApplication { gl.setSizeFull(); gl.setMargin(false); p3.getContent().addComponent(gl); - w.getContent().addComponent(p3); + w.addComponent(p3); tf3 = new TextArea(); tf3.setRows(5); diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2024.java b/uitest/src/com/vaadin/tests/tickets/Ticket2024.java index c38ba7822a..2861c9beca 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket2024.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket2024.java @@ -19,7 +19,7 @@ public class Ticket2024 extends LegacyApplication { layout.setWidth("700"); w.getContent().setSizeFull(); w.getContent().setHeight("2000"); - w.getContent().addComponent(layout); + w.addComponent(layout); layout.addComponent(new Label( "This should NOT get stuck when scrolling down")); @@ -28,7 +28,7 @@ public class Ticket2024 extends LegacyApplication { VerticalLayout ol = new VerticalLayout(); ol.setHeight("1000"); ol.setWidth("200"); - w.getContent().addComponent(ol); + w.addComponent(ol); ol.addComponent(new Label("Just a label to enable the scrollbar")); } diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2029.java b/uitest/src/com/vaadin/tests/tickets/Ticket2029.java index 8031041e5b..db3334d570 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket2029.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket2029.java @@ -32,9 +32,9 @@ public class Ticket2029 extends LegacyApplication { setMainWindow(w); // setTheme("tests-tickets"); Panel p = createPanel(); - w.getContent().addComponent(p); + w.addComponent(p); // w.getLayout().addComponent(createGLPanel()); - w.getContent().addComponent(createPanelV()); + w.addComponent(createPanelV()); } private Panel createPanel() { diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2048.java b/uitest/src/com/vaadin/tests/tickets/Ticket2048.java index cb6fba3ab8..b2a6e64cd2 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket2048.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket2048.java @@ -75,8 +75,7 @@ public class Ticket2048 extends LegacyApplication { public void buttonClick(ClickEvent event) { Embedded newEmbedded = new Embedded(null, new ThemeResource("icons/64/folder-add.png")); - getMainWindow().getContent().replaceComponent(embedded, - newEmbedded); + getMainWindow().replaceComponent(embedded, newEmbedded); embedded = newEmbedded; } diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2101.java b/uitest/src/com/vaadin/tests/tickets/Ticket2101.java index d3e6202542..dd10943108 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket2101.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket2101.java @@ -15,7 +15,7 @@ public class Ticket2101 extends LegacyApplication { "Button with a long text which will not fit on 50 pixels"); b.setWidth("50px"); - w.getContent().addComponent(b); + w.addComponent(b); } } diff --git a/uitest/src/com/vaadin/tests/util/SampleDirectory.java b/uitest/src/com/vaadin/tests/util/SampleDirectory.java index 504a4e5dfd..2f21026118 100644 --- a/uitest/src/com/vaadin/tests/util/SampleDirectory.java +++ b/uitest/src/com/vaadin/tests/util/SampleDirectory.java @@ -23,8 +23,8 @@ import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinServiceSession; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.ui.Label; +import com.vaadin.ui.LegacyWindow; import com.vaadin.ui.Panel; -import com.vaadin.ui.UI; /** * Provides sample directory based on application directory. If this fails then @@ -42,7 +42,8 @@ public class SampleDirectory { * @param application * @return file pointing to sample directory */ - public static File getDirectory(VaadinServiceSession application, UI uI) { + public static File getDirectory(VaadinServiceSession application, + LegacyWindow uI) { String errorMessage = "Access to application " + "context base directory failed, " + "possible security constraint with Application " @@ -82,9 +83,9 @@ public class SampleDirectory { "Cannot provide sample directory")); errorPanel.addComponent(new Label(errorMessage, ContentMode.HTML)); // Remove all components from applications main window - uI.getContent().removeAllComponents(); + uI.removeAllComponents(); // Add error panel - uI.getContent().addComponent(errorPanel); + uI.addComponent(errorPanel); return null; } } -- 2.39.5