use of org.eclipse.e4.ui.internal.workbench.E4Workbench in project eclipse.platform.ui by eclipse-platform.
the class Workbench method runUI.
/**
* Internal method for running the workbench UI. This entails processing and
* dispatching events until the workbench is closed or restarted.
*
* @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}; {@link PlatformUI#RETURN_UNSTARTABLE
* RETURN_UNSTARTABLE}if the workbench could not be started; other
* values reserved for future use
* @since 3.0
*/
private int runUI() {
// $NON-NLS-1$
UIStats.start(UIStats.START_WORKBENCH, "Workbench");
// deadlock code
boolean avoidDeadlock = true;
String[] commandLineArgs = Platform.getCommandLineArgs();
for (String commandLineArg : commandLineArgs) {
if (commandLineArg.equalsIgnoreCase("-allowDeadlock")) {
// $NON-NLS-1$
avoidDeadlock = false;
}
}
final UISynchronizer synchronizer;
if (avoidDeadlock) {
UILockListener uiLockListener = new UILockListener(display);
Job.getJobManager().setLockListener(uiLockListener);
synchronizer = new UISynchronizer(display, uiLockListener);
display.setSynchronizer(synchronizer);
// declare the main thread to be a startup thread.
UISynchronizer.startupThread.set(Boolean.TRUE);
} else
synchronizer = null;
// ModalContext should not spin the event loop (there is no UI yet to block)
ModalContext.setAllowReadAndDispatch(false);
// run while starting the Workbench, log a warning.
if (WorkbenchPlugin.getDefault().isDebugging()) {
display.asyncExec(() -> {
if (isStarting()) {
WorkbenchPlugin.log(StatusUtil.newStatus(IStatus.WARNING, // $NON-NLS-1$
"Event loop should not be run while the Workbench is starting.", new RuntimeException()));
}
});
}
Listener closeListener = event -> event.doit = close();
// Initialize an exception handler.
Window.IExceptionHandler handler = ExceptionHandler.getInstance();
try {
// react to display close event by closing workbench nicely
display.addListener(SWT.Close, closeListener);
// install backstop to catch exceptions thrown out of event loop
Window.setExceptionHandler(handler);
final boolean[] initOK = new boolean[1];
// initialize workbench and restore or open one window
initOK[0] = init();
if (initOK[0] && runEventLoop) {
// Same registration as in E4Workbench
Hashtable<String, Object> properties = new Hashtable<>();
// $NON-NLS-1$
properties.put("id", getId());
workbenchService = WorkbenchPlugin.getDefault().getBundleContext().registerService(IWorkbench.class.getName(), this, properties);
e4WorkbenchService = WorkbenchPlugin.getDefault().getBundleContext().registerService(org.eclipse.e4.ui.workbench.IWorkbench.class.getName(), this, properties);
Runnable earlyStartup = () -> {
// Let the advisor run its start-up code.
// May trigger a close/restart.
advisor.postStartup();
// start eager plug-ins
startPlugins();
addStartupRegistryListener();
};
e4Context.set(PartRenderingEngine.EARLY_STARTUP_HOOK, earlyStartup);
// start workspace auto-save
final int millisecondInterval = getAutoSaveJobTime();
if (millisecondInterval > 0 && workbenchAutoSave) {
autoSaveJob = new WorkbenchJob(WORKBENCH_AUTO_SAVE_JOB) {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
final int nextDelay = getAutoSaveJobTime();
try {
if (applicationModelChanged) {
persist(false);
applicationModelChanged = false;
}
monitor.done();
} finally {
// repeat
if (nextDelay > 0 && workbenchAutoSave) {
this.schedule(nextDelay);
}
}
return Status.OK_STATUS;
}
};
autoSaveJob.setSystem(true);
autoSaveJob.schedule(millisecondInterval);
}
display.asyncExec(new Runnable() {
@Override
public void run() {
// $NON-NLS-1$
UIStats.end(UIStats.START_WORKBENCH, this, "Workbench");
UIStats.startupComplete();
}
});
getWorkbenchTestable().init(display, this);
// allow ModalContext to spin the event loop
ModalContext.setAllowReadAndDispatch(true);
isStarting = false;
if (synchronizer != null)
synchronizer.started();
}
returnCode = PlatformUI.RETURN_OK;
if (!initOK[0]) {
returnCode = PlatformUI.RETURN_UNSTARTABLE;
}
} catch (final Exception e) {
if (!display.isDisposed()) {
handler.handleException(e);
} else {
// $NON-NLS-1$
String msg = "Exception in Workbench.runUI after display was disposed";
WorkbenchPlugin.log(msg, new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, 1, msg, e));
}
}
// restart or exit based on returnCode
return returnCode;
}
use of org.eclipse.e4.ui.internal.workbench.E4Workbench in project eclipse.platform.ui by eclipse-platform.
the class NewMWindowTest method testCreateWindow.
@Test
public void testCreateWindow() {
final MWindow window = ems.createModelElement(MWindow.class);
window.setLabel("MyWindow");
wb = new E4Workbench(window, appContext);
Widget topWidget = (Widget) window.getWidget();
assertTrue(topWidget instanceof Shell);
assertEquals("MyWindow", ((Shell) topWidget).getText());
assertEquals(topWidget, appContext.get(IServiceConstants.ACTIVE_SHELL));
}
use of org.eclipse.e4.ui.internal.workbench.E4Workbench in project eclipse.platform.ui by eclipse-platform.
the class NewMWindowTest method testCreateView.
@Test
public void testCreateView() {
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());
Control[] controls = shell.getChildren();
assertEquals(1, controls.length);
SashForm sash = (SashForm) controls[0];
Control[] sashChildren = sash.getChildren();
assertEquals(1, sashChildren.length);
CTabFolder folder = (CTabFolder) sashChildren[0];
assertEquals(1, folder.getItemCount());
Control c = folder.getItem(0).getControl();
assertTrue(c instanceof Composite);
Control[] viewPart = ((Composite) c).getChildren();
assertEquals(1, viewPart.length);
assertTrue(viewPart[0] instanceof Tree);
}
use of org.eclipse.e4.ui.internal.workbench.E4Workbench in project eclipse.platform.ui by eclipse-platform.
the class SashRendererTest method testBug310027.
@Test
public void testBug310027() {
MApplication application = ems.createModelElement(MApplication.class);
MWindow window = ems.createModelElement(MWindow.class);
MPartSashContainer container = ems.createModelElement(MPartSashContainer.class);
MPartStack partStackA = ems.createModelElement(MPartStack.class);
MPartStack partStackB = ems.createModelElement(MPartStack.class);
MPart partA = ems.createModelElement(MPart.class);
MPart partB = ems.createModelElement(MPart.class);
window.setWidth(600);
window.setHeight(400);
partStackA.setContainerData("50");
partStackB.setContainerData("50");
application.getChildren().add(window);
application.setSelectedElement(window);
window.getChildren().add(container);
window.setSelectedElement(container);
container.getChildren().add(partStackA);
container.getChildren().add(partStackB);
container.setSelectedElement(partStackA);
partStackA.getChildren().add(partA);
partStackA.setSelectedElement(partA);
partStackA.getChildren().add(partB);
partStackA.setSelectedElement(partB);
application.setContext(appContext);
appContext.set(MApplication.class, application);
wb = new E4Workbench(application, appContext);
wb.createAndRunUI(window);
assertEquals("50", partStackA.getContainerData());
assertEquals("50", partStackB.getContainerData());
partStackB.setToBeRendered(false);
while (Display.getDefault().readAndDispatch()) {
}
assertEquals("50", partStackA.getContainerData());
}
use of org.eclipse.e4.ui.internal.workbench.E4Workbench in project eclipse.platform.ui by eclipse-platform.
the class AreaRendererTest method testStackInsideMCompositePartDoesNotCreateACTabFolder.
@Test
public void testStackInsideMCompositePartDoesNotCreateACTabFolder() {
MWindow window = ems.createModelElement(MWindow.class);
MArea area = ems.createModelElement(MArea.class);
// Create a CompositePart with MParts inside
MCompositePart composite = ems.createModelElement(MCompositePart.class);
MPartStack stack1 = ems.createModelElement(MPartStack.class);
stack1.getChildren().add(ems.createModelElement(MPart.class));
stack1.getChildren().add(ems.createModelElement(MPart.class));
MPartStack stack2 = ems.createModelElement(MPartStack.class);
stack2.getChildren().add(ems.createModelElement(MPart.class));
stack2.getChildren().add(ems.createModelElement(MPart.class));
composite.getChildren().add(stack1);
composite.getChildren().add(stack2);
// Place the container in the area
area.getChildren().add(composite);
// Add area to the window
window.getChildren().add(area);
MApplication application = ems.createModelElement(MApplication.class);
application.getChildren().add(window);
application.setContext(appContext);
appContext.set(MApplication.class, application);
wb = new E4Workbench(application, appContext);
wb.createAndRunUI(window);
// Make sure the widget is not a CTabFolder
Assert.assertFalse(area.getWidget() instanceof CTabFolder);
}
Aggregations