fable.framework.toolbox
Class SWTUtils

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

public class SWTUtils
extends java.lang.Object


Field Summary
static java.lang.String LS
           
 
Constructor Summary
SWTUtils()
           
 
Method Summary
static java.lang.String convertText(java.lang.String string)
          If the SWT Text DELIMITER is CRLF, then it converts LF not preceeded by CR to DELIMITER.
static java.awt.image.BufferedImage convertToAWT(org.eclipse.swt.graphics.ImageData data)
          Converts an SWT ImageData to an AWT BufferedImage.
static org.eclipse.swt.graphics.ImageData convertToSWT(java.awt.image.BufferedImage bufferedImage)
          Converts an AWT BufferedImage to an SWT ImageData.
static org.eclipse.ui.IEditorInput createEditorInput(java.io.File file)
          Creates a new IEditorInput from a File.
static void createFileFromIFile(org.eclipse.core.resources.IFile fileHandle, java.io.InputStream contents, org.eclipse.core.runtime.IProgressMonitor monitor)
          Creates a file resource given the file handle and contents.
static void enableControlTree(org.eclipse.swt.widgets.Control control, boolean enabled)
          Recursively enables or disables this control and all its children.
static void errMsg(org.eclipse.swt.widgets.Shell shell, java.lang.String msg)
          Displays an error MessageDialog.
static void errMsg(java.lang.String msg)
          Displays an error MessageDialog.
static void errMsgAsync(org.eclipse.swt.widgets.Shell shell, java.lang.String msg)
          Displays an error MessageDialog using asyncExec.
static void errMsgAsync(java.lang.String msg)
          Same as errMsgAsync(null, msg).
static void excMsg(org.eclipse.swt.widgets.Shell shell, java.lang.String msg, java.lang.Exception ex)
          Displays an exception MessageDialog.
static void excMsg(java.lang.String msg, java.lang.Exception ex)
          Displays an exception MessageDialog.
static void excMsgAsync(org.eclipse.swt.widgets.Shell shell, java.lang.String msg, java.lang.Exception ex)
          Displays an exception MessageDialog using asyncExec.
static void excMsgAsync(java.lang.String msg, java.lang.Exception ex)
          Displays an exception MessageDialog using asyncExec.
static void excTraceMsg(org.eclipse.swt.widgets.Shell shell, java.lang.String msg, java.lang.Exception ex)
          Displays an exception ExceptionMessageDialog.
static void excTraceMsg(java.lang.String msg, java.lang.Exception ex)
          Displays an ExceptionMessageDialog.
static void excTraceMsgAsync(org.eclipse.swt.widgets.Shell shell, java.lang.String msg, java.lang.Exception ex)
          Displays an ExceptionMessageDialog using asyncExec.
static void excTraceMsgAsync(java.lang.String msg, java.lang.Exception ex)
          Displays an ExceptionMessageDialog using asyncExec.
static org.eclipse.core.resources.IFile getFile(org.eclipse.ui.IEditorInput editorInput)
          From the IMP project.
static java.lang.String getNameExtension(org.eclipse.ui.IEditorInput editorInput)
           
static org.eclipse.core.runtime.IPath getPath(org.eclipse.ui.IEditorInput editorInput)
          Returns the IPath for a variety of IEditorInput's.
static int getTextWidth(org.eclipse.swt.widgets.Text text, int cols)
          Finds the width for a Text control given the number of columns desired.
static void infoMsg(org.eclipse.swt.widgets.Shell shell, java.lang.String msg)
          Displays an information MessageDialog.
static void infoMsg(java.lang.String msg)
          Displays an information MessageDialog.
static void infoMsgAsync(org.eclipse.swt.widgets.Shell shell, java.lang.String msg)
          Displays an information MessageDialog using asyncExec.
static void infoMsgAsync(java.lang.String msg)
          Same as infoMsgAsync(null, msg).
static java.lang.String timeStamp()
          Generates a timestamp.
static java.lang.String timeStamp(java.lang.String pattern)
          Generates a timestamp given a pattern
static boolean tryToOpenExternalFileEditor(java.lang.String fileName)
          Tries to open an editor on the given external file.
static boolean tryToOpenWorkspaceFileEditor(java.lang.String fileName, java.lang.String editorID)
          Checks if the file is in the workspace.
static boolean tryToRefreshProject(java.lang.String fileName)
          Checks if the file is in the workspace.
static void warnMsg(org.eclipse.swt.widgets.Shell shell, java.lang.String msg)
          Displays a warning MessageDialog.
static void warnMsg(java.lang.String msg)
          Displays a warning MessageDialog.
static void warnMsgAsync(org.eclipse.swt.widgets.Shell shell, java.lang.String msg)
          Displays a warning MessageDialog using asyncExec.
static void warnMsgAsync(java.lang.String msg)
          Displays a warning MessageDialog using asyncExec.
 
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

SWTUtils

public SWTUtils()
Method Detail

timeStamp

public static java.lang.String timeStamp()
Generates a timestamp.

Returns:
String timestamp with the current time

timeStamp

public static java.lang.String timeStamp(java.lang.String pattern)
Generates a timestamp given a pattern

Parameters:
pattern - appropriate for SimpleDateFormat
Returns:
String timestamp with the current time

errMsg

public static void errMsg(java.lang.String msg)
Displays an error MessageDialog. Same as errMsg(null, msg).

Parameters:
msg -

errMsg

public static void errMsg(org.eclipse.swt.widgets.Shell shell,
                          java.lang.String msg)
Displays an error MessageDialog.

Parameters:
shell - Can be null.
msg -

errMsgAsync

public static void errMsgAsync(java.lang.String msg)
Same as errMsgAsync(null, msg). Displays an error MessageDialog using asyncExec.

Parameters:
msg -

errMsgAsync

public static void errMsgAsync(org.eclipse.swt.widgets.Shell shell,
                               java.lang.String msg)
Displays an error MessageDialog using asyncExec.

Parameters:
shell - Can be null.
msg -

warnMsg

public static void warnMsg(java.lang.String msg)
Displays a warning MessageDialog. Same as warnMsg(null, msg).

Parameters:
msg -

warnMsg

public static void warnMsg(org.eclipse.swt.widgets.Shell shell,
                           java.lang.String msg)
Displays a warning MessageDialog.

Parameters:
shell - Can be null.
msg -

warnMsgAsync

public static void warnMsgAsync(java.lang.String msg)
Displays a warning MessageDialog using asyncExec. Same as warnMsgAsync(null, msg).

Parameters:
msg -

warnMsgAsync

public static void warnMsgAsync(org.eclipse.swt.widgets.Shell shell,
                                java.lang.String msg)
Displays a warning MessageDialog using asyncExec.

Parameters:
shell - Can be null.
msg -

infoMsg

public static void infoMsg(java.lang.String msg)
Displays an information MessageDialog. Same as infoMsg(null, msg).

Parameters:
msg -

infoMsg

public static void infoMsg(org.eclipse.swt.widgets.Shell shell,
                           java.lang.String msg)
Displays an information MessageDialog.

Parameters:
shell - Can be null.
msg -

infoMsgAsync

public static void infoMsgAsync(java.lang.String msg)
Same as infoMsgAsync(null, msg). Displays an information MessageDialog using asyncExec.

Parameters:
msg -

infoMsgAsync

public static void infoMsgAsync(org.eclipse.swt.widgets.Shell shell,
                                java.lang.String msg)
Displays an information MessageDialog using asyncExec.

Parameters:
shell - Can be null.
msg -

excMsg

public static void excMsg(java.lang.String msg,
                          java.lang.Exception ex)
Displays an exception MessageDialog. Same as excMsg(null, msg, ex).

Parameters:
msg - The first part of the message, to which exception information is added.
ex -

excMsg

public static void excMsg(org.eclipse.swt.widgets.Shell shell,
                          java.lang.String msg,
                          java.lang.Exception ex)
Displays an exception MessageDialog.

Parameters:
shell - Can be null.
msg - The first part of the message, to which exception information is added.
ex -

excMsgAsync

public static void excMsgAsync(java.lang.String msg,
                               java.lang.Exception ex)
Displays an exception MessageDialog using asyncExec. Same as excMsgAsync(null, msg, ex).

Parameters:
msg - The first part of the message, to which exception information is added.
ex -

excMsgAsync

public static void excMsgAsync(org.eclipse.swt.widgets.Shell shell,
                               java.lang.String msg,
                               java.lang.Exception ex)
Displays an exception MessageDialog using asyncExec.

Parameters:
shell - Can be null.
msg - The first part of the message, to which exception information is added.
ex -

excTraceMsg

public static void excTraceMsg(java.lang.String msg,
                               java.lang.Exception ex)
Displays an ExceptionMessageDialog. Same as excTraceMsg(null, msg, ex).

Parameters:
msg - The first part of the message, to which exception information is added.
ex -

excTraceMsg

public static void excTraceMsg(org.eclipse.swt.widgets.Shell shell,
                               java.lang.String msg,
                               java.lang.Exception ex)
Displays an exception ExceptionMessageDialog.

Parameters:
shell - Can be null.
msg - The first part of the message, to which exception information is added.
ex -

excTraceMsgAsync

public static void excTraceMsgAsync(java.lang.String msg,
                                    java.lang.Exception ex)
Displays an ExceptionMessageDialog using asyncExec. Same as excTraceMsgAsync(null, msg, ex).

Parameters:
msg - The first part of the message, to which exception information is added.
ex -

excTraceMsgAsync

public static void excTraceMsgAsync(org.eclipse.swt.widgets.Shell shell,
                                    java.lang.String msg,
                                    java.lang.Exception ex)
Displays an ExceptionMessageDialog using asyncExec.

Parameters:
shell - Can be null.
msg - The first part of the message, to which exception information is added.
ex -

convertText

public static java.lang.String convertText(java.lang.String string)
If the SWT Text DELIMITER is CRLF, then it converts LF not preceeded by CR to DELIMITER. Otherwise it just returns the string. This is necessary for mixed CRLF and LF to appear as new lines in Text. The Swing TextArea does not have this problem.

Parameters:
string - The string to convert.
Returns:

createFileFromIFile

public static void createFileFromIFile(org.eclipse.core.resources.IFile fileHandle,
                                       java.io.InputStream contents,
                                       org.eclipse.core.runtime.IProgressMonitor monitor)
                                throws org.eclipse.core.runtime.CoreException
Creates a file resource given the file handle and contents. From org.eclipse.ui.dialogs.WizardnewFileCreationPage.

Parameters:
fileHandle - the file handle to create a file resource with
contents - the initial contents of the new file resource, or null if none (equivalent to an empty stream)
monitor - the progress monitor to show visual progress with
Throws:
org.eclipse.core.runtime.CoreException - if the operation fails
org.eclipse.core.runtime.OperationCanceledException - if the operation is canceled

getPath

public static org.eclipse.core.runtime.IPath getPath(org.eclipse.ui.IEditorInput editorInput)
Returns the IPath for a variety of IEditorInput's. From the IMP project, but modified. Note that given the IPath, you can find the fileName and other information by using IPath.toFile().

Returns:
the IPath corresponding to the given input, or null if none.

getFile

public static org.eclipse.core.resources.IFile getFile(org.eclipse.ui.IEditorInput editorInput)
From the IMP project.

Returns:
the IFile corresponding to the given input, or null if none.

getNameExtension

public static java.lang.String getNameExtension(org.eclipse.ui.IEditorInput editorInput)
Returns:
the name extension (e.g., "java" or "cpp") corresponding to this input, if known, or the empty string if none. Does not include a leading ".". From the IMP project.

enableControlTree

public static void enableControlTree(org.eclipse.swt.widgets.Control control,
                                     boolean enabled)
Recursively enables or disables this control and all its children.

Parameters:
control - Control to be enabled or disabled.
enabled - Whether to enable or disable.

convertToAWT

public static java.awt.image.BufferedImage convertToAWT(org.eclipse.swt.graphics.ImageData data)
Converts an SWT ImageData to an AWT BufferedImage.

Parameters:
bufferedImage -
Returns:

convertToSWT

public static org.eclipse.swt.graphics.ImageData convertToSWT(java.awt.image.BufferedImage bufferedImage)
Converts an AWT BufferedImage to an SWT ImageData.

Parameters:
bufferedImage -
Returns:

getTextWidth

public static int getTextWidth(org.eclipse.swt.widgets.Text text,
                               int cols)
Finds the width for a Text control given the number of columns desired.

Parameters:
text -
cols -
Returns:

createEditorInput

public static org.eclipse.ui.IEditorInput createEditorInput(java.io.File file)
Creates a new IEditorInput from a File. Tries to create a FileEditorInput if the file is in the workbench, otherwise creates a PathEditorInput.

Parameters:
file -
Returns:

tryToRefreshProject

public static boolean tryToRefreshProject(java.lang.String fileName)
Checks if the file is in the workspace. If so, tries to refresh the project. Fails silently if this cannot be done.

Parameters:
fileName - The name of the file.
Returns:
If [apparently] successful or not

tryToOpenWorkspaceFileEditor

public static boolean tryToOpenWorkspaceFileEditor(java.lang.String fileName,
                                                   java.lang.String editorID)
Checks if the file is in the workspace. If so tries to open an editor on it. Fails silently if this cannot be done.

Parameters:
fileName - The name of the file.
editorID - The ID of the editor to open; e.g., "org.eclipse.ui.DefaultTextEditor"
Returns:
If [apparently] successful or not

tryToOpenExternalFileEditor

public static boolean tryToOpenExternalFileEditor(java.lang.String fileName)
Tries to open an editor on the given external file. Fails silently if this cannot be done.

Parameters:
fileName - External file name.
Returns:
If [apparently] successful or not