Class UIModule
java.lang.Object
org.eclipse.ease.modules.AbstractScriptModule
org.eclipse.ease.modules.platform.UIModule
- All Implemented Interfaces:
IScriptModule
public class UIModule extends AbstractScriptModule
Methods providing access to UI components. Allows to show dialogs, execute code in the UI thread, access views and editors.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description UIModule()
-
Method Summary
Modifier and Type Method Description void
clearConsole()
Clear the script console.static void
closeView(String name, String secondaryID)
Close a dedicated view.static Object
convertSelection(org.eclipse.jface.viewers.ISelection selection)
Converts selection to a consumable form.static org.eclipse.swt.graphics.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).Object
executeUI(Object code)
Run code in UI thread.static void
exitApplication()
Close the application.static org.eclipse.ui.IEditorPart
getActiveEditor()
Get the active editor instance.static org.eclipse.ui.IWorkbenchPart
getActiveView()
Get the active view instance.static Object
getClipboard()
Get text data from the clipboard.ScriptConsole
getConsole()
Get the script console for the current engine.static org.eclipse.jface.viewers.ISelection
getSelection(String name)
Get the current selection.static org.eclipse.swt.widgets.Shell
getShell()
Get the workbench shell instance.static boolean
isHeadless()
Verify if we are running in headless mode.static boolean
isUIThread()
Returnstrue
when executed in the UI thread.static void
maximizeView(String name)
Maximize a dedicated view.static void
minimizeView(String name)
Minimize a dedicated view.static void
moveView(String sourceView, String relativeTo, String position)
Move an existing view to a new position relative to another view.static int
openDialog(org.eclipse.jface.window.Window dialog)
Show a generic dialog.void
renameScriptShell(String newName)
Renames the script shell window to the specified name.static void
setClipboard(String data)
Write text data to the clipboard.boolean
showConfirmDialog(String message, String title)
Displays a confirmation dialog.org.eclipse.ui.IEditorPart
showEditor(Object location)
Opens a file in an editor.static org.eclipse.ui.IEditorPart
showEditor(org.eclipse.core.resources.IFile file)
Opens a file in an editor.void
showErrorDialog(String message, String title)
Displays an error dialog.void
showInfoDialog(String message, String title)
Displays an info dialog.String
showInputDialog(String message, String initialValue, String title)
Displays an input dialog.boolean
showQuestionDialog(String message, String title)
Displays a question dialog.Object
showSelectionDialog(Object[] elements, String message, String title)
Displays a selection dialog.static org.eclipse.ui.IViewPart
showView(String name)
Opens a view by given Name or id.static org.eclipse.ui.IViewPart
showView(String name, String secondaryId, int mode)
Shows a view in this page with the given id and secondary id.void
showWarningDialog(String message, String title)
Displays a warning dialog.static void
shutdown()
Shut down the application.Methods inherited from class org.eclipse.ease.modules.AbstractScriptModule
getScriptEngine, initialize
-
Field Details
-
MODULE_ID
Module identifier.- See Also:
- Constant Field Values
-
-
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()Returnstrue
when executed in the UI thread.- Returns:
true
in 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:
true
when 'yes' was pressed,false
otherwise
-
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
null
in 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
null
in 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:
true
when 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 org.eclipse.ui.IViewPart showView(String name, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String secondaryId, @ScriptParameter(defaultValue="1") int mode) throws ThrowableShows a view in this page with the given id and secondary id. The Behavior of this method varies based on the supplied mode. IfVIEW_ACTIVATE
is supplied, the view is given focus. IfVIEW_VISIBLE
is supplied, then it is made visible but not given focus. Finally, ifVIEW_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, ornull
for no secondary idmode
- the activation mode. Must be#VIEW_ACTIVATE
,#VIEW_VISIBLE
or#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.- Parameters:
location
- file location to open, eitherIFile
or workspace file location- Returns:
- editor instance or
null
- Throws:
Throwable
- when we cannot open the editor
-
showEditor
public static org.eclipse.ui.IEditorPart showEditor(org.eclipse.core.resources.IFile file) throws ThrowableOpens a file in an editor.- Parameters:
file
- file location to open- Returns:
- editor instance or
null
- Throws:
Throwable
- when we cannot open the editor
-
getSelection
public static org.eclipse.jface.viewers.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
public static org.eclipse.swt.widgets.Shell getShell()Get the workbench shell instance.- Returns:
- shell
-
getActiveView
public static org.eclipse.ui.IWorkbenchPart 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
public static org.eclipse.ui.IEditorPart 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:
true
if we are running without UI
-
createColor
public static org.eclipse.swt.graphics.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 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
-