Class PlatformUI
- creation of the workbench.
- access to the workbench.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Supplier<RuntimeException>
A supplier that supplies anIllegalStateException
that a Workbench is not running.static final String
Identifies the workbench plug-in.static final int
Return code (value 3) indicating that the workbench was terminated with a call to IWorkbenchConfigurer#emergencyClose.static final int
Return code (value 0) indicating that the workbench terminated normally.static final int
Return code (value 1) indicating that the workbench was terminated with a call toIWorkbench.restart
.static final int
Return code (value 2) indicating that the workbench failed to start. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
createAndRunWorkbench
(Display display, WorkbenchAdvisor advisor) Creates the workbench and associates it with the given display and workbench advisor, and runs the workbench UI.static Display
Creates theDisplay
to be used by the workbench.static IPreferenceStore
createPreferenceStore
(Class<?> clazz) Creates aIPreferenceStore
store for the bundle that loaded that classstatic Optional<MApplication>
This methods allows code of eclipse.ui to gracefully migrate to E4 as it has the following properties: It does not throw an exception but returns an empty optional if something is not ready (yet or anymore) so code can choose how to handle this (e.g. useOptional.orElseThrow()
if required orOptional.orElse(Object)
if a fallback exits. If this is is actually a (ui) Workbench running, this is returned and could be used If not the service registry is searched for an org.eclipse.e4.ui.workbench.IWorkbench so code can run inside a pure E4 (e.g.static IDialogSettingsProvider
getDialogSettingsProvider
(Bundle bundle) Returns the dialog settings provider for the passed bundle.static IPreferenceStore
Returns the preference store used for publicly settable workbench preferences.static TestableObject
Returns the testable object facade, for use by the test harness.static IWorkbench
Returns the workbench.static boolean
Returns whethercreateAndRunWorkbench
has been called to create the workbench, and the workbench has yet to terminate.static void
Sets the given help id on the given control in a way that works both for E3/E4 applications
-
Field Details
-
PLUGIN_ID
Identifies the workbench plug-in.- See Also:
-
RETURN_OK
public static final int RETURN_OKReturn code (value 0) indicating that the workbench terminated normally. -
RETURN_RESTART
public static final int RETURN_RESTARTReturn code (value 1) indicating that the workbench was terminated with a call toIWorkbench.restart
. -
RETURN_UNSTARTABLE
public static final int RETURN_UNSTARTABLEReturn code (value 2) indicating that the workbench failed to start. -
RETURN_EMERGENCY_CLOSE
public static final int RETURN_EMERGENCY_CLOSEReturn code (value 3) indicating that the workbench was terminated with a call to IWorkbenchConfigurer#emergencyClose. -
NO_WORKBENCH
A supplier that supplies anIllegalStateException
that a Workbench is not running.- Since:
- 3.126
-
-
Method Details
-
getWorkbench
Returns the workbench. Fails if the workbench has not been created yet.- Returns:
- the workbench
-
isWorkbenchRunning
public static boolean isWorkbenchRunning()Returns whethercreateAndRunWorkbench
has been called to create the workbench, and the workbench has yet to terminate.Note that this method may return
true
while the workbench is still being initialized, so it may not be safe to call workbench API methods even if this method returns true. See bug 49316 for details.- Returns:
true
if the workbench has been created and is still running, andfalse
if the workbench has not yet been created or has completed- Since:
- 3.0
-
createAndRunWorkbench
Creates the workbench and associates it with the given display and workbench advisor, and runs the workbench UI. This entails processing and dispatching events until the workbench is closed or restarted.This method is intended to be called by the main class (the "application"). Fails if the workbench UI has already been created.
Use
createDisplay
to create the display to pass in.Note that this method is intended to be called by the application. It must be called exactly once, and early on before anyone else asks
getWorkbench()
for the workbench.- Parameters:
display
- the display to be used for all UI interactions with the workbenchadvisor
- the application-specific advisor that configures and specializes the workbench- Returns:
- return code
RETURN_OK
for normal exit;RETURN_RESTART
if the workbench was terminated with a call toIWorkbench.restart
;RETURN_UNSTARTABLE
if the workbench could not be started;RETURN_EMERGENCY_CLOSE
if the UI quit because of an emergency; other values reserved for future use - Since:
- 3.0
-
createDisplay
Creates theDisplay
to be used by the workbench. It is the caller's responsibility to dispose the resultingDisplay
, not the workbench's.- Returns:
- the display
- Since:
- 3.0
-
getTestableObject
Returns the testable object facade, for use by the test harness.IMPORTANT: This method is only for use by the test harness. Applications and regular plug-ins should not call this method.
To avoid depending on the the Workbench a
TestableObject
can be obtained via OSGi service.- Returns:
- the testable object facade
- Since:
- 3.0
-
getPreferenceStore
Returns the preference store used for publicly settable workbench preferences. Constants for these preferences are defined onIWorkbenchPreferenceConstants
.- Returns:
- the workbench public preference store
- Since:
- 3.0
-
getDialogSettingsProvider
Returns the dialog settings provider for the passed bundle. The dialog settings is used to hold persistent state data for the various wizards and dialogs of the bundle in the context of a workbench.If an error occurs reading the dialog store, an empty one is quietly created and returned (errors are logged).
- Parameters:
bundle
- the bundle for which the dialog settings are to be returned- Returns:
- the dialog settings provider
- Since:
- 3.122
-
createPreferenceStore
Creates aIPreferenceStore
store for the bundle that loaded that class- Parameters:
clazz
- the class to use for determining the responsible bundle- Returns:
- the instance scoped preference store for the given class
- Since:
- 3.117
-
getApplication
This methods allows code of eclipse.ui to gracefully migrate to E4 as it has the following properties:- It does not throw an exception but returns an empty optional if something
is not ready (yet or anymore) so code can choose how to handle this (e.g. use
Optional.orElseThrow()
if required orOptional.orElse(Object)
if a fallback exits. - If this is is actually a (ui) Workbench running, this is returned and could be used
- If not the service registry is searched for an org.eclipse.e4.ui.workbench.IWorkbench so code can run inside a pure E4 (e.g. RCP) application as well.
- With the Application at hand, it is possible to get access to the
IEclipseContext
(seeMContext.getContext()
to further interact with the plain E4 Application Model.
PlatformUI.getWorkbench().getExtensionTracker()
PlatformUI.getApplication().map(MApplication::getContext).map(ctx -> ctx.get(IExtensionTracker.class)).orElseThrow(PlatformUI.NO_WORKBENCH);
- Returns:
- a reference to the
MApplication
running the Workbench or an empty optional if currently no Workbench is available. - Since:
- 3.126
- It does not throw an exception but returns an empty optional if something
is not ready (yet or anymore) so code can choose how to handle this (e.g. use
-
setHelp
Sets the given help id on the given control in a way that works both for E3/E4 applications- Parameters:
control
- the control on which to register the idhelpContextId
- the id to use when F1 help is invoked- Since:
- 3.131
-