}
protected ComponentConnector getContent() {
- return (ComponentConnector) getState().content;
+ List<ComponentConnector> 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
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()) {
package com.vaadin.ui;
-import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
}
}
- /* 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);
}
/**
/* 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);
}
/**
/* 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);
}
/**
/* documented in interface */
@Override
public void removeComponentDetachListener(ComponentDetachListener listener) {
- removeListener(ComponentContainer.ComponentDetachEvent.class, listener,
- COMPONENT_DETACHED_METHOD);
+ removeListener(ComponentDetachEvent.class, listener,
+ ComponentDetachListener.detachMethod);
}
/**
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);
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();
}
private Collection<Component> getInvalidSizedChildren(final boolean vertical) {
HashSet<Component> 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<Component>(1);
- components.add(content);
- }
- } else {
- for (Iterator<Component> 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<Component>();
- }
- components.add(component);
+ if (components == null) {
+ components = new HashSet<Component>();
}
+ components.add(component);
}
}
return components;
--- /dev/null
+/*
+ * 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<Component> iterator() {
+ if (content != null) {
+ return Collections.singletonList(content).iterator();
+ } else {
+ return Collections.<Component> 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);
+ }
+
+}
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
* @author Vaadin Ltd.
* @since 3.0
*/
-public interface ComponentContainer extends HasComponents {
+public interface ComponentContainer extends HasComponents,
+ ComponentAttachDetachNotifier {
/**
* Adds the component into this container.
*/
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)}
@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)}
@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)}
@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)}
@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;
- }
- }
-
}
*/
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.
*/
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;
+ }
+ }
+
}
/*
@VaadinApache2LicenseForJavaFiles@
-*/
+ */
package com.vaadin.ui;
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 {
* Create a new legacy window
*/
public LegacyWindow() {
- super();
+ super(new VerticalLayout());
+ ((VerticalLayout) getContent()).setMargin(true);
}
/**
* the caption of the window
*/
public LegacyWindow(String caption) {
- super();
+ super(new VerticalLayout());
+ ((VerticalLayout) getContent()).setMargin(true);
setCaption(caption);
}
* Gets the unique name of the window. The name of the window is used to
* uniquely identify it.
* <p>
- * 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.
* </p>
* <p>
* Note! Portlets do not support direct window access through URLs.
* Sets the unique name of the window. The name of the window is used to
* uniquely identify it inside the application.
* <p>
- * 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.
* </p>
* <p>
* This method can only be called before the window is added to an
* </p>
*
* @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
*/
}
/**
- * 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.
* <p>
* Note! This method can not be used for portlets.
* </p>
*
- * @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();
}
/**
- * 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
* Opens the given resource in a window with the given name.
* <p>
* 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 <code>null</code> 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
+ * <code>null</code> window name is also a special case.
* </p>
* <p>
- * "", 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.
* </p>
* <p>
- * "_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).
* </p>
* <p>
- * "_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.
* </p>
* <p>
- * 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.
* </p>
* <p>
- * 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.
* </p>
*
* @param resource
* name. For more information on the meaning of {@code windowName}, see
* {@link #open(Resource, String)}.
* <p>
- * 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.
* </p>
*
* @param resource
}
/**
- * 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
}
/**
- * 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
}
/**
- * 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
*
* Executes JavaScript in this window.
*
* <p>
- * 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.
* </p>
*
* <p>
- * 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.
* </p>
*
* @param script
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
--- /dev/null
+/*
+ * 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);
+
+}
* 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.
* </p>
*
* @see #init(VaadinRequest)
*
* @since 7.0
*/
-public abstract class UI extends AbstractComponentContainer implements
+public abstract class UI extends AbstractSingleComponentContainer implements
Action.Container, Action.Notifier, LegacyComponent {
/**
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);
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.
*
/*
* (non-Javadoc)
*
- * @see com.vaadin.ui.ComponentContainer#getComponentIterator()
+ * @see com.vaadin.ui.HasComponents#iterator()
*/
@Override
public Iterator<Component> iterator() {
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.
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;
--- /dev/null
+package com.vaadin.tests.server.component.ui;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.LegacyWindow;
+
+public class LegacyUIAddRemoveComponents {
+
+ private static class TestUI extends LegacyWindow {
+ @Override
+ protected void init(VaadinRequest request) {
+ }
+ }
+
+ @Test
+ public void addComponent() {
+ TestUI ui = new TestUI();
+ Component c = new Label("abc");
+
+ ui.addComponent(c);
+
+ assertSame(c, ui.iterator().next());
+ assertSame(c, ui.getContent().iterator().next());
+ assertEquals(1, ui.getComponentCount());
+ assertEquals(1, ui.getContent().getComponentCount());
+ }
+
+ @Test
+ public void removeComponent() {
+ TestUI ui = new TestUI();
+ Component c = new Label("abc");
+
+ ui.addComponent(c);
+
+ ui.removeComponent(c);
+
+ assertFalse(ui.iterator().hasNext());
+ assertFalse(ui.getContent().iterator().hasNext());
+ assertEquals(0, ui.getComponentCount());
+ assertEquals(0, ui.getContent().getComponentCount());
+ }
+
+ @Test
+ public void replaceComponent() {
+ TestUI ui = new TestUI();
+ Component c = new Label("abc");
+ Component d = new Label("def");
+
+ ui.addComponent(c);
+
+ ui.replaceComponent(c, d);
+
+ assertSame(d, ui.iterator().next());
+ assertSame(d, ui.getContent().iterator().next());
+ assertEquals(1, ui.getComponentCount());
+ assertEquals(1, ui.getContent().getComponentCount());
+ }
+}
+++ /dev/null
-package com.vaadin.tests.server.component.ui;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-
-import org.junit.Test;
-
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.UI;
-
-public class UIAddRemoveComponents {
-
- private static class TestUI extends UI {
- @Override
- protected void init(VaadinRequest request) {
- }
- }
-
- @Test
- public void addComponent() {
- UI ui = new TestUI();
- Component c = new Label("abc");
-
- ui.addComponent(c);
-
- assertSame(c, ui.iterator().next());
- assertSame(c, ui.getContent().iterator().next());
- assertEquals(1, ui.getComponentCount());
- assertEquals(1, ui.getContent().getComponentCount());
- }
-
- @Test
- public void removeComponent() {
- UI ui = new TestUI();
- Component c = new Label("abc");
-
- ui.addComponent(c);
-
- ui.removeComponent(c);
-
- assertFalse(ui.iterator().hasNext());
- assertFalse(ui.getContent().iterator().hasNext());
- assertEquals(0, ui.getComponentCount());
- assertEquals(0, ui.getContent().getComponentCount());
- }
-
- @Test
- public void replaceComponent() {
- UI ui = new TestUI();
- Component c = new Label("abc");
- Component d = new Label("def");
-
- ui.addComponent(c);
-
- ui.replaceComponent(c, d);
-
- assertSame(d, ui.iterator().next());
- assertSame(d, ui.getContent().iterator().next());
- assertEquals(1, ui.getComponentCount());
- assertEquals(1, ui.getContent().getComponentCount());
- }
-}
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;
// 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;
attachTarget = event.getContainer();
// Search for component in container (should be found)
- Iterator<Component> iter = attachTarget.getComponentIterator();
+ Iterator<Component> iter = attachTarget.iterator();
while (iter.hasNext()) {
if (iter.next() == attachedComponent) {
foundInContainer = true;
detachedTarget = event.getContainer();
// Search for component in container (should NOT be found)
- Iterator<Component> iter = detachedTarget.getComponentIterator();
+ Iterator<Component> iter = detachedTarget.iterator();
while (iter.hasNext()) {
if (iter.next() == detachedComponent) {
foundInContainer = true;
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() {
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);
}
}
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
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;
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) {
el.addComponent(ol);
- main.getContent().addComponent(el);
+ main.addComponent(el);
main.removeWindow(subwindow);
}
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)));
}
}
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;
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);
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);
}
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;
"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")) {
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();
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();
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();
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();
@Override
protected void setup(VaadinRequest request) {
- setContent(new GridLayout(5, 5));
+ GridLayout layout = new GridLayout(5, 5);
+ setContent(layout);
for (Class<? extends Component> cls : VaadinClasses.getComponents()) {
try {
AbstractComponent c = (AbstractComponent) cls.newInstance();
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());
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);
@Override
protected void setup(VaadinRequest request) {
- getUI().setCaption("test");
VerticalLayout vPrinc = new VerticalLayout();
vPrinc.setStyleName(Reindeer.LAYOUT_BLUE);
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 {
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));
}
}
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;
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);
}
};
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
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));
}
}
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;
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() {
window.bringToFront();
}
});
- main.addComponent(button);
+ ((ComponentContainer) main.getContent()).addComponent(button);
Window window2 = new Window("Another window for testing");
main.addWindow(window2);
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");
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"));
selectedLabel.setValue(String.valueOf(table.getValue()));
}
});
- addComponent(selectedLabel);
+ layout.addComponent(selectedLabel);
}
}
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
@Override
protected void init(VaadinRequest request) {
+ VerticalLayout layout = new VerticalLayout();
+ layout.setMargin(true);
+ setContent(layout);
+
FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);
// We need an item data source before we create the fields to be able to
// 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));
}
}
public void init(VaadinRequest request) {
TextField tf = new TextField("Window #" + (++windowCounter));
tf.setImmediate(true);
- getContent().addComponent(tf);
+ setContent(tf);
}
}
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"));
}
}
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));
}
}
// Add an image using the resource
Image image = new Image("A dynamically generated image", resource);
- getContent().addComponent(image);
+ addComponent(image);
}
@Override
}
});
- addComponent(helloButton);
+ setContent(helloButton);
}
}
TextField firstName = new TextField("First name",
item.getItemProperty("name"));
firstName.setImmediate(true);
- addComponent(firstName);
+ setContent(firstName);
firstName.addValidator(new BeanValidator(Person.class, "name"));
}
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
*/
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() {
// 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) {
}
private void handleFragment(String uriFragment) {
- addComponent(new Label("Got new fragment: " + uriFragment));
+ layout.addComponent(new Label("Got new fragment: " + uriFragment));
}
}
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
/**
* Mini tutorial code for
@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();
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
/**
* Mini tutorial code for
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()));
}
}
component.setText("My component text");
- addComponent(component);
+ setContent(component);
}
}
\ No newline at end of file
ResourceInStateComponent component = new ResourceInStateComponent();
component.setMyIcon(new ThemeResource("../runo/icons/32/calendar.png"));
- addComponent(component);
+ setContent(component);
}
}
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() {
widgetContainer.addComponent(component);
}
});
- addComponent(button);
+ layout.addComponent(button);
}
}
\ No newline at end of file
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");
protected void init(VaadinRequest request) {
ComplexTypesComponent complexTypesComponent = new ComplexTypesComponent();
complexTypesComponent.sendComplexTypes();
- addComponent(complexTypesComponent);
+ setContent(complexTypesComponent);
}
}
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);
+ }
+ }));
}
}
}
});
- addComponent(new Link(
+ setContent(new Link(
"Send message",
new ExternalResource(
"javascript:(function(){com.example.api.notify(prompt('Message'),2);})();")));
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
@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);
}
+++ /dev/null
-/*
- * 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.tests.minitutorials.v7b6;
-
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.imageio.ImageIO;
-
-import com.vaadin.server.FileDownloader;
-import com.vaadin.server.StreamResource;
-import com.vaadin.server.StreamResource.StreamSource;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.UI;
-
-public class LettingUserDownladFile extends UI {
-
- @Override
- protected void init(VaadinRequest request) {
- Button downloadButton = new Button("Download image");
-
- StreamResource myResource = createResource();
- FileDownloader fileDownloader = new FileDownloader(myResource);
- fileDownloader.extend(downloadButton);
-
- addComponent(downloadButton);
- }
-
- private StreamResource createResource() {
- return new StreamResource(new StreamSource() {
- @Override
- public InputStream getStream() {
- String text = "My image";
- BufferedImage bi = new BufferedImage(100, 30,
- BufferedImage.TYPE_3BYTE_BGR);
- bi.getGraphics().drawChars(text.toCharArray(), 0,
- text.length(), 10, 20);
-
- try {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ImageIO.write(bi, "png", bos);
- return new ByteArrayInputStream(bos.toByteArray());
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
-
- }
- }, "myImage.png");
- }
-
-}
--- /dev/null
+/*
+ * 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.tests.minitutorials.v7b6;
+
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.ImageIO;
+
+import com.vaadin.server.FileDownloader;
+import com.vaadin.server.StreamResource;
+import com.vaadin.server.StreamResource.StreamSource;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.UI;
+
+public class LettingUserDownloadFile extends UI {
+
+ @Override
+ protected void init(VaadinRequest request) {
+ Button downloadButton = new Button("Download image");
+
+ StreamResource myResource = createResource();
+ FileDownloader fileDownloader = new FileDownloader(myResource);
+ fileDownloader.extend(downloadButton);
+
+ setContent(downloadButton);
+ }
+
+ private StreamResource createResource() {
+ return new StreamResource(new StreamSource() {
+ @Override
+ public InputStream getStream() {
+ String text = "My image";
+ BufferedImage bi = new BufferedImage(100, 30,
+ BufferedImage.TYPE_3BYTE_BGR);
+ bi.getGraphics().drawChars(text.toCharArray(), 0,
+ text.length(), 10, 20);
+
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ImageIO.write(bi, "png", bos);
+ return new ByteArrayInputStream(bos.toByteArray());
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+ }, "myImage.png");
+ }
+
+}
@Override
protected void init(VaadinRequest request) {
- addComponent(new Label("This is MyPopupUI"));
+ setContent(new Label("This is MyPopupUI"));
}
}
popupOpener.setFeatures("height=300,width=300");
popupOpener.extend(popupButton);
- addComponent(popupButton);
+ setContent(popupButton);
}
}
@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());
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);
p.setContent(new VerticalLayout());
p.getContent().setSizeFull();
- w.getContent().addComponent(p);
+ w.addComponent(p);
tf1 = new TextArea();
tf1.setRows(5);
p2.setContent(new VerticalLayout());
p2.getContent().setSizeFull();
- w.getContent().addComponent(p2);
+ w.addComponent(p2);
tf2 = new TextArea();
tf2.setRows(5);
gl.setSizeFull();
gl.setMargin(false);
p3.getContent().addComponent(gl);
- w.getContent().addComponent(p3);
+ w.addComponent(p3);
tf3 = new TextArea();
tf3.setRows(5);
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"));
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"));
}
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() {
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;
}
"Button with a long text which will not fit on 50 pixels");
b.setWidth("50px");
- w.getContent().addComponent(b);
+ w.addComponent(b);
}
}
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
* @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 "
"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;
}
}