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

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

Introduction

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

Prototype

@NotNull
    public static IdeFocusManager findInstanceByComponent(@NotNull Component component) 

Source Link

Usage

From source file:com.intellij.ui.table.JBTable.java

License:Apache License

@Override
public boolean editCellAt(final int row, final int column, final EventObject e) {
    if (cellEditor != null && !cellEditor.stopCellEditing()) {
        return false;
    }/*w  w w  .  j  a v  a  2 s.  c  om*/

    if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount()) {
        return false;
    }

    if (!isCellEditable(row, column)) {
        return false;
    }

    if (e instanceof KeyEvent && UIUtil.isReallyTypedEvent((KeyEvent) e)) {
        SpeedSearchSupply supply = SpeedSearchSupply.getSupply(this);
        if (supply != null && supply.isPopupActive()) {
            return false;
        }
    }

    if (myEditorRemover == null) {
        final KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        myEditorRemover = new MyCellEditorRemover();
        //noinspection HardCodedStringLiteral
        keyboardFocusManager.addPropertyChangeListener("focusOwner", myEditorRemover);
        //noinspection HardCodedStringLiteral
        keyboardFocusManager.addPropertyChangeListener("permanentFocusOwner", myEditorRemover);
    }

    final TableCellEditor editor = getCellEditor(row, column);
    if (editor != null && editor.isCellEditable(e)) {
        editorComp = prepareEditor(editor, row, column);
        //((JComponent)editorComp).setBorder(null);
        if (editorComp == null) {
            removeEditor();
            return false;
        }
        editorComp.setBounds(getCellRect(row, column, false));
        add(editorComp);
        editorComp.validate();

        IdeFocusManager.findInstanceByComponent(this).requestFocus(editorComp, false);

        setCellEditor(editor);
        setEditingRow(row);
        setEditingColumn(column);
        editor.addCellEditorListener(this);
        if (isTypeAhead) {
            JTableCellEditorHelper.typeAhead(this, e, row, column);
        }
        return true;
    }
    return false;
}

From source file:com.intellij.uiDesigner.actions.IncreaseIndentAction.java

License:Apache License

protected void update(@NotNull GuiEditor editor, final ArrayList<RadComponent> selection,
        final AnActionEvent e) {
    final boolean applicable = canAdjustIndent(selection);
    e.getPresentation().setVisible(applicable);
    final Component focusOwner = IdeFocusManager.findInstanceByComponent(editor).getFocusOwner();
    e.getPresentation().setEnabled(applicable && (focusOwner == editor || editor.isAncestorOf(focusOwner)));
}

From source file:com.intellij.util.ui.ValidatingTableEditor.java

License:Apache License

protected void addItem() {
    Item newItem = createItem();/*from   ww  w .j  a v  a 2s.  c  o m*/
    if (newItem == null) {
        return;
    }
    List<Item> items = new ArrayList<Item>(doGetItems());
    items.add(newItem);

    setItems(items);

    final int row = items.size() - 1;
    myTable.getSelectionModel().setSelectionInterval(row, row);
    myTable.scrollRectToVisible(myTable.getCellRect(row, 0, true));
    if (getTableModel().getColumnInfos()[1].isCellEditable(items.get(row))) {
        myTable.editCellAt(row, 1);
        IdeFocusManager.findInstanceByComponent(myContentPane).requestFocus(myTable.getEditorComponent(), true);
    }
    updateMessage(-1, null);
}

From source file:com.urswolfer.intellij.plugin.gerrit.ui.diff.CommentForm.java

License:Apache License

public void requestFocus() {
    IdeFocusManager.findInstanceByComponent(reviewTextField).requestFocus(reviewTextField, true);
}

From source file:io.ballerina.plugins.idea.webview.diagram.split.SplitFileEditor.java

License:Open Source License

private void invalidateLayout(boolean requestFocus) {
    adjustEditorsVisibility();/* w w w .j a  v  a2 s  .  c  o m*/
    myToolbarWrapper.refresh();
    myComponent.repaint();

    if (!requestFocus) {
        return;
    }

    final JComponent focusComponent = getPreferredFocusedComponent();
    if (focusComponent != null) {
        IdeFocusManager.findInstanceByComponent(focusComponent).requestFocus(focusComponent, true);
    }
}

From source file:org.jetbrains.tfsIntegration.ui.checkoutwizard.CheckoutModeForm.java

License:Apache License

public CheckoutModeForm() {
    myErrorLabel.setIcon(UIUtil.getBalloonWarningIcon());

    myAutoModeButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            myEventDispatcher.getMulticaster().stateChanged(new ChangeEvent(this));
            IdeFocusManager.findInstanceByComponent(myContentPanel).requestFocus(myWorkspaceNameField, true);
        }/* w  w w.  ja va 2  s  . co m*/
    });
    myManualModeButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            myEventDispatcher.getMulticaster().stateChanged(new ChangeEvent(this));
        }
    });
    myWorkspaceNameField.getDocument().addDocumentListener(new DocumentAdapter() {
        protected void textChanged(final DocumentEvent e) {
            myAutoModeButton.setSelected(true);
            myEventDispatcher.getMulticaster().stateChanged(new ChangeEvent(this));
        }
    });
}

From source file:org.jetbrains.tfsIntegration.ui.TfsLoginForm.java

License:Apache License

public TfsLoginForm(URI initialUri, Credentials initialCredentials, boolean allowUrlChange) {
    myAddressField.setText(initialUri != null ? TfsUtil.getPresentableUri(initialUri) : null);
    myAddressField.setEditable(allowUrlChange);
    myUsernameField.setText(initialCredentials != null ? initialCredentials.getUserName() : null);
    myDomainField.setText(initialCredentials != null ? initialCredentials.getDomain() : null);
    myPasswordField.setText(initialCredentials != null ? initialCredentials.getPassword() : null);

    final DocumentListener changeListener = new DocumentAdapter() {
        @Override/*from www .j av  a2 s .c om*/
        protected void textChanged(final DocumentEvent e) {
            myEventDispatcher.getMulticaster().stateChanged(new ChangeEvent(this));
        }
    };

    myAddressField.getDocument().addDocumentListener(changeListener);
    myUsernameField.getDocument().addDocumentListener(changeListener);
    myDomainField.getDocument().addDocumentListener(changeListener);
    myPasswordField.getDocument().addDocumentListener(changeListener);

    myProxyPasswordLabel.setHyperlinkText("", TFSBundle.message("login.dialog.proxy.label.1"),
            TFSBundle.message("login.dialog.proxy.label.2"));
    myProxyPasswordLabel.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                HttpConfigurable.editConfigurable(myContentPane);
            }
        }
    });

    if (TfsLoginDialog.shouldPromptForProxyPassword(false)) {
        HttpConfigurable hc = HttpConfigurable.getInstance();
        myProxyPasswordField.setText(hc.getPlainProxyPassword());
        myProxyPanel.setVisible(true);
    } else {
        myProxyPanel.setVisible(false);
    }

    myTypeCombo.setRenderer(new ListCellRendererWrapper<Credentials.Type>() {
        @Override
        public void customize(final JList list, final Credentials.Type value, final int index,
                final boolean selected, final boolean hasFocus) {
            setText(value.getPresentableText());
        }
    });
    if (NativeNTLM2Scheme.isAvailable()) {
        myTypeCombo.setModel(new DefaultComboBoxModel(new Credentials.Type[] { Credentials.Type.NtlmNative,
                Credentials.Type.NtlmExplicit, Credentials.Type.Alternate }));
        myTypeCombo.setSelectedItem(
                initialCredentials == null ? Credentials.Type.NtlmNative : initialCredentials.getType());
        myTypeCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                updateOnTypeChange();
                if (getCredentialsType() != Credentials.Type.NtlmNative) {
                    IdeFocusManager.findInstanceByComponent(myContentPane).requestFocus(myUsernameField, true);
                }
            }
        });
    } else {
        myTypeCombo.setModel(new DefaultComboBoxModel(
                new Credentials.Type[] { Credentials.Type.NtlmExplicit, Credentials.Type.Alternate }));
    }

    updateOnTypeChange();
}

From source file:ru.list.search.AssistantSearchEverywhereAction.java

License:Apache License

private void doNavigate(final int index, final int windowIndex) {
    final DataManager dataManager = DataManager.getInstance();
    if (dataManager == null)
        return;//from ww  w.  j a v a 2s . com
    final Project project = CommonDataKeys.PROJECT
            .getData(dataManager.getDataContext(getField().getTextEditor()));
    final Executor executor = ourShiftIsPressed.get() ? DefaultRunExecutor.getRunExecutorInstance()
            : ExecutorRegistry.getInstance().getExecutorById(ToolWindowId.DEBUG);
    assert project != null;
    final SearchListModel model = getModel();
    if (isMoreItem(index)) {
        final String pattern = myPopupField.getText();
        WidgetID wid = null;
        if (index == model.moreIndex.classes)
            wid = WidgetID.CLASSES;
        else if (index == model.moreIndex.files)
            wid = WidgetID.FILES;
        else if (index == model.moreIndex.settings)
            wid = WidgetID.SETTINGS;
        else if (index == model.moreIndex.actions)
            wid = WidgetID.ACTIONS;
        else if (index == model.moreIndex.symbols)
            wid = WidgetID.SYMBOLS;
        else if (index == model.moreIndex.runConfigurations)
            wid = WidgetID.RUN_CONFIGURATIONS;
        if (wid != null) {
            final WidgetID widgetID = wid;
            myCurrentWorker.doWhenProcessed(new Runnable() {
                @Override
                public void run() {
                    myCalcThread = new CalcThread(project, pattern, true);
                    myPopupActualWidth = 0;
                    myCurrentWorker = myCalcThread.insert(index, widgetID);
                }
            });

            return;
        }
    }
    final String pattern = getField().getText();
    final Object value = myList.getSelectedValue();
    saveHistory(project, pattern, value);
    IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(getField().getTextEditor());
    if (myPopup != null && myPopup.isVisible()) {
        myPopup.cancel();
    }

    if (value instanceof BooleanOptionDescription) {
        final BooleanOptionDescription option = (BooleanOptionDescription) value;
        option.setOptionState(!option.isOptionEnabled());
        myList.revalidate();
        myList.repaint();
        getField().requestFocus();
        return;
    }

    if (value instanceof OptionsTopHitProvider) {
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                getField().setText("#" + ((OptionsTopHitProvider) value).getId() + " ");
            }
        });
        return;
    }
    Runnable onDone = null;

    AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        if (value instanceof PsiElement) {
            onDone = new Runnable() {
                public void run() {
                    PsiElement psiElement = (PsiElement) value;
                    FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
                    AssistantUtils.openPsiElement(windowIndex, psiElement, fileEditorManager, myEditorWindow);
                }
            };
            return;
        } else if (isVirtualFile(value)) {
            onDone = new Runnable() {
                public void run() {
                    VirtualFile virtualFile = (VirtualFile) value;
                    FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
                    AssistantUtils.openFileInEditorGroup(windowIndex, virtualFile, fileEditorManager,
                            myEditorWindow);
                }
            };
            return;
        } else if (isActionValue(value) || isSetting(value) || isRunConfiguration(value)) {
            focusManager.requestDefaultFocus(true);
            final Component comp = myContextComponent;
            final AnActionEvent event = myActionEvent;
            IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
                @Override
                public void run() {
                    Component c = comp;
                    if (c == null) {
                        c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
                    }

                    if (isRunConfiguration(value)) {
                        ((ChooseRunConfigurationPopup.ItemWrapper) value).perform(project, executor,
                                dataManager.getDataContext(c));
                    } else {
                        GotoActionAction.openOptionOrPerformAction(value, pattern, project, c, event);
                        if (isToolWindowAction(value))
                            return;
                    }
                }
            });
            return;
        } else if (value instanceof Navigatable) {
            onDone = new Runnable() {
                @Override
                public void run() {
                    Navigatable navigatable = (Navigatable) value;
                    FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
                    AssistantUtils.openNavigatable(windowIndex, navigatable, fileEditorManager, myEditorWindow);
                }
            };
            return;
        }
    } finally {
        token.finish();
        final ActionCallback callback = onFocusLost();
        if (onDone != null) {
            callback.doWhenDone(onDone);
        }
    }
    focusManager.requestDefaultFocus(true);
}