Search in sources :

Example 11 with E4Workbench

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) CommandService(org.eclipse.ui.internal.commands.CommandService) ISaveableFilter(org.eclipse.ui.ISaveableFilter) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewReference(org.eclipse.ui.IViewReference) Point(org.eclipse.swt.graphics.Point) IIntroManager(org.eclipse.ui.intro.IIntroManager) E4XMIResource(org.eclipse.e4.ui.internal.workbench.E4XMIResource) AbstractSplashHandler(org.eclipse.ui.splash.AbstractSplashHandler) ULocale(com.ibm.icu.util.ULocale) Map(java.util.Map) SWTException(org.eclipse.swt.SWTException) IServiceScopes(org.eclipse.ui.services.IServiceScopes) StatusManager(org.eclipse.ui.statushandlers.StatusManager) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IEditorPart(org.eclipse.ui.IEditorPart) IEvaluationService(org.eclipse.ui.services.IEvaluationService) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) StatusUtil(org.eclipse.ui.internal.misc.StatusUtil) IThemeManager(org.eclipse.ui.themes.IThemeManager) IRunnableContext(org.eclipse.jface.operation.IRunnableContext) OpenStrategy(org.eclipse.jface.util.OpenStrategy) ActiveContextSourceProvider(org.eclipse.ui.internal.contexts.ActiveContextSourceProvider) Window(org.eclipse.jface.window.Window) WorkbenchMenuService(org.eclipse.ui.internal.menus.WorkbenchMenuService) BindingManager(org.eclipse.jface.bindings.BindingManager) IApplicationContext(org.eclipse.equinox.app.IApplicationContext) XMLMemento(org.eclipse.ui.XMLMemento) IShellProvider(org.eclipse.jface.window.IShellProvider) SafeRunner(org.eclipse.core.runtime.SafeRunner) MPartDescriptor(org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor) SubMonitor(org.eclipse.core.runtime.SubMonitor) CommandsFactoryImpl(org.eclipse.e4.ui.model.application.commands.impl.CommandsFactoryImpl) BusyIndicator(org.eclipse.swt.custom.BusyIndicator) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) ICommandService(org.eclipse.ui.commands.ICommandService) ListenerList(org.eclipse.core.runtime.ListenerList) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) WorkbenchContextSupport(org.eclipse.ui.internal.contexts.WorkbenchContextSupport) ColorDefinition(org.eclipse.ui.internal.themes.ColorDefinition) SplashHandlerFactory(org.eclipse.ui.internal.splash.SplashHandlerFactory) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) ContributionService(org.eclipse.ui.internal.model.ContributionService) IMemento(org.eclipse.ui.IMemento) IWorkbenchContextSupport(org.eclipse.ui.contexts.IWorkbenchContextSupport) ProgressManager(org.eclipse.ui.internal.progress.ProgressManager) MCategory(org.eclipse.e4.ui.model.application.commands.MCategory) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) CompatibilityEditor(org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor) IOException(java.io.IOException) ServiceLocatorCreator(org.eclipse.ui.internal.services.ServiceLocatorCreator) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) WorkbenchCommandSupport(org.eclipse.ui.internal.commands.WorkbenchCommandSupport) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) StringReader(java.io.StringReader) IContextService(org.eclipse.ui.contexts.IContextService) EvaluationService(org.eclipse.ui.internal.services.EvaluationService) ViewDescriptor(org.eclipse.ui.internal.registry.ViewDescriptor) ContextInjectionFactory(org.eclipse.e4.core.contexts.ContextInjectionFactory) UIEvents(org.eclipse.e4.ui.workbench.UIEvents) WorkbenchException(org.eclipse.ui.WorkbenchException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) WorkbenchAdvisor(org.eclipse.ui.application.WorkbenchAdvisor) URISyntaxException(java.net.URISyntaxException) IAction(org.eclipse.jface.action.IAction) IBindingManagerListener(org.eclipse.jface.bindings.IBindingManagerListener) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) Policy(org.eclipse.ui.internal.misc.Policy) IWorkbenchRegistryConstants(org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants) MCommandsFactory(org.eclipse.e4.ui.model.application.commands.MCommandsFactory) IStatus(org.eclipse.core.runtime.IStatus) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) FontDefinition(org.eclipse.ui.internal.themes.FontDefinition) IAdaptable(org.eclipse.core.runtime.IAdaptable) IWizardRegistry(org.eclipse.ui.wizards.IWizardRegistry) IBindingService(org.eclipse.ui.keys.IBindingService) Collection(java.util.Collection) UUID(java.util.UUID) ShowKeysListener(org.eclipse.ui.internal.keys.show.ShowKeysListener) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SourceProviderService(org.eclipse.ui.internal.services.SourceProviderService) Objects(java.util.Objects) ISourceProvider(org.eclipse.ui.ISourceProvider) WorkbenchThemeManager(org.eclipse.ui.internal.themes.WorkbenchThemeManager) ISourceProviderService(org.eclipse.ui.services.ISourceProviderService) ISelection(org.eclipse.jface.viewers.ISelection) IEditorRegistry(org.eclipse.ui.IEditorRegistry) CommandCallback(org.eclipse.jface.action.ExternalActionManager.CommandCallback) CompatibilityPart(org.eclipse.ui.internal.e4.compatibility.CompatibilityPart) SafeRunnable(org.eclipse.jface.util.SafeRunnable) WWinPartServiceSaveHandler(org.eclipse.ui.internal.WorkbenchWindow.WWinPartServiceSaveHandler) IExtensionDelta(org.eclipse.core.runtime.IExtensionDelta) IDecoratorManager(org.eclipse.ui.IDecoratorManager) IPerspectiveRegistry(org.eclipse.ui.IPerspectiveRegistry) Image(org.eclipse.swt.graphics.Image) IEventLoopAdvisor(org.eclipse.e4.ui.internal.workbench.swt.IEventLoopAdvisor) BundleEvent(org.osgi.framework.BundleEvent) HashSet(java.util.HashSet) E4Util(org.eclipse.ui.internal.e4.compatibility.E4Util) E4Application(org.eclipse.e4.ui.internal.workbench.swt.E4Application) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) DeviceData(org.eclipse.swt.graphics.DeviceData) IWorkbenchPreferenceConstants(org.eclipse.ui.IWorkbenchPreferenceConstants) WorkbenchLocationService(org.eclipse.ui.internal.services.WorkbenchLocationService) NotHandledException(org.eclipse.core.commands.NotHandledException) BindingService(org.eclipse.ui.internal.keys.BindingService) ServiceRegistration(org.osgi.framework.ServiceRegistration) IRegistryChangeListener(org.eclipse.core.runtime.IRegistryChangeListener) ISaveHandler(org.eclipse.e4.ui.workbench.modeling.ISaveHandler) FileInputStream(java.io.FileInputStream) EclipseSplashHandler(org.eclipse.ui.internal.splash.EclipseSplashHandler) UIStats(org.eclipse.ui.internal.misc.UIStats) ITheme(org.eclipse.ui.themes.ITheme) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener) FrameworkUtil(org.osgi.framework.FrameworkUtil) Arrays(java.util.Arrays) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) MultiStatus(org.eclipse.core.runtime.MultiStatus) MTrimContribution(org.eclipse.e4.ui.model.application.ui.menu.MTrimContribution) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) CoreException(org.eclipse.core.runtime.CoreException) PartRenderingEngine(org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine) IServiceLocatorCreator(org.eclipse.ui.internal.services.IServiceLocatorCreator) MenuSourceProvider(org.eclipse.ui.internal.services.MenuSourceProvider) IUpdateService(org.eclipse.e4.ui.internal.workbench.renderers.swt.IUpdateService) PartInitException(org.eclipse.ui.PartInitException) MBindingContext(org.eclipse.e4.ui.model.application.commands.MBindingContext) BidiUtils(org.eclipse.jface.util.BidiUtils) WorkbenchHelpSystem(org.eclipse.ui.internal.help.WorkbenchHelpSystem) MApplication(org.eclipse.e4.ui.model.application.MApplication) ServiceLocator(org.eclipse.ui.internal.services.ServiceLocator) Realm(org.eclipse.core.databinding.observable.Realm) EContextService(org.eclipse.e4.ui.services.EContextService) PreferenceConverter(org.eclipse.jface.preference.PreferenceConverter) MenuManager(org.eclipse.jface.action.MenuManager) Assert(org.eclipse.core.runtime.Assert) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) IModelResourceHandler(org.eclipse.e4.ui.workbench.IModelResourceHandler) Saveable(org.eclipse.ui.Saveable) DisplayRealm(org.eclipse.jface.databinding.swt.DisplayRealm) IFocusService(org.eclipse.ui.swt.IFocusService) SWT(org.eclipse.swt.SWT) ICommandImageService(org.eclipse.ui.commands.ICommandImageService) IWorkbenchOperationSupport(org.eclipse.ui.operations.IWorkbenchOperationSupport) Dictionary(java.util.Dictionary) MCommand(org.eclipse.e4.ui.model.application.commands.MCommand) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) ArrayList(java.util.ArrayList) Listener(org.eclipse.swt.widgets.Listener) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IApplication(org.eclipse.equinox.app.IApplication) IViewRegistry(org.eclipse.ui.views.IViewRegistry) NotEnabledException(org.eclipse.core.commands.NotEnabledException) FocusControlSourceProvider(org.eclipse.ui.internal.menus.FocusControlSourceProvider) LegacyHandlerService(org.eclipse.ui.internal.handlers.LegacyHandlerService) CommandManager(org.eclipse.core.commands.CommandManager) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchHelpSystem(org.eclipse.ui.help.IWorkbenchHelpSystem) StringWriter(java.io.StringWriter) IElementFactory(org.eclipse.ui.IElementFactory) ExecutionException(org.eclipse.core.commands.ExecutionException) IPresentationEngine(org.eclipse.e4.ui.workbench.IPresentationEngine) PrefUtil(org.eclipse.ui.internal.util.PrefUtil) EventManager(org.eclipse.core.commands.common.EventManager) Command(org.eclipse.core.commands.Command) IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) IIntroRegistry(org.eclipse.ui.internal.intro.IIntroRegistry) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Platform(org.eclipse.core.runtime.Platform) ModalContext(org.eclipse.jface.operation.ModalContext) IEventBroker(org.eclipse.e4.core.services.events.IEventBroker) StartupRunnable(org.eclipse.ui.internal.StartupThreading.StartupRunnable) IExtensionTracker(org.eclipse.core.runtime.dynamichelpers.IExtensionTracker) Constants(org.osgi.framework.Constants) URL(java.net.URL) IWorkbenchCommandConstants(org.eclipse.ui.IWorkbenchCommandConstants) CommandImageManager(org.eclipse.ui.internal.commands.CommandImageManager) IMenuService(org.eclipse.ui.menus.IMenuService) UIExtensionTracker(org.eclipse.ui.internal.registry.UIExtensionTracker) ThemeElementHelper(org.eclipse.ui.internal.themes.ThemeElementHelper) IProgressService(org.eclipse.ui.progress.IProgressService) URI(java.net.URI) ProgressManagerUtil(org.eclipse.ui.internal.progress.ProgressManagerUtil) IExtension(org.eclipse.core.runtime.IExtension) MElementContainer(org.eclipse.e4.ui.model.application.ui.MElementContainer) NLS(org.eclipse.osgi.util.NLS) ExternalActionManager(org.eclipse.jface.action.ExternalActionManager) EObject(org.eclipse.emf.ecore.EObject) Display(org.eclipse.swt.widgets.Display) ContextService(org.eclipse.ui.internal.contexts.ContextService) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) BundleContext(org.osgi.framework.BundleContext) ISharedImages(org.eclipse.ui.ISharedImages) IHandlerService(org.eclipse.ui.handlers.IHandlerService) List(java.util.List) IDisposable(org.eclipse.ui.services.IDisposable) Category(com.ibm.icu.util.ULocale.Category) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) IViewDescriptor(org.eclipse.ui.views.IViewDescriptor) IProduct(org.eclipse.core.runtime.IProduct) Resource(org.eclipse.emf.ecore.resource.Resource) ContributionInfoMessages(org.eclipse.ui.internal.testing.ContributionInfoMessages) IWindowListener(org.eclipse.ui.IWindowListener) ILocalWorkingSetManager(org.eclipse.ui.ILocalWorkingSetManager) MBindingTable(org.eclipse.e4.ui.model.application.commands.MBindingTable) StartupMonitor(org.eclipse.osgi.service.runnable.StartupMonitor) PropertyPageContributorManager(org.eclipse.ui.internal.dialogs.PropertyPageContributorManager) HashMap(java.util.HashMap) IWorkbenchLocationService(org.eclipse.ui.internal.services.IWorkbenchLocationService) ContextManager(org.eclipse.core.commands.contexts.ContextManager) IntroDescriptor(org.eclipse.ui.internal.intro.IntroDescriptor) ContextFunction(org.eclipse.e4.core.contexts.ContextFunction) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) IWorkbenchActivitySupport(org.eclipse.ui.activities.IWorkbenchActivitySupport) IWorkbenchCommandSupport(org.eclipse.ui.commands.IWorkbenchCommandSupport) ContributionInfo(org.eclipse.ui.testing.ContributionInfo) Hashtable(java.util.Hashtable) WorkbenchActivitySupport(org.eclipse.ui.internal.activities.ws.WorkbenchActivitySupport) Job(org.eclipse.core.runtime.jobs.Job) E4Workbench(org.eclipse.e4.ui.internal.workbench.E4Workbench) InjectionException(org.eclipse.e4.core.di.InjectionException) CommandAction(org.eclipse.ui.internal.actions.CommandAction) WorkbenchTestable(org.eclipse.ui.internal.testing.WorkbenchTestable) CommandImageService(org.eclipse.ui.internal.commands.CommandImageService) FontData(org.eclipse.swt.graphics.FontData) WorkbenchBrowserSupport(org.eclipse.ui.internal.browser.WorkbenchBrowserSupport) IWorkbench(org.eclipse.ui.IWorkbench) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) Collections(java.util.Collections) InputStream(java.io.InputStream) BasicFactoryImpl(org.eclipse.e4.ui.model.application.ui.basic.impl.BasicFactoryImpl) ISources(org.eclipse.ui.ISources) IContributionService(org.eclipse.ui.model.IContributionService) IStatus(org.eclipse.core.runtime.IStatus) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) IBindingManagerListener(org.eclipse.jface.bindings.IBindingManagerListener) ShowKeysListener(org.eclipse.ui.internal.keys.show.ShowKeysListener) IRegistryChangeListener(org.eclipse.core.runtime.IRegistryChangeListener) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener) Listener(org.eclipse.swt.widgets.Listener) IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) IWindowListener(org.eclipse.ui.IWindowListener) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Window(org.eclipse.jface.window.Window) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) IStatus(org.eclipse.core.runtime.IStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) Hashtable(java.util.Hashtable) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) Point(org.eclipse.swt.graphics.Point) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) SWTException(org.eclipse.swt.SWTException) IOException(java.io.IOException) WorkbenchException(org.eclipse.ui.WorkbenchException) URISyntaxException(java.net.URISyntaxException) NotHandledException(org.eclipse.core.commands.NotHandledException) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) NotEnabledException(org.eclipse.core.commands.NotEnabledException) ExecutionException(org.eclipse.core.commands.ExecutionException) InjectionException(org.eclipse.e4.core.di.InjectionException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SafeRunnable(org.eclipse.jface.util.SafeRunnable) StartupRunnable(org.eclipse.ui.internal.StartupThreading.StartupRunnable) EObject(org.eclipse.emf.ecore.EObject)

Example 12 with E4Workbench

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));
}
Also used : Shell(org.eclipse.swt.widgets.Shell) E4Workbench(org.eclipse.e4.ui.internal.workbench.E4Workbench) Widget(org.eclipse.swt.widgets.Widget) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) Test(org.junit.Test)

Example 13 with E4Workbench

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);
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) CTabFolder(org.eclipse.swt.custom.CTabFolder) E4Workbench(org.eclipse.e4.ui.internal.workbench.E4Workbench) Composite(org.eclipse.swt.widgets.Composite) Widget(org.eclipse.swt.widgets.Widget) Tree(org.eclipse.swt.widgets.Tree) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) Test(org.junit.Test)

Example 14 with E4Workbench

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());
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) E4Workbench(org.eclipse.e4.ui.internal.workbench.E4Workbench) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) MPartSashContainer(org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer) MApplication(org.eclipse.e4.ui.model.application.MApplication) Test(org.junit.Test)

Example 15 with E4Workbench

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);
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) CTabFolder(org.eclipse.swt.custom.CTabFolder) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) E4Workbench(org.eclipse.e4.ui.internal.workbench.E4Workbench) MArea(org.eclipse.e4.ui.model.application.ui.advanced.MArea) MCompositePart(org.eclipse.e4.ui.model.application.ui.basic.MCompositePart) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) MApplication(org.eclipse.e4.ui.model.application.MApplication) Test(org.junit.Test)

Aggregations

E4Workbench (org.eclipse.e4.ui.internal.workbench.E4Workbench)15 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)12 MApplication (org.eclipse.e4.ui.model.application.MApplication)10 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)9 Test (org.junit.Test)9 Shell (org.eclipse.swt.widgets.Shell)8 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)5 Widget (org.eclipse.swt.widgets.Widget)5 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 MPartSashContainer (org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer)3 CTabFolder (org.eclipse.swt.custom.CTabFolder)3 ULocale (com.ibm.icu.util.ULocale)2 Hashtable (java.util.Hashtable)2 EPartService (org.eclipse.e4.ui.workbench.modeling.EPartService)2 EObject (org.eclipse.emf.ecore.EObject)2 Category (com.ibm.icu.util.ULocale.Category)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1