Class ApplicationModelUtils
java.lang.Object
com.amalgamasimulation.desktop.appelements.utils.ApplicationModelUtils
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 inApplication.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. IfApplication.e4xmi uses these ids, call the short version; otherwise
call the version with ids.
MAIN_WINDOW_ID: the main window. Used bygetMainWindow(MApplication)andresetPerspective(MApplication).TRIM_BAR_ID: the topTrimBarof the window.setToolBarsVisible(boolean, EModelService, MWindow)pins it so that the user cannot drag it.com.amalgamasimulation.enginetoolbarandcom.amalgamasimulation.updatertoolbar: toolbars in thisTrimBar. Used bysetToolBarsVisible(boolean, EModelService, MWindow).
getMainWindow(MApplication) returns null.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddRecentFileMenuItems(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 voidaddRecentFileMenuItems(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 asaddRecentFileMenuItems(List, String[], MApplication, String), except thatlabelProviderbuilds the label from the full path.static voidcopyAllPerspectivesFromSnippets(org.eclipse.e4.ui.model.application.MApplication application) Adds a copy of every snippet of the application to the perspective stack.static voidexecuteCommand(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.MPerspectivefindPerspective(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.MWindowgetMainWindow(org.eclipse.e4.ui.model.application.MApplication application) Returns the main window of the application, the window with the idMAIN_WINDOW_ID.static org.eclipse.e4.ui.model.application.ui.basic.MWindowgetMainWindow(org.eclipse.e4.ui.model.application.MApplication application, String mainWindowId) Returns the main window with another id.static StringgetSelectedMenuItemParameter(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 voidresetPerspective(org.eclipse.e4.ui.model.application.MApplication application) Restores the layout of the active perspective from its snippet.static voidresetPerspective(org.eclipse.e4.ui.model.application.MApplication application, String mainWindowId) Same asresetPerspective(MApplication)for a main window with another id.static voidselectMenuItems(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 voidsetPartStackVisible(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 voidsetPartStackVisible(org.eclipse.e4.ui.model.application.MApplication application, org.eclipse.e4.ui.workbench.modeling.EPartService partService, String partId, boolean visible, Consumer<Boolean> onVisibilityChanged) Same assetPartStackVisible(MApplication, EPartService, String, boolean); if the visibility has changed, also passes the new visibility toonVisibilityChanged.static voidsetToolBarsVisible(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 theTRIM_BAR_IDtrim bar so that the user cannot drag them.static voidsetToolBarsVisible(boolean visible, org.eclipse.e4.ui.workbench.modeling.EModelService modelService, org.eclipse.e4.ui.model.application.ui.basic.MWindow window, String trimBarId, String... toolBarIds) Same assetToolBarsVisible(boolean, EModelService, MWindow)for other ids.static voidshowPart(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.
-
Field Details
-
MAIN_WINDOW_ID
- See Also:
-
TRIM_BAR_ID
- See Also:
-
FILE_PATH_PARAMETER
Id of the command parameter that holds the full path of a file. A command passed toaddRecentFileMenuItems(List, String[], MApplication, String)declares this parameter inApplication.e4xmi, and its handler reads the path with@Named(FILE_PATH_PARAMETER).- See Also:
-
-
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 idMAIN_WINDOW_ID.- Parameters:
application- the application- Returns:
- the main window, or
nullif 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 applicationmainWindowId- id of the main window in the model- Returns:
- the window, or
nullif 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 asresetPerspective(MApplication)for a main window with another id.- Parameters:
application- the applicationmainWindowId- 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 applicationperspectiveId- id of the perspective, the same as the id of its snippet- Returns:
- the perspective, or
nullif 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 servicewindow- window whose main menu holds the menumenuId- id of the menu in the main menu of the windowparameterName- name of the command parameter of the itemsvalue- 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 ofselectMenuItems(EModelService, MWindow, String, String, String).- Parameters:
modelService- model servicewindow- window whose main menu holds the menumenuId- id of the menu in the main menu of the windowparameterName- name of the command parameter of the items- Returns:
- the parameter value, or
nullif 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 inFILE_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@AboutToShowmethodpaths- paths of the filesapplication- the applicationcommandId- 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 asaddRecentFileMenuItems(List, String[], MApplication, String), except thatlabelProviderbuilds the label from the full path.- Parameters:
items- items of the menu from the@AboutToShowmethodpaths- paths of the filesapplication- the applicationcommandId- id of the command that opens the filelabelProvider- 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 theTRIM_BAR_IDtrim bar so that the user cannot drag them. The toolbars themselves stay in the window.- Parameters:
visible-trueto show the itemsmodelService- model servicewindow- 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) Same assetToolBarsVisible(boolean, EModelService, MWindow)for other ids.- Parameters:
visible-trueto show the itemsmodelService- model servicewindow- window to search for the trim bar and the toolbarstrimBarId- id of the trim bar to pintoolBarIds- 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 applicationpartService- part servicepartId- id of the partvisible-trueto 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 assetPartStackVisible(MApplication, EPartService, String, boolean); if the visibility has changed, also passes the new visibility toonVisibilityChanged.- Parameters:
application- the applicationpartService- part servicepartId- id of the partvisible-trueto show the stackonVisibilityChanged- called after the visibility changes; can benull
-
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 applicationpartService- part servicepartClass- 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 applicationcommandId- id of the commandparameters- names and values of the command parameters
-