Search in sources :

Example 6 with Focus

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();
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) StatusLineManager(org.eclipse.jface.action.StatusLineManager) ArrayList(java.util.ArrayList) TrimmedPartLayout(org.eclipse.e4.ui.workbench.renderers.swt.TrimmedPartLayout) InvocationTargetException(java.lang.reflect.InvocationTargetException) MToolControl(org.eclipse.e4.ui.model.application.ui.menu.MToolControl) Control(org.eclipse.swt.widgets.Control) Shell(org.eclipse.swt.widgets.Shell) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) MUIElement(org.eclipse.e4.ui.model.application.ui.MUIElement) EObject(org.eclipse.emf.ecore.EObject) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) Menu(org.eclipse.swt.widgets.Menu) IBindingService(org.eclipse.ui.keys.IBindingService) Display(org.eclipse.swt.widgets.Display)

Example 7 with Focus

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);
    }
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart)

Example 8 with Focus

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());
}
Also used : MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) MToolControl(org.eclipse.e4.ui.model.application.ui.menu.MToolControl) E4Workbench(org.eclipse.e4.ui.internal.workbench.E4Workbench) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) MPartSashContainer(org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer) MApplication(org.eclipse.e4.ui.model.application.MApplication) Before(org.junit.Before)

Example 9 with Focus

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");
        }
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) EObject(org.eclipse.emf.ecore.EObject) MContribution(org.eclipse.e4.ui.model.application.MContribution)

Example 10 with Focus

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());
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Aggregations

MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)9 ArrayList (java.util.ArrayList)4 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 EPartService (org.eclipse.e4.ui.workbench.modeling.EPartService)3 EObject (org.eclipse.emf.ecore.EObject)3 Control (org.eclipse.swt.widgets.Control)3 Shell (org.eclipse.swt.widgets.Shell)3 File (java.io.File)2 List (java.util.List)2 Named (javax.inject.Named)2 Extractor (name.abuchen.portfolio.datatransfer.Extractor)2 Client (name.abuchen.portfolio.model.Client)2 Messages (name.abuchen.portfolio.ui.Messages)2 PortfolioPlugin (name.abuchen.portfolio.ui.PortfolioPlugin)2 ImportExtractedItemsWizard (name.abuchen.portfolio.ui.wizards.datatransfer.ImportExtractedItemsWizard)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2