use of org.eclipse.e4.ui.workbench.swt.DisplayUISynchronize 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.workbench.swt.DisplayUISynchronize in project eclipse.platform.ui by eclipse-platform.
the class MaximizableChildrenTag method prepareApplicationModel.
private void prepareApplicationModel() {
MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication();
window = BasicFactoryImpl.eINSTANCE.createTrimmedWindow();
window.setElementId("MainWindow");
MPerspectiveStack perspectiveStackMain = AdvancedFactoryImpl.eINSTANCE.createPerspectiveStack();
perspectiveStackMain.setElementId("perspectiveStackMain");
MPerspective perspectiveMain = AdvancedFactoryImpl.eINSTANCE.createPerspective();
perspectiveMain.setElementId("perspectiveMain");
MPartSashContainer containerMain = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
partStackMain = BasicFactoryImpl.eINSTANCE.createPartStack();
partStackMain.setElementId("mainPartStack");
MPart partMain = BasicFactoryImpl.eINSTANCE.createPart();
partStackMain.getChildren().add(partMain);
containerMain.getChildren().add(partStackMain);
placeholderMain = AdvancedFactoryImpl.eINSTANCE.createPlaceholder();
// placeholderMain.setElementId("placeholderMain");
placeholderMain.setElementId("org.eclipse.ui.editorss");
containerMain.getChildren().add(placeholderMain);
perspectiveMain.getChildren().add(containerMain);
perspectiveMain.setSelectedElement(containerMain);
perspectiveStackMain.getChildren().add(perspectiveMain);
perspectiveStackMain.setSelectedElement(perspectiveMain);
window.getChildren().add(perspectiveStackMain);
window.setSelectedElement(perspectiveStackMain);
application.getChildren().add(window);
application.setSelectedElement(window);
MArea mArea = AdvancedFactoryImpl.eINSTANCE.createArea();
mArea.getTags().add(MAXIMIZEABLE_CHILDREN);
partStack1 = BasicFactoryImpl.eINSTANCE.createPartStack();
MPart part1 = BasicFactoryImpl.eINSTANCE.createPart();
partStack1.getChildren().add(part1);
mArea.getChildren().add(partStack1);
partStack2 = BasicFactoryImpl.eINSTANCE.createPartStack();
MPart part2 = BasicFactoryImpl.eINSTANCE.createPart();
partStack2.getChildren().add(part2);
mArea.getChildren().add(partStack2);
window.getSharedElements().add(mArea);
placeholderMain.setRef(mArea);
mArea.setCurSharedRef(placeholderMain);
// instantiate addon
MAddon minMaxAddon = ApplicationFactoryImpl.eINSTANCE.createAddon();
// $NON-NLS-1$
minMaxAddon.setElementId("MinMaxAddon");
minMaxAddon.setContributionURI(// $NON-NLS-1$
"bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.MinMaxAddon");
appContext = E4Application.createDefaultContext();
Display display = Display.getDefault();
appContext.set(Display.class, display);
appContext.set(MApplication.class.getName(), application);
appContext.set(MWindow.class, window);
appContext.set(UISynchronize.class, new DisplayUISynchronize(display));
appContext.set(EModelService.class, new ModelServiceImpl(appContext));
ContextInjectionFactory.setDefault(appContext);
renderer = ContextInjectionFactory.make(PartRenderingEngine.class, appContext);
appContext.set(IPresentationEngine.class, renderer);
appContext.set(EPartService.class, ContextInjectionFactory.make(PartServiceImpl.class, appContext));
application.setContext(appContext);
final UIEventPublisher ep = new UIEventPublisher(appContext);
((Notifier) application).eAdapters().add(ep);
appContext.set(UIEventPublisher.class, ep);
appContext.set(MAddon.class, minMaxAddon);
ContextInjectionFactory.setDefault(appContext);
ContextInjectionFactory.make(MinMaxAddon.class, appContext);
appContext.set(IResourceUtilities.class, new ISWTResourceUtilities() {
@Override
public ImageDescriptor imageDescriptorFromURI(URI iconPath) {
try {
return ImageDescriptor.createFromURL(new URL(iconPath.toString()));
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
@Override
public Image adornImage(Image toAdorn, Image adornment) {
return null;
}
});
appContext.set(CSSRenderingUtils.class, new CSSRenderingUtils());
E4Application.initializeServices(application);
shell = (Shell) renderer.createGui(window);
}
use of org.eclipse.e4.ui.workbench.swt.DisplayUISynchronize in project eclipse.platform.ui by eclipse-platform.
the class MaximizeBugTest method prepareApplicationModel.
private void prepareApplicationModel() {
MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication();
window = BasicFactoryImpl.eINSTANCE.createTrimmedWindow();
window.setElementId("MainWindow");
MPerspectiveStack perspectiveStackMain = AdvancedFactoryImpl.eINSTANCE.createPerspectiveStack();
perspectiveStackMain.setElementId("perspectiveStackMain");
MPerspective perspectiveMain = AdvancedFactoryImpl.eINSTANCE.createPerspective();
perspectiveMain.setElementId("perspectiveMain");
MPartSashContainer containerMain = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
partStackMain = BasicFactoryImpl.eINSTANCE.createPartStack();
partStackMain.setElementId("mainPartStack");
MPart partMain = BasicFactoryImpl.eINSTANCE.createPart();
MArea areaMain = AdvancedFactoryImpl.eINSTANCE.createArea();
MPartStack partStackAreaMain = BasicFactoryImpl.eINSTANCE.createPartStack();
MPart partAreaMain = BasicFactoryImpl.eINSTANCE.createPart();
placeholderMain = AdvancedFactoryImpl.eINSTANCE.createPlaceholder();
placeholderMain.setElementId("placeholderMain");
application.getChildren().add(window);
application.setSelectedElement(window);
window.getChildren().add(perspectiveStackMain);
window.setSelectedElement(perspectiveStackMain);
perspectiveStackMain.getChildren().add(perspectiveMain);
perspectiveStackMain.setSelectedElement(perspectiveMain);
perspectiveMain.getChildren().add(containerMain);
perspectiveMain.setSelectedElement(containerMain);
containerMain.getChildren().add(partStackMain);
containerMain.getChildren().add(placeholderMain);
partStackMain.getChildren().add(partMain);
areaMain.getChildren().add(partStackAreaMain);
partStackAreaMain.getChildren().add(partAreaMain);
placeholderMain.setRef(areaMain);
window.getSharedElements().add(areaMain);
windowSub = BasicFactoryImpl.eINSTANCE.createTrimmedWindow();
windowSub.setElementId("SubWindow");
MPartSashContainer containerSub = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
partStackSub = BasicFactoryImpl.eINSTANCE.createPartStack();
partStackSub.setElementId("partStackSub");
MPart partSub = BasicFactoryImpl.eINSTANCE.createPart();
placeholderSub = AdvancedFactoryImpl.eINSTANCE.createPlaceholder();
placeholderSub.setElementId("placeholderSub");
MArea areaSub = AdvancedFactoryImpl.eINSTANCE.createArea();
MPartStack partStackAreaSub = BasicFactoryImpl.eINSTANCE.createPartStack();
MPart partAreaSub = BasicFactoryImpl.eINSTANCE.createPart();
placeholderSub.setRef(areaSub);
if (usePerspektiveInSubWindow) {
MPerspectiveStack perspectiveStackSub = AdvancedFactoryImpl.eINSTANCE.createPerspectiveStack();
perspectiveStackSub.setElementId("perspectiveStackSub");
MPerspective perspectiveSub = AdvancedFactoryImpl.eINSTANCE.createPerspective();
perspectiveSub.setElementId("perspectiveSub");
perspectiveStackSub.getChildren().add(perspectiveSub);
perspectiveStackSub.setSelectedElement(perspectiveSub);
perspectiveSub.getChildren().add(containerSub);
perspectiveSub.setSelectedElement(containerSub);
windowSub.getChildren().add(perspectiveStackSub);
windowSub.setSelectedElement(perspectiveStackSub);
} else {
windowSub.getChildren().add(containerSub);
windowSub.setSelectedElement(containerSub);
}
containerSub.getChildren().add(partStackSub);
containerSub.getChildren().add(placeholderSub);
partStackSub.getChildren().add(partSub);
areaSub.getChildren().add(partStackAreaSub);
partStackAreaSub.getChildren().add(partAreaSub);
windowSub.getSharedElements().add(areaSub);
if (addSubwindowToPerspective) {
perspectiveMain.getWindows().add(windowSub);
} else {
window.getWindows().add(windowSub);
}
// set correct ids
if (useCorrectPlaceholderId) {
placeholderMain.setElementId("org.eclipse.ui.editorss");
placeholderSub.setElementId("org.eclipse.ui.editorss");
} else {
placeholderMain.setElementId("placeholderMain");
placeholderSub.setElementId("placeholderSub");
}
// instantiate addon
MAddon minMaxAddon = ApplicationFactoryImpl.eINSTANCE.createAddon();
// $NON-NLS-1$
minMaxAddon.setElementId("MinMaxAddon");
minMaxAddon.setContributionURI(// $NON-NLS-1$
"bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.MinMaxAddon");
appContext = E4Application.createDefaultContext();
appContext.set(Display.class, Display.getDefault());
appContext.set(MApplication.class.getName(), application);
appContext.set(MWindow.class, window);
appContext.set(UISynchronize.class, new DisplayUISynchronize(Display.getDefault()));
appContext.set(EModelService.class, new ModelServiceImpl(appContext));
ContextInjectionFactory.setDefault(appContext);
renderer = ContextInjectionFactory.make(PartRenderingEngine.class, appContext);
appContext.set(IPresentationEngine.class, renderer);
appContext.set(EPartService.class, ContextInjectionFactory.make(PartServiceImpl.class, appContext));
application.setContext(appContext);
final UIEventPublisher ep = new UIEventPublisher(appContext);
((Notifier) application).eAdapters().add(ep);
appContext.set(UIEventPublisher.class, ep);
appContext.set(MAddon.class, minMaxAddon);
ContextInjectionFactory.setDefault(appContext);
ContextInjectionFactory.make(MinMaxAddon.class, appContext);
appContext.set(IResourceUtilities.class, new ISWTResourceUtilities() {
@Override
public ImageDescriptor imageDescriptorFromURI(URI iconPath) {
try {
return ImageDescriptor.createFromURL(new URL(iconPath.toString()));
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
@Override
public Image adornImage(Image toAdorn, Image adornment) {
return null;
}
});
appContext.set(CSSRenderingUtils.class, new CSSRenderingUtils());
E4Application.initializeServices(application);
shell = (Shell) renderer.createGui(window);
}
use of org.eclipse.e4.ui.workbench.swt.DisplayUISynchronize in project eclipse.platform.ui by eclipse-platform.
the class MaximizePartSashContainerPlaceholderTest method prepareApplicationModel.
private void prepareApplicationModel() {
MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication();
MTrimmedWindow window = BasicFactoryImpl.eINSTANCE.createTrimmedWindow();
window.setElementId("MainWindow");
MPerspectiveStack perspectiveStackMain = AdvancedFactoryImpl.eINSTANCE.createPerspectiveStack();
perspectiveStackMain.setElementId("perspectiveStackMain");
MPerspective perspectiveMain = AdvancedFactoryImpl.eINSTANCE.createPerspective();
perspectiveMain.setElementId("perspectiveMain");
MPartSashContainer containerMain = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
partStackMain = BasicFactoryImpl.eINSTANCE.createPartStack();
partStackMain.setElementId("mainPartStack");
MPart partMain = BasicFactoryImpl.eINSTANCE.createPart();
MPartSashContainer patSashConatiner = BasicFactoryImpl.eINSTANCE.createPartSashContainer();
MPartStack partStackAreaMain = BasicFactoryImpl.eINSTANCE.createPartStack();
MPart partAreaMain = BasicFactoryImpl.eINSTANCE.createPart();
placeholderMain = AdvancedFactoryImpl.eINSTANCE.createPlaceholder();
placeholderMain.setElementId("placeholderMain");
application.getChildren().add(window);
application.setSelectedElement(window);
window.getChildren().add(perspectiveStackMain);
window.setSelectedElement(perspectiveStackMain);
perspectiveStackMain.getChildren().add(perspectiveMain);
perspectiveStackMain.setSelectedElement(perspectiveMain);
perspectiveMain.getChildren().add(containerMain);
perspectiveMain.setSelectedElement(containerMain);
containerMain.getChildren().add(partStackMain);
containerMain.getChildren().add(placeholderMain);
partStackMain.getChildren().add(partMain);
patSashConatiner.getChildren().add(partStackAreaMain);
partStackAreaMain.getChildren().add(partAreaMain);
placeholderMain.setRef(patSashConatiner);
window.getSharedElements().add(patSashConatiner);
// set correct ids
if (useCorrectPlaceholderId) {
placeholderMain.setElementId("org.eclipse.ui.editorss");
} else {
placeholderMain.setElementId("placeholderMain");
}
// instantiate addon
MAddon minMaxAddon = ApplicationFactoryImpl.eINSTANCE.createAddon();
// $NON-NLS-1$
minMaxAddon.setElementId("MinMaxAddon");
minMaxAddon.setContributionURI(// $NON-NLS-1$
"bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.MinMaxAddon");
IEclipseContext appContext = E4Application.createDefaultContext();
appContext.set(Display.class, Display.getDefault());
appContext.set(MApplication.class.getName(), application);
appContext.set(MWindow.class, window);
appContext.set(UISynchronize.class, new DisplayUISynchronize(Display.getDefault()));
appContext.set(EModelService.class, new ModelServiceImpl(appContext));
ContextInjectionFactory.setDefault(appContext);
IPresentationEngine newEngine = ContextInjectionFactory.make(PartRenderingEngine.class, appContext);
appContext.set(IPresentationEngine.class, newEngine);
appContext.set(EPartService.class, ContextInjectionFactory.make(PartServiceImpl.class, appContext));
application.setContext(appContext);
final UIEventPublisher ep = new UIEventPublisher(appContext);
((Notifier) application).eAdapters().add(ep);
appContext.set(UIEventPublisher.class, ep);
appContext.set(MAddon.class, minMaxAddon);
ContextInjectionFactory.setDefault(appContext);
ContextInjectionFactory.make(MinMaxAddon.class, appContext);
appContext.set(IResourceUtilities.class, new ISWTResourceUtilities() {
@Override
public ImageDescriptor imageDescriptorFromURI(URI iconPath) {
try {
return ImageDescriptor.createFromURL(new URL(iconPath.toString()));
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
@Override
public Image adornImage(Image toAdorn, Image adornment) {
return null;
}
});
appContext.set(CSSRenderingUtils.class, new CSSRenderingUtils());
E4Application.initializeServices(application);
shell = (Shell) newEngine.createGui(window);
}
use of org.eclipse.e4.ui.workbench.swt.DisplayUISynchronize in project eclipse.platform.ui by eclipse-platform.
the class InjectionEventTest method testEventInjection.
@Test
public void testEventInjection() {
IInjector injector = InjectorFactory.getDefault();
injector.addBinding(MyBinding.class);
IEclipseContext context = EclipseContextFactory.create();
final Display d = Display.getDefault();
context.set(UISynchronize.class, new DisplayUISynchronize(d));
ContextInjectionFactory.setDefault(context);
// Workaround, enforce injection on UIEventTopic provider with current context
ExtendedObjectSupplier supplier = ProviderHelper.findProvider(UIEventTopic.class.getName(), null);
ContextInjectionFactory.inject(supplier, context);
InjectTarget target = ContextInjectionFactory.make(InjectTarget.class, context);
// initial state
assertEquals(0, target.counter1);
assertNull(target.string1);
assertEquals(0, target.counter2);
assertNull(target.string2);
assertEquals(1, target.counter3);
assertNull(target.string3);
assertNotNull(target.myBinding);
// send event1
helper.sendEvent("e4/test/event1", "event1data");
assertEquals(1, target.counter1);
assertEquals("event1data", target.string1);
assertEquals(0, target.counter2);
assertNull(target.string2);
assertEquals(1, target.counter3);
assertNull(target.string3);
assertNotNull(target.myBinding);
// send event2
helper.sendEvent("e4/test/event2", "event2data");
assertEquals(1, target.counter1);
assertEquals("event1data", target.string1);
assertEquals(1, target.counter2);
assertEquals("event2data", target.string2);
assertEquals(1, target.counter3);
assertNull(target.string3);
assertNotNull(target.myBinding);
// send event3
helper.sendEvent("e4/test/event3", "event3data");
assertEquals(1, target.counter1);
assertEquals("event1data", target.string1);
assertEquals(1, target.counter2);
assertEquals("event2data", target.string2);
assertEquals(2, target.counter3);
assertEquals("event3data", target.string3);
assertNotNull(target.myBinding);
// send event1 again
helper.sendEvent("e4/test/event1", "abc");
assertEquals(2, target.counter1);
assertEquals("abc", target.string1);
assertEquals(1, target.counter2);
assertEquals("event2data", target.string2);
assertEquals(2, target.counter3);
assertEquals("event3data", target.string3);
assertNotNull(target.myBinding);
ContextInjectionFactory.setDefault(null);
// Workaround, enforce uninjection on the UIEventTopic provider from context
ContextInjectionFactory.uninject(supplier, context);
context.dispose();
}
Aggregations