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 Details

  • Constructor Details

    • UIModule

      public UIModule()
  • Method Details

    • executeUI

      public Object executeUI​(Object code) throws ExecutionException
      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()
      Returns true when executed in the UI thread.
      Returns:
      true in UI thread
    • showInfoDialog

      public void showInfoDialog​(String message, @ScriptParameter(defaultValue="Info") 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​(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 message
      title - 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 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 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 from
      message - dialog message
      title - 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 message
      title - 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 message
      title - dialog title
    • showErrorDialog

      public void showErrorDialog​(String message, @ScriptParameter(defaultValue="Error") 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 org.eclipse.ui.IViewPart showView​(String name) throws 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:
      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 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:
      Throwable - when the view cannot be opened
      IllegalArgumentException - when the supplied mode is not valid
      Since:
      3.0
    • showEditor

      public org.eclipse.ui.IEditorPart showEditor​(Object location) throws 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:
      Throwable - when we cannot open the editor
    • showEditor

      public static org.eclipse.ui.IEditorPart showEditor​(org.eclipse.core.resources.IFile file) throws Throwable
      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
    • 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

      public static Object convertSelection​(org.eclipse.jface.viewers.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​(org.eclipse.jface.window.Window dialog) throws Throwable
      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

      public void renameScriptShell​(String newName)
      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

      public static void setClipboard​(String data)
      Write text data to the clipboard.
      Parameters:
      data - data to write to the clipboard
    • getClipboard

      public static Object getClipboard()
      Get text data from the clipboard.
      Returns:
      clipboard text
    • clearConsole

      public void clearConsole()
      Clear the script console.
    • getConsole

      public ScriptConsole getConsole()
      Get the script console for the current engine.
      Returns:
      script console or null
    • maximizeView

      public static void maximizeView​(String name) throws 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:
      Throwable - when view cannot be opened
    • minimizeView

      public static void minimizeView​(String name) throws 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:
      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 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 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 color
      green - the amount of green in the color
      blue - 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 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