Class WDialog
- java.lang.Object
-
- eu.webtoolkit.jwt.WObject
-
- eu.webtoolkit.jwt.WWidget
-
- eu.webtoolkit.jwt.WCompositeWidget
-
- eu.webtoolkit.jwt.WPopupWidget
-
- eu.webtoolkit.jwt.WDialog
-
- Direct Known Subclasses:
PasswordPromptDialog,WMessageBox
public class WDialog extends WPopupWidget
A WDialog shows a dialog.By default, the dialog is modal. A modal window blocks the user interface, and does not allow the user to interact with any other part of the user interface until the dialog is closed (this is enforced at the server side, so you may rely on this behavior).
A modal dialog can be instantiated synchronously or asynchronously. A non-modal dialog can only be instantiated asynchronously.
When using a dialog asynchronously, there is no API call that waits for the dialog to be closed. Then, the usage is similar to instantiating any other widget. The dialog may be closed by calling
accept(),reject()ordone()(or connecting a signal to one of these methods). This will hide the dialog and emit thefinished()signal, which you then can listen for to process the dialog result and delete the dialog. Unlike other widgets, a dialog does not need to be added to a parent widget, but is hidden by default. You must use the methodWWidget.show()orsetHidden()to show the dialog.The synchronous use of a dialog involves a call to
exec()which will block (suspend the thread) until the dialog window is closed, and return the dialog result. Events within dialog are handled using a so-called recursive event loop. Typically, an OK button will be connected toaccept(), and in some cases aStandardButton.Cancelbutton toreject(). This solution has the drawback that it is not scalable to many concurrent sessions, since for every session with a recursive event loop, a thread is locked untilexec()returns. A thread that is locked by a recursive event loop cannot be used to process requests from another sessions. When all threads in the threadpool are locked in recursive event loops, the server will be unresponsive to requests from any other session. In practical terms, this means you must not useexec(), unless your application will never be used by more concurrent users than the amount of threads in your threadpool (like on some intranets or extranets). Usingexec()is not supported from outside the regular event loop (i.e. when taking a lock on a session usingWApplication.getUpdateLock()or by posting an event using WServer::post()). This functionality is only available on Servlet 3.0 compatible servlet containers. UsesetModal()to create a non-modal dialog. A non-modal dialog does not block the underlying user interface: the user must not first deal with the dialog before interacting with the rest of the user interface.Contents for the dialog is defined by adding it to the
getContents()widget.This dialog looks like this (using the default css themes):
A simple custom dialog (default)
A simple custom dialog (polished)
Note: For the dialog (or rather, the silkscreen covering the user interface below) to render properly in IE, the "html body" margin is set to 0 (if it wasn't already).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
-
Field Summary
-
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept()Closes the dialog, with result is Accepted.voiddone(DialogCode result)Stops the dialog.EventSignalenterPressed()Event signal emitted when enter was pressed.EventSignalescapePressed()Event signal emitted when escape was pressed.DialogCodeexec()Executes the dialog in a recursive event loop.DialogCodeexec(WAnimation animation)Executes the dialog in a recursive event loop.Signal1<DialogCode>finished()Signal emitted when the dialog is closed.WContainerWidgetgetContents()Returns the dialog contents container.WContainerWidgetgetFooter()Returns the dialog footer container.DialogCodegetResult()Returns the result that was set for this dialog.WContainerWidgetgetTitleBar()Returns the dialog title bar container.WStringgetWindowTitle()Returns the dialog window title.booleanisClosable()Returns whether the dialog can be closed.booleanisModal()Returns whether the dialog is modal.booleanisMovable()Returns whether the dialog can be moved.booleanisResizable()Returns whether the dialog has a resize handle.booleanisTitleBarEnabled()Returns whether the title bar is enabled.EventSignal1<WKeyEvent>keyPressed()Event signal emitted when a "character" was entered.EventSignal1<WKeyEvent>keyWentDown()Event signal emitted when a keyboard key is pushed down.EventSignal1<WKeyEvent>keyWentUp()Event signal emitted when a keyboard key is released.JSignal2<java.lang.Integer,java.lang.Integer>moved()Signal emitted when the dialog is being moved by the user.protected voidonPathChange()voidpositionAt(WMouseEvent ev)Set the position of the widget at the mouse position.voidpositionAt(WWidget widget, Orientation orientation, java.util.EnumSet<Orientation> adjustOrientations)Positions a widget next to another widget.voidraiseToFront()Raises this dialog to be the top-most dialog.voidreject()Closes the dialog, with result is Rejected.voidrejectWhenEscapePressed()Lets pressing the escape key reject the dialog.voidrejectWhenEscapePressed(boolean enable)Lets pressing the escape key reject the dialog.voidremove()Deletes a dialog.protected voidrender(java.util.EnumSet<RenderFlag> flags)Renders the widget.JSignal2<java.lang.Integer,java.lang.Integer>resized()Signal emitted when the dialog is being resized by the user.voidsetAutoFocus(boolean enable)Set focus on the first widget in the dialog.voidsetClosable(boolean closable)Adds a close button to the titlebar.voidsetHidden(boolean hidden, WAnimation animation)Hides or shows the widget.voidsetMaximumSize(WLength width, WLength height)Sets a maximum size.voidsetMinimumSize(WLength width, WLength height)Sets a minimum size.voidsetModal(boolean modal)Sets whether the dialog is modal.voidsetMovable(boolean movable)Allows the dialog to be moved.voidsetResizable(boolean resizable)Adds a resize handle to the dialog.voidsetTitleBarEnabled(boolean enable)Enables or disables the title bar.voidsetWindowTitle(java.lang.CharSequence windowTitle)Sets the dialog window title.EventSignal1<WTouchEvent>touchEnded()Event signal emitted when a finger is removed from the screen.EventSignal1<WTouchEvent>touchMoved()Event signal emitted when a finger, which is already placed on the screen, is moved across the screen.EventSignal1<WTouchEvent>touchStarted()Event signal emitted when a finger is placed on the screen.-
Methods inherited from class eu.webtoolkit.jwt.WPopupWidget
getAdjust, getAnchorWidget, getAutoHideDelay, getOrientation, hidden, isTransient, setAdjust, setAdjust, setAnchorWidget, setAnchorWidget, setTransient, setTransient, shown
-
Methods inherited from class eu.webtoolkit.jwt.WCompositeWidget
addStyleClass, boxBorder, boxPadding, callJavaScriptMember, doJavaScript, enableAjax, find, findById, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getImplementation, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getObjectName, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getTakeImplementation, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isEnabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, load, propagateSetEnabled, propagateSetVisible, refresh, removeStyleClass, removeWidget, resize, scrollVisibilityChanged, setAttributeValue, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFloatSide, setFocus, setHiddenKeepsGeometry, setId, setImplementation, setInline, setJavaScriptMember, setLineHeight, setMargin, setObjectName, setOffsets, setParentWidget, setPopup, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment
-
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, isRendered, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
-
Methods inherited from class eu.webtoolkit.jwt.WObject
setFormData
-
-
-
-
Constructor Detail
-
WDialog
public WDialog()
Constructs a new dialog.Unlike other widgets, the dialog does not require a parent container since it is a top-level widget.
-
WDialog
public WDialog(java.lang.CharSequence windowTitle)
Constructs a dialog with a given window title.Unlike other widgets, the dialog does not require a parent container since it is a top-level widget.
-
-
Method Detail
-
remove
public void remove()
Deletes a dialog.- Overrides:
removein classWPopupWidget- See Also:
WWidget.removeWidget(WWidget widget)
-
setWindowTitle
public void setWindowTitle(java.lang.CharSequence windowTitle)
Sets the dialog window title.The window title is displayed in the title bar.
- See Also:
setTitleBarEnabled(boolean enable)
-
getWindowTitle
public WString getWindowTitle()
Returns the dialog window title.- See Also:
setWindowTitle(CharSequence windowTitle)
-
setTitleBarEnabled
public void setTitleBarEnabled(boolean enable)
Enables or disables the title bar.The titlebar is enabled by default.
-
isTitleBarEnabled
public boolean isTitleBarEnabled()
Returns whether the title bar is enabled.- See Also:
setTitleBarEnabled(boolean enable)
-
getTitleBar
public WContainerWidget getTitleBar()
Returns the dialog title bar container.The title bar contains a single text that contains the caption. You may customize the title bar by for example adding other content.
-
getContents
public WContainerWidget getContents()
Returns the dialog contents container.Content to the dialog window may be added to this container widget.
-
getFooter
public WContainerWidget getFooter()
Returns the dialog footer container.This is an optional section which is typically used for buttons.
-
exec
public DialogCode exec(WAnimation animation)
Executes the dialog in a recursive event loop.Executes the dialog synchronously. This blocks the current thread of execution until one of
done(),accept()orreject()is called.Warning: using
exec()does not scale to many concurrent sessions, since the thread is locked until exec returns, so the entire server will be unresponsive when the thread pool is exhausted.This functionality is only available on Servlet 3.0 compatible servlet containers.
- See Also:
done(DialogCode result),accept(),reject()
-
exec
public final DialogCode exec()
Executes the dialog in a recursive event loop.Returns
exec(new WAnimation())
-
done
public void done(DialogCode result)
Stops the dialog.Sets the dialog result, and emits the
finished()signal.- See Also:
finished(),getResult()
-
accept
public void accept()
Closes the dialog, with result is Accepted.- See Also:
done(DialogCode result),reject()
-
reject
public void reject()
Closes the dialog, with result is Rejected.- See Also:
done(DialogCode result),accept()
-
rejectWhenEscapePressed
public void rejectWhenEscapePressed(boolean enable)
Lets pressing the escape key reject the dialog.Before JWt 3.1.5, pressing escape automatically rejected the dialog. Since 3.1.4 this behaviour is no longer the default since it may interfere with other functionality in the dialog. Use this method to enable this behaviour.
- See Also:
reject()
-
rejectWhenEscapePressed
public final void rejectWhenEscapePressed()
Lets pressing the escape key reject the dialog.
-
finished
public Signal1<DialogCode> finished()
Signal emitted when the dialog is closed.- See Also:
done(DialogCode result),accept(),reject()
-
getResult
public DialogCode getResult()
Returns the result that was set for this dialog.- See Also:
done(DialogCode result)
-
setModal
public void setModal(boolean modal)
Sets whether the dialog is modal.A modal dialog will block the underlying user interface. A modal dialog can be shown synchronously or asynchronously. A non-modal dialog can only be shown asynchronously.
By default a dialog is modal.
-
isModal
public boolean isModal()
Returns whether the dialog is modal.- See Also:
setModal(boolean modal)
-
setResizable
public void setResizable(boolean resizable)
Adds a resize handle to the dialog.The resize handle is shown in the bottom right corner of the dialog, and allows the user to resize the dialog (but not smaller than the content allows).
This also sets the minimum width and height to
WLength.Autoto use the initial width and height as minimum sizes. You may want to provide other values for minimum width and height to allow the dialog to be reduced in size.The default value is
false.
-
isResizable
public boolean isResizable()
Returns whether the dialog has a resize handle.- See Also:
setResizable(boolean resizable)
-
setMovable
public void setMovable(boolean movable)
Allows the dialog to be moved.The dialog can be moved by grabbing the titlebar.
The default value is
true.
-
isMovable
public boolean isMovable()
Returns whether the dialog can be moved.- See Also:
setMovable(boolean movable)
-
setClosable
public void setClosable(boolean closable)
Adds a close button to the titlebar.The close button is shown in the title bar. Clicking the close button will reject the dialog.
-
isClosable
public boolean isClosable()
Returns whether the dialog can be closed.
-
setAutoFocus
public void setAutoFocus(boolean enable)
Set focus on the first widget in the dialog.Autofocus is enabled by default. If a widget inside of this dialog already has focus, the focus will not be changed.
-
setHidden
public void setHidden(boolean hidden, WAnimation animation)Description copied from class:WWidgetHides or shows the widget.Hides or show the widget (including all its descendant widgets). When setting
hidden=false, this widget and all descendant widgets that are not hidden will be shown. A widget is only visible if it and all its ancestors in the widget tree are visible, which may be checked usingisVisible().- Overrides:
setHiddenin classWPopupWidget
-
positionAt
public void positionAt(WWidget widget, Orientation orientation, java.util.EnumSet<Orientation> adjustOrientations)
Description copied from class:WWidgetPositions a widget next to another widget.Positions this absolutely positioned widget next to another
widget. Both widgets must be visible (including all their ancestors). The current widget is shown automatically if needed.When
orientation=Orientation.Vertical, the widget is displayed below the other widget (or above in case there is not enough room below). It is aligned so that the left edges align (or the right edges if there is not enough room to the right).Conversely, when
orientation=Orientation.Horizontal, the widget is displayed to the right of the other widget (or to the left in case there is not enough room to the right). It is aligned so that the top edges align (or the bottom edges if there is not enough room below).adjustOrientationsallows to specify the axes on which the widget can adjust it's position if there is not enough room next to the other widget, breaking the previous rules if necessary. For example, ifOrientation.Verticalflag ofadjustOrientationsis set, and part of the widget would be cut off by the top of the window, the widget would be move downward until the top of the widget is fully visible (or the widget reaches the bottom of the window). In that case, the widget would not be aligned with the other widget, in caseorientation=Orientation.Horizontal, or would be displayed over the other widget, in caseorientation=Orientation.Vertical.Note: This only works if JavaScript is available.
- Overrides:
positionAtin classWWidget
-
positionAt
public void positionAt(WMouseEvent ev)
Set the position of the widget at the mouse position.
-
raiseToFront
public void raiseToFront()
Raises this dialog to be the top-most dialog.
-
setMinimumSize
public void setMinimumSize(WLength width, WLength height)
Description copied from class:WWidgetSets a minimum size.Specifies a minimum size for this widget, setting CSS
min-widthandmin-heightproperties.The default minimum width and height is 0. The special value
WLength.Autoindicates that the initial width is used as minimum size. ALengthUnit.Percentagesize should not be used, as this is (in virtually all cases) undefined behaviour.When the widget is inserted in a layout manager, then the minimum size will be taken into account.
- Overrides:
setMinimumSizein classWCompositeWidget- See Also:
WWidget.resize(WLength width, WLength height),WWidget.getMinimumWidth(),WWidget.getMinimumHeight()
-
setMaximumSize
public void setMaximumSize(WLength width, WLength height)
Description copied from class:WWidgetSets a maximum size.Specifies a maximum size for this widget, setting CSS
max-widthandmax-heightproperties.The default the maximum width and height are
WLength.Auto, indicating no maximum size. ALengthUnit.Percentagesize should not be used, as this is (in virtually all cases) undefined behaviour.When the widget is a container widget that contains a layout manager, then setting a maximum size will have the effect of letting the size of the container to reflect the preferred size of the contents (rather than constraining the size of the children based on the size of the container), up to the specified maximum size.
- Overrides:
setMaximumSizein classWCompositeWidget- See Also:
WWidget.resize(WLength width, WLength height),WWidget.setMinimumSize(WLength width, WLength height)
-
resized
public JSignal2<java.lang.Integer,java.lang.Integer> resized()
Signal emitted when the dialog is being resized by the user.The information passed are the new width and height.
- See Also:
setResizable(boolean resizable)
-
moved
public JSignal2<java.lang.Integer,java.lang.Integer> moved()
Signal emitted when the dialog is being moved by the user.The information passed are the new x and y position (relative to the wietdow).
-
keyWentDown
public EventSignal1<WKeyEvent> keyWentDown()
Event signal emitted when a keyboard key is pushed down.The event will be triggered if nothing in the
WDialoghas focus
-
keyPressed
public EventSignal1<WKeyEvent> keyPressed()
Event signal emitted when a "character" was entered.The event will be triggered if nothing in the
WDialoghas focus
-
keyWentUp
public EventSignal1<WKeyEvent> keyWentUp()
Event signal emitted when a keyboard key is released.The event will be triggered if nothing in the
WDialoghas focus
-
enterPressed
public EventSignal enterPressed()
Event signal emitted when enter was pressed.The event will be triggered if nothing in the
WDialoghas focus
-
escapePressed
public EventSignal escapePressed()
Event signal emitted when escape was pressed.The event will be triggered if nothing in the
WDialoghas focus
-
touchStarted
public EventSignal1<WTouchEvent> touchStarted()
Event signal emitted when a finger is placed on the screen.
-
touchEnded
public EventSignal1<WTouchEvent> touchEnded()
Event signal emitted when a finger is removed from the screen.
-
touchMoved
public EventSignal1<WTouchEvent> touchMoved()
Event signal emitted when a finger, which is already placed on the screen, is moved across the screen.
-
render
protected void render(java.util.EnumSet<RenderFlag> flags)
Description copied from class:WWidgetRenders the widget.This function renders the widget (or an update for the widget), after this has been scheduled using
scheduleRender().The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
- Overrides:
renderin classWPopupWidget
-
onPathChange
protected void onPathChange()
- Overrides:
onPathChangein classWPopupWidget
-
-