Example usage for com.intellij.openapi.wm IdeFocusManager getFocusOwner

List of usage examples for com.intellij.openapi.wm IdeFocusManager getFocusOwner

Introduction

In this page you can find the example usage for com.intellij.openapi.wm IdeFocusManager getFocusOwner.

Prototype

public abstract Component getFocusOwner();

Source Link

Document

Computes effective focus owner.

Usage

From source file:com.intellij.ui.FocusTrackback.java

License:Apache License

public void restoreFocus() {
    final Application app = ApplicationManager.getApplication();
    if (app == null || wrongOS() || myConsumed || isSheduledForRestore())
        return;/*  w  w w  .  j  a v  a2 s  .co  m*/

    Project project = null;
    DataContext context = myParentWindow == null ? DataManager.getInstance().getDataContext()
            : DataManager.getInstance().getDataContext(myParentWindow);
    if (context != null) {
        project = CommonDataKeys.PROJECT.getData(context);
    }

    mySheduledForRestore = true;
    final List<FocusTrackback> stack = getCleanStackForRoot();
    final int index = stack.indexOf(this);
    for (int i = index - 1; i >= 0; i--) {
        if (stack.get(i).isSheduledForRestore()) {
            dispose();
            return;
        }
    }

    if (project != null && !project.isDisposed()) {
        final IdeFocusManager focusManager = IdeFocusManager.getInstance(project);
        cleanParentWindow();
        final Project finalProject = project;
        focusManager.requestFocus(new MyFocusCommand(), myForcedRestore).doWhenProcessed(new Runnable() {
            public void run() {
                dispose();
            }
        }).doWhenRejected(new Runnable() {
            @Override
            public void run() {
                focusManager.revalidateFocus(new ExpirableRunnable.ForProject(finalProject) {
                    @Override
                    public void run() {
                        if (UIUtil.isMeaninglessFocusOwner(focusManager.getFocusOwner())) {
                            focusManager.requestDefaultFocus(false);
                        }
                    }
                });
            }
        });
    } else {
        // no ide focus manager, so no way -- do just later
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                _restoreFocus();
                dispose();
            }
        });
    }
}

From source file:org.codinjutsu.tools.mongo.view.QueryPanel.java

License:Apache License

public void requestFocusOnEditor() {// Code from requestFocus of EditorImpl
    final IdeFocusManager focusManager = IdeFocusManager.getInstance(this.project);
    JComponent editorContentComponent = getCurrentOperatorPanel().getRequestFocusComponent();
    if (focusManager.getFocusOwner() != editorContentComponent) {
        focusManager.requestFocus(editorContentComponent, true);
    }/*from ww w. j av a  2s. c  o m*/
}

From source file:org.eclipse.xtext.idea.trace.TraceBasedGeneratedSourcesFilter.java

License:Open Source License

@Override
public List<? extends PsiElement> getOriginalElements(final PsiElement element) {
    Application _application = ApplicationManager.getApplication();
    boolean _isDispatchThread = _application.isDispatchThread();
    if (_isDispatchThread) {
        Project _project = element.getProject();
        IdeFocusManager _instance = IdeFocusManager.getInstance(_project);
        final Component focusOwner = _instance.getFocusOwner();
        if (((!Objects.equal(focusOwner, null))
                && focusOwner.getClass().getName().startsWith(ProjectViewPane.class.getName()))) {
            return CollectionLiterals.<PsiElement>emptyList();
        }/*from  w  w  w .  j  a v a2  s  .c  o m*/
    }
    return this.traceProvider.getOriginalElements(element);
}