public void testCreateView() { final MWindow window = createWindowWithOneView("Part Name"); MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication(); application.getChildren().add(window); application.setContext(appContext); appContext.set(MApplication.class.getName(), application); wb = new E4Workbench(application, appContext); wb.createAndRunUI(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); MPart part = (MPart) stack.getChildren().get(0); CTabFolder folder = (CTabFolder) stack.getWidget(); CTabItem item = folder.getItem(0); assertEquals("Part Name", item.getText()); assertFalse(part.isDirty()); part.setDirty(true); assertEquals("*Part Name", item.getText()); part.setDirty(false); assertEquals("Part Name", item.getText()); }
@Test public void testBug310027() { MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication(); MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); MPartSashContainer container = BasicFactoryImpl.eINSTANCE.createPartSashContainer(); MPartStack partStackA = BasicFactoryImpl.eINSTANCE.createPartStack(); MPartStack partStackB = BasicFactoryImpl.eINSTANCE.createPartStack(); MPart partA = BasicFactoryImpl.eINSTANCE.createPart(); MPart partB = BasicFactoryImpl.eINSTANCE.createPart(); 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()); }
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 UISynchronize() { @Override public void syncExec(Runnable runnable) { if (display != null && !display.isDisposed()) { display.syncExec(runnable); } } @Override public void asyncExec(Runnable runnable) { if (display != null && !display.isDisposed()) { display.asyncExec(runnable); } } }); 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); // for compatibility layer: set the application in the OSGi service // 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)); // Instantiate the Workbench (which is responsible for // 'running' the UI (if any)... return workbench = new E4Workbench(appModel, appContext); }
@Before public void setUp() throws Exception { appContext = E4Application.createDefaultContext(); appContext.set(E4Workbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI); ems = appContext.get(EModelService.class); window = ems.createModelElement(MWindow.class); window.setWidth(500); window.setHeight(500); MPartSashContainer sash = ems.createModelElement(MPartSashContainer.class); window.getChildren().add(sash); window.setSelectedElement(sash); MPartStack stack = ems.createModelElement(MPartStack.class); sash.getChildren().add(stack); sash.setSelectedElement(stack); part = ems.createModelElement(MPart.class); part.setElementId("Part"); part.setLabel("Part"); part.setToolbar(ems.createModelElement(MToolBar.class)); part.setContributionURI(Activator.asURI(PartBackend.class)); stack.getChildren().add(part); toolControl = ems.createModelElement(MToolControl.class); toolControl.setElementId("ToolControl"); toolControl.setContributionURI(Activator.asURI(TextField.class)); part.getToolbar().getChildren().add(toolControl); stack = ems.createModelElement(MPartStack.class); sash.getChildren().add(stack); sash.setSelectedElement(stack); otherPart = ems.createModelElement(MPart.class); otherPart.setElementId("OtherPart"); otherPart.setLabel("OtherPart"); otherPart.setContributionURI(Activator.asURI(PartBackend.class)); stack.getChildren().add(otherPart); 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); eps = window.getContext().get(EPartService.class); // ensure the parts are populated and the contributions instantiated eps.activate(part); eps.activate(otherPart); processEvents(); // ensure our model backend objects are created assertNotNull(part.getObject()); assertNotNull(toolControl.getObject()); assertNotNull(otherPart.getObject()); assertNotNull(part.getWidget()); assertNotNull(toolControl.getWidget()); assertNotNull(otherPart.getWidget()); // ensure focus is set to otherPart.text1 eps.activate(otherPart); processEvents(); assertTrue(((PartBackend) otherPart.getObject()).text1.isFocusControl()); }