GWT Tk 0.2.3

asquare.gwt.tk.client.ui
Class AlertDialog

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Panel
              extended by com.google.gwt.user.client.ui.SimplePanel
                  extended by com.google.gwt.user.client.ui.PopupPanel
                      extended by asquare.gwt.tk.client.ui.CPopupPanel
                          extended by asquare.gwt.tk.client.ui.ModalDialog
                              extended by asquare.gwt.tk.client.ui.AlertDialog
All Implemented Interfaces:
ControllerSupport, EventListener, EventPreview, HasWidgets, SourcesPopupEvents

public class AlertDialog
extends ModalDialog

A modal dialog tailored to conveniently displaying alerts.

Features:

Icon
An image indicating the type / severity of the condition.
Caption Text
A brief summary of the condition which triggered the dialog. Displayed in the "title".
Message
A detail of the consequences of the actions presented by the dialog.
Buttons
0 or more buttons. The button text should correspond to the alert message, as if the user is answering a question.
Hot keys
Hot keys can be assigned to trigger actions when pressed.
Button roles
The "Default" button is automatically focused when the dialog is shown. The "Cancel" button maps to the "Esc" hotkey.

A callback is assigned to each button in the form of a Command. When a button is pressed, the dialog will be hidden and the command will be executed.

CSS Style Rules

See Also:
Apple Human Interface Guidlines, Windows User Interface Guidelines

Nested Class Summary
static class AlertDialog.ArrowKeyFocusController
          A controller which cycles the focus when the arrow keys are pressed.
static class AlertDialog.HideAndExecuteCommand
          A command wrapper which hides the dialog then executes a wrapped command.
static class AlertDialog.HotKeyController
          A controller which listens for the onkeydown event of a registered hotkey and executes the associated command.
 
Nested classes/interfaces inherited from class asquare.gwt.tk.client.ui.ModalDialog
ModalDialog.CaptionWrapper, ModalDialog.FocusOnCloseController, ModalDialog.InitializeFocusController, ModalDialog.PositionDialogController, ModalDialog.PositionDialogControllerIE6
 
Field Summary
static int BUTTON_CANCEL
          Indicates that a button has the Cancel role.
static int BUTTON_CANCEL_DEFAULT
          Indicates that a button has both the Default and Cancel roles.
static int BUTTON_DEFAULT
          Indicates that a button has the Default role.
static int BUTTON_PLAIN
          Indicates a button which has no special roles.
static String TEXT_CANCEL
          Text for the "Cancel" button used in factory generated dialogs.
static String TEXT_OK
          Text for the "OK" button used in factory generated dialogs.
 
Fields inherited from class asquare.gwt.tk.client.ui.ModalDialog
s_focusImpl, STYLENAME_CAPTION, STYLENAME_CONTENT, STYLENAME_DIALOG, STYLENAME_DRAGGING, STYLENAME_GLASSPANEL
 
Constructor Summary
AlertDialog()
          Creates an empty AlertDialog.
 
Method Summary
 void addButton(String text, char hotKey, Command command, int type)
          Adds a button to button panel.
 void addButton(Widget widget, char hotKey, Command command, int type)
          Adds a widget to button panel.
protected  Widget buildCaption()
          Factory method which creates the caption.
protected  List createControllers()
          A factory method which gives a subclass the opportunity to override default controller creation.
static AlertDialog createError(Command okCommand, String captionText, String message)
          Creates a high severity "stop" modal dialog with an OK button.
static AlertDialog createInfo(Command okCommand, String captionText, String message)
          Creates a low severity modal dialog with an OK button.
static AlertDialog createWarning(Command okCommand, String captionText, String message)
          Creates a medium severity modal dialog with a OK and Cancel buttons.
 Widget getButton(int index)
          Gets the widget in the button panel corresponding to index.
 int getButtonCount()
          Gets the number of widgets in the button panel.
 String getCaptionText()
          Get the text which will be displayed in the caption.
 Image getIcon()
          Get the image which will be displayed in the caption.
 KeyMap getKeyMap()
          Gets the map of hotkeys to commands.
 Widget getMessage()
          Get the message which will be displayed in the dialog.
 void removeButton(Widget button)
          Removes the specified button from the button panel.
 void setCaptionText(String captionText, boolean asHtml)
          Set the text which will be displayed in the caption.
 void setIcon(Image icon)
          Set the image will be displayed in the caption.
 void setIcon(String url)
          Set the image will be displayed in the caption.
 void setMessage(String text)
          Set the message which will be displayed in the dialog.
 void setMessage(String text, boolean asHtml)
          Set the message which will be displayed in the dialog.
 void setMessage(Widget widget)
          Set a widget to be displayed in the message area of the dialog.
 void show()
          Shows the glasspanel and dialog then focuses the widget selected in the focus model.
 void show(HasFocus focusOnCloseWidget)
          Shows the glasspanel and dialog then focuses the widget selected in the focus model.
 
Methods inherited from class asquare.gwt.tk.client.ui.ModalDialog
add, createCaptionControllers, getContentElement, getContentMinHeight, getContentMinWidth, getContentOffsetHeight, getContentOffsetWidth, getFocusModel, getFocusOnCloseWidget, getGlassPanel, hide, onAttach, onDetach, remove, setCaption, setCaption, setContentHeight, setContentMinHeight, setContentMinWidth, setContentWidth, setFocusModel, setWidget
 
Methods inherited from class asquare.gwt.tk.client.ui.CPopupPanel
addController, getController, onBrowserEvent, onEventPreview, removeController, setControllers, sinkEvents, unsinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.PopupPanel
addPopupListener, getPopupLeft, getPopupTop, onKeyDownPreview, onKeyPressPreview, onKeyUpPreview, removePopupListener, setPopupPosition
 
Methods inherited from class com.google.gwt.user.client.ui.SimplePanel
getContainerElement, getWidget, iterator
 
Methods inherited from class com.google.gwt.user.client.ui.Panel
adopt, clear, disown
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
getParent, isAttached, onLoad, removeFromParent
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleName, getTitle, isVisible, isVisible, removeStyleName, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setTitle, setVisible, setVisible, setWidth, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TEXT_OK

public static final String TEXT_OK
Text for the "OK" button used in factory generated dialogs. Applies the .tk-AlertDialog-hotKeyChar style to "O".

See Also:
Constant Field Values

TEXT_CANCEL

public static final String TEXT_CANCEL
Text for the "Cancel" button used in factory generated dialogs. Applies the .tk-AlertDialog-hotKeyChar style to "C".

See Also:
Constant Field Values

BUTTON_PLAIN

public static final int BUTTON_PLAIN
Indicates a button which has no special roles.

See Also:
Constant Field Values

BUTTON_DEFAULT

public static final int BUTTON_DEFAULT
Indicates that a button has the Default role. The Default button will have initial focus. Never make an action default if it could have severe consequences such as data loss. The dialog may only have one button of this type.

See Also:
Constant Field Values

BUTTON_CANCEL

public static final int BUTTON_CANCEL
Indicates that a button has the Cancel role. Pressing Esc will execute the button's associated command. The dialog may only have one button of this type.

See Also:
Constant Field Values

BUTTON_CANCEL_DEFAULT

public static final int BUTTON_CANCEL_DEFAULT
Indicates that a button has both the Default and Cancel roles. It will have initial focus and the user can press Esc to execute this button's command. The dialog may have no other buttons of type Default or Cancel.

See Also:
Constant Field Values
Constructor Detail

AlertDialog

public AlertDialog()
Creates an empty AlertDialog.

Method Detail

createInfo

public static AlertDialog createInfo(Command okCommand,
                                     String captionText,
                                     String message)
Creates a low severity modal dialog with an OK button. Use for hints, tips, welcome messages, etc....

Parameters:
okCommand - a command to execute after the dialog is dismissed, or null
captionText - a String to display in the dialog title, or null
message - text a String display in the content area of the dialog, or null

createWarning

public static AlertDialog createWarning(Command okCommand,
                                        String captionText,
                                        String message)
Creates a medium severity modal dialog with a OK and Cancel buttons. Use for "Do you want to continue" style dialogs.

Parameters:
okCommand - a command to execute if the user presses the OK button, or null
captionText - a String to display in the dialog title, or null
message - text a String display in the content area of the dialog, or null

createError

public static AlertDialog createError(Command okCommand,
                                      String captionText,
                                      String message)
Creates a high severity "stop" modal dialog with an OK button. Use when an error condition prevents the normal execution of the application.

Parameters:
okCommand - a command to execute after the dialog is dismissed, or null
captionText - a String to display in the dialog title, or null
message - text a String display in the content area of the dialog, or null

createControllers

protected List createControllers()
Description copied from class: CPopupPanel
A factory method which gives a subclass the opportunity to override default controller creation.

Overrides:
createControllers in class ModalDialog
Returns:
a List with 0 or more controllers, or null

getKeyMap

public KeyMap getKeyMap()
Gets the map of hotkeys to commands. Alpha keycodes are represented in upper case.

Returns:
the keymap

getIcon

public Image getIcon()
Get the image which will be displayed in the caption.


setIcon

public void setIcon(String url)
Set the image will be displayed in the caption.

Parameters:
url - a URL to an image or null

setIcon

public void setIcon(Image icon)
Set the image will be displayed in the caption. You can use an Icon to ensure size information is available when the dialog layout is calculated.

Parameters:
icon - an image or null
See Also:
Icon

getCaptionText

public String getCaptionText()
Get the text which will be displayed in the caption.

Returns:
a String or null

setCaptionText

public void setCaptionText(String captionText,
                           boolean asHtml)
Set the text which will be displayed in the caption.

Parameters:
captionText - a String or null
asHtml - true to treat captionText as HTML, false to treat captionText as plain text

buildCaption

protected Widget buildCaption()
Factory method which creates the caption. Called just before the dialog is shown.

Returns:
the caption, or null

getMessage

public Widget getMessage()
Get the message which will be displayed in the dialog.

Returns:
a String, or null

setMessage

public void setMessage(String text)
Set the message which will be displayed in the dialog.

Parameters:
text - a String, or null

setMessage

public void setMessage(String text,
                       boolean asHtml)
Set the message which will be displayed in the dialog.

Parameters:
text - a String, or null
asHtml - true to treat captionText as HTML, false to treat captionText as plain text

setMessage

public void setMessage(Widget widget)
Set a widget to be displayed in the message area of the dialog.

Parameters:
widget - a Widget, or null

getButton

public Widget getButton(int index)
Gets the widget in the button panel corresponding to index.

Parameters:
index - an integer >= 0
Returns:
the button widget

getButtonCount

public int getButtonCount()
Gets the number of widgets in the button panel.


addButton

public void addButton(String text,
                      char hotKey,
                      Command command,
                      int type)
Adds a button to button panel.

Parameters:
text - the text to display in the button
hotKey - the keycode of a key which will execute the widget's associated command when pressed
command - a command to execute if the button is clicked, or null
type - a constant representing special button behavior

addButton

public void addButton(Widget widget,
                      char hotKey,
                      Command command,
                      int type)
Adds a widget to button panel. The widget will be added to the focus cycle if it implements HasFocus and does not have a tabIndex < 0. The widget must implement SourcesClickEvents. When a button is clicked, the dialog will be closed and the specified command will be executed.

Parameters:
widget - the widget to add
hotKey - the keycode of a key which will execute the widget's associated command when pressed
command - a command to execute if the button is clicked, or null
type - a constant representing special button behavior
Throws:
ClassCastException - if widget does not implement HasFocus

removeButton

public void removeButton(Widget button)
Removes the specified button from the button panel. Note: this will not remove commands that were put in the keymap when the button was added.

Parameters:
button -
See Also:
getKeyMap()

show

public void show()
Description copied from class: ModalDialog
Shows the glasspanel and dialog then focuses the widget selected in the focus model.

Overrides:
show in class ModalDialog

show

public void show(HasFocus focusOnCloseWidget)
Description copied from class: ModalDialog
Shows the glasspanel and dialog then focuses the widget selected in the focus model.

Overrides:
show in class ModalDialog
Parameters:
focusOnCloseWidget - a widget to focus after this dialog is closed

GWT Tk 0.2.3

© 2007 Mat Gessel