public class Dialog extends Window implements DialogHideEvent.HasDialogHideHandlers
Window
with specialized support for buttons. Defaults to a dialog with an 'ok' button.
Code snippet:
Dialog d = new Dialog(); d.setHeadingText("Exit Warning!"); d.setWidget(new HTML("Do you wish to save before exiting?")); d.setBodyStyle("fontWeight:bold;padding:13px;"); d.setPixelSize(300, 100); d.setHideOnButtonClick(true); d.setPredefinedButtons(PredefinedButton.YES, PredefinedButton.NO, PredefinedButton.CANCEL); d.show();To check which button is clicked using the basic MVP pattern, add a
SelectEvent.HasSelectHandlers
or DialogHideEvent.HasDialogHideHandlers
method to the view's display
interface defined by the presenter:
public interface Display extends IsWidget { HasSelectHandlers getYesButton(); HasDialogHideHandlers getDialog(); }Add an implementation of the method(s) to the view:
@Override public HasSelectHandlers getYesButton() { return dialog.getButton(PredefinedButton.YES); } @Override public HasDialogHideHandlers getDialog() { return dialog; }And add a handler for the method(s) to the presenter:
display.getYesButton().addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { // Take action when user hides dialog by clicking on YES button } }); display.getDialog().addDialogHideHandler(new DialogHideHandler() { @Override public void onDialogHide(DialogHideEvent event) { // Invoke event.getHideButton() and take action based on value of returned enum } });Note: this example illustrates using both a select handler and a dialog hide handler; you can use either approach.
Modifier and Type | Class and Description |
---|---|
protected class |
Dialog.DefaultDialogMessages |
static interface |
Dialog.DialogMessages
The translatable strings (e.g.
|
static class |
Dialog.PredefinedButton
The predefined buttons supported by this dialog window.
|
Window.DefaultWindowMessages, Window.WindowAppearance, Window.WindowMessages
ContentPanel.ContentPanelAppearance, ContentPanel.ContentPanelMessages, ContentPanel.DefaultContentPanelMessages, ContentPanel.PanelHeaderAppearance
ariaMoveResizeDistance, closeBtn, dragger, manager, removeFromParentOnHide, restoreBtn
buttonBar, header, secondPassRequired
resize, widget
forceLayoutCommand, forceLayoutOnResize, hadLayoutRunning, layoutCommand, layoutRequiredThisEventLoop, layoutRunning
adjustSize, allowTextSelection, cacheSizes, disableContextMenu, disabled, disabledStyle, ensureVisibilityOnSizing, height, hidden, lastSize, layer, left, mask, maskMessage, monitorWindowResize, pageX, pageY, shim, tabIndex, toolTip, toolTipConfig, top, width, windowResizeDelay, windowResizeTask
Constructor and Description |
---|
Dialog()
Creates a dialog window with default appearance.
|
Dialog(Window.WindowAppearance appearance)
Creates a dialog window with the specified appearance.
|
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addDialogHideHandler(DialogHideEvent.DialogHideHandler handler)
Adds a
DialogHideEvent.DialogHideHandler handler for DialogHideEvent events. |
protected void |
createButtons()
Creates the buttons based on button creation constant
|
TextButton |
getButton(Dialog.PredefinedButton predefinedButton)
Returns the text button associated with the specified predefined button.
|
Dialog.DialogMessages |
getDialogMessages()
Returns the translatable strings (e.g.
|
Dialog.PredefinedButton |
getPredefinedButton(TextButton textButton)
Returns the predefined button associated with the specified text button or null if no predefined button is
associated with the text button.
|
List<Dialog.PredefinedButton> |
getPredefinedButtons()
Returns the buttons that are currently configured for this dialog window.
|
protected String |
getText(Dialog.PredefinedButton button) |
void |
hide()
Hide this widget.
|
boolean |
isHideOnButtonClick()
Returns true if the dialog will be hidden on any button click.
|
protected void |
onButtonPressed(TextButton textButton)
Called after a button in the button bar is selected.
|
void |
setDialogMessages(Dialog.DialogMessages dialogMessages)
Sets the translatable strings (e.g.
|
void |
setHideOnButtonClick(boolean hideOnButtonClick)
True to hide the dialog on any button click.
|
void |
setPredefinedButtons(Dialog.PredefinedButton... buttons)
Sets the predefined buttons to display (defaults to OK).
|
addActivateHandler, addDeactivateHandler, addMaximizeHandler, addMinimizeHandler, addRestoreHandler, afterShow, alignTo, center, createGhost, doFocus, doLayout, fitContainer, focus, getAppearance, getConstrain, getContainer, getDraggable, getFocusWidget, getMinHeight, getMinWidth, getModalPanel, getResizable, getWindowMessages, ghost, initTools, isAutoHide, isBlinkModal, isClosable, isDraggable, isMaximizable, isMaximized, isMinimizable, isModal, isOnEsc, isResizable, maximize, minimize, onAfterFirstAttach, onBrowserEvent, onDetach, onDragCancel, onDragEnd, onDragMove, onDragStart, onEndResize, onKeyPress, onResize, onStartResize, onWindowResize, restore, setActive, setAutoHide, setBlinkModal, setClosable, setConstrain, setContainer, setDraggable, setFocusWidget, setMaximizable, setMinHeight, setMinimizable, setMinWidth, setModal, setOnEsc, setPagePosition, setPosition, setResizable, setWindowMessages, setZIndex, show, showWindow, toBack, toFront, unghost
addBeforeCollapseHandler, addBeforeExpandHandler, addButton, addCollapseHandler, addExpandHandler, addTool, adjustBodySize, afterCollapse, afterExpand, collapse, doAttachChildren, doDetachChildren, doLayoutButtonBar, expand, forceLayout, getAnimationDuration, getBody, getButtonAlign, getButtonBar, getContainerTarget, getFrameSize, getHeader, getHTML, getMessages, getMinButtonWidth, getText, isAnimCollapse, isCollapsed, isCollapsible, isExpanded, isHideCollapseTool, isTitleCollapse, layoutBars, onClick, onCollapse, onDisable, onEnable, onExpand, setAnimationDuration, setAnimCollapse, setBodyBorder, setBodyStyle, setBodyStyleName, setButtonAlign, setCollapsible, setExpanded, setHeaderVisible, setHeadingHtml, setHeadingText, setHideCollapseTool, setMessages, setMinButtonWidth, setTitleCollapse
add, add, getWidget, isResize, onRemove, setElement, setResize, setWidget, setWidget
applyLayout, applyLayout, forceLayoutOnChildren, forceLayoutOnChildren, getLeftRightMargins, getParentLayoutWidget, getSideMargins, getTopBottomMargins, isLayoutRunning, isOrWasLayoutRunning, isWidgetVisible, onBeforeDoLayout, onLoad, onResize
addAddHandler, addBeforeAddHandler, addBeforeRemoveHandler, addContainerHandler, addRemoveHandler, adjustIndex, adopt, checkIndexBoundsForInsertion, clear, disable, doPhysicalAttach, doPhysicalDetach, enable, ensureGroupingHandlerRegistration, findWidget, getChildren, getItemByItemId, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, iterator, onInsert, onWidgetHide, onWidgetShow, orphan, remove, remove, remove
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleDependentName, addStyleOnOver, adjustPosition, adjustSize, applyState, assertAfterRender, assertPreRender, blur, clearSizeCache, disableContextMenu, disableEvents, enableEvents, fireCancellableEvent, fireEvent, getData, getElement, getFocusEl, getFocusSupport, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getPositionEl, getShadow, getShadowPosition, getStateId, getTabIndex, getToolTip, hideShadow, hideToolTip, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isMonitorWindowResize, isRendered, isStateful, isVisible, isVisible, mask, mask, notifyHide, notifyShow, onAttach, onBlur, onFocus, onHide, onHideContextMenu, onPosition, onRightClick, onShow, onShowContextMenu, onUnload, removeStyleDependentName, removeStyleOnOver, removeToolTip, setAllowTextSelection, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setMonitorWindowResize, setPixelSize, setShadow, setShadowPosition, setSize, setStateful, setStateId, setStyleDependentName, setTabIndex, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, sync, syncSize, unmask
public Dialog()
public Dialog(Window.WindowAppearance appearance)
appearance
- the dialog window appearancepublic HandlerRegistration addDialogHideHandler(DialogHideEvent.DialogHideHandler handler)
DialogHideEvent.HasDialogHideHandlers
DialogHideEvent.DialogHideHandler
handler for DialogHideEvent
events.addDialogHideHandler
in interface DialogHideEvent.HasDialogHideHandlers
handler
- the handlerpublic TextButton getButton(Dialog.PredefinedButton predefinedButton)
predefinedButton
- the predefined buttonsetPredefinedButtons(PredefinedButton...)
).public Dialog.DialogMessages getDialogMessages()
public Dialog.PredefinedButton getPredefinedButton(TextButton textButton)
textButton
- the text button to look uppublic List<Dialog.PredefinedButton> getPredefinedButtons()
public void hide()
Component
public boolean isHideOnButtonClick()
public void setDialogMessages(Dialog.DialogMessages dialogMessages)
dialogMessages
- the translatable stringspublic void setHideOnButtonClick(boolean hideOnButtonClick)
hideOnButtonClick
- true to hidepublic void setPredefinedButtons(Dialog.PredefinedButton... buttons)
Dialog.PredefinedButton.OK
Dialog.PredefinedButton.CANCEL
Dialog.PredefinedButton.CLOSE
Dialog.PredefinedButton.YES
Dialog.PredefinedButton.NO
buttons
- the buttons to displayprotected void createButtons()
protected String getText(Dialog.PredefinedButton button)
protected void onButtonPressed(TextButton textButton)
setHideOnButtonClick(boolean)
is true, hides the
dialog when any button is pressed.textButton
- the buttonCopyright © 2018. All rights reserved.