use of org.eclipse.e4.ui.internal.workbench.E4Workbench in project eclipse.platform.ui by eclipse-platform.
the class E4Application method start.
@Override
public Object start(IApplicationContext applicationContext) throws Exception {
// set the display name before the Display is
// created to ensure the app name is used in any
// platform menus, etc. See
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=329456#c14
IProduct product = Platform.getProduct();
if (product != null && product.getName() != null) {
Display.setAppName(product.getName());
}
Display display = getApplicationDisplay();
Location instanceLocation = null;
try {
E4Workbench workbench = createE4Workbench(applicationContext, display);
instanceLocation = (Location) workbench.getContext().get(E4Workbench.INSTANCE_LOCATION);
Shell shell = display.getActiveShell();
if (shell == null) {
shell = new Shell();
// place it off so it's not visible
shell.setLocation(0, 10000);
}
if (!checkInstanceLocation(instanceLocation, shell, workbench.getContext()))
return EXIT_OK;
// Create and run the UI (if any)
workbench.createAndRunUI(workbench.getApplication());
saveModel();
workbench.close();
if (lcManager != null) {
ContextInjectionFactory.invoke(lcManager, PostWorkbenchClose.class, workbench.getContext(), null);
}
if (workbench.isRestart()) {
return EXIT_RESTART;
}
return EXIT_OK;
} finally {
if (display != null)
display.dispose();
if (instanceLocation != null)
instanceLocation.release();
}
}
use of org.eclipse.e4.ui.internal.workbench.E4Workbench in project eclipse.platform.ui by eclipse-platform.
the class E4Application method createE4Workbench.
public E4Workbench createE4Workbench(IApplicationContext applicationContext, final Display display) {
args = (String[]) applicationContext.getArguments().get(IApplicationContext.APPLICATION_ARGS);
IEclipseContext appContext = createDefaultContext();
appContext.set(Display.class, display);
appContext.set(Realm.class, DisplayRealm.getRealm(display));
appContext.set(UISynchronize.class, new DisplayUISynchronize(display));
appContext.set(IApplicationContext.class, applicationContext);
// This context will be used by the injector for its
// extended data suppliers
ContextInjectionFactory.setDefault(appContext);
// Get the factory to create DI instances with
IContributionFactory factory = appContext.get(IContributionFactory.class);
// Install the life-cycle manager for this session if there's one
// defined
Optional<String> lifeCycleURI = getArgValue(IWorkbench.LIFE_CYCLE_URI_ARG, applicationContext, false);
lifeCycleURI.ifPresent(lifeCycleURIValue -> {
lcManager = factory.create(lifeCycleURIValue, appContext);
if (lcManager != null) {
// Let the manager manipulate the appContext if desired
ContextInjectionFactory.invoke(lcManager, PostContextCreate.class, appContext, null);
}
});
Optional<String> forcedPerspectiveId = getArgValue(PERSPECTIVE_ARG_NAME, applicationContext, false);
forcedPerspectiveId.ifPresent(forcedPerspectiveIdValue -> appContext.set(E4Workbench.FORCED_PERSPECTIVE_ID, forcedPerspectiveIdValue));
String showLocation = getLocationFromCommandLine();
if (showLocation != null) {
appContext.set(E4Workbench.FORCED_SHOW_LOCATION, showLocation);
}
// Create the app model and its context
MApplication appModel = loadApplicationModel(applicationContext, appContext);
appModel.setContext(appContext);
boolean isRtl = ((Window.getDefaultOrientation() & SWT.RIGHT_TO_LEFT) != 0);
appModel.getTransientData().put(E4Workbench.RTL_MODE, isRtl);
// context (see Workbench#getInstance())
if (!E4Workbench.getServiceContext().containsKey(MApplication.class)) {
// first one wins.
E4Workbench.getServiceContext().set(MApplication.class, appModel);
}
// Set the app's context after adding itself
appContext.set(MApplication.class, appModel);
// adds basic services to the contexts
initializeServices(appModel);
// let the life cycle manager add to the model
if (lcManager != null) {
ContextInjectionFactory.invoke(lcManager, ProcessAdditions.class, appContext, null);
ContextInjectionFactory.invoke(lcManager, ProcessRemovals.class, appContext, null);
}
// Create the addons
IEclipseContext addonStaticContext = EclipseContextFactory.create();
for (MAddon addon : appModel.getAddons()) {
addonStaticContext.set(MAddon.class, addon);
Object obj = factory.create(addon.getContributionURI(), appContext, addonStaticContext);
addon.setObject(obj);
}
// Parse out parameters from both the command line and/or the product
// definition (if any) and put them in the context
Optional<String> xmiURI = getArgValue(IWorkbench.XMI_URI_ARG, applicationContext, false);
xmiURI.ifPresent(xmiURIValue -> {
appContext.set(IWorkbench.XMI_URI_ARG, xmiURIValue);
});
setCSSContextVariables(applicationContext, appContext);
Optional<String> rendererFactoryURI = getArgValue(E4Workbench.RENDERER_FACTORY_URI, applicationContext, false);
rendererFactoryURI.ifPresent(rendererFactoryURIValue -> {
appContext.set(E4Workbench.RENDERER_FACTORY_URI, rendererFactoryURIValue);
});
// This is a default arg, if missing we use the default rendering engine
Optional<String> presentationURI = getArgValue(IWorkbench.PRESENTATION_URI_ARG, applicationContext, false);
appContext.set(IWorkbench.PRESENTATION_URI_ARG, presentationURI.orElse(PartRenderingEngine.engineURI));
// 'running' the UI (if any)...
return workbench = new E4Workbench(appModel, appContext);
}
use of org.eclipse.e4.ui.internal.workbench.E4Workbench 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];
}
use of org.eclipse.e4.ui.internal.workbench.E4Workbench in project eclipse.platform.ui by eclipse-platform.
the class NewMWindowTest method testContextChildren.
@Test
public void testContextChildren() {
final MWindow window = createWindowWithOneView();
wb = new E4Workbench(window, appContext);
Widget topWidget = (Widget) window.getWidget();
assertTrue(topWidget instanceof Shell);
Shell shell = (Shell) topWidget;
assertEquals("MyWindow", shell.getText());
// should get the window context
IEclipseContext child = appContext.getActiveChild();
assertNotNull(child);
assertEquals(window.getContext(), child);
MPart modelPart = getContributedPart(window);
assertNotNull(modelPart);
assertEquals(window, modelPart.getParent().getParent().getParent());
// "activate" the part, same as (in theory) an
// SWT.Activate event.
AbstractPartRenderer factory = (AbstractPartRenderer) modelPart.getRenderer();
factory.activate(modelPart);
IEclipseContext next = child.getActiveChild();
while (next != null) {
child = next;
next = child.getActiveChild();
if (next == child) {
fail("Cycle detected in part context");
break;
}
}
assertFalse(window.getContext() == child);
MPart contextPart = child.get(MPart.class);
assertNotNull(contextPart);
assertEquals(window, contextPart.getParent().getParent().getParent());
}
use of org.eclipse.e4.ui.internal.workbench.E4Workbench in project eclipse.platform.ui by eclipse-platform.
the class NewMWindowTest method testCreateMenu.
@Test
public void testCreateMenu() {
final MWindow window = createWindowWithOneViewAndMenu();
wb = new E4Workbench(window, appContext);
Widget topWidget = (Widget) window.getWidget();
assertTrue(topWidget instanceof Shell);
Shell shell = (Shell) topWidget;
final Menu menuBar = shell.getMenuBar();
assertNotNull(menuBar);
assertEquals(1, menuBar.getItemCount());
final MenuItem fileItem = menuBar.getItem(0);
assertEquals("File", fileItem.getText());
final Menu fileMenu = fileItem.getMenu();
fileMenu.notifyListeners(SWT.Show, null);
assertEquals(2, fileMenu.getItemCount());
fileMenu.notifyListeners(SWT.Hide, null);
MMenu mainMenu = window.getMainMenu();
MMenu modelFileMenu = (MMenu) mainMenu.getChildren().get(0);
final MMenuItem item2Model = (MMenuItem) modelFileMenu.getChildren().get(0);
item2Model.setToBeRendered(false);
fileMenu.notifyListeners(SWT.Show, null);
assertEquals(1, fileMenu.getItemCount());
fileMenu.notifyListeners(SWT.Hide, null);
item2Model.setToBeRendered(true);
fileMenu.notifyListeners(SWT.Show, null);
assertEquals(2, fileMenu.getItemCount());
fileMenu.notifyListeners(SWT.Hide, null);
}
Aggregations