use of org.eclipse.e4.ui.di.Focus in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchWindow method run.
@Override
public void run(final boolean fork, boolean cancelable, final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
final StatusLineManager manager = getStatusLineManager();
// Temporary Hack for bug 330106, remove when bug 334093 is fixed
boolean progressHack = manager.getControl() == null;
if (manager == null || progressHack) {
runnable.run(new NullProgressMonitor());
} else {
EPartService partService = model.getContext().get(EPartService.class);
final MPart curActive = partService.getActivePart();
boolean wasCancelEnabled = manager.isCancelEnabled();
boolean enableMainMenu = false;
IBindingService bs = model.getContext().get(IBindingService.class);
boolean keyFilterEnabled = bs.isKeyFilterEnabled();
List<Control> toEnable = new ArrayList<>();
Shell theShell = getShell();
Display display = theShell.getDisplay();
Control currentFocus = display.getFocusControl();
try {
Menu mainMenu = (Menu) model.getMainMenu().getWidget();
if (mainMenu != null && !mainMenu.isDisposed() && mainMenu.isEnabled()) {
mainMenu.setEnabled(false);
enableMainMenu = true;
}
if (keyFilterEnabled)
bs.setKeyFilterEnabled(false);
// disable all other shells
for (Shell childShell : display.getShells()) {
if (childShell != theShell) {
disableControl(childShell, toEnable);
}
}
// Disable the presentation (except the bottom trim)
TrimmedPartLayout tpl = (TrimmedPartLayout) getShell().getLayout();
disableControl(tpl.clientArea, toEnable);
disableControl(tpl.top, toEnable);
disableControl(tpl.left, toEnable);
disableControl(tpl.right, toEnable);
// Disable everything in the bottom trim except the status line
if (tpl.bottom != null && !tpl.bottom.isDisposed() && tpl.bottom.isEnabled()) {
MUIElement statusLine = modelService.find(STATUS_LINE_ID, model);
Object slCtrl = statusLine != null ? statusLine.getWidget() : null;
for (Control bottomCtrl : tpl.bottom.getChildren()) {
if (bottomCtrl != slCtrl)
disableControl(bottomCtrl, toEnable);
}
}
manager.setCancelEnabled(cancelable);
final InvocationTargetException[] ite = new InvocationTargetException[1];
final InterruptedException[] ie = new InterruptedException[1];
BusyIndicator.showWhile(getShell().getDisplay(), () -> {
try {
ModalContext.run(runnable, fork, manager.getProgressMonitor(), getShell().getDisplay());
} catch (InvocationTargetException e1) {
ite[0] = e1;
} catch (InterruptedException e2) {
ie[0] = e2;
} finally {
manager.getProgressMonitor().done();
}
});
if (ite[0] != null) {
throw ite[0];
} else if (ie[0] != null) {
throw ie[0];
}
} finally {
manager.setCancelEnabled(wasCancelEnabled);
// re-enable the main menu if necessary
if (enableMainMenu && model != null && model.getMainMenu() != null) {
Menu mainMenu = (Menu) model.getMainMenu().getWidget();
mainMenu.setEnabled(true);
}
if (keyFilterEnabled)
bs.setKeyFilterEnabled(true);
// Re-enable any disabled controls
for (Control ctrl : toEnable) {
if (!ctrl.isDisposed() && !ctrl.isEnabled())
ctrl.setEnabled(true);
}
MPart activePart = partService.getActivePart();
if (curActive != activePart && activePart != null) {
engine.focusGui(activePart);
} else if (currentFocus != null && !currentFocus.isDisposed()) {
// It's necessary to restore focus after reenabling the
// controls
// because disabling them causes focus to jump elsewhere.
// Use forceFocus rather than setFocus to avoid SWT's
// search for children which can take focus, so focus
// ends up back on the actual control that previously had
// it.
currentFocus.forceFocus();
}
}
}
}
use of org.eclipse.e4.ui.di.Focus in project eclipse.platform.ui by eclipse-platform.
the class WorkbenchPage method activate.
/**
* Activates a part. The part will be brought to the front and given focus.
*
* @param part the part to activate
*/
@Override
public void activate(IWorkbenchPart part) {
if (part == null || !certifyPart(part) || legacyWindow.isClosing()) {
return;
}
MPart mpart = findPart(part);
if (mpart != null) {
partService.activate(mpart);
actionSwitcher.updateActivePart(part);
}
}
use of org.eclipse.e4.ui.di.Focus in project eclipse.platform.ui by eclipse-platform.
the class TextField method setUp.
@Before
public void setUp() throws Exception {
appContext = E4Application.createDefaultContext();
appContext.set(IWorkbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI);
ems = appContext.get(EModelService.class);
window = ems.createModelElement(MWindow.class);
window.setWidth(500);
window.setHeight(500);
MPartSashContainer sash = ems.createModelElement(MPartSashContainer.class);
window.getChildren().add(sash);
window.setSelectedElement(sash);
MPartStack stack = ems.createModelElement(MPartStack.class);
sash.getChildren().add(stack);
sash.setSelectedElement(stack);
part = ems.createModelElement(MPart.class);
part.setElementId("Part");
part.setLabel("Part");
part.setToolbar(ems.createModelElement(MToolBar.class));
part.setContributionURI(asURI(PartBackend.class));
stack.getChildren().add(part);
toolControl = ems.createModelElement(MToolControl.class);
toolControl.setElementId("ToolControl");
toolControl.setContributionURI(asURI(TextField.class));
part.getToolbar().getChildren().add(toolControl);
stack = ems.createModelElement(MPartStack.class);
sash.getChildren().add(stack);
sash.setSelectedElement(stack);
otherPart = ems.createModelElement(MPart.class);
otherPart.setElementId("OtherPart");
otherPart.setLabel("OtherPart");
otherPart.setContributionURI(asURI(PartBackend.class));
stack.getChildren().add(otherPart);
MApplication application = ems.createModelElement(MApplication.class);
application.getChildren().add(window);
application.setContext(appContext);
appContext.set(MApplication.class, application);
wb = new E4Workbench(application, appContext);
wb.createAndRunUI(window);
eps = window.getContext().get(EPartService.class);
// ensure the parts are populated and the contributions instantiated
eps.activate(part);
eps.activate(otherPart);
processEvents();
// ensure our model backend objects are created
assertNotNull(part.getObject());
assertNotNull(toolControl.getObject());
assertNotNull(otherPart.getObject());
assertNotNull(part.getWidget());
assertNotNull(toolControl.getWidget());
assertNotNull(otherPart.getWidget());
// ensure focus is set to otherPart.text1
eps.activate(otherPart);
processEvents();
assertTrue(((PartBackend) otherPart.getObject()).text1.isFocusControl());
}
use of org.eclipse.e4.ui.di.Focus 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.di.Focus in project eclipse.platform.ui by eclipse-platform.
the class E4PartWrapper method setFocus.
@Override
public void setFocus() {
Object object = wrappedPart.getObject();
IEclipseContext context = wrappedPart.getContext();
if (object != null && context != null) {
ContextInjectionFactory.invoke(object, Focus.class, context);
if (Policy.DEBUG_FOCUS) {
// $NON-NLS-1$
Activator.trace(Policy.DEBUG_FOCUS_FLAG, "Focused: " + object, null);
}
} else if (Policy.DEBUG_FOCUS) {
Activator.trace(Policy.DEBUG_FOCUS_FLAG, // $NON-NLS-1$ //$NON-NLS-2$
"Focus not set, object or context missing: " + object + ", " + context, new IllegalStateException());
}
}
Aggregations