fable.framework.toolbox
Class FableUtils

java.lang.Object
  extended by fable.framework.toolbox.FableUtils

public class FableUtils
extends java.lang.Object

FableUtils is a class with error handling and possibly other methods that are specific to Fable and are designed for easy use and to provide a consistent user experience.

Author:
evans

Field Summary
static java.lang.String LS
           
 
Constructor Summary
FableUtils()
           
 
Method Summary
static java.lang.String changeFileExtension(java.lang.String fileName, java.lang.String newExtension)
          Changes the extension of a file name or adds the extension if the file name does not have one.
static boolean confirmMsg(java.lang.Object id, java.lang.String msg)
          Displays an confirm MessageDialog.
static void errMsg(java.lang.Object id, java.lang.String msg)
          Displays an error MessageDialog using asyncExec and writes an error entry to the Fable log.
static void excMsg(java.lang.Object id, java.lang.String msg, java.lang.Throwable t)
          Displays an error MessageDialog using asyncExec and writes an error entry to the Fable log using the throwable message and stack trace.
static void excNoTraceMsg(java.lang.Object id, java.lang.String msg, java.lang.Throwable t)
          Displays an error MessageDialog using asyncExec and writes an error entry to the Fable log using the throwable message but not the stack trace.
static void excTraceMsg(java.lang.Object id, java.lang.String msg, java.lang.Throwable t)
          Displays an ExceptionMessageDialog using asyncExec and writes an error entry to the Fable log using the throwable message and stack trace.
static java.lang.String generateIDMessage(java.lang.Object object, java.lang.String msg)
          Generates a message with an ID based on the Object.
static java.lang.String getExtension(java.io.File file)
          Get the extension of a File.
static java.lang.String getExtension(java.lang.String fileName)
          Get the extension of a file name.
static java.lang.String getShortName(java.lang.String fileName)
          Get the short part of a full file name.
static void infoMsg(java.lang.Object id, java.lang.String msg)
          Displays an information MessageDialog using asyncExec and writes an info entry to the Fable log.
static int questionMsg(java.lang.String message)
          Displays an question MessageDialog.
static void warnMsg(java.lang.Object id, java.lang.String msg)
          Displays a warning MessageDialog using asyncExec and writes a warning entry to the Fable log.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LS

public static final java.lang.String LS
Constructor Detail

FableUtils

public FableUtils()
Method Detail

generateIDMessage

public static java.lang.String generateIDMessage(java.lang.Object object,
                                                 java.lang.String msg)
Generates a message with an ID based on the Object. The ID is determined based on the class of the object:

String: Use the string
Class: Use the name of the class
Otherwise: Use the name of the class of the object

The expected usage is to pass the this keyword. Note that anonymous inner classes will have a number appended to the class name. You can use MyClass.class for static classes.

Parameters:
object - The Object from which the ID is generated. If the object is null, then the msg is returned.
msg - The text part of the message. May be null in which case just the ID is returned.
Returns:
The returned string of the form "ID: msg", e.g.
"fable.imageviewer.views.ImageView: Invalid operation" If msg is null, then just the ID without the colon is returned.

excTraceMsg

public static void excTraceMsg(java.lang.Object id,
                               java.lang.String msg,
                               java.lang.Throwable t)
Displays an ExceptionMessageDialog using asyncExec and writes an error entry to the Fable log using the throwable message and stack trace. Note that the ExceptionMessageDialog also includes the stack trace. This method provides the most information of the three methods associated with exceptions.

Parameters:
id - An object used to generate an ID for the logging message. Will not be used in the MessageDialog. May be null for no ID.
msg - The message to display. Information from the throwable will be appended.
See Also:
generateIDMessage(java.lang.Object, java.lang.String), ExceptionMessageDialog, excMsg(java.lang.Object, java.lang.String, java.lang.Throwable), excNoTraceMsg(java.lang.Object, java.lang.String, java.lang.Throwable)

excMsg

public static void excMsg(java.lang.Object id,
                          java.lang.String msg,
                          java.lang.Throwable t)
Displays an error MessageDialog using asyncExec and writes an error entry to the Fable log using the throwable message and stack trace. This method provides the middle amount of information of the three methods associated with exceptions.

Parameters:
id - An object used to generate an ID for the logging message. Will not be used in the MessageDialog. May be null for no ID.
msg - The message to display. Information from the throwable will be appended.
See Also:
generateIDMessage(java.lang.Object, java.lang.String), ExceptionMessageDialog, excTraceMsg(java.lang.Object, java.lang.String, java.lang.Throwable), excNoTraceMsg(java.lang.Object, java.lang.String, java.lang.Throwable)

excNoTraceMsg

public static void excNoTraceMsg(java.lang.Object id,
                                 java.lang.String msg,
                                 java.lang.Throwable t)
Displays an error MessageDialog using asyncExec and writes an error entry to the Fable log using the throwable message but not the stack trace. This method provides the least amount of information of the three methods associated with exceptions.

Parameters:
id - An object used to generate an ID for the logging message. Will not be used in the MessageDialog. May be null for no ID.
msg - The message to display. Information from the throwable will be appended.
See Also:
generateIDMessage(java.lang.Object, java.lang.String), ExceptionMessageDialog, excMsg(java.lang.Object, java.lang.String, java.lang.Throwable), excTraceMsg(java.lang.Object, java.lang.String, java.lang.Throwable)

errMsg

public static void errMsg(java.lang.Object id,
                          java.lang.String msg)
Displays an error MessageDialog using asyncExec and writes an error entry to the Fable log.

Parameters:
id - An object used to generate an ID for the logging message. Will not be used in the MessageDialog. May be null for no ID.
msg - The message to display.
See Also:
#generateID(Object)

warnMsg

public static void warnMsg(java.lang.Object id,
                           java.lang.String msg)
Displays a warning MessageDialog using asyncExec and writes a warning entry to the Fable log.

Parameters:
id - An object used to generate an ID for the logging message. Will not be used in the MessageDialog. May be null for no ID.
msg - The message to display.
See Also:
generateIDMessage(java.lang.Object, java.lang.String)

infoMsg

public static void infoMsg(java.lang.Object id,
                           java.lang.String msg)
Displays an information MessageDialog using asyncExec and writes an info entry to the Fable log.

Parameters:
id - An object used to generate an ID for the logging message. Will not be used in the MessageDialog. May be null for no ID.
msg - The message to display.
See Also:
generateIDMessage(java.lang.Object, java.lang.String)

confirmMsg

public static boolean confirmMsg(java.lang.Object id,
                                 java.lang.String msg)
Displays an confirm MessageDialog.

Parameters:
id - An object used to generate an ID for the logging message. Will not be used in the MessageDialog. May be null for no ID.
msg - The message to display.
Returns:
true if user confirms its decision
See Also:
generateIDMessage(java.lang.Object, java.lang.String), ExceptionMessageDialog

getShortName

public static java.lang.String getShortName(java.lang.String fileName)
Get the short part of a full file name.

Parameters:
fileName - The name of the file.
Returns:

getExtension

public static java.lang.String getExtension(java.io.File file)
Get the extension of a File.

Parameters:
file -
Returns:

getExtension

public static java.lang.String getExtension(java.lang.String fileName)
Get the extension of a file name.

Parameters:
fileName - The name of the file.
Returns:

changeFileExtension

public static java.lang.String changeFileExtension(java.lang.String fileName,
                                                   java.lang.String newExtension)
Changes the extension of a file name or adds the extension if the file name does not have one.

Parameters:
fileName -
newExtension -
Returns:

questionMsg

public static int questionMsg(java.lang.String message)
Displays an question MessageDialog.

Parameters:
message - The question to ask.
Returns:
0 if the user presses OK button, 1 for Cancel, 2 for No.