Class ApplicationModelUtils

java.lang.Object
com.amalgamasimulation.desktop.appelements.utils.ApplicationModelUtils

public class ApplicationModelUtils extends Object
Helpers for the e4 application model: the main window, perspectives and resetting their layout, part stacks, menu items, toolbars and commands.

Perspectives

The perspectives are snippets in Application.e4xmi. On startup the application calls copyAllPerspectivesFromSnippets(MApplication), which adds a copy of each snippet to the perspective stack. resetPerspective(MApplication) copies the snippet of the active perspective again and puts the copy in its place. All snippets of the application must be perspectives. The methods work with the first perspective stack of the application.

Ids of model elements

Some methods find model elements by id and come in two versions. The short version uses the default ids below, the other takes the ids as arguments. If Application.e4xmi uses these ids, call the short version; otherwise call the version with ids. If the window has no element with the id, the method skips it, and getMainWindow(MApplication) returns null.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Id of the command parameter that holds the full path of a file.
    static final String
     
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addRecentFileMenuItems(List<org.eclipse.e4.ui.model.application.ui.menu.MMenuElement> items, String[] paths, org.eclipse.e4.ui.model.application.MApplication application, String commandId)
    Adds menu items for recent files to a dynamic menu.
    static void
    addRecentFileMenuItems(List<org.eclipse.e4.ui.model.application.ui.menu.MMenuElement> items, String[] paths, org.eclipse.e4.ui.model.application.MApplication application, String commandId, Function<String,String> labelProvider)
    Same as addRecentFileMenuItems(List, String[], MApplication, String), except that labelProvider builds the label from the full path.
    static void
    copyAllPerspectivesFromSnippets(org.eclipse.e4.ui.model.application.MApplication application)
    Adds a copy of every snippet of the application to the perspective stack.
    static void
    executeCommand(org.eclipse.e4.ui.model.application.MApplication application, String commandId, Map<String,String> parameters)
    Runs the command with the parameters if it has an enabled handler.
    static org.eclipse.e4.ui.model.application.ui.advanced.MPerspective
    findPerspective(org.eclipse.e4.ui.model.application.MApplication application, String perspectiveId)
    Finds the perspective with the id in the perspective stack.
    static org.eclipse.e4.ui.model.application.ui.basic.MWindow
    getMainWindow(org.eclipse.e4.ui.model.application.MApplication application)
    Returns the main window of the application, the window with the id MAIN_WINDOW_ID.
    static org.eclipse.e4.ui.model.application.ui.basic.MWindow
    getMainWindow(org.eclipse.e4.ui.model.application.MApplication application, String mainWindowId)
    Returns the main window with another id.
    static String
    getSelectedMenuItemParameter(org.eclipse.e4.ui.workbench.modeling.EModelService modelService, org.eclipse.e4.ui.model.application.ui.basic.MWindow window, String menuId, String parameterName)
    Returns the command parameter value of the selected menu item.
    static void
    resetPerspective(org.eclipse.e4.ui.model.application.MApplication application)
    Restores the layout of the active perspective from its snippet.
    static void
    resetPerspective(org.eclipse.e4.ui.model.application.MApplication application, String mainWindowId)
    Same as resetPerspective(MApplication) for a main window with another id.
    static void
    selectMenuItems(org.eclipse.e4.ui.workbench.modeling.EModelService modelService, org.eclipse.e4.ui.model.application.ui.basic.MWindow window, String menuId, String parameterName, String value)
    Selects the menu items whose command parameter equals the value and clears the others.
    static void
    setPartStackVisible(org.eclipse.e4.ui.model.application.MApplication application, org.eclipse.e4.ui.workbench.modeling.EPartService partService, String partId, boolean visible)
    Shows or hides the part stack that holds the part.
    static void
    setPartStackVisible(org.eclipse.e4.ui.model.application.MApplication application, org.eclipse.e4.ui.workbench.modeling.EPartService partService, String partId, boolean visible, Consumer<Boolean> onVisibilityChanged)
    Same as setPartStackVisible(MApplication, EPartService, String, boolean); if the visibility has changed, also passes the new visibility to onVisibilityChanged.
    static void
    setToolBarsVisible(boolean visible, org.eclipse.e4.ui.workbench.modeling.EModelService modelService, org.eclipse.e4.ui.model.application.ui.basic.MWindow window)
    Shows or hides the items of the engine and updater toolbars and pins the toolbars and the TRIM_BAR_ID trim bar so that the user cannot drag them.
    static void
    setToolBarsVisible(boolean visible, org.eclipse.e4.ui.workbench.modeling.EModelService modelService, org.eclipse.e4.ui.model.application.ui.basic.MWindow window, String trimBarId, String... toolBarIds)
    static void
    showPart(org.eclipse.e4.ui.model.application.MApplication application, org.eclipse.e4.ui.workbench.modeling.EPartService partService, Class<?> partClass)
    Shows and activates every part whose contribution URI contains the simple name of the class, and shows its part stack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getMainWindow

      public static org.eclipse.e4.ui.model.application.ui.basic.MWindow getMainWindow(org.eclipse.e4.ui.model.application.MApplication application)
      Returns the main window of the application, the window with the id MAIN_WINDOW_ID.
      Parameters:
      application - the application
      Returns:
      the main window, or null if there is no window with this id
    • getMainWindow

      public static org.eclipse.e4.ui.model.application.ui.basic.MWindow getMainWindow(org.eclipse.e4.ui.model.application.MApplication application, String mainWindowId)
      Returns the main window with another id.
      Parameters:
      application - the application
      mainWindowId - id of the main window in the model
      Returns:
      the window, or null if there is none
    • copyAllPerspectivesFromSnippets

      public static void copyAllPerspectivesFromSnippets(org.eclipse.e4.ui.model.application.MApplication application)
      Adds a copy of every snippet of the application to the perspective stack. Call it once on startup: a second call adds the perspectives again.
      Parameters:
      application - the application
    • resetPerspective

      public static void resetPerspective(org.eclipse.e4.ui.model.application.MApplication application)
      Restores the layout of the active perspective from its snippet. Open parts keep their content and move to their places from the snippet. Closed parts open again. Does nothing if there is no active perspective.
      Parameters:
      application - the application
    • resetPerspective

      public static void resetPerspective(org.eclipse.e4.ui.model.application.MApplication application, String mainWindowId)
      Same as resetPerspective(MApplication) for a main window with another id.
      Parameters:
      application - the application
      mainWindowId - id of the main window in the model
    • findPerspective

      public static org.eclipse.e4.ui.model.application.ui.advanced.MPerspective findPerspective(org.eclipse.e4.ui.model.application.MApplication application, String perspectiveId)
      Finds the perspective with the id in the perspective stack.
      Parameters:
      application - the application
      perspectiveId - id of the perspective, the same as the id of its snippet
      Returns:
      the perspective, or null if there is none
    • selectMenuItems

      public static void selectMenuItems(org.eclipse.e4.ui.workbench.modeling.EModelService modelService, org.eclipse.e4.ui.model.application.ui.basic.MWindow window, String menuId, String parameterName, String value)
      Selects the menu items whose command parameter equals the value and clears the others. Items without this parameter do not change. Useful for menus that switch a setting, such as the language or the mode.
      Parameters:
      modelService - model service
      window - window whose main menu holds the menu
      menuId - id of the menu in the main menu of the window
      parameterName - name of the command parameter of the items
      value - parameter value of the item to select
    • getSelectedMenuItemParameter

      public static String getSelectedMenuItemParameter(org.eclipse.e4.ui.workbench.modeling.EModelService modelService, org.eclipse.e4.ui.model.application.ui.basic.MWindow window, String menuId, String parameterName)
      Returns the command parameter value of the selected menu item. This is the reverse of selectMenuItems(EModelService, MWindow, String, String, String).
      Parameters:
      modelService - model service
      window - window whose main menu holds the menu
      menuId - id of the menu in the main menu of the window
      parameterName - name of the command parameter of the items
      Returns:
      the parameter value, or null if no selected item has this parameter
    • addRecentFileMenuItems

      public static void addRecentFileMenuItems(List<org.eclipse.e4.ui.model.application.ui.menu.MMenuElement> items, String[] paths, org.eclipse.e4.ui.model.application.MApplication application, String commandId)
      Adds menu items for recent files to a dynamic menu. Each item runs the command with the path of its file in FILE_PATH_PARAMETER. The label is the path shortened in the middle to 50 characters. Empty paths are skipped. If the application has no command with this id, nothing is added.
      Parameters:
      items - items of the menu from the @AboutToShow method
      paths - paths of the files
      application - the application
      commandId - id of the command that opens the file
    • addRecentFileMenuItems

      public static void addRecentFileMenuItems(List<org.eclipse.e4.ui.model.application.ui.menu.MMenuElement> items, String[] paths, org.eclipse.e4.ui.model.application.MApplication application, String commandId, Function<String,String> labelProvider)
      Same as addRecentFileMenuItems(List, String[], MApplication, String), except that labelProvider builds the label from the full path.
      Parameters:
      items - items of the menu from the @AboutToShow method
      paths - paths of the files
      application - the application
      commandId - id of the command that opens the file
      labelProvider - returns the label for a path
    • setToolBarsVisible

      public static void setToolBarsVisible(boolean visible, org.eclipse.e4.ui.workbench.modeling.EModelService modelService, org.eclipse.e4.ui.model.application.ui.basic.MWindow window)
      Shows or hides the items of the engine and updater toolbars and pins the toolbars and the TRIM_BAR_ID trim bar so that the user cannot drag them. The toolbars themselves stay in the window.
      Parameters:
      visible - true to show the items
      modelService - model service
      window - window to search for the toolbars
    • setToolBarsVisible

      public static void setToolBarsVisible(boolean visible, org.eclipse.e4.ui.workbench.modeling.EModelService modelService, org.eclipse.e4.ui.model.application.ui.basic.MWindow window, String trimBarId, String... toolBarIds)
      Parameters:
      visible - true to show the items
      modelService - model service
      window - window to search for the trim bar and the toolbars
      trimBarId - id of the trim bar to pin
      toolBarIds - ids of the toolbars
    • setPartStackVisible

      public static void setPartStackVisible(org.eclipse.e4.ui.model.application.MApplication application, org.eclipse.e4.ui.workbench.modeling.EPartService partService, String partId, boolean visible)
      Shows or hides the part stack that holds the part. For a shared part, this is the stack that holds its placeholder. Does nothing if the part or the stack is not found or the stack already has this visibility.
      Parameters:
      application - the application
      partService - part service
      partId - id of the part
      visible - true to show the stack
    • setPartStackVisible

      public static void setPartStackVisible(org.eclipse.e4.ui.model.application.MApplication application, org.eclipse.e4.ui.workbench.modeling.EPartService partService, String partId, boolean visible, Consumer<Boolean> onVisibilityChanged)
      Same as setPartStackVisible(MApplication, EPartService, String, boolean); if the visibility has changed, also passes the new visibility to onVisibilityChanged.
      Parameters:
      application - the application
      partService - part service
      partId - id of the part
      visible - true to show the stack
      onVisibilityChanged - called after the visibility changes; can be null
    • showPart

      public static void showPart(org.eclipse.e4.ui.model.application.MApplication application, org.eclipse.e4.ui.workbench.modeling.EPartService partService, Class<?> partClass)
      Shows and activates every part whose contribution URI contains the simple name of the class, and shows its part stack. Does nothing if the application has no active window.
      Parameters:
      application - the application
      partService - part service
      partClass - class of the part
    • executeCommand

      public static void executeCommand(org.eclipse.e4.ui.model.application.MApplication application, String commandId, Map<String,String> parameters)
      Runs the command with the parameters if it has an enabled handler. Otherwise does nothing, as for an unknown command.
      Parameters:
      application - the application
      commandId - id of the command
      parameters - names and values of the command parameters