use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class ToolControlRenderer method createWidget.
@Override
public Object createWidget(final MUIElement element, Object parent) {
if (!(element instanceof MToolControl) || !(parent instanceof ToolBar || parent instanceof Composite))
return null;
Composite parentComp = (Composite) parent;
MToolControl toolControl = (MToolControl) element;
if (((Object) toolControl.getParent()) instanceof MToolBar) {
IRendererFactory factory = context.get(IRendererFactory.class);
AbstractPartRenderer renderer = factory.getRenderer(toolControl.getParent(), parent);
if (renderer instanceof ToolBarManagerRenderer) {
return null;
}
}
Widget parentWidget = (Widget) parent;
IEclipseContext parentContext = getContextForParent(element);
ToolItem sep = null;
if (parent instanceof ToolBar) {
sep = new ToolItem((ToolBar) parentWidget, SWT.SEPARATOR);
}
// final Composite newComposite = new Composite((Composite)
// parentWidget,
// SWT.NONE);
// newComposite.setLayout(new FillLayout());
// bindWidget(element, newComposite);
// Create a context just to contain the parameters for injection
IContributionFactory contributionFactory = parentContext.get(IContributionFactory.class);
IEclipseContext localContext = EclipseContextFactory.create();
localContext.set(Composite.class.getName(), parentComp);
localContext.set(MToolControl.class.getName(), toolControl);
Object tcImpl = contributionFactory.create(toolControl.getContributionURI(), parentContext, localContext);
toolControl.setObject(tcImpl);
Control[] kids = parentComp.getChildren();
// No kids means that the trim failed curing creation
if (kids.length == 0)
return null;
// The new control is assumed to be the last child created
// We could safe this up even more by asserting that the
// number of children should go up by *one* during injection
Control newCtrl = kids[kids.length - 1];
if (sep != null && newCtrl != null) {
sep.setControl(newCtrl);
newCtrl.pack();
sep.setWidth(newCtrl.getSize().x);
}
bindWidget(toolControl, newCtrl);
boolean vertical = false;
MUIElement parentElement = element.getParent();
if (parentElement instanceof MTrimBar) {
MTrimBar bar = (MTrimBar) parentElement;
vertical = bar.getSide() == SideValue.LEFT || bar.getSide() == SideValue.RIGHT;
}
CSSRenderingUtils cssUtils = parentContext.get(CSSRenderingUtils.class);
MUIElement modelElement = (MUIElement) newCtrl.getData(AbstractPartRenderer.OWNING_ME);
boolean draggable = ((modelElement != null) && (modelElement.getTags().contains(IPresentationEngine.DRAGGABLE)));
newCtrl = cssUtils.frameMeIfPossible(newCtrl, null, vertical, draggable);
boolean hideable = isHideable(toolControl);
boolean showRestoreMenu = isRestoreMenuShowable(toolControl);
if (showRestoreMenu || hideable) {
createToolControlMenu(toolControl, newCtrl, hideable);
}
return newCtrl;
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class E4Application method loadApplicationModel.
private MApplication loadApplicationModel(IApplicationContext appContext, IEclipseContext eclipseContext) {
Location instanceLocation = WorkbenchSWTActivator.getDefault().getInstanceLocation();
URI applicationModelURI = determineApplicationModelURI(appContext);
eclipseContext.set(E4Workbench.INITIAL_WORKBENCH_MODEL_URI, applicationModelURI);
// Save and restore
Boolean saveAndRestore = getArgValue(IWorkbench.PERSIST_STATE, appContext, false).map(Boolean::parseBoolean).orElse(Boolean.TRUE);
eclipseContext.set(IWorkbench.PERSIST_STATE, saveAndRestore);
// when -data @none or -data @noDefault options
if (instanceLocation != null && instanceLocation.getURL() != null) {
eclipseContext.set(E4Workbench.INSTANCE_LOCATION, instanceLocation);
} else {
eclipseContext.set(IWorkbench.PERSIST_STATE, false);
}
// Persisted state
Boolean clearPersistedState = getArgValue(IWorkbench.CLEAR_PERSISTED_STATE, appContext, true).map(Boolean::parseBoolean).orElse(Boolean.FALSE);
eclipseContext.set(IWorkbench.CLEAR_PERSISTED_STATE, clearPersistedState);
String resourceHandler = getArgValue(IWorkbench.MODEL_RESOURCE_HANDLER, appContext, false).orElse("bundleclass://org.eclipse.e4.ui.workbench/" + ResourceHandler.class.getName());
IContributionFactory factory = eclipseContext.get(IContributionFactory.class);
handler = (IModelResourceHandler) factory.create(resourceHandler, eclipseContext);
eclipseContext.set(IModelResourceHandler.class, handler);
Resource resource = handler.loadMostRecentModel();
return (MApplication) resource.getContents().get(0);
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class PartRenderingEngine method initialize.
/**
* Initialize a part renderer from the extension point.
*
* @param context
* the context for the part factories
*/
@PostConstruct
void initialize(IEclipseContext context) {
this.appContext = context;
// initialize the correct key-binding display formatter
KeyFormatterFactory.setDefault(SWTKeySupport.getKeyFormatterForPlatform());
// Add the renderer to the context
context.set(IPresentationEngine.class, this);
IRendererFactory factory = null;
IContributionFactory contribFactory = context.get(IContributionFactory.class);
try {
factory = (IRendererFactory) contribFactory.create(factoryUrl, context);
} catch (Exception e) {
logger.warn(e, "Could not create rendering factory");
}
// Try to load the default one
if (factory == null) {
try {
factory = (IRendererFactory) contribFactory.create(defaultFactoryUrl, context);
} catch (Exception e) {
logger.error(e, "Could not create default rendering factory");
}
}
if (factory == null) {
throw new IllegalStateException("Could not create any rendering factory. Aborting ...");
}
curFactory = factory;
context.set(IRendererFactory.class, curFactory);
cssThemeChangedHandler = new StylingPreferencesHandler(context.get(Display.class));
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class ModelAssembler method runProcessor.
private void runProcessor(IConfigurationElement ce) {
IEclipseContext localContext = EclipseContextFactory.create();
IContributionFactory factory = context.get(IContributionFactory.class);
for (IConfigurationElement ceEl : ce.getChildren("element")) {
// $NON-NLS-1$
// $NON-NLS-1$
String id = ceEl.getAttribute("id");
if (id == null) {
// $NON-NLS-1$
log(LogLevel.WARN, "No element id given");
continue;
}
// $NON-NLS-1$
String key = ceEl.getAttribute("contextKey");
if (key == null) {
key = id;
}
MApplicationElement el = ModelUtils.findElementById(application, id);
if (el == null) {
// $NON-NLS-1$
log(LogLevel.WARN, "Could not find element with id {}", id);
}
localContext.set(key, el);
}
try {
Object o = // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
factory.create(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
"bundleclass://" + ce.getContributor().getName() + "/" + ce.getAttribute("class"), context, localContext);
if (o == null) {
log(// $NON-NLS-1$
LogLevel.WARN, // $NON-NLS-1$
"Unable to create processor {} from {}", // $NON-NLS-1$
ce.getAttribute("class"), ce.getContributor().getName());
} else {
ContextInjectionFactory.invoke(o, Execute.class, context, localContext, null);
}
} catch (Exception e) {
// $NON-NLS-1$
log(LogLevel.WARN, "Could not run processor: {}", e);
}
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class HandlerProcessingAddon method processActiveHandler.
/**
* @param handler
* @param context
*/
private void processActiveHandler(MHandler handler, IEclipseContext context) {
MCommand command = handler.getCommand();
if (command == null) {
return;
}
String commandId = command.getElementId();
if (handler.getObject() == null) {
IContributionFactory contributionFactory = context.get(IContributionFactory.class);
handler.setObject(contributionFactory.create(handler.getContributionURI(), context));
}
EHandlerService handlerService = context.get(EHandlerService.class);
handlerService.activateHandler(commandId, handler.getObject());
}
Aggregations