org.mailster.gui.dialogs
Class ErrorDialog

java.lang.Object
  extended by org.eclipse.jface.window.Window
      extended by org.eclipse.jface.dialogs.Dialog
          extended by org.eclipse.jface.dialogs.IconAndMessageDialog
              extended by org.mailster.gui.dialogs.ErrorDialog
All Implemented Interfaces:
org.eclipse.jface.window.IShellProvider

public class ErrorDialog
extends org.eclipse.jface.dialogs.IconAndMessageDialog


Nested Class Summary
static class ErrorDialog.StringPrintWriter
           
 
Nested classes/interfaces inherited from class org.eclipse.jface.window.Window
org.eclipse.jface.window.Window.IExceptionHandler
 
Field Summary
static boolean AUTOMATED_MODE
          Static to prevent opening of error dialogs for automated testing.
private  org.eclipse.swt.dnd.Clipboard clipboard
          The current clipboard.
private  org.eclipse.swt.widgets.Button detailsButton
          The Details button.
private  int displayMask
          Filter mask for determining which status items to display.
private  org.eclipse.swt.widgets.List list
          The SWT list control that displays the error details.
private static int LIST_ITEM_COUNT
          Reserve room for this many list items.
private  boolean listCreated
          Indicates whether the error details viewer is currently created.
private static java.lang.String NESTING_INDENT
          The nesting indent.
private  boolean shouldIncludeTopLevelErrorInDetails
           
private  org.eclipse.core.runtime.IStatus status
          The main status object.
private  java.lang.String title
          The title of the dialog.
 
Fields inherited from class org.eclipse.jface.dialogs.IconAndMessageDialog
imageLabel, message, messageLabel
 
Fields inherited from class org.eclipse.jface.dialogs.Dialog
blockedHandler, buttonBar, DIALOG_DEFAULT_BOUNDS, DIALOG_PERSISTLOCATION, DIALOG_PERSISTSIZE, dialogArea, DLG_IMG_ERROR, DLG_IMG_HELP, DLG_IMG_INFO, DLG_IMG_MESSAGE_ERROR, DLG_IMG_MESSAGE_INFO, DLG_IMG_MESSAGE_WARNING, DLG_IMG_QUESTION, DLG_IMG_WARNING, ELLIPSIS
 
Fields inherited from class org.eclipse.jface.window.Window
CANCEL, OK
 
Constructor Summary
ErrorDialog(org.eclipse.swt.widgets.Shell parentShell, java.lang.String dialogTitle, java.lang.String message, org.eclipse.core.runtime.IStatus status, int displayMask)
          Creates an error dialog.
 
Method Summary
protected  void buttonPressed(int id)
           
 boolean close()
           
protected  void configureShell(org.eclipse.swt.widgets.Shell shell)
           
private  void copyToClipboard()
          Copy the contents of the statuses to the clipboard.
protected  void createButtonsForButtonBar(org.eclipse.swt.widgets.Composite parent)
           
protected  void createDetailsButton(org.eclipse.swt.widgets.Composite parent)
          Create the details button if it should be included.
protected  void createDialogAndButtonArea(org.eclipse.swt.widgets.Composite parent)
           
protected  org.eclipse.swt.widgets.Control createDialogArea(org.eclipse.swt.widgets.Composite parent)
          This implementation of the Dialog framework method creates and lays out a composite and calls createMessageArea and createCustomArea to populate it.
protected  org.eclipse.swt.widgets.List createDropDownList(org.eclipse.swt.widgets.Composite parent)
          Create this dialog's drop-down list component.
protected  org.eclipse.swt.graphics.Image getImage()
           
private  java.util.List<java.lang.String> getStackTrace(java.lang.Throwable t)
           
 int open()
          Extends Window.open().
static int openError(org.eclipse.swt.widgets.Shell parent, java.lang.String dialogTitle, java.lang.String message, org.eclipse.core.runtime.IStatus status)
          Opens an error dialog to display the given error.
static int openError(org.eclipse.swt.widgets.Shell parentShell, java.lang.String title, java.lang.String message, org.eclipse.core.runtime.IStatus status, int displayMask)
          Opens an error dialog to display the given error.
private  void populateCopyBuffer(org.eclipse.core.runtime.IStatus buildingStatus, java.lang.StringBuffer buffer, int nesting)
          Put the details of the status of the error onto the stream.
private  void populateList(org.eclipse.swt.widgets.List listToPopulate)
          Populates the list using this error dialog's status object.
private  void populateList(org.eclipse.swt.widgets.List listToPopulate, org.eclipse.core.runtime.IStatus buildingStatus, int nesting, boolean includeStatus)
          Populate the list with the messages from the given status.
private  void repopulateList()
          Repopulate the supplied list widget.
protected  void setStatus(org.eclipse.core.runtime.IStatus status)
          Set the status displayed by this error dialog to the given status.
protected static boolean shouldDisplay(org.eclipse.core.runtime.IStatus status, int mask)
          Returns whether the given status object should be displayed.
protected  boolean shouldShowDetailsButton()
          Return whether the Details button should be included.
protected  void showDetailsArea()
          Show the details portion of the dialog if it is not already visible.
private  void toggleDetailsArea()
          Toggles the unfolding of the details area.
 
Methods inherited from class org.eclipse.jface.dialogs.IconAndMessageDialog
createButtonBar, createContents, createMessageArea, getErrorImage, getInfoImage, getMessageLabelStyle, getQuestionImage, getWarningImage
 
Methods inherited from class org.eclipse.jface.dialogs.Dialog
applyDialogFont, cancelPressed, convertHeightInCharsToPixels, convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, convertWidthInCharsToPixels, create, createButton, dialogFontIsDefault, getBlockedHandler, getButton, getButtonBar, getCancelButton, getDialogArea, getDialogBoundsSettings, getDialogBoundsStrategy, getImage, getInitialLocation, getInitialSize, getOKButton, initializeBounds, initializeDialogUnits, isResizable, okPressed, setBlockedHandler, setButtonLayoutData, setButtonLayoutFormData, shortenText
 
Methods inherited from class org.eclipse.jface.window.Window
canHandleShellCloseEvent, constrainShellSize, createShell, getConstrainedShellBounds, getContents, getDefaultImage, getDefaultImages, getDefaultOrientation, getLayout, getParentShell, getReturnCode, getShell, getShellListener, getShellStyle, getWindowManager, handleFontChange, handleShellCloseEvent, setBlockOnOpen, setDefaultImage, setDefaultImages, setDefaultModalParent, setDefaultOrientation, setExceptionHandler, setParentShell, setReturnCode, setShellStyle, setWindowManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTOMATED_MODE

public static final boolean AUTOMATED_MODE
Static to prevent opening of error dialogs for automated testing.

See Also:
Constant Field Values

LIST_ITEM_COUNT

private static final int LIST_ITEM_COUNT
Reserve room for this many list items.

See Also:
Constant Field Values

NESTING_INDENT

private static final java.lang.String NESTING_INDENT
The nesting indent.

See Also:
Constant Field Values

detailsButton

private org.eclipse.swt.widgets.Button detailsButton
The Details button.


title

private java.lang.String title
The title of the dialog.


list

private org.eclipse.swt.widgets.List list
The SWT list control that displays the error details.


listCreated

private boolean listCreated
Indicates whether the error details viewer is currently created.


displayMask

private int displayMask
Filter mask for determining which status items to display.


status

private org.eclipse.core.runtime.IStatus status
The main status object.


clipboard

private org.eclipse.swt.dnd.Clipboard clipboard
The current clipboard. To be disposed when closing the dialog.


shouldIncludeTopLevelErrorInDetails

private boolean shouldIncludeTopLevelErrorInDetails
Constructor Detail

ErrorDialog

public ErrorDialog(org.eclipse.swt.widgets.Shell parentShell,
                   java.lang.String dialogTitle,
                   java.lang.String message,
                   org.eclipse.core.runtime.IStatus status,
                   int displayMask)
Creates an error dialog. Note that the dialog will have no visual representation (no widgets) until it is told to open.

Normally one should use openError to create and open one of these. This constructor is useful only if the error object being displayed contains child items and you need to specify a mask which will be used to filter the displaying of these children.

Parameters:
parentShell - the shell under which to create this dialog
dialogTitle - the title to use for this dialog, or null to indicate that the default title should be used
message - the message to show in this dialog, or null to indicate that the error's message should be shown as the primary message
status - the error to show to the user
displayMask - the mask to use to filter the displaying of child items, as per IStatus.matches
See Also:
IStatus.matches(int)
Method Detail

buttonPressed

protected void buttonPressed(int id)
Overrides:
buttonPressed in class org.eclipse.jface.dialogs.Dialog

configureShell

protected void configureShell(org.eclipse.swt.widgets.Shell shell)
Overrides:
configureShell in class org.eclipse.jface.window.Window

createButtonsForButtonBar

protected void createButtonsForButtonBar(org.eclipse.swt.widgets.Composite parent)
Overrides:
createButtonsForButtonBar in class org.eclipse.jface.dialogs.Dialog

createDetailsButton

protected void createDetailsButton(org.eclipse.swt.widgets.Composite parent)
Create the details button if it should be included.

Parameters:
parent - the parent composite
Since:
3.2

createDialogArea

protected org.eclipse.swt.widgets.Control createDialogArea(org.eclipse.swt.widgets.Composite parent)
This implementation of the Dialog framework method creates and lays out a composite and calls createMessageArea and createCustomArea to populate it. Subclasses should override createCustomArea to add contents below the message.

Overrides:
createDialogArea in class org.eclipse.jface.dialogs.Dialog

createDialogAndButtonArea

protected void createDialogAndButtonArea(org.eclipse.swt.widgets.Composite parent)
Overrides:
createDialogAndButtonArea in class org.eclipse.jface.dialogs.IconAndMessageDialog

getImage

protected org.eclipse.swt.graphics.Image getImage()
Specified by:
getImage in class org.eclipse.jface.dialogs.IconAndMessageDialog

createDropDownList

protected org.eclipse.swt.widgets.List createDropDownList(org.eclipse.swt.widgets.Composite parent)
Create this dialog's drop-down list component.

Parameters:
parent - the parent composite
Returns:
the drop-down list component

open

public int open()
Extends Window.open(). Opens an error dialog to display the error. If you specified a mask to filter the displaying of these children, the error dialog will only be displayed if there is at least one child status matching the mask.

Overrides:
open in class org.eclipse.jface.window.Window

openError

public static int openError(org.eclipse.swt.widgets.Shell parent,
                            java.lang.String dialogTitle,
                            java.lang.String message,
                            org.eclipse.core.runtime.IStatus status)
Opens an error dialog to display the given error. Use this method if the error object being displayed does not contain child items, or if you wish to display all such items without filtering.

Parameters:
parent - the parent shell of the dialog, or null if none
dialogTitle - the title to use for this dialog, or null to indicate that the default title should be used
message - the message to show in this dialog, or null to indicate that the error's message should be shown as the primary message
status - the error to show to the user
Returns:
the code of the button that was pressed that resulted in this dialog closing. This will be Dialog.OK if the OK button was pressed, or Dialog.CANCEL if this dialog's close window decoration or the ESC key was used.

openError

public static int openError(org.eclipse.swt.widgets.Shell parentShell,
                            java.lang.String title,
                            java.lang.String message,
                            org.eclipse.core.runtime.IStatus status,
                            int displayMask)
Opens an error dialog to display the given error. Use this method if the error object being displayed contains child items and you wish to specify a mask which will be used to filter the displaying of these children. The error dialog will only be displayed if there is at least one child status matching the mask.

Parameters:
parentShell - the parent shell of the dialog, or null if none
title - the title to use for this dialog, or null to indicate that the default title should be used
message - the message to show in this dialog, or null to indicate that the error's message should be shown as the primary message
status - the error to show to the user
displayMask - the mask to use to filter the displaying of child items, as per IStatus.matches
Returns:
the code of the button that was pressed that resulted in this dialog closing. This will be Dialog.OK if the OK button was pressed, or Dialog.CANCEL if this dialog's close window decoration or the ESC key was used.
See Also:
IStatus.matches(int)

populateList

private void populateList(org.eclipse.swt.widgets.List listToPopulate)
Populates the list using this error dialog's status object. This walks the child static of the status object and displays them in a list. The format for each entry is status_path : status_message If the status's path was null then it (and the colon) are omitted.

Parameters:
listToPopulate - The list to fill.

populateList

private void populateList(org.eclipse.swt.widgets.List listToPopulate,
                          org.eclipse.core.runtime.IStatus buildingStatus,
                          int nesting,
                          boolean includeStatus)
Populate the list with the messages from the given status. Traverse the children of the status deeply and also traverse CoreExceptions that appear in the status.

Parameters:
listToPopulate - the list to populate
buildingStatus - the status being displayed
nesting - the nesting level (increases one level for each level of children)
includeStatus - whether to include the buildingStatus in the display or just its children

getStackTrace

private java.util.List<java.lang.String> getStackTrace(java.lang.Throwable t)

shouldDisplay

protected static boolean shouldDisplay(org.eclipse.core.runtime.IStatus status,
                                       int mask)
Returns whether the given status object should be displayed.

Parameters:
status - a status object
mask - a mask as per IStatus.matches
Returns:
true if the given status should be displayed, and false otherwise
See Also:
IStatus.matches(int)

toggleDetailsArea

private void toggleDetailsArea()
Toggles the unfolding of the details area. This is triggered by the user pressing the details button.


populateCopyBuffer

private void populateCopyBuffer(org.eclipse.core.runtime.IStatus buildingStatus,
                                java.lang.StringBuffer buffer,
                                int nesting)
Put the details of the status of the error onto the stream.

Parameters:
buildingStatus -
buffer -
nesting -

copyToClipboard

private void copyToClipboard()
Copy the contents of the statuses to the clipboard.


close

public boolean close()
Overrides:
close in class org.eclipse.jface.dialogs.Dialog

showDetailsArea

protected final void showDetailsArea()
Show the details portion of the dialog if it is not already visible. This method will only work when it is invoked after the control of the dialog has been set. In other words, after the createContents method has been invoked and has returned the control for the content area of the dialog. Invoking the method before the content area has been set or after the dialog has been disposed will have no effect.

Since:
3.1

shouldShowDetailsButton

protected boolean shouldShowDetailsButton()
Return whether the Details button should be included. This method is invoked once when the dialog is built. By default, the Details button is only included if the status used when creating the dialog was a multi-status or if the status contains an exception. Subclasses may override.

Returns:
whether the Details button should be included
Since:
3.1

setStatus

protected final void setStatus(org.eclipse.core.runtime.IStatus status)
Set the status displayed by this error dialog to the given status. This only affects the status displayed by the Details list. The message, image and title should be updated by the subclass, if desired.

Parameters:
status - the status to be displayed in the details list
Since:
3.1

repopulateList

private void repopulateList()
Repopulate the supplied list widget.