use of org.eclipse.e4.ui.internal.workbench.swt.E4Application in project eclipse.platform.ui by eclipse-platform.
the class Workbench method createAndRunWorkbench.
/**
* Creates the workbench and associates it with the the given display and
* workbench advisor, and runs the workbench UI. This entails processing and
* dispatching events until the workbench is closed or restarted.
* <p>
* This method is intended to be called by <code>PlatformUI</code>. Fails if the
* workbench UI has already been created.
* </p>
* <p>
* The display passed in must be the default display.
* </p>
*
* @param display the display to be used for all UI interactions with the
* workbench
* @param advisor the application-specific advisor that configures and
* specializes the workbench
* @return return code {@link PlatformUI#RETURN_OK RETURN_OK}for normal exit;
* {@link PlatformUI#RETURN_RESTART RETURN_RESTART}if the workbench was
* terminated with a call to {@link IWorkbench#restart
* IWorkbench.restart}; other values reserved for future use
*/
public static int createAndRunWorkbench(final Display display, final WorkbenchAdvisor advisor) {
final int[] returnCode = new int[1];
Realm.runWithDefault(DisplayRealm.getRealm(display), () -> {
boolean showProgress = PrefUtil.getAPIPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_PROGRESS_ON_STARTUP);
final String nlExtensions = Platform.getNLExtensions();
if (nlExtensions.length() > 0) {
ULocale.setDefault(Category.FORMAT, new ULocale(ULocale.getDefault(Category.FORMAT).getBaseName() + nlExtensions));
}
System.setProperty(org.eclipse.e4.ui.workbench.IWorkbench.XMI_URI_ARG, // $NON-NLS-1$
"org.eclipse.ui.workbench/LegacyIDE.e4xmi");
Object obj = getApplication(Platform.getCommandLineArgs());
IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore();
if (!store.isDefault(IPreferenceConstants.LAYOUT_DIRECTION)) {
int orientation = store.getInt(IPreferenceConstants.LAYOUT_DIRECTION);
Window.setDefaultOrientation(orientation);
}
if (obj instanceof E4Application) {
E4Application e4app = (E4Application) obj;
E4Workbench e4Workbench = e4app.createE4Workbench(getApplicationContext(), display);
MApplication appModel = e4Workbench.getApplication();
IEclipseContext context = e4Workbench.getContext();
// create the workbench instance
Workbench workbench = new Workbench(display, advisor, appModel, context);
Dictionary<String, Object> properties = new Hashtable<>();
properties.put(Constants.SERVICE_RANKING, Integer.valueOf(Integer.MAX_VALUE - 1));
ServiceRegistration<?>[] registration = new ServiceRegistration[1];
StartupMonitor startupMonitor = new StartupMonitor() {
@Override
public void applicationRunning() {
// unregister ourself
registration[0].unregister();
// fire part visibility events now that we're up
for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
((WorkbenchPage) page).fireInitialPartVisibilityEvents();
}
}
}
@Override
public void update() {
// do nothing - we come into the picture far too late
// for this to be relevant
}
};
registration[0] = FrameworkUtil.getBundle(WorkbenchPlugin.class).getBundleContext().registerService(StartupMonitor.class.getName(), startupMonitor, properties);
// listener for updating the splash screen
SynchronousBundleListener bundleListener = null;
createSplash = WorkbenchPlugin.isSplashHandleSpecified();
if (createSplash) {
// prime the splash nice and early
workbench.createSplashWrapper();
// Bug 539376, 427393, 455162: show the splash screen after
// the image is loaded. See IDEApplication#checkInstanceLocation
// where the splash shell got hidden to avoid empty shell
AbstractSplashHandler handler = getSplash();
if (handler != null) {
Shell splashShell = handler.getSplash();
if (splashShell != null && !splashShell.isDisposed()) {
splashShell.setVisible(true);
splashShell.forceActive();
}
}
spinEventQueueToUpdateSplash(display);
if (handler != null && showProgress) {
IProgressMonitor progressMonitor = SubMonitor.convert(handler.getBundleProgressMonitor());
bundleListener = new Workbench.StartupProgressBundleListener(progressMonitor, display);
WorkbenchPlugin.getDefault().addBundleListener(bundleListener);
}
}
setSearchContribution(appModel, true);
// run the legacy workbench once
returnCode[0] = workbench.runUI();
if (returnCode[0] == PlatformUI.RETURN_OK) {
// run the e4 event loop and instantiate ... well, stuff
if (bundleListener != null) {
WorkbenchPlugin.getDefault().removeBundleListener(bundleListener);
}
e4Workbench.createAndRunUI(e4Workbench.getApplication());
}
if (returnCode[0] != PlatformUI.RETURN_UNSTARTABLE) {
setSearchContribution(appModel, false);
e4app.saveModel();
}
// code needs to be set appropriately
if (e4Workbench.isRestart()) {
returnCode[0] = PlatformUI.RETURN_RESTART;
} else {
e4Workbench.close();
returnCode[0] = workbench.returnCode;
}
}
});
return returnCode[0];
}
Aggregations