com.extjs.gxt.ui.client.widget
Class MessageBox

java.lang.Object
  extended by com.extjs.gxt.ui.client.widget.MessageBox

public class MessageBox
extends java.lang.Object

Utility class for generating different styles of message boxes.

Note that the MessageBox is asynchronous. Unlike a regular JavaScript alert (which will halt browser execution), showing a MessageBox will not cause the code to stop.


Nested Class Summary
static class MessageBox.MessageBoxType
          MessageBox type enumeration.
 
Field Summary
static java.lang.String CANCEL
          Button constant that displays a single CANCEL button.
static java.lang.String ERROR
          The CSS style name that provides the ERROR icon image.
static java.lang.String INFO
          The CSS style name that provides the INFO icon image.
static java.lang.String OK
          Button constant that displays a single OK button.
static java.lang.String OKCANCEL
          Button constant that displays a OK and CANCEL button.
static java.lang.String QUESTION
          The CSS style name that provides the QUESTION icon image.
static java.lang.String WARNING
          The CSS style name that provides the WARNING icon image.
static java.lang.String YESNO
          Button constant that displays a YES and NO button.
static java.lang.String YESNOCANCEL
          Button constant that displays a YES, NO, and CANCEL button.
 
Constructor Summary
MessageBox()
           
 
Method Summary
 void addCallback(Listener<MessageBoxEvent> listener)
          Adds a listener that will be called when the message box is closed.
 void addListener(EventType event, Listener<MessageBoxEvent> listener)
          Convenience method to add a listener to the underlying dialog instance.
static MessageBox alert(java.lang.String title, java.lang.String msg, Listener<MessageBoxEvent> callback)
          Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).
 void close()
          Closes the message box.
static MessageBox confirm(java.lang.String title, java.lang.String msg, Listener<MessageBoxEvent> callback)
          Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm).
 java.lang.String getButtons()
          Returns the buttons.
 int getDefaultTextHeight()
          Returns the default text height.
 Dialog getDialog()
          Returns the underlying window.
 int getMaxWidth()
          Returns the max width.
 java.lang.String getMessage()
          Returns the message.
 int getMinProgressWidth()
          Returns the min progress width.
 int getMinWidth()
          Returns the min width.
 ProgressBar getProgressBar()
          Returns the box's progress applies.
 java.lang.String getProgressText()
          Returns the progress text.
 TextArea getTextArea()
          Returns the box's text area.
 TextField<java.lang.String> getTextBox()
          Returns the box's text box.
 java.lang.String getTitle()
          Returns the title text.
 MessageBox.MessageBoxType getType()
          Returns the message box type.
 void hide()
          Deprecated. use close()
static MessageBox info(java.lang.String title, java.lang.String msg, Listener<MessageBoxEvent> callback)
          Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).
 boolean isClosable()
          Returns true if the hide button is displayed.
 boolean isModal()
          Returns true if modal is enabled.
 boolean isVisible()
          Returns true if the message box is currently displayed.
static MessageBox progress(java.lang.String title, java.lang.String msg, java.lang.String progressText)
          Displays a message box with a progress bar.
static MessageBox prompt(java.lang.String title, java.lang.String msg)
          Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
static MessageBox prompt(java.lang.String title, java.lang.String msg, boolean multiline)
          Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
static MessageBox prompt(java.lang.String title, java.lang.String msg, boolean multiline, Listener<MessageBoxEvent> callback)
          Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
static MessageBox prompt(java.lang.String title, java.lang.String msg, Listener<MessageBoxEvent> callback)
          Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
 void setButtons(java.lang.String buttons)
          The buttons to display (defaults to OK, pre-render).
 void setClosable(boolean closable)
          False to hide the top-right close button (defaults to true, pre-render).
 void setDefaultTextHeight(int defaultTextHeight)
          The default height in pixels of the message box's multiline textarea if displayed (defaults to 75, pre-render).
 void setIcon(java.lang.String iconStyle)
          Adds the specified icon to the dialog.
 void setMaxWidth(int maxWidth)
          The maximum width in pixels of the message box (defaults to 600, pre-render).
 void setMessage(java.lang.String message)
          A string that will replace the existing message box body text (defaults to the XHTML-compliant non-breaking space character ' ').
 void setMinProgressWidth(int minProgressWidth)
          The minimum width in pixels of the message box if it is a progress-style dialog.
 void setMinWidth(int minWidth)
          The minimum width in pixels of the message box (defaults to 100, pre-render).
 void setModal(boolean modal)
          False to allow user interaction with the page while the message box is displayed (defaults to true, pre-render).
 void setProgressText(java.lang.String progressText)
          The text to display inside the progress bar if progress = true (defaults to "", pre-render).
 void setTitle(java.lang.String title)
          Sets the title text (pre-render).
 void setType(MessageBox.MessageBoxType type)
          Sets the message box type (pre-render).
 void show()
          Displays the message box.
 MessageBox updateProgress(double value, java.lang.String text)
          Updates a progress-style message box's text and progress bar.
 MessageBox updateText(java.lang.String text)
          Updates the message box body text.
static MessageBox wait(java.lang.String title, java.lang.String msg, java.lang.String progressText)
          Displays a message box with an infinitely auto-updating progress bar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OK

public static final java.lang.String OK
Button constant that displays a single OK button.

See Also:
Constant Field Values

CANCEL

public static final java.lang.String CANCEL
Button constant that displays a single CANCEL button.

See Also:
Constant Field Values

OKCANCEL

public static final java.lang.String OKCANCEL
Button constant that displays a OK and CANCEL button.

See Also:
Constant Field Values

YESNO

public static final java.lang.String YESNO
Button constant that displays a YES and NO button.

See Also:
Constant Field Values

YESNOCANCEL

public static final java.lang.String YESNOCANCEL
Button constant that displays a YES, NO, and CANCEL button.

See Also:
Constant Field Values

INFO

public static java.lang.String INFO
The CSS style name that provides the INFO icon image.


WARNING

public static java.lang.String WARNING
The CSS style name that provides the WARNING icon image.


QUESTION

public static java.lang.String QUESTION
The CSS style name that provides the QUESTION icon image.


ERROR

public static java.lang.String ERROR
The CSS style name that provides the ERROR icon image.

Constructor Detail

MessageBox

public MessageBox()
Method Detail

alert

public static MessageBox alert(java.lang.String title,
                               java.lang.String msg,
                               Listener<MessageBoxEvent> callback)
Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).

Parameters:
title - the title bar text
msg - the message box body text
callback - listener to be called when the box is closed
Returns:
the new message box instance

confirm

public static MessageBox confirm(java.lang.String title,
                                 java.lang.String msg,
                                 Listener<MessageBoxEvent> callback)
Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm).

Parameters:
title - the title bar text
msg - the message box body text
callback - the listener invoked after the message box is closed
Returns:
the new message box instance

info

public static MessageBox info(java.lang.String title,
                              java.lang.String msg,
                              Listener<MessageBoxEvent> callback)
Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).

Parameters:
title - the title bar text
msg - the message box body text
callback - listener to be called when the box is closed
Returns:
the new message box instance

progress

public static MessageBox progress(java.lang.String title,
                                  java.lang.String msg,
                                  java.lang.String progressText)
Displays a message box with a progress bar. This message box has no buttons and is not closeable by the user. You are responsible for updating the progress bar as needed via updateProgress(double, java.lang.String)

Parameters:
title - the title bar text
msg - the message box body text
progressText - the text to display inside the progress bar
Returns:
the new message box

prompt

public static MessageBox prompt(java.lang.String title,
                                java.lang.String msg)
Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).

Parameters:
title - the title bar text
msg - the message box body text
Returns:
the new message box

prompt

public static MessageBox prompt(java.lang.String title,
                                java.lang.String msg,
                                boolean multiline)
Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).

Parameters:
title - the title bar text
msg - the message box body text
multiline - true for a multi-line text aread
Returns:
the new message box

prompt

public static MessageBox prompt(java.lang.String title,
                                java.lang.String msg,
                                boolean multiline,
                                Listener<MessageBoxEvent> callback)
Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).

Parameters:
title - the title bar text
msg - the message box body text
multiline - true for a multi-line text aread
Returns:
the new message box

prompt

public static MessageBox prompt(java.lang.String title,
                                java.lang.String msg,
                                Listener<MessageBoxEvent> callback)
Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).

Parameters:
title - the title bar text
msg - the message box body text
callback - the callback
Returns:
the new message box

wait

public static MessageBox wait(java.lang.String title,
                              java.lang.String msg,
                              java.lang.String progressText)
Displays a message box with an infinitely auto-updating progress bar. This can be used to block user interaction while waiting for a long-running process to complete that does not have defined intervals. You are responsible for closing the message box when the process is complete.

Parameters:
title - the title bar text
msg - the message box body text
progressText - the text to display inside the progress bar
Returns:
the new message box instance

addCallback

public void addCallback(Listener<MessageBoxEvent> listener)
Adds a listener that will be called when the message box is closed. Note that the listener will be based a MessageBoxEvent.

Parameters:
listener - the callback listener

addListener

public void addListener(EventType event,
                        Listener<MessageBoxEvent> listener)
Convenience method to add a listener to the underlying dialog instance.

Parameters:
event - the event type
listener - the listener

close

public void close()
Closes the message box.


getButtons

public java.lang.String getButtons()
Returns the buttons.

Returns:
the buttons

getDefaultTextHeight

public int getDefaultTextHeight()
Returns the default text height.

Returns:
the height

getDialog

public Dialog getDialog()
Returns the underlying window.

Returns:
the window

getMaxWidth

public int getMaxWidth()
Returns the max width.

Returns:
the max width

getMessage

public java.lang.String getMessage()
Returns the message.

Returns:
the message

getMinProgressWidth

public int getMinProgressWidth()
Returns the min progress width.

Returns:
the width

getMinWidth

public int getMinWidth()
Returns the min width.

Returns:
the min width

getProgressBar

public ProgressBar getProgressBar()
Returns the box's progress applies.

Returns:
the progress bar

getProgressText

public java.lang.String getProgressText()
Returns the progress text.

Returns:
the progress text

getTextArea

public TextArea getTextArea()
Returns the box's text area.

Returns:
the text area

getTextBox

public TextField<java.lang.String> getTextBox()
Returns the box's text box.

Returns:
the text box

getTitle

public java.lang.String getTitle()
Returns the title text.

Returns:
the title text

getType

public MessageBox.MessageBoxType getType()
Returns the message box type.

Returns:
the type

hide

public void hide()
Deprecated. use close()

Hides the message box if it is displayed.


isClosable

public boolean isClosable()
Returns true if the hide button is displayed.

Returns:
the closable state

isModal

public boolean isModal()
Returns true if modal is enabled.

Returns:
the modal state

isVisible

public boolean isVisible()
Returns true if the message box is currently displayed.

Returns:
the visible state

setButtons

public void setButtons(java.lang.String buttons)
The buttons to display (defaults to OK, pre-render).

Parameters:
buttons - the buttons

setClosable

public void setClosable(boolean closable)
False to hide the top-right close button (defaults to true, pre-render). Note that progress and wait dialogs will ignore this property and always hide the close button as they can only be closed programmatically.

Parameters:
closable - false to hide the top-right close button

setDefaultTextHeight

public void setDefaultTextHeight(int defaultTextHeight)
The default height in pixels of the message box's multiline textarea if displayed (defaults to 75, pre-render).

Parameters:
defaultTextHeight - the default text height

setIcon

public void setIcon(java.lang.String iconStyle)
Adds the specified icon to the dialog. By default, the class 'ext-mb-icon' is applied for default styling, and the class passed in is expected to supply the background image url. Pass in empty string ('') to clear any existing icon. The following built-in icon classes are supported, but you can also pass in a custom class name:
 MessageBox.INFO
 MessageBox.WARNING
 MessageBox.QUESTION
 MessageBox.ERROR
 

Parameters:
iconStyle - the icon style

setMaxWidth

public void setMaxWidth(int maxWidth)
The maximum width in pixels of the message box (defaults to 600, pre-render).

Parameters:
maxWidth - the max width

setMessage

public void setMessage(java.lang.String message)
A string that will replace the existing message box body text (defaults to the XHTML-compliant non-breaking space character ' ').

Parameters:
message - the message

setMinProgressWidth

public void setMinProgressWidth(int minProgressWidth)
The minimum width in pixels of the message box if it is a progress-style dialog. This is useful for setting a different minimum width than text-only dialogs may need (defaults to 250).

Parameters:
minProgressWidth - the min progress width

setMinWidth

public void setMinWidth(int minWidth)
The minimum width in pixels of the message box (defaults to 100, pre-render).

Parameters:
minWidth - the min width

setModal

public void setModal(boolean modal)
False to allow user interaction with the page while the message box is displayed (defaults to true, pre-render).

Parameters:
modal - true for modal

setProgressText

public void setProgressText(java.lang.String progressText)
The text to display inside the progress bar if progress = true (defaults to "", pre-render).

Parameters:
progressText - the progress text

setTitle

public void setTitle(java.lang.String title)
Sets the title text (pre-render).

Parameters:
title - the title text

setType

public void setType(MessageBox.MessageBoxType type)
Sets the message box type (pre-render).

Parameters:
type - the type

show

public void show()
Displays the message box.


updateProgress

public MessageBox updateProgress(double value,
                                 java.lang.String text)
Updates a progress-style message box's text and progress bar. Only relevant on message boxes initiated via progress(java.lang.String, java.lang.String, java.lang.String).

Parameters:
value - any number between 0 and 1 (e.g., .5)
text - the progress text to display inside the progress bar or null
Returns:
this

updateText

public MessageBox updateText(java.lang.String text)
Updates the message box body text.

Parameters:
text - the new text or null to clear
Returns:
this