Class UIModule
java.lang.Object
org.eclipse.ease.modules.AbstractScriptModule
org.eclipse.ease.modules.platform.UIModule
- All Implemented Interfaces:
IScriptModule
Methods providing access to UI components. Allows to show dialogs, execute code in the UI thread, access views and editors.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClear the script console.static voidClose a dedicated view.static ObjectconvertSelection(ISelection selection) Converts selection to a consumable form.static ColorcreateColor(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).Run code in UI thread.static voidClose the application.static IEditorPartGet the active editor instance.static IWorkbenchPartGet the active view instance.static ObjectGet text data from the clipboard.Get the script console for the current engine.static ISelectiongetSelection(String name) Get the current selection.static ShellgetShell()Get the workbench shell instance.static booleanVerify if we are running in headless mode.static booleanReturnstruewhen executed in the UI thread.static voidmaximizeView(String name) Maximize a dedicated view.static voidminimizeView(String name) Minimize a dedicated view.static voidMove an existing view to a new position relative to another view.static intopenDialog(Window dialog) Show a generic dialog.voidopenInSystemEditor(Object location) Open a file using the system default editor.voidrenameScriptShell(String newName) Renames the script shell window to the specified name.static voidsetClipboard(String data) Write text data to the clipboard.booleanshowConfirmDialog(String message, String title) Displays a confirmation dialog.showEditor(Object location) Opens a file in an editor.static IEditorPartshowEditor(IFile file) Opens a file in an editor.voidshowErrorDialog(String message, String title) Displays an error dialog.voidshowInfoDialog(String message, String title) Displays an info dialog.showInputDialog(String message, String initialValue, String title) Displays an input dialog.booleanshowQuestionDialog(String message, String title) Displays a question dialog.showSelectionDialog(Object[] elements, String message, String title) Displays a selection dialog.static IViewPartOpens a view by given Name or id.static IViewPartShows a view in this page with the given id and secondary id.voidshowWarningDialog(String message, String title) Displays a warning dialog.static voidshutdown()Shut down the application.Methods inherited from class org.eclipse.ease.modules.AbstractScriptModule
initialize
-
Field Details
-
MODULE_ID
Module identifier.- See Also:
-
-
Constructor Details
-
UIModule
public UIModule()
-
-
Method Details
-
executeUI
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
- Throws:
ExecutionException- when execution of UI code fails
-
isUIThread
public static boolean isUIThread()Returnstruewhen executed in the UI thread.- Returns:
truein UI thread
-
showInfoDialog
Displays an info dialog. Uses the engine output stream in headless mode.- Parameters:
message- dialog messagetitle- dialog title
-
showQuestionDialog
public boolean showQuestionDialog(String message, @ScriptParameter(defaultValue="Question") String title) Displays a question dialog. Contains yes/no buttons. Uses the engine I/O streams in headless mode.- Parameters:
message- dialog messagetitle- dialog title- Returns:
truewhen 'yes' was pressed,falseotherwise
-
showInputDialog
public String showInputDialog(String message, @ScriptParameter(defaultValue="") String initialValue, @ScriptParameter(defaultValue="Information request") String title) Displays an input dialog. Uses the engine I/O streams in headless mode.- Parameters:
message- dialog messageinitialValue- default value used to populate input boxtitle- dialog title- Returns:
- user input or
nullin case the user aborted/closed the dialog
-
showSelectionDialog
public Object showSelectionDialog(Object[] elements, @ScriptParameter(defaultValue="") String message, @ScriptParameter(defaultValue="Selection request") 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 frommessage- dialog messagetitle- dialog title- Returns:
- selected element or
nullin case the user aborted/closed the dialog
-
showConfirmDialog
public boolean showConfirmDialog(String message, @ScriptParameter(defaultValue="Confirmation") String title) Displays a confirmation dialog. Uses the engine I/O streams in headless mode.- Parameters:
message- dialog messagetitle- dialog title- Returns:
truewhen accepted
-
showWarningDialog
public void showWarningDialog(String message, @ScriptParameter(defaultValue="Warning") String title) Displays a warning dialog. Uses the engine output stream in headless mode.- Parameters:
message- dialog messagetitle- dialog title
-
showErrorDialog
Displays an error dialog. Uses the engine output stream in headless mode.- Parameters:
message- dialog messagetitle- dialog title
-
exitApplication
public static void exitApplication()Close the application. On unsaved editors user will be asked to save before closing. -
showView
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:
Throwable- when view cannot be created
-
showView
public static IViewPart showView(String name, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String secondaryId, @ScriptParameter(defaultValue="1") int mode) throws 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. IfVIEW_ACTIVATEis supplied, the view is given focus. IfVIEW_VISIBLEis supplied, then it is made visible but not given focus. Finally, ifVIEW_CREATEis 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, ornullfor no secondary idmode- the activation mode. Must be#VIEW_ACTIVATE,#VIEW_VISIBLEor#VIEW_CREATE, Default is#VIEW_ACTIVATE- Returns:
- a view
- Throws:
Throwable- when the view cannot be openedIllegalArgumentException- when the supplied mode is not valid- Since:
- 3.0
-
showEditor
Opens a file in an editor. -
showEditor
Opens a file in an editor.- Parameters:
file- file location to open- Returns:
- editor instance or
null - Throws:
Throwable- when we cannot open the editor
-
openInSystemEditor
Open a file using the system default editor.- Parameters:
location- file location to open.- Throws:
IOException- when file cannot be found
-
getSelection
public static ISelection getSelection(@ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") 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
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
Show a generic dialog.- Parameters:
dialog- dialog to display- Returns:
- result of dialog.open() method
- Throws:
Throwable- when we cannot open the dialog
-
getShell
Get the workbench shell instance.- Returns:
- shell
-
getActiveView
Get the active view instance.- Returns:
- active view
-
renameScriptShell
Renames the script shell window to the specified name.- Parameters:
newName- new name for the script shell window
-
getActiveEditor
Get the active editor instance.- Returns:
- active editor
-
setClipboard
Write text data to the clipboard.- Parameters:
data- data to write to the clipboard
-
getClipboard
Get text data from the clipboard.- Returns:
- clipboard text
-
clearConsole
public void clearConsole()Clear the script console. -
getConsole
Get the script console for the current engine.- Returns:
- script console or
null
-
maximizeView
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:
Throwable- when view cannot be opened
-
minimizeView
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:
Throwable- when view cannot be opened
-
closeView
public static void closeView(String name, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String secondaryID) Close a dedicated view.- Parameters:
name- visible name or id of view to closesecondaryID- 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:
trueif we are running without UI
-
createColor
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 colorgreen- the amount of green in the colorblue- the amount of blue in the color- Returns:
- color instance
- Throws:
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(String sourceView, String relativeTo, @ScriptParameter(defaultValue="x") String position) Move an existing view to a new position relative to another view.- Parameters:
sourceView- view to move: view ID or view titlerelativeTo- view to move source relative to: view ID or view titleposition- one of- x,o ... same stack
- v ... below target view
- ^ ... above target view
- < ... left of target view
- > ... right of target view
-