use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class ContributionsAnalyzer method isImperativeExpressionVisible.
private static boolean isImperativeExpressionVisible(MImperativeExpression exp, final ExpressionContext eContext) {
Object imperativeExpressionObject = exp.getObject();
if (imperativeExpressionObject == null) {
IContributionFactory contributionFactory = eContext.eclipseContext.get(IContributionFactory.class);
Object newImperativeExpression = contributionFactory.create(exp.getContributionURI(), eContext.eclipseContext);
exp.setObject(newImperativeExpression);
imperativeExpressionObject = newImperativeExpression;
}
if (imperativeExpressionObject == null) {
return false;
}
Object result = null;
// $NON-NLS-1$
IEclipseContext staticContext = EclipseContextFactory.create("Evaluation-Static");
staticContext.set(MImperativeExpression.class, exp);
try {
if (exp.isTracking()) {
result = invoke(imperativeExpressionObject, Evaluate.class, eContext.eclipseContext, staticContext, missingEvaluate);
} else {
result = ContextInjectionFactory.invoke(imperativeExpressionObject, Evaluate.class, eContext.eclipseContext, staticContext, missingEvaluate);
}
} finally {
staticContext.dispose();
}
if (result == missingEvaluate) {
// $NON-NLS-1$
String className = "null";
if (imperativeExpressionObject != null) {
className = imperativeExpressionObject.getClass().getName();
}
throw new IllegalStateException(// $NON-NLS-1$ //$NON-NLS-2$
"There is no method annotated with @Evaluate in the " + className + " imperative expression class ");
}
return (boolean) result;
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class E4Workbench method instantiateRenderer.
/**
*/
public void instantiateRenderer() {
renderer = appContext.get(IPresentationEngine.class);
if (renderer == null) {
String presentationURI = (String) appContext.get(IWorkbench.PRESENTATION_URI_ARG);
if (presentationURI != null) {
IContributionFactory factory = appContext.get(IContributionFactory.class);
renderer = (IPresentationEngine) factory.create(presentationURI, appContext);
appContext.set(IPresentationEngine.class, renderer);
}
if (renderer == null) {
Logger logger = appContext.get(Logger.class);
// $NON-NLS-1$
logger.error("Failed to create the presentation engine for URI: " + presentationURI);
}
}
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class PartRenderingEngine method getRenderer.
private AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
// Is there a custom renderer defined ?
String customURI = uiElement.getPersistedState().get(IPresentationEngine.CUSTOM_RENDERER_KEY);
if (customURI != null) {
AbstractPartRenderer abstractPartRenderer = customRendererMap.get(customURI);
if (abstractPartRenderer != null) {
return abstractPartRenderer;
}
IEclipseContext owningContext = modelService.getContainingContext(uiElement);
IContributionFactory contributionFactory = owningContext.get(IContributionFactory.class);
Object customRenderer = contributionFactory.create(customURI, owningContext);
if (customRenderer instanceof AbstractPartRenderer) {
customRendererMap.put(customURI, (AbstractPartRenderer) customRenderer);
return (AbstractPartRenderer) customRenderer;
}
}
// If not then use the default renderer
return curFactory.getRenderer(uiElement, parent);
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class PartRenderingEngine method createThemeEngine.
private static IThemeEngine createThemeEngine(Display display, IEclipseContext appContext) {
// Store the app context
IContributionFactory contribution = appContext.get(IContributionFactory.class);
IEclipseContext cssContext = EclipseContextFactory.create();
cssContext.set(IContributionFactory.class, contribution);
// $NON-NLS-1$
display.setData("org.eclipse.e4.ui.css.context", cssContext);
IThemeManager mgr = appContext.get(IThemeManager.class);
IThemeEngine themeEngine = mgr.getEngineForDisplay(display);
appContext.set(IThemeEngine.class, themeEngine);
return themeEngine;
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory 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);
}
Aggregations