use of org.eclipse.e4.ui.model.application.MAddon 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.model.application.MAddon in project eclipse.platform.ui by eclipse-platform.
the class MinMaxProcessor method addMinMaxAddon.
@Execute
void addMinMaxAddon(MApplication app, EModelService modelService) {
List<MAddon> addons = app.getAddons();
// prevent multiple copies
for (MAddon addon : addons) {
if (addon.getContributionURI().contains("ui.workbench.addons.minmax.MinMaxAddon")) {
// $NON-NLS-1$
return;
}
}
// add the add-on to the application model
MAddon minMaxAddon = modelService.createModelElement(MAddon.class);
// $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");
app.getAddons().add(minMaxAddon);
}
use of org.eclipse.e4.ui.model.application.MAddon in project eclipse.platform.ui by eclipse-platform.
the class SplitterProcessor method addSplitterAddon.
@Execute
void addSplitterAddon(MApplication app, EModelService modelService) {
List<MAddon> addons = app.getAddons();
// prevent multiple copies
for (MAddon addon : addons) {
if (addon.getContributionURI().contains("ui.workbench.addons.splitteraddon.SplitterAddon")) {
// $NON-NLS-1$
return;
}
}
// adds the add-on to the application model
MAddon splitterAddon = modelService.createModelElement(MAddon.class);
// $NON-NLS-1$
splitterAddon.setElementId("SplitterAddon");
splitterAddon.setContributionURI(// $NON-NLS-1$
"bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.splitteraddon.SplitterAddon");
app.getAddons().add(splitterAddon);
}
use of org.eclipse.e4.ui.model.application.MAddon in project eclipse.platform.ui by eclipse-platform.
the class CocoaUIProcessor method installAddon.
/**
* Install the addon.
*/
public void installAddon() {
String addonId = CocoaUIHandler.class.getName();
for (MAddon addon : app.getAddons()) {
if (addonId.equals(addon.getElementId())) {
return;
}
}
MAddon addon = MApplicationFactory.INSTANCE.createAddon();
addon.setContributionURI(getClassURI(CocoaUIHandler.class));
addon.setElementId(addonId);
app.getAddons().add(addon);
}
use of org.eclipse.e4.ui.model.application.MAddon 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);
}
Aggregations