com.vaadin.ui
Class Window

java.lang.Object
  extended by com.vaadin.terminal.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.AbstractComponentContainer
              extended by com.vaadin.ui.Panel
                  extended by com.vaadin.ui.Window
All Implemented Interfaces:
Action.Container, Action.Notifier, FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, MethodEventSource, Connector, ClientConnector, RpcTarget, Scrollable, Sizeable, Vaadin6Component, VariableOwner, Component, Component.Focusable, ComponentContainer, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachListener, HasComponents, Serializable, Iterable<Component>, EventListener

public class Window
extends Panel
implements FieldEvents.FocusNotifier, FieldEvents.BlurNotifier, Vaadin6Component

A component that represents a floating popup window that can be added to a Root. A window is added to a Root using Root.addWindow(Window).

The contents of a window is set using Panel.setContent(ComponentContainer) or by using the Window(String, ComponentContainer) constructor. The contents can in turn contain other components. By default, a VerticalLayout is used as content.

A window can be positioned on the screen using absolute coordinates (pixels) or set to be centered using center()

The caption is displayed in the window header.

In Vaadin versions prior to 7.0.0, Window was also used as application level windows. This function is now covered by the Root class.

Since:
3.0
Version:
7.0.0.alpha3
Author:
Vaadin Ltd.
See Also:
Serialized Form

Nested Class Summary
 class Window.CloseEvent
           
static interface Window.CloseListener
          An interface used for listening to Window close events.
static class Window.CloseShortcut
          A ShortcutListener specifically made to define a keyboard shortcut that closes the window.
 class Window.ResizeEvent
          Resize events are fired whenever the client-side fires a resize-event (e.g.
static interface Window.ResizeListener
          Listener for window resize events.
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.VariableOwner
VariableOwner.ErrorEvent
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.Sizeable
Sizeable.Unit
 
Nested classes/interfaces inherited from interface com.vaadin.ui.ComponentContainer
ComponentContainer.ComponentAttachEvent, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachEvent, ComponentContainer.ComponentDetachListener
 
Field Summary
protected  Window.CloseShortcut closeShortcut
           
 
Fields inherited from class com.vaadin.ui.Panel
actionManager
 
Fields inherited from interface com.vaadin.terminal.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
Window()
          Creates a new unnamed window with a default layout.
Window(String caption)
          Creates a new unnamed window with a default layout and given title.
Window(String caption, ComponentContainer content)
          Creates a new unnamed window with the given content and title.
 
Method Summary
 void addComponent(Component c)
          Adds the component into this container.
 void addListener(FieldEvents.BlurListener listener)
          Note, that focus/blur listeners in Window class are only supported by sub windows.
 void addListener(FieldEvents.FocusListener listener)
          Note, that focus/blur listeners in Window class are only supported by sub windows.
 void addListener(Window.CloseListener listener)
          Adds a CloseListener to the window.
 void addListener(Window.ResizeListener listener)
          Add a resize listener.
 void bringToFront()
          If there are currently several windows visible, calling this method makes this window topmost.
 void center()
          Sets this window to be centered relative to its parent window.
 void changeVariables(Object source, Map<String,Object> variables)
          Called when one or more variables handled by the implementing class are changed.
 void close()
          Method that handles window closing (from UI).
protected  void fireClose()
           
protected  void fireResize()
          Fire the resize event.
 void focus()
          Moves keyboard focus to the component.
 int getPositionX()
          Gets the distance of Window left border in pixels from left border of the containing (main window).
 int getPositionY()
          Gets the distance of Window top border in pixels from top border of the containing (main window).
 WindowState getState()
          Returns the shared state bean with information to be sent from the server to the client.
 boolean isClosable()
          Returns the closable status of the sub window.
 boolean isDraggable()
          Indicates whether a sub window can be dragged or not.
 boolean isModal()
           
 boolean isResizable()
           
 boolean isResizeLazy()
           
 void paintContent(PaintTarget target)
           Paints the Paintable into a UIDL stream.
 void removeCloseShortcut()
          Removes the keyboard shortcut previously set with setCloseShortcut(int, int...).
 void removeListener(FieldEvents.BlurListener listener)
          Removes a BlurListener from the Component.
 void removeListener(FieldEvents.FocusListener listener)
          Removes a FocusListener from the Component.
 void removeListener(Window.CloseListener listener)
          Removes the CloseListener from the window.
 void removeListener(Window.ResizeListener listener)
          Remove a resize listener.
 void setClosable(boolean closable)
          Sets the closable status for the sub window.
 void setCloseShortcut(int keyCode, int... modifiers)
          Makes is possible to close the window by pressing the given ShortcutAction.KeyCode and (optional) ShortcutAction.ModifierKeys.
Note that this shortcut only reacts while the window has focus, closing itself - if you want to close a subwindow from a parent window, use Panel.addAction(com.vaadin.event.Action) of the parent window instead.
 void setDraggable(boolean draggable)
          Enables or disables that a sub window can be dragged (moved) by the user.
 void setModal(boolean modal)
          Sets sub-window modal, so that widgets behind it cannot be accessed.
 void setPositionX(int positionX)
          Sets the distance of Window left border in pixels from left border of the containing (main window).
 void setPositionY(int positionY)
          Sets the distance of Window top border in pixels from top border of the containing (main window).
 void setResizable(boolean resizable)
          Sets sub-window resizable.
 void setResizeLazy(boolean resizeLazy)
          Should resize operations be lazy, i.e.
 
Methods inherited from class com.vaadin.ui.Panel
addAction, addActionHandler, addListener, componentAttachedToContainer, componentDetachedFromContainer, getActionManager, getComponentCount, getComponentIterator, getContent, getScrollLeft, getScrollTop, getTabIndex, removeAction, removeActionHandler, removeAllActionHandlers, removeAllComponents, removeComponent, removeListener, replaceComponent, setCaption, setContent, setScrollLeft, setScrollTop, setTabIndex
 
Methods inherited from class com.vaadin.ui.AbstractComponentContainer
addListener, addListener, fireComponentAttachEvent, fireComponentDetachEvent, isComponentVisible, iterator, moveComponentsFrom, removeListener, removeListener, setHeight, setVisible, setWidth
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addListener, addListener, addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, fireEvent, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getErrorMessage, getHeight, getHeightUnits, getIcon, getListeners, getLocale, getParent, getRoot, getStyle, getStyleName, getWidth, getWidthUnits, handleError, hasListeners, isConnectorEnabled, isEnabled, isImmediate, isReadOnly, isVisible, removeListener, removeListener, removeListener, removeListener, removeListener, removeShortcutListener, removeStyleName, requestRepaint, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setIcon, setImmediate, setLocale, setParent, setReadOnly, setSizeFull, setSizeUndefined, setStyle, setStyleName, setWidth, updateState
 
Methods inherited from class com.vaadin.terminal.AbstractClientConnector
addExtension, addMethodInvocationToQueue, createState, getAllChildrenIterable, getConnectorId, getExtensions, getRpcManager, getRpcProxy, getStateType, registerRpc, registerRpc, removeExtension, requestRepaintAll, retrievePendingRpcCalls
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.terminal.VariableOwner
isEnabled, isImmediate
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, getApplication, getCaption, getDebugId, getIcon, getLocale, getParent, getRoot, getStyleName, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setDebugId, setEnabled, setIcon, setReadOnly, setStyleName, setVisible, updateState
 
Methods inherited from interface com.vaadin.terminal.gwt.server.ClientConnector
detach, getExtensions, getStateType, isConnectorEnabled, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setParent
 
Methods inherited from interface com.vaadin.terminal.gwt.client.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.terminal.gwt.server.RpcTarget
getRpcManager
 
Methods inherited from interface com.vaadin.terminal.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setSizeFull, setSizeUndefined, setWidth, setWidth
 

Field Detail

closeShortcut

protected Window.CloseShortcut closeShortcut
Constructor Detail

Window

public Window()
Creates a new unnamed window with a default layout.


Window

public Window(String caption)
Creates a new unnamed window with a default layout and given title.

Parameters:
caption - the title of the window.

Window

public Window(String caption,
              ComponentContainer content)
Creates a new unnamed window with the given content and title.

Parameters:
caption - the title of the window.
content - the contents of the window
Method Detail

addComponent

public void addComponent(Component c)
Description copied from class: Panel
Adds the component into this container.

Specified by:
addComponent in interface ComponentContainer
Overrides:
addComponent in class Panel
Parameters:
c - the component to be added.
See Also:
AbstractComponentContainer.addComponent(com.vaadin.ui.Component)

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException
Description copied from interface: Vaadin6Component

Paints the Paintable into a UIDL stream. This method creates the UIDL sequence describing it and outputs it to the given UIDL stream.

It is called when the contents of the component should be painted in response to the component first being shown or having been altered so that its visual representation is changed.

Specified by:
paintContent in interface Vaadin6Component
Overrides:
paintContent in class Panel
Parameters:
target - the target UIDL stream where the component should paint itself to.
Throws:
PaintException - if the paint operation failed.

changeVariables

public void changeVariables(Object source,
                            Map<String,Object> variables)
Description copied from class: Panel
Called when one or more variables handled by the implementing class are changed.

Specified by:
changeVariables in interface VariableOwner
Overrides:
changeVariables in class Panel
Parameters:
source - the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.
variables - the Mapping from variable names to new variable values.
See Also:
VariableOwner.changeVariables(Object, Map)

close

public void close()
Method that handles window closing (from UI).

By default, sub-windows are removed from their respective parent windows and thus visually closed on browser-side. Browser-level windows also closed on the client-side, but they are not implicitly removed from the application.

To explicitly close a sub-window, use #removeWindow(Window). To react to a window being closed (after it is closed), register a Window.CloseListener.


getPositionX

public int getPositionX()
Gets the distance of Window left border in pixels from left border of the containing (main window).

Returns:
the Distance of Window left border in pixels from left border of the containing (main window). or -1 if unspecified.
Since:
4.0.0

setPositionX

public void setPositionX(int positionX)
Sets the distance of Window left border in pixels from left border of the containing (main window).

Parameters:
positionX - the Distance of Window left border in pixels from left border of the containing (main window). or -1 if unspecified.
Since:
4.0.0

getPositionY

public int getPositionY()
Gets the distance of Window top border in pixels from top border of the containing (main window).

Returns:
Distance of Window top border in pixels from top border of the containing (main window). or -1 if unspecified .
Since:
4.0.0

setPositionY

public void setPositionY(int positionY)
Sets the distance of Window top border in pixels from top border of the containing (main window).

Parameters:
positionY - the Distance of Window top border in pixels from top border of the containing (main window). or -1 if unspecified
Since:
4.0.0

addListener

public void addListener(Window.CloseListener listener)
Adds a CloseListener to the window. For a sub window the CloseListener is fired when the user closes it (clicks on the close button). For a browser level window the CloseListener is fired when the browser level window is closed. Note that closing a browser level window does not mean it will be destroyed. Also note that Opera does not send events like all other browsers and therefore the close listener might not be called if Opera is used.

Since Vaadin 6.5, removing windows using #removeWindow(Window) does fire the CloseListener.

Parameters:
listener - the CloseListener to add.

removeListener

public void removeListener(Window.CloseListener listener)
Removes the CloseListener from the window.

For more information on CloseListeners see Window.CloseListener.

Parameters:
listener - the CloseListener to remove.

fireClose

protected void fireClose()

addListener

public void addListener(Window.ResizeListener listener)
Add a resize listener.

Parameters:
listener -

removeListener

public void removeListener(Window.ResizeListener listener)
Remove a resize listener.

Parameters:
listener -

fireResize

protected void fireResize()
Fire the resize event.


bringToFront

public void bringToFront()
If there are currently several windows visible, calling this method makes this window topmost.

This method can only be called if this window connected a root. Else an illegal state exception is thrown. Also if there are modal windows and this window is not modal, and illegal state exception is thrown.


setModal

public void setModal(boolean modal)
Sets sub-window modal, so that widgets behind it cannot be accessed. Note: affects sub-windows only.

Parameters:
modal - true if modality is to be turned on

isModal

public boolean isModal()
Returns:
true if this window is modal.

setResizable

public void setResizable(boolean resizable)
Sets sub-window resizable. Note: affects sub-windows only.

Parameters:
resizable - true if resizability is to be turned on

isResizable

public boolean isResizable()
Returns:
true if window is resizable by the end-user, otherwise false.

isResizeLazy

public boolean isResizeLazy()
Returns:
true if a delay is used before recalculating sizes, false if sizes are recalculated immediately.

setResizeLazy

public void setResizeLazy(boolean resizeLazy)
Should resize operations be lazy, i.e. should there be a delay before layout sizes are recalculated. Speeds up resize operations in slow UIs with the penalty of slightly decreased usability. Note, some browser send false resize events for the browser window and are therefore always lazy.

Parameters:
resizeLazy - true to use a delay before recalculating sizes, false to calculate immediately.

center

public void center()
Sets this window to be centered relative to its parent window. Affects sub-windows only. If the window is resized as a result of the size of its content changing, it will keep itself centered as long as its position is not explicitly changed programmatically or by the user.

NOTE: This method has several issues as currently implemented. Please refer to http://dev.vaadin.com/ticket/8971 for details.


isClosable

public boolean isClosable()
Returns the closable status of the sub window. If a sub window is closable it typically shows an X in the upper right corner. Clicking on the X sends a close event to the server. Setting closable to false will remove the X from the sub window and prevent the user from closing the window. Note! For historical reasons readonly controls the closability of the sub window and therefore readonly and closable affect each other. Setting readonly to true will set closable to false and vice versa.

Closable only applies to sub windows, not to browser level windows.

Returns:
true if the sub window can be closed by the user.

setClosable

public void setClosable(boolean closable)
Sets the closable status for the sub window. If a sub window is closable it typically shows an X in the upper right corner. Clicking on the X sends a close event to the server. Setting closable to false will remove the X from the sub window and prevent the user from closing the window. Note! For historical reasons readonly controls the closability of the sub window and therefore readonly and closable affect each other. Setting readonly to true will set closable to false and vice versa.

Closable only applies to sub windows, not to browser level windows.

Parameters:
closable - determines if the sub window can be closed by the user.

isDraggable

public boolean isDraggable()
Indicates whether a sub window can be dragged or not. By default a sub window is draggable.

Draggable only applies to sub windows, not to browser level windows.

Parameters:
draggable - true if the sub window can be dragged by the user

setDraggable

public void setDraggable(boolean draggable)
Enables or disables that a sub window can be dragged (moved) by the user. By default a sub window is draggable.

Draggable only applies to sub windows, not to browser level windows.

Parameters:
draggable - true if the sub window can be dragged by the user

setCloseShortcut

public void setCloseShortcut(int keyCode,
                             int... modifiers)
Makes is possible to close the window by pressing the given ShortcutAction.KeyCode and (optional) ShortcutAction.ModifierKeys.
Note that this shortcut only reacts while the window has focus, closing itself - if you want to close a subwindow from a parent window, use Panel.addAction(com.vaadin.event.Action) of the parent window instead.

Parameters:
keyCode - the keycode for invoking the shortcut
modifiers - the (optional) modifiers for invoking the shortcut, null for none

removeCloseShortcut

public void removeCloseShortcut()
Removes the keyboard shortcut previously set with setCloseShortcut(int, int...).


addListener

public void addListener(FieldEvents.FocusListener listener)
Note, that focus/blur listeners in Window class are only supported by sub windows. Also note that Window is not considered focused if its contained component currently has focus.

Specified by:
addListener in interface FieldEvents.FocusNotifier
See Also:
FieldEvents.FocusNotifier.addListener(com.vaadin.event.FieldEvents.FocusListener)

removeListener

public void removeListener(FieldEvents.FocusListener listener)
Description copied from interface: FieldEvents.FocusNotifier
Removes a FocusListener from the Component.

Specified by:
removeListener in interface FieldEvents.FocusNotifier
See Also:
FieldEvents.FocusListener

addListener

public void addListener(FieldEvents.BlurListener listener)
Note, that focus/blur listeners in Window class are only supported by sub windows. Also note that Window is not considered focused if its contained component currently has focus.

Specified by:
addListener in interface FieldEvents.BlurNotifier
See Also:
FieldEvents.BlurNotifier.addListener(com.vaadin.event.FieldEvents.BlurListener)

removeListener

public void removeListener(FieldEvents.BlurListener listener)
Description copied from interface: FieldEvents.BlurNotifier
Removes a BlurListener from the Component.

Specified by:
removeListener in interface FieldEvents.BlurNotifier
See Also:
FieldEvents.BlurListener

focus

public void focus()
Moves keyboard focus to the component. Component.Focusable.focus() If the window is a sub-window focusing will cause the sub-window to be brought on top of other sub-windows on gain keyboard focus.

Specified by:
focus in interface Component.Focusable
Overrides:
focus in class Panel
See Also:
FieldEvents, FieldEvents.FocusEvent, FieldEvents.FocusListener, FieldEvents.BlurEvent, FieldEvents.BlurListener

getState

public WindowState getState()
Description copied from class: AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

Specified by:
getState in interface Connector
Specified by:
getState in interface Component
Overrides:
getState in class Panel
Returns:
updated component shared state


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.