Class Dialog

All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsWidget, LogicalStructure, HasButtonClickHandlers, HasClearHandlers, HasClickHandlers, HasCloseClickHandlers, HasDoubleClickHandlers, HasDragMoveHandlers, HasDragRepositionMoveHandlers, HasDragRepositionStartHandlers, HasDragRepositionStopHandlers, HasDragResizeMoveHandlers, HasDragResizeStartHandlers, HasDragResizeStopHandlers, HasDragStartHandlers, HasDragStopHandlers, HasDropHandlers, HasDropMoveHandlers, HasDropOutHandlers, HasDropOverHandlers, HasFocusChangedHandlers, HasHoverHandlers, HasHoverHiddenHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasMaximizeClickHandlers, HasMinimizeClickHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseStillDownHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasMovedHandlers, HasParentMovedHandlers, HasResizedHandlers, HasRestoreClickHandlers, HasRightMouseDownHandlers, HasRuleContextChangedHandlers, HasScrolledHandlers, HasShowContextMenuHandlers, HasVisibilityChangedHandlers, HasMembersChangedHandlers
Direct Known Subclasses:
BuildViaAIProgressDialog

public class Dialog extends Window implements HasButtonClickHandlers
Dialogs are a specialized version of Window used for small windows that contain just a text message or a text mesage with some standard buttons.

Many typical modal dialogs such as alerts and confirmations are built into the system with convenience APIs - see SC.say(), SC.warn() and SC.askforValue().

Dialogs can be modal or non-modal according to isModal.

NOTE: If you are building a dialog that will involve more than just buttons and a message, consider starting from the Window class instead, where arbitrary components can be added to the body area via Window.addItem().

This is an example of creating a custom dialog:

  final Dialog dialog = new Dialog();
  dialog.setMessage("Please choose whether to proceed");
  dialog.setIcon("[SKIN]ask.png");
  dialog.setButtons(new Button("OK"), new Button("Cancel"));
  dialog.addButtonClickHandler(new ButtonClickHandler() {
      public void onButtonClick(ButtonClickEvent event) {
          dialog.hide();
      }
  });
  dialog.draw();
  
  • Field Details

  • Constructor Details

  • Method Details

    • getOrCreateRef

      public static Dialog getOrCreateRef(JavaScriptObject jsObj)
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, Canvas defaults)
      Changes the defaults for Canvas AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - Canvas defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, FormItem defaults)
      Changes the defaults for FormItem AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - FormItem defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • create

      protected JavaScriptObject create()
      Overrides:
      create in class Window
    • setAskIcon

      public Dialog setAskIcon(String askIcon) throws IllegalStateException
      Icon to show in the SC.ask() dialog.
      Parameters:
      askIcon - New askIcon value. Default value is "[SKIN]ask.png"
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getAskIcon

      public String getAskIcon()
      Icon to show in the SC.ask() dialog.
      Returns:
      Current askIcon value. Default value is "[SKIN]ask.png"
      See Also:
    • setAutoFocus

      public Dialog setAutoFocus(Boolean autoFocus) throws IllegalStateException
      If a toolbar is showing, automatically place keyboard focus in the first button.

      An alternative button can be specified by autoFocusButton.

      Parameters:
      autoFocus - New autoFocus value. Default value is true
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getAutoFocus

      public Boolean getAutoFocus()
      If a toolbar is showing, automatically place keyboard focus in the first button.

      An alternative button can be specified by autoFocusButton.

      Returns:
      Current autoFocus value. Default value is true
      See Also:
    • setAutoFocusButton

      public Dialog setAutoFocusButton(Canvas autoFocusButton) throws IllegalStateException
      If a toolbar is showing and autoFocus is enabled, which button should receive initial focus.
      Parameters:
      autoFocusButton - New autoFocusButton value. Default value is true
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getAutoFocusButton

      public Canvas getAutoFocusButton()
      If a toolbar is showing and autoFocus is enabled, which button should receive initial focus.
      Returns:
      Current autoFocusButton value. Default value is true
      See Also:
    • setAutoFocusButton

      public Dialog setAutoFocusButton(String autoFocusButton) throws IllegalStateException
      If a toolbar is showing and autoFocus is enabled, which button should receive initial focus.
      Parameters:
      autoFocusButton - New autoFocusButton value. Default value is true
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getAutoFocusButtonAsString

      public String getAutoFocusButtonAsString()
      If a toolbar is showing and autoFocus is enabled, which button should receive initial focus.
      Returns:
      Current autoFocusButton value. Default value is true
      See Also:
    • setAutoFocusButton

      public Dialog setAutoFocusButton(int autoFocusButton) throws IllegalStateException
      If a toolbar is showing and autoFocus is enabled, which button should receive initial focus.
      Parameters:
      autoFocusButton - New autoFocusButton value. Default value is true
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getAutoFocusButtonAsInt

      public int getAutoFocusButtonAsInt()
      If a toolbar is showing and autoFocus is enabled, which button should receive initial focus.

      Note : This method will return -1 if the underlying SmartClient JavaScript attribute value cannot be expressed as a(n) int. In that case, other getters, similarly-named but ending in AsString, AsCanvas, etc., may be provided.

      Returns:
      Current autoFocusButton value. Default value is true
      See Also:
    • setConfirmIcon

      public Dialog setConfirmIcon(String confirmIcon) throws IllegalStateException
      Icon to show in the SC.confirm() dialog.
      Parameters:
      confirmIcon - New confirmIcon value. Default value is "[SKIN]confirm.png"
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getConfirmIcon

      public String getConfirmIcon()
      Icon to show in the SC.confirm() dialog.
      Returns:
      Current confirmIcon value. Default value is "[SKIN]confirm.png"
      See Also:
    • setDefaultWidth

      public Dialog setDefaultWidth(int defaultWidth) throws IllegalStateException
      Description copied from class: Canvas
      For custom components, establishes a default width for the component.

      For a component that should potentially be sized automatically by a Layout, set this property rather than width directly, because Layouts regard a width setting as an explicit size that shouldn't be changed.

      Note : This is an advanced setting

      Overrides:
      setDefaultWidth in class Canvas
      Parameters:
      defaultWidth - New defaultWidth value. Default value is 360
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getDefaultWidth

      public int getDefaultWidth()
      Description copied from class: Canvas
      For custom components, establishes a default width for the component.

      For a component that should potentially be sized automatically by a Layout, set this property rather than width directly, because Layouts regard a width setting as an explicit size that shouldn't be changed.

      Overrides:
      getDefaultWidth in class Canvas
      Returns:
      Current defaultWidth value. Default value is 360
      See Also:
    • setIcon

      public Dialog setIcon(String icon) throws IllegalStateException
      Icon to show in this dialog - see message.
      Parameters:
      icon - New icon value. Default value is null
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getIcon

      public String getIcon()
      Icon to show in this dialog - see message.
      Returns:
      Current icon value. Default value is null
      See Also:
    • setIconSize

      public Dialog setIconSize(int iconSize) throws IllegalStateException
      Size of the icon to show in this dialog.
      Parameters:
      iconSize - New iconSize value. Default value is 32
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getIconSize

      public int getIconSize()
      Size of the icon to show in this dialog.
      Returns:
      Current iconSize value. Default value is 32
    • setIconStyle

      public Dialog setIconStyle(String iconStyle) throws IllegalStateException
      Specifies the CSS style if the icon in this Dialog.
      Parameters:
      iconStyle - New iconStyle value. Default value is "icon"
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • getIconStyle

      public String getIconStyle()
      Specifies the CSS style if the icon in this Dialog.
      Returns:
      Current iconStyle value. Default value is "icon"
    • setMessage

      public Dialog setMessage(String message)
      Message to show in this dialog.

      If a message is set the primary purpose of the dialog will be assumed to be to show a message with buttons - auto-sizing to the message text will be enabled, and, if icon has also been set, the messageLabel and messageIcon AutoChildren will be created and placed together in the messageStack AutoChild, with the toolbar underneath as usual. If any of these behaviors are inconvenient or you want more precise control over a message and some custom widgets, start from the superclass Window instead, and add controls via Window.addItem().

      The message string may contain "${loadingImage}", if so, the standard loading spinner will appear at that location in the text (see loadingImageSrc).

      The message will be styled with the messageStyle.

      If this method is called after the component has been drawn/initialized: Method to update the message on this Dialog.

      Parameters:
      message - new message to show. Default value is null
      Returns:
      Dialog instance, for chaining setter calls
      See Also:
    • getMessage

      public String getMessage()
      Message to show in this dialog.

      If a message is set the primary purpose of the dialog will be assumed to be to show a message with buttons - auto-sizing to the message text will be enabled, and, if icon has also been set, the messageLabel and messageIcon AutoChildren will be created and placed together in the messageStack AutoChild, with the toolbar underneath as usual. If any of these behaviors are inconvenient or you want more precise control over a message and some custom widgets, start from the superclass Window instead, and add controls via Window.addItem().

      The message string may contain "${loadingImage}", if so, the standard loading spinner will appear at that location in the text (see loadingImageSrc).

      The message will be styled with the messageStyle.

      Returns:
      Current message value. Default value is null
      See Also:
    • getMessageIcon

      public Img getMessageIcon() throws IllegalStateException
      AutoChild that shows icon.

      This component is an AutoChild named "messageIcon". For an overview of how to use and configure AutoChildren, see Using AutoChildren.

      Returns:
      Current messageIcon value. Default value is null
      Throws:
      IllegalStateException - if this widget has not yet been rendered.
    • getMessageLabel

      public Label getMessageLabel() throws IllegalStateException
      AutoChild that shows message.

      This component is an AutoChild named "messageLabel". For an overview of how to use and configure AutoChildren, see Using AutoChildren.

      Returns:
      Current messageLabel value. Default value is null
      Throws:
      IllegalStateException - if this widget has not yet been rendered.
    • getMessageStack

      public Layout getMessageStack() throws IllegalStateException
      AutoChild that combines message and icon.

      This component is an AutoChild named "messageStack". For an overview of how to use and configure AutoChildren, see Using AutoChildren.

      Returns:
      Current messageStack value. Default value is null
      Throws:
      IllegalStateException - if this widget has not yet been rendered.
    • setSayIcon

      public Dialog setSayIcon(String sayIcon) throws IllegalStateException
      Icon to show in the SC.say() dialog.
      Parameters:
      sayIcon - New sayIcon value. Default value is "[SKIN]say.png"
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getSayIcon

      public String getSayIcon()
      Icon to show in the SC.say() dialog.
      Returns:
      Current sayIcon value. Default value is "[SKIN]say.png"
      See Also:
    • setShowToolbar

      public Dialog setShowToolbar(Boolean showToolbar) throws IllegalStateException
      Whether to show a toolbar of buttons at the bottom of the Dialog. Default of null will cause the value to be resolved automatically to true or false when the Dialog is first drawn according as toolbarButtons contains buttons or not.
      Parameters:
      showToolbar - New showToolbar value. Default value is null
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getShowToolbar

      public Boolean getShowToolbar()
      Whether to show a toolbar of buttons at the bottom of the Dialog. Default of null will cause the value to be resolved automatically to true or false when the Dialog is first drawn according as toolbarButtons contains buttons or not.
      Returns:
      Current showToolbar value. Default value is null
      See Also:
    • setStyleName

      public void setStyleName(String styleName)
      Style of the Dialog background
      Overrides:
      setStyleName in class Canvas
      Parameters:
      styleName - New styleName value. Default value is "dialogBackground"
      See Also:
    • getStyleName

      public String getStyleName()
      Style of the Dialog background
      Overrides:
      getStyleName in class Canvas
      Returns:
      Current styleName value. Default value is "dialogBackground"
      See Also:
    • getToolbar

      public Toolbar getToolbar() throws IllegalStateException
      com.smartgwt.client.types.AutoChild of type Toolbar used to create the toolbarButtons.

      This component is an AutoChild named "toolbar". For an overview of how to use and configure AutoChildren, see Using AutoChildren.

      Returns:
      Current toolbar value. Default value is null
      Throws:
      IllegalStateException - if this widget has not yet been rendered.
    • setWarnIcon

      public Dialog setWarnIcon(String warnIcon) throws IllegalStateException
      Icon to show in the SC.warn() dialog.
      Parameters:
      warnIcon - New warnIcon value. Default value is "[SKIN]warn.png"
      Returns:
      Dialog instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • getWarnIcon

      public String getWarnIcon()
      Icon to show in the SC.warn() dialog.
      Returns:
      Current warnIcon value. Default value is "[SKIN]warn.png"
      See Also:
    • buttonClick

      public void buttonClick(StatefulCanvas button, int index)
      Fires when any button in this Dialog's toolbar is clicked. Default implementation does nothing.
      Parameters:
      button - button that was clicked
      index - index of the button that was clicked
    • addButtonClickHandler

      public HandlerRegistration addButtonClickHandler(ButtonClickHandler handler)
      Add a buttonClick handler.

      Fires when any button in this Dialog's toolbar is clicked. Default implementation does nothing.

      Specified by:
      addButtonClickHandler in interface HasButtonClickHandlers
      Parameters:
      handler - the buttonClick handler
      Returns:
      HandlerRegistration used to remove this handler
    • setDefaultProperties

      public static void setDefaultProperties(Dialog dialogProperties)
      Class level method to set the default properties of this class. If set, then all existing and subsequently created instances of this class will automatically have default properties corresponding to the properties set on the SmartGWT class instance passed to this function before its underlying SmartClient JS object was created. This is a powerful feature that eliminates the need for users to create a separate hierarchy of subclasses that only alter the default properties of this class. Can also be used for skinning / styling purposes.

      Note: This method is intended for setting default attributes only and will affect all instances of the underlying class (including those automatically generated in JavaScript). This method should not be used to apply standard EventHandlers or override methods for a class - use a custom subclass instead. Calling this method after instances have been created can result in undefined behavior, since it bypasses any setters and a class instance may have already examined a particular property and not be expecting any changes through this route.

      Parameters:
      dialogProperties - properties that should be used as new defaults when instances of this class are created
      See Also:
    • setToolbarButtons

      public void setToolbarButtons(Canvas... toolbarButtons)
      This is a synonym for setButtons().

      Sets the array of Buttons to show in the toolbar, if shown.

      Note that the buttons passed to this API may either be widgets intended as live buttons, or configuration objects (as in the case of ListGrid.setFilterButtonProperties()). However, the safeguards present in the latter API can't be imposed here, because there's no way to tell which widgets are live objects, and which are intended for configuration. In effect, all widgets will be treated as live objects. As a result, you musn't reuse any configuration object passed to this API, which includes passing anything to thsi API that's already been passed to "real" config APIs (like the one mentioned).

      Parameters:
      toolbarButtons - buttons for the toolbar. Default value is null
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • setMessageStyle

      public void setMessageStyle(String messageStyle) throws IllegalStateException
      Style to apply to the message text shown in the center of the dialog

      Note : This is an advanced setting

      Parameters:
      messageStyle - messageStyle Default value is "normal"
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
    • setButtons

      public void setButtons(Button... buttons) throws IllegalStateException
      Array of Buttons to show in the toolbar, if shown.

      The set of buttons to use is typically set by calling one of the shortcuts such as SC.say() or SC.confirm(). A custom set of buttons can be passed to these shortcuts methods via the "properties" argument, or to a directly created Dialog.

      In both cases, a mixture of built-in buttons, custom buttons, and other components (such as a LayoutSpacer) can be passed.

      Built-in buttons can be referred to via static fields on the Dialog class such as Dialog.OK, for example:

       Dialog dialog = new Dialog();
       Canvas layoutSpacer = new LayoutSpacer();
       layoutSpacer.setWidth(50);
       Button notNowButton = new Button("Not now");
       notNowButton.addClickHandler(new ClickHandler() {
           public void onClick(ClickEvent event) {
               doSomething();
           }
       });
       dialog.setButtons(Dialog.OK, Dialog.CANCEL, layoutSpacer, notNowButton);
       dialog.draw();
       
      All buttons will fire the Dialog.buttonClick() handler.

      Note that the buttons passed to this API may either be widgets intended as live buttons, or configuration objects (as in the case of ListGrid.setFilterButtonProperties()). However, the safeguards present in the latter API can't be imposed here, because there's no way to tell which widgets are live objects, and which are intended for configuration. In effect, all widgets will be treated as live objects. As a result, you musn't reuse any configuration object passed to this API, which includes passing anything to thsi API that's already been passed to "real" config APIs (like the one mentioned).

      While any live objects that have already been instantiated at the time this call is made will become Buttons in the Dialog, uninstantiated live objects will merely be used as templates to create separate SmartGWT Button objects when the Dialog instance is created. If you need the live objects you pass in to be the ones actually returned by Dialog-related events, you can force instantiation beforehand by calling button.completeCreation().

      Parameters:
      buttons - buttons Default value is null
      Throws:
      IllegalStateException - this property cannot be changed after the component has been created
      See Also:
    • setLogicalStructure

      public LogicalStructureObject setLogicalStructure(DialogLogicalStructure s)
      Setter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
    • getLogicalStructure

      public LogicalStructureObject getLogicalStructure()
      Getter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
      Specified by:
      getLogicalStructure in interface LogicalStructure
      Overrides:
      getLogicalStructure in class Window