use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class HeadlessApplicationTest method createPresentationEngine.
protected IPresentationEngine createPresentationEngine(String renderingEngineURI) throws Exception {
IContributionFactory contributionFactory = rule.getApplicationContext().get(IContributionFactory.class);
Object newEngine = contributionFactory.create(renderingEngineURI, rule.getApplicationContext());
return (IPresentationEngine) newEngine;
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class Bug320857Test method getEngine.
private IPresentationEngine getEngine() {
if (engine == null) {
IContributionFactory contributionFactory = applicationContext.get(IContributionFactory.class);
Object newEngine = contributionFactory.create(getEngineURI(), applicationContext);
assertTrue(newEngine instanceof IPresentationEngine);
applicationContext.set(IPresentationEngine.class.getName(), newEngine);
engine = (IPresentationEngine) newEngine;
}
return engine;
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class MenuManagerRendererFilter method updateElementVisibility.
/**
* @param menuModel
* @param renderer
* @param menuManager
* @param evalContext
*/
public static void updateElementVisibility(final MMenu menuModel, MenuManagerRenderer renderer, MenuManager menuManager, final IEclipseContext evalContext, final int recurseLevel, boolean updateEnablement) {
final ExpressionContext exprContext = new ExpressionContext(evalContext);
HashSet<ContributionRecord> records = new HashSet<>();
for (MMenuElement element : menuModel.getChildren()) {
ContributionRecord record = renderer.getContributionRecord(element);
if (record != null) {
if (records.add(record)) {
record.updateVisibility(evalContext);
}
} else {
MenuManagerRenderer.updateVisibility(menuManager, element, exprContext);
}
if (recurseLevel > 0 && element.isVisible() && element instanceof MMenu) {
MMenu childMenu = (MMenu) element;
MenuManager childManager = renderer.getManager(childMenu);
if (childManager != null) {
updateElementVisibility(childMenu, renderer, childManager, evalContext, recurseLevel - 1, false);
}
}
if (updateEnablement && element instanceof MHandledMenuItem) {
ParameterizedCommand cmd = ((MHandledMenuItem) element).getWbCommand();
EHandlerService handlerService = evalContext.get(EHandlerService.class);
if (cmd != null && handlerService != null) {
MHandledMenuItem item = (MHandledMenuItem) element;
final IEclipseContext staticContext = EclipseContextFactory.create(MMRF_STATIC_CONTEXT);
ContributionsAnalyzer.populateModelInterfaces(item, staticContext, item.getClass().getInterfaces());
try {
((MHandledMenuItem) element).setEnabled(handlerService.canExecute(cmd, staticContext));
} finally {
staticContext.dispose();
}
}
} else if (updateEnablement && OpaqueElementUtil.isOpaqueMenuItem(element)) {
Object obj = OpaqueElementUtil.getOpaqueItem(element);
if (obj instanceof IContributionItem) {
IContributionItem ici = (IContributionItem) obj;
ici.update();
// Update the model to reflect changes
((MItem) element).setEnabled(ici.isEnabled());
}
} else if (updateEnablement && element instanceof MDirectMenuItem) {
MDirectMenuItem contrib = (MDirectMenuItem) element;
if (contrib.getObject() == null) {
IContributionFactory icf = evalContext.get(IContributionFactory.class);
contrib.setObject(icf.create(contrib.getContributionURI(), evalContext, EclipseContextFactory.create()));
}
if (contrib.getObject() == null) {
contrib.setEnabled(false);
continue;
}
MDirectMenuItem item = (MDirectMenuItem) element;
IEclipseContext staticContext = EclipseContextFactory.create(MMRF_STATIC_CONTEXT);
ContributionsAnalyzer.populateModelInterfaces(item, staticContext, item.getClass().getInterfaces());
try {
Object rc = ContextInjectionFactory.invoke(contrib.getObject(), CanExecute.class, evalContext, staticContext, Boolean.TRUE);
if (rc instanceof Boolean) {
contrib.setEnabled((Boolean) rc);
}
} finally {
staticContext.dispose();
}
}
}
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class ContributedPartRenderer method createWidget.
@Override
public Object createWidget(final MUIElement element, Object parent) {
if (!(element instanceof MPart) || !(parent instanceof Composite)) {
return null;
}
// retrieve context for this part
final MPart part = (MPart) element;
IEclipseContext localContext = part.getContext();
Widget parentWidget = (Widget) parent;
// retrieve existing Composite, e.g., for the e4 compatibility case
Composite partComposite = localContext.getLocal(Composite.class);
// does the part already have a composite in its contexts?
if (partComposite == null) {
final Composite newComposite = new Composite((Composite) parentWidget, SWT.NONE) {
/**
* Field to determine whether we are currently in the midst of
* granting focus to the part.
*/
private boolean beingFocused = false;
@Override
public boolean setFocus() {
if (!beingFocused) {
try {
// we are currently asking the part to take focus
beingFocused = true;
// delegate an attempt to set the focus here to the
// part's implementation (if there is one)
Object object = part.getObject();
if (object != null && isEnabled()) {
IPresentationEngine pe = part.getContext().get(IPresentationEngine.class);
pe.focusGui(part);
return true;
}
return super.setFocus();
} finally {
// we are done, unset our flag
beingFocused = false;
}
}
// just return
return true;
}
};
newComposite.setLayout(new FillLayout(SWT.VERTICAL));
partComposite = newComposite;
}
bindWidget(element, partComposite);
localContext.set(Composite.class, partComposite);
IContributionFactory contributionFactory = localContext.get(IContributionFactory.class);
Object newPart = contributionFactory.create(part.getContributionURI(), localContext);
part.setObject(newPart);
return partComposite;
}
use of org.eclipse.e4.core.services.contributions.IContributionFactory in project eclipse.platform.ui by eclipse-platform.
the class CocoaUIHandler method simulateMenuSelection.
private void simulateMenuSelection(MMenuItem item) {
// FIXME: pity this code isn't available through the MMenuItem instance
// somehow
IEclipseContext lclContext = getContext(item);
if (item instanceof MDirectMenuItem) {
MDirectMenuItem dmi = (MDirectMenuItem) item;
if (dmi.getObject() == null) {
IContributionFactory cf = (IContributionFactory) lclContext.get(IContributionFactory.class.getName());
dmi.setObject(cf.create(dmi.getContributionURI(), lclContext));
}
lclContext.set(MItem.class.getName(), item);
ContextInjectionFactory.invoke(dmi.getObject(), Execute.class, lclContext);
lclContext.remove(MItem.class.getName());
} else if (item instanceof MHandledMenuItem) {
MHandledMenuItem hmi = (MHandledMenuItem) item;
EHandlerService service = (EHandlerService) lclContext.get(EHandlerService.class.getName());
ParameterizedCommand cmd = hmi.getWbCommand();
if (cmd == null) {
cmd = generateParameterizedCommand(hmi);
}
lclContext.set(MItem.class.getName(), item);
service.executeHandler(cmd);
lclContext.remove(MItem.class.getName());
} else {
statusReporter.get().report(new Status(IStatus.WARNING, CocoaUIProcessor.FRAGMENT_ID, // $NON-NLS-1$ //$NON-NLS-2$
"Unhandled menu type: " + item.getClass() + ": " + item), StatusReporter.LOG);
}
}
Aggregations