use of org.eclipse.e4.ui.model.application.MContribution in project eclipse.platform.ui by eclipse-platform.
the class DirectContributionItem method executeItem.
@Override
protected void executeItem(Event trigger) {
final IEclipseContext lclContext = getContext(getModel());
if (!checkContribution(lclContext)) {
return;
}
MContribution contrib = (MContribution) getModel();
IEclipseContext staticContext = getStaticContext(trigger);
Object result = ContextInjectionFactory.invoke(contrib.getObject(), Execute.class, getExecutionContext(lclContext), staticContext, missingExecute);
if (result == missingExecute && logger != null) {
// $NON-NLS-1$
logger.error("Contribution is missing @Execute: " + contrib.getContributionURI());
}
}
use of org.eclipse.e4.ui.model.application.MContribution in project eclipse.platform.ui by eclipse-platform.
the class PartRenderingEngine method safeRemoveGui.
private void safeRemoveGui(MUIElement element) {
if (removeRoot == null)
removeRoot = element;
// We call 'hideChild' *before* checking if the actual element
// has been rendered in order to pick up cases of 'lazy loading'
MUIElement parent = element.getParent();
AbstractPartRenderer parentRenderer = parent != null ? getRendererFor(parent) : null;
if (parentRenderer != null) {
parentRenderer.hideChild(element.getParent(), element);
}
AbstractPartRenderer renderer = getRendererFor(element);
// If the element hasn't been rendered then this is a NO-OP
if (renderer != null) {
if (element instanceof MElementContainer<?>) {
@SuppressWarnings("unchecked") MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) element;
MUIElement selectedElement = container.getSelectedElement();
List<MUIElement> children = container.getChildren();
// Bug 458460: Operate on a copy in case child nulls out parent
for (MUIElement child : new ArrayList<>(children)) {
// remove stuff in the "back" first
if (child != selectedElement) {
removeGui(child);
}
}
if (selectedElement != null && children.contains(selectedElement)) {
// now remove the selected element
removeGui(selectedElement);
}
}
if (element instanceof MPerspective) {
MPerspective perspective = (MPerspective) element;
for (MWindow subWindow : perspective.getWindows()) {
removeGui(subWindow);
}
} else if (element instanceof MWindow) {
MWindow window = (MWindow) element;
for (MWindow subWindow : window.getWindows()) {
removeGui(subWindow);
}
if (window instanceof MTrimmedWindow) {
MTrimmedWindow trimmedWindow = (MTrimmedWindow) window;
for (MUIElement trimBar : trimmedWindow.getTrimBars()) {
removeGui(trimBar);
}
}
}
if (element instanceof MContribution) {
MContribution contribution = (MContribution) element;
Object client = contribution.getObject();
IEclipseContext parentContext = renderer.getContext(element);
if (parentContext != null && client != null) {
try {
ContextInjectionFactory.invoke(client, PersistState.class, parentContext, null);
} catch (Exception e) {
if (logger != null) {
logger.error(e);
}
}
}
}
renderer.disposeWidget(element);
// unset the client object
if (element instanceof MContribution) {
MContribution contribution = (MContribution) element;
Object client = contribution.getObject();
IEclipseContext parentContext = renderer.getContext(element);
if (parentContext != null && client != null) {
try {
ContextInjectionFactory.uninject(client, parentContext);
} catch (Exception e) {
if (logger != null) {
logger.error(e);
}
}
}
contribution.setObject(null);
}
// dispose the context
if (element instanceof MContext) {
clearContext((MContext) element);
}
}
if (element instanceof MPlaceholder) {
MPlaceholder ph = (MPlaceholder) element;
if (ph.getRef() != null && ph.getRef().getCurSharedRef() == ph) {
ph.getRef().setCurSharedRef(null);
}
}
if (removeRoot == element)
removeRoot = null;
}
use of org.eclipse.e4.ui.model.application.MContribution in project eclipse.platform.ui by eclipse-platform.
the class HeadlessContextPresentationEngine method focusGui.
@Override
public void focusGui(MUIElement element) {
Object implementation = element instanceof MContribution ? ((MContribution) element).getObject() : null;
if (implementation != null) {
IEclipseContext context = getContext(element);
Object defaultValue = new Object();
Object returnValue = ContextInjectionFactory.invoke(implementation, Focus.class, context, defaultValue);
if (returnValue == defaultValue) {
System.err.println("No @Focus method");
}
}
}
use of org.eclipse.e4.ui.model.application.MContribution in project eclipse.platform.ui by eclipse-platform.
the class DirectContributionItem method canExecuteItem.
@Override
protected boolean canExecuteItem(Event trigger) {
final IEclipseContext lclContext = getContext(getModel());
if (!checkContribution(lclContext)) {
return false;
}
MContribution contrib = (MContribution) getModel();
IEclipseContext staticContext = getStaticContext(trigger);
Boolean result = ((Boolean) ContextInjectionFactory.invoke(contrib.getObject(), CanExecute.class, getExecutionContext(lclContext), staticContext, Boolean.TRUE));
return result.booleanValue();
}
use of org.eclipse.e4.ui.model.application.MContribution in project eclipse.platform.ui by eclipse-platform.
the class PartRenderingEngine method focusGui.
@Override
public void focusGui(MUIElement element) {
AbstractPartRenderer renderer = (AbstractPartRenderer) element.getRenderer();
if (renderer == null || element.getWidget() == null) {
if (Policy.DEBUG_FOCUS) {
WorkbenchSWTActivator.trace(Policy.DEBUG_FOCUS_FLAG, "Trying to focus GUI on element without renderer or widget: " + element, // $NON-NLS-1$
new Exception());
}
return;
}
Object implementation = element instanceof MContribution ? ((MContribution) element).getObject() : null;
// If there is no class to call @Focus on then revert to the default
if (implementation == null) {
renderer.forceFocus(element);
return;
}
try {
IEclipseContext context = getContext(element);
Object defaultValue = new Object();
Object returnValue = ContextInjectionFactory.invoke(implementation, Focus.class, context, defaultValue);
if (returnValue == defaultValue) {
// No @Focus method, force the focus
renderer.forceFocus(element);
} else if (Policy.DEBUG_FOCUS) {
// $NON-NLS-1$
WorkbenchSWTActivator.trace(Policy.DEBUG_FOCUS_FLAG, "Focused GUI on element: " + element, null);
}
} catch (InjectionException e) {
log(// $NON-NLS-1$ //$NON-NLS-2$
"Failed to grant focus to element", // $NON-NLS-1$ //$NON-NLS-2$
"Failed to grant focus to element ({0})", element.getElementId(), e);
} catch (RuntimeException e) {
log(// $NON-NLS-1$
"Failed to grant focus to element via DI", "Failed to grant focus via DI to element ({0})", element.getElementId(), // $NON-NLS-1$
e);
}
}
Aggregations