org.eclipse.ease.modules.platform

## Class UIModule

- java.lang.Object
- - org.eclipse.ease.modules.AbstractScriptModule
  - - org.eclipse.ease.modules.platform.UIModule

All Implemented Interfaces:
  org.eclipse.ease.modules.IScriptModule

    public class UIModule
    extends org.eclipse.ease.modules.AbstractScriptModule

Methods providing access to UI components. Allows to show dialogs, execute code in the UI thread, access views and editors.

### Field Summary

Fields
`static java.lang.String` `MODULE_ID` Module identifier.

### Constructor Summary

Constructors
Constructor and Description
`UIModule()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `clearConsole()` Clear the script console.
`static void` `closeView(java.lang.String name, java.lang.String secondaryID)` Close a dedicated view.
`static java.lang.Object` `convertSelection(ISelection selection)` Converts selection to a consumable form.
`static Color` `createColor(int red, int green, int blue)` Constructs a new color given the desired red, green and blue values expressed as ints in the range 0 to 255 (where 0 is black and 255 is full brightness).
`java.lang.Object` `executeUI(java.lang.Object code)` Run code in UI thread.
`static void` `exitApplication()` Close the application.
`static IEditorPart` `getActiveEditor()` Get the active editor instance.
`static IWorkbenchPart` `getActiveView()` Get the active view instance.
`static java.lang.Object` `getClipboard()` Get text data from the clipboard.
`org.eclipse.ease.ui.console.ScriptConsole` `getConsole()` Get the script console for the current engine.
`static ISelection` `getSelection(java.lang.String name)` Get the current selection.
`static Shell` `getShell()` Get the workbench shell instance.
`static boolean` `isHeadless()` Verify if we are running in headless mode.
`static boolean` `isUIThread()` Returns `true` when executed in the UI thread.
`static void` `maximizeView(java.lang.String name)` Maximize a dedicated view.
`static void` `minimizeView(java.lang.String name)` Minimize a dedicated view.
`static void` `moveView(java.lang.String sourceView, java.lang.String relativeTo, java.lang.String position)` Move an existing view to a new position relative to another view.
`static int` `openDialog(Window dialog)` Show a generic dialog.
`void` `renameScriptShell(java.lang.String newName)` Renames the script shell window to the specified name.
`static void` `setClipboard(java.lang.String data)` Write text data to the clipboard.
`boolean` `showConfirmDialog(java.lang.String message, java.lang.String title)` Displays a confirmation dialog.
`static IEditorPart` `showEditor(IFile file)` Opens a file in an editor.
`IEditorPart` `showEditor(java.lang.Object location)` Opens a file in an editor.
`void` `showErrorDialog(java.lang.String message, java.lang.String title)` Displays an error dialog.
`void` `showInfoDialog(java.lang.String message, java.lang.String title)` Displays an info dialog.
`java.lang.String` `showInputDialog(java.lang.String message, java.lang.String initialValue, java.lang.String title)` Displays an input dialog.
`boolean` `showQuestionDialog(java.lang.String message, java.lang.String title)` Displays a question dialog.
`java.lang.Object` `showSelectionDialog(java.lang.Object[] elements, java.lang.String message, java.lang.String title)` Displays a selection dialog.
`static IViewPart` `showView(java.lang.String name)` Opens a view by given Name or id.
`static IViewPart` `showView(java.lang.String name, java.lang.String secondaryId, int mode)` Shows a view in this page with the given id and secondary id.
`void` `showWarningDialog(java.lang.String message, java.lang.String title)` Displays a warning dialog.
`static void` `shutdown()` Shut down the application.

### Methods inherited from class org.eclipse.ease.modules.AbstractScriptModule

`getScriptEngine, initialize`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### MODULE_ID

    public static final java.lang.String MODULE_ID

Module identifier.

See Also:
  Constant Field Values

### Constructor Detail

#### UIModule

    public UIModule()

### Method Detail

#### executeUI

    public java.lang.Object executeUI(java.lang.Object code)

Run code in UI thread. Needed to interact with SWT elements. Might not be supported by some engines. Might be disabled by the user. Code will be executed synchronously and stall UI updates while executed.

Parameters:
  `code` - code/object to execute
Returns:
  execution result

#### isUIThread

    public static boolean isUIThread()

Returns `true` when executed in the UI thread.

Returns:
  `true` in UI thread

#### showInfoDialog

    public void showInfoDialog(java.lang.String message,
                               @ScriptParameter(defaultValue="Info")
                               java.lang.String title)

Displays an info dialog. Uses the engine output stream in headless mode.

Parameters:
  `message` - dialog message
  `title` - dialog title

#### showQuestionDialog

    public boolean showQuestionDialog(java.lang.String message,
                                      @ScriptParameter(defaultValue="Question")
                                      java.lang.String title)

Displays a question dialog. Contains yes/no buttons. Uses the engine I/O streams in headless mode.

Parameters:
  `message` - dialog message
  `title` - dialog title
Returns:
  `true` when 'yes' was pressed, `false` otherwise

#### showInputDialog

    public java.lang.String showInputDialog(java.lang.String message,
                                            @ScriptParameter(defaultValue="")
                                            java.lang.String initialValue,
                                            @ScriptParameter(defaultValue="Information request")
                                            java.lang.String title)

Displays an input dialog. Uses the engine I/O streams in headless mode.

Parameters:
  `message` - dialog message
  `initialValue` - default value used to populate input box
  `title` - dialog title
Returns:
  user input or `null` in case the user aborted/closed the dialog

#### showSelectionDialog

    public java.lang.Object showSelectionDialog(java.lang.Object[] elements,
                                                @ScriptParameter(defaultValue="")
                                                java.lang.String message,
                                                @ScriptParameter(defaultValue="Selection request")
                                                java.lang.String title)

Displays a selection dialog. Selection elements need to provide a useful toString() method. Uses the engine I/O streams in headless mode.

Parameters:
  `elements` - array of elements to choose from
  `message` - dialog message
  `title` - dialog title
Returns:
  selected element or `null` in case the user aborted/closed the dialog

#### showConfirmDialog

    public boolean showConfirmDialog(java.lang.String message,
                                     @ScriptParameter(defaultValue="Confirmation")
                                     java.lang.String title)

Displays a confirmation dialog. Uses the engine I/O streams in headless mode.

Parameters:
  `message` - dialog message
  `title` - dialog title
Returns:
  `true` when accepted

#### showWarningDialog

    public void showWarningDialog(java.lang.String message,
                                  @ScriptParameter(defaultValue="Warning")
                                  java.lang.String title)

Displays a warning dialog. Uses the engine output stream in headless mode.

Parameters:
  `message` - dialog message
  `title` - dialog title

#### showErrorDialog

    public void showErrorDialog(java.lang.String message,
                                @ScriptParameter(defaultValue="Error")
                                java.lang.String title)

Displays an error dialog. Uses the engine output stream in headless mode.

Parameters:
  `message` - dialog message
  `title` - dialog title

#### exitApplication

    public static void exitApplication()

Close the application. On unsaved editors user will be asked to save before closing.

#### showView

    public static IViewPart showView(java.lang.String name)
                              throws java.lang.Throwable

Opens a view by given Name or id. When name does not match any known view id we try to match it with a view title. When found the view is opened. If the view is already visible it will be given focus.

Parameters:
  `name` - name or id of view to open
Returns:
  view instance or `null`
Throws:
  `java.lang.Throwable` - when view cannot be created

#### showView

    public static IViewPart showView(java.lang.String name,
                                     @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null")
                                     java.lang.String secondaryId,
                                     @ScriptParameter(defaultValue="1")
                                     int mode)
                              throws java.lang.Throwable

Shows a view in this page with the given id and secondary id. The Behavior of this method varies based on the supplied mode. If `VIEW_ACTIVATE` is supplied, the view is given focus. If `VIEW_VISIBLE` is supplied, then it is made visible but not given focus. Finally, if `VIEW_CREATE` is supplied the view is created and will only be made visible if it is not created in a folder that already contains visible views.

This allows multiple instances of a particular view to be created. They are disambiguated using the secondary id. If a secondary id is given, the view must allow multiple instances by having specified allowMultiple="true" in its extension.

Parameters:
  `name` - either the id of the view extension to use or the visible name of the view (tab title)
  `secondaryId` - the secondary id to use, or `null` for no secondary id
  `mode` - the activation mode. Must be `#VIEW_ACTIVATE`, `#VIEW_VISIBLE` or `#VIEW_CREATE`, Default is `#VIEW_ACTIVATE`
Returns:
  a view
Throws:
  `java.lang.Throwable` - when the view cannot be opened
  `java.lang.IllegalArgumentException` - when the supplied mode is not valid
Since:
  3.0

#### showEditor

    public IEditorPart showEditor(java.lang.Object location)
                           throws java.lang.Throwable

Opens a file in an editor.

Parameters:
  `location` - file location to open, either `IFile` or workspace file location
Returns:
  editor instance or `null`
Throws:
  `java.lang.Throwable` - when we cannot open the editor

#### showEditor

    public static IEditorPart showEditor(IFile file)
                                  throws java.lang.Throwable

Opens a file in an editor.

Parameters:
  `file` - file location to open
Returns:
  editor instance or `null`
Throws:
  `java.lang.Throwable` - when we cannot open the editor

#### getSelection

    public static ISelection getSelection(@ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null")
                                          java.lang.String name)

Get the current selection. If partID is provided, the selection of the given part is returned. Otherwise the selection of the current active part is returned.

Parameters:
  `name` - name or ID of part to get selection from
Returns:
  current selection

#### convertSelection

    public static java.lang.Object convertSelection(ISelection selection)

Converts selection to a consumable form. Table/Tree selections are transformed into Object[], Text selections into the selected String.

Parameters:
  `selection` - selection to convert
Returns:
  converted elements

#### openDialog

    public static int openDialog(Window dialog)
                          throws java.lang.Throwable

Show a generic dialog.

Parameters:
  `dialog` - dialog to display
Returns:
  result of dialog.open() method
Throws:
  `java.lang.Throwable` - when we cannot open the dialog

#### getShell

    public static Shell getShell()

Get the workbench shell instance.

Returns:
  shell

#### getActiveView

    public static IWorkbenchPart getActiveView()

Get the active view instance.

Returns:
  active view

#### renameScriptShell

    public void renameScriptShell(java.lang.String newName)

Renames the script shell window to the specified name.

Parameters:
  `newName` - new name for the script shell window

#### getActiveEditor

    public static IEditorPart getActiveEditor()

Get the active editor instance.

Returns:
  active editor

#### setClipboard

    public static void setClipboard(java.lang.String data)

Write text data to the clipboard.

Parameters:
  `data` - data to write to the clipboard

#### getClipboard

    public static java.lang.Object getClipboard()

Get text data from the clipboard.

Returns:
  clipboard text

#### clearConsole

    public void clearConsole()

Clear the script console.

#### getConsole

    public org.eclipse.ease.ui.console.ScriptConsole getConsole()

Get the script console for the current engine.

Returns:
  script console or `null`

#### maximizeView

    public static void maximizeView(java.lang.String name)
                             throws java.lang.Throwable

Maximize a dedicated view. If the view is not opened yet, it will be opened by this call. A second call will restore the original size of the view.

Parameters:
  `name` - visible name or id of view to maximize
Throws:
  `java.lang.Throwable` - when view cannot be opened

#### minimizeView

    public static void minimizeView(java.lang.String name)
                             throws java.lang.Throwable

Minimize a dedicated view. If the view is not opened yet, it will be opened by this call. A second call will restore view on a floating dock.

Parameters:
  `name` - name or id of view to minimize
Throws:
  `java.lang.Throwable` - when view cannot be opened

#### closeView

    public static void closeView(java.lang.String name,
                                 @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null")
                                 java.lang.String secondaryID)

Close a dedicated view.

Parameters:
  `name` - visible name or id of view to close
  `secondaryID` - secondary ID of view to close

#### shutdown

    public static void shutdown()

Shut down the application.

#### isHeadless

    public static boolean isHeadless()

Verify if we are running in headless mode.

Returns:
  `true` if we are running without UI

#### createColor

    public static Color createColor(int red,
                                    int green,
                                    int blue)

Constructs a new color given the desired red, green and blue values expressed as ints in the range 0 to 255 (where 0 is black and 255 is full brightness).

You must dispose the color when it is no longer required.

Parameters:
  `red` - the amount of red in the color
  `green` - the amount of green in the color
  `blue` - the amount of blue in the color
Returns:
  color instance
Throws:
  `java.lang.IllegalArgumentException` -
  - ERROR_NULL_ARGUMENT - if device is null and there is no current device
  - ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255

#### moveView

    public static void moveView(java.lang.String sourceView,
                                java.lang.String relativeTo,
                                @ScriptParameter(defaultValue="x")
                                java.lang.String position)

Move an existing view to a new position relative to another view.

Parameters:
  `sourceView` - view to move: view ID or view title
  `relativeTo` - view to move source relative to: view ID or view title
  `position` - one of
  - x,o ... same stack
  - v ... below target view
  - ^ ... above target view
  - < ... left of target view
  - > ... right of target view