Search in sources :

Example 91 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.

the class IntentionHintComponent method recreateMyPopup.

private void recreateMyPopup(@NotNull ListPopupStep step) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (myPopup != null) {
        Disposer.dispose(myPopup);
    }
    myPopup = JBPopupFactory.getInstance().createListPopup(step);
    if (myPopup instanceof WizardPopup) {
        Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_INTENTION_ACTIONS);
        for (Shortcut shortcut : shortcuts) {
            if (shortcut instanceof KeyboardShortcut) {
                KeyboardShortcut keyboardShortcut = (KeyboardShortcut) shortcut;
                if (keyboardShortcut.getSecondKeyStroke() == null) {
                    ((WizardPopup) myPopup).registerAction("activateSelectedElement", keyboardShortcut.getFirstKeyStroke(), new AbstractAction() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            myPopup.handleSelect(true);
                        }
                    });
                }
            }
        }
    }
    boolean committed = PsiDocumentManager.getInstance(myFile.getProject()).isCommitted(myEditor.getDocument());
    final PsiFile injectedFile = committed ? InjectedLanguageUtil.findInjectedPsiNoCommit(myFile, myEditor.getCaretModel().getOffset()) : null;
    final Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(myEditor, injectedFile);
    final ScopeHighlighter highlighter = new ScopeHighlighter(myEditor);
    final ScopeHighlighter injectionHighlighter = new ScopeHighlighter(injectedEditor);
    myPopup.addListener(new JBPopupListener.Adapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            highlighter.dropHighlight();
            injectionHighlighter.dropHighlight();
            myPopupShown = false;
        }
    });
    myPopup.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(@NotNull ListSelectionEvent e) {
            final Object source = e.getSource();
            highlighter.dropHighlight();
            injectionHighlighter.dropHighlight();
            if (source instanceof DataProvider) {
                final Object selectedItem = PlatformDataKeys.SELECTED_ITEM.getData((DataProvider) source);
                if (selectedItem instanceof IntentionActionWithTextCaching) {
                    final IntentionAction action = ((IntentionActionWithTextCaching) selectedItem).getAction();
                    if (action instanceof SuppressIntentionActionFromFix) {
                        if (injectedFile != null && ((SuppressIntentionActionFromFix) action).isShouldBeAppliedToInjectionHost() == ThreeState.NO) {
                            final PsiElement at = injectedFile.findElementAt(injectedEditor.getCaretModel().getOffset());
                            final PsiElement container = ((SuppressIntentionActionFromFix) action).getContainer(at);
                            if (container != null) {
                                injectionHighlighter.highlight(container, Collections.singletonList(container));
                            }
                        } else {
                            final PsiElement at = myFile.findElementAt(myEditor.getCaretModel().getOffset());
                            final PsiElement container = ((SuppressIntentionActionFromFix) action).getContainer(at);
                            if (container != null) {
                                highlighter.highlight(container, Collections.singletonList(container));
                            }
                        }
                    }
                }
            }
        }
    });
    if (myEditor.isOneLineMode()) {
        // hide popup on combobox popup show
        final Container ancestor = SwingUtilities.getAncestorOfClass(JComboBox.class, myEditor.getContentComponent());
        if (ancestor != null) {
            final JComboBox comboBox = (JComboBox) ancestor;
            myOuterComboboxPopupListener = new PopupMenuListenerAdapter() {

                @Override
                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    hide();
                }
            };
            comboBox.addPopupMenuListener(myOuterComboboxPopupListener);
        }
    }
    Disposer.register(this, myPopup);
    Disposer.register(myPopup, new Disposable() {

        @Override
        public void dispose() {
            ApplicationManager.getApplication().assertIsDispatchThread();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) PopupMenuEvent(javax.swing.event.PopupMenuEvent) PsiFile(com.intellij.psi.PsiFile) ScopeHighlighter(com.intellij.codeInsight.unwrap.ScopeHighlighter) PsiElement(com.intellij.psi.PsiElement) Disposable(com.intellij.openapi.Disposable) SuppressIntentionActionFromFix(com.intellij.codeInspection.SuppressIntentionActionFromFix) PopupMenuListenerAdapter(com.intellij.ui.PopupMenuListenerAdapter) WizardPopup(com.intellij.ui.popup.WizardPopup) ListSelectionListener(javax.swing.event.ListSelectionListener) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) BaseRefactoringIntentionAction(com.intellij.refactoring.BaseRefactoringIntentionAction) Editor(com.intellij.openapi.editor.Editor)

Example 92 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.

the class IntroduceParameterHandler method chooseMethodToIntroduceParameter.

private void chooseMethodToIntroduceParameter(final Editor editor, final List<PsiMethod> validEnclosingMethods, final PairConsumer<PsiMethod, PsiMethod> consumer) {
    final boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode();
    if (validEnclosingMethods.size() == 1 || unitTestMode) {
        final PsiMethod methodToIntroduceParameterTo = validEnclosingMethods.get(0);
        if (methodToIntroduceParameterTo.findDeepestSuperMethod() == null || unitTestMode) {
            consumer.consume(methodToIntroduceParameterTo, methodToIntroduceParameterTo);
            return;
        }
    }
    final JPanel panel = new JPanel(new BorderLayout());
    final JCheckBox superMethod = new JCheckBox("Refactor super method", true);
    superMethod.setMnemonic('U');
    panel.add(superMethod, BorderLayout.SOUTH);
    final JBList list = new JBList(validEnclosingMethods.toArray());
    list.setVisibleRowCount(5);
    list.setCellRenderer(new MethodCellRenderer());
    list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    final List<RangeHighlighter> highlighters = new ArrayList<>();
    final TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    list.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(final ListSelectionEvent e) {
            final PsiMethod selectedMethod = (PsiMethod) list.getSelectedValue();
            if (selectedMethod == null)
                return;
            dropHighlighters(highlighters);
            updateView(selectedMethod, editor, attributes, highlighters, superMethod);
        }
    });
    updateView(validEnclosingMethods.get(0), editor, attributes, highlighters, superMethod);
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(list);
    scrollPane.setBorder(null);
    panel.add(scrollPane, BorderLayout.CENTER);
    final List<Pair<ActionListener, KeyStroke>> keyboardActions = Collections.singletonList(Pair.<ActionListener, KeyStroke>create(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final PsiMethod methodToSearchIn = (PsiMethod) list.getSelectedValue();
            if (myEnclosingMethodsPopup != null && myEnclosingMethodsPopup.isVisible()) {
                myEnclosingMethodsPopup.cancel();
            }
            final PsiMethod methodToSearchFor = superMethod.isEnabled() && superMethod.isSelected() ? methodToSearchIn.findDeepestSuperMethod() : methodToSearchIn;
            consumer.consume(methodToSearchIn, methodToSearchFor);
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)));
    myEnclosingMethodsPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, list).setTitle("Introduce parameter to method").setMovable(false).setResizable(false).setRequestFocus(true).setKeyboardActions(keyboardActions).addListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            dropHighlighters(highlighters);
        }
    }).createPopup();
    myEnclosingMethodsPopup.showInBestPositionFor(editor);
}
Also used : ActionEvent(java.awt.event.ActionEvent) TIntArrayList(gnu.trove.TIntArrayList) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MethodCellRenderer(com.intellij.refactoring.ui.MethodCellRenderer) ListSelectionListener(javax.swing.event.ListSelectionListener) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) ActionListener(java.awt.event.ActionListener) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) JBList(com.intellij.ui.components.JBList) Pair(com.intellij.openapi.util.Pair)

Example 93 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.

the class JvmSmartStepIntoHandler method handleTargets.

protected final boolean handleTargets(SourcePosition position, DebuggerSession session, TextEditor fileEditor, List<SmartStepTarget> targets) {
    if (!targets.isEmpty()) {
        SmartStepTarget firstTarget = targets.get(0);
        if (targets.size() == 1) {
            doStepInto(session, Registry.is("debugger.single.smart.step.force"), firstTarget);
        } else {
            Editor editor = fileEditor.getEditor();
            PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(editor, targets, chosenTarget -> doStepInto(session, true, chosenTarget));
            ListPopupImpl popup = new ListPopupImpl(popupStep);
            DebuggerUIUtil.registerExtraHandleShortcuts(popup, XDebuggerActions.STEP_INTO, XDebuggerActions.SMART_STEP_INTO);
            popup.setAdText(DebuggerUIUtil.getSelectionShortcutsAdText(XDebuggerActions.STEP_INTO, XDebuggerActions.SMART_STEP_INTO));
            UIUtil.maybeInstall(popup.getList().getInputMap(JComponent.WHEN_FOCUSED), "selectNextRow", KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
            popup.addListSelectionListener(new ListSelectionListener() {

                public void valueChanged(ListSelectionEvent e) {
                    popupStep.getScopeHighlighter().dropHighlight();
                    if (!e.getValueIsAdjusting()) {
                        final SmartStepTarget selectedTarget = (SmartStepTarget) ((JBList) e.getSource()).getSelectedValue();
                        if (selectedTarget != null) {
                            highlightTarget(popupStep, selectedTarget);
                        }
                    }
                }
            });
            highlightTarget(popupStep, firstTarget);
            DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine());
        }
        return true;
    }
    return false;
}
Also used : ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBList(com.intellij.ui.components.JBList) Editor(com.intellij.openapi.editor.Editor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 94 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.

the class MavenRepositoriesConfigurable method configControls.

private void configControls() {
    myServiceList.setModel(myModel);
    myServiceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myAddButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final String value = (String) myServiceList.getSelectedValue();
            final String text = Messages.showInputDialog("Artifactory or Nexus Service URL", "Add Service URL", Messages.getQuestionIcon(), value == null ? "http://" : value, new URLInputVaslidator());
            if (StringUtil.isNotEmpty(text)) {
                myModel.add(text);
                myServiceList.setSelectedValue(text, true);
            }
        }
    });
    myEditButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final int index = myServiceList.getSelectedIndex();
            final String text = Messages.showInputDialog("Artifactory or Nexus Service URL", "Edit Service URL", Messages.getQuestionIcon(), myModel.getElementAt(index), new URLInputVaslidator());
            if (StringUtil.isNotEmpty(text)) {
                myModel.setElementAt(text, index);
            }
        }
    });
    ListUtil.addRemoveListener(myRemoveButton, myServiceList);
    ListUtil.disableWhenNoSelection(myTestButton, myServiceList);
    ListUtil.disableWhenNoSelection(myEditButton, myServiceList);
    myTestButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final String value = (String) myServiceList.getSelectedValue();
            if (value != null) {
                testServiceConnection(value);
            }
        }
    });
    myUpdateButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            doUpdateIndex();
        }
    });
    myIndicesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            updateButtonsState();
        }
    });
    myIndicesTable.addMouseMotionListener(new MouseMotionListener() {

        public void mouseDragged(MouseEvent e) {
        }

        public void mouseMoved(MouseEvent e) {
            int row = myIndicesTable.rowAtPoint(e.getPoint());
            if (row == -1)
                return;
            updateIndexHint(row);
        }
    });
    myIndicesTable.setDefaultRenderer(Object.class, new MyCellRenderer());
    myIndicesTable.setDefaultRenderer(MavenIndicesManager.IndexUpdatingState.class, new MyIconCellRenderer());
    myServiceList.getEmptyText().setText("No services");
    myIndicesTable.getEmptyText().setText("No remote repositories");
    updateButtonsState();
}
Also used : MouseEvent(java.awt.event.MouseEvent) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseMotionListener(java.awt.event.MouseMotionListener) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 95 with ListSelectionEvent

use of javax.swing.event.ListSelectionEvent in project intellij-community by JetBrains.

the class PaletteWindow method clearActiveItem.

public void clearActiveItem() {
    if (getActiveItem() == null)
        return;
    for (PaletteGroupHeader group : myGroupHeaders) {
        group.getComponentList().clearSelection();
    }
    ListSelectionEvent event = new ListSelectionEvent(this, -1, -1, false);
    notifySelectionChanged(event);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent)

Aggregations

ListSelectionEvent (javax.swing.event.ListSelectionEvent)129 ListSelectionListener (javax.swing.event.ListSelectionListener)120 ActionEvent (java.awt.event.ActionEvent)35 JScrollPane (javax.swing.JScrollPane)32 ActionListener (java.awt.event.ActionListener)29 JPanel (javax.swing.JPanel)28 MouseEvent (java.awt.event.MouseEvent)25 BorderLayout (java.awt.BorderLayout)21 JButton (javax.swing.JButton)20 Dimension (java.awt.Dimension)18 JLabel (javax.swing.JLabel)18 JBList (com.intellij.ui.components.JBList)16 MouseAdapter (java.awt.event.MouseAdapter)15 FlowLayout (java.awt.FlowLayout)11 Insets (java.awt.Insets)11 JList (javax.swing.JList)11 NotNull (org.jetbrains.annotations.NotNull)11 KeyAdapter (java.awt.event.KeyAdapter)10 KeyEvent (java.awt.event.KeyEvent)10 ArrayList (java.util.ArrayList)10