Search in sources :

Example 21 with PopupChooserBuilder

use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.

the class CreateFromUsageBaseFix method chooseTargetClass.

private void chooseTargetClass(List<PsiClass> classes, final Editor editor) {
    final PsiClass firstClass = classes.get(0);
    final Project project = firstClass.getProject();
    final JList list = new JBList(classes);
    PsiElementListCellRenderer renderer = new PsiClassListCellRenderer();
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setCellRenderer(renderer);
    final PopupChooserBuilder builder = new PopupChooserBuilder(list);
    renderer.installSpeedSearch(builder);
    final PsiClass preselection = AnonymousTargetClassPreselectionUtil.getPreselection(classes, firstClass);
    if (preselection != null) {
        list.setSelectedValue(preselection, true);
    }
    Runnable runnable = () -> {
        int index = list.getSelectedIndex();
        if (index < 0)
            return;
        final PsiClass aClass = (PsiClass) list.getSelectedValue();
        AnonymousTargetClassPreselectionUtil.rememberSelection(aClass, firstClass);
        CommandProcessor.getInstance().executeCommand(project, () -> doInvoke(project, aClass), getText(), null);
    };
    builder.setTitle(QuickFixBundle.message("target.class.chooser.title")).setItemChoosenCallback(runnable).createPopup().showInBestPositionFor(editor);
}
Also used : Project(com.intellij.openapi.project.Project) JBList(com.intellij.ui.components.JBList) PsiClassListCellRenderer(com.intellij.ide.util.PsiClassListCellRenderer) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) PsiElementListCellRenderer(com.intellij.ide.util.PsiElementListCellRenderer)

Example 22 with PopupChooserBuilder

use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.

the class GroovyStaticImportMethodFix method chooseAndImport.

private void chooseAndImport(Editor editor) {
    final JList list = new JBList(getCandidates().toArray(new PsiMethod[getCandidates().size()]));
    list.setCellRenderer(new MethodCellRenderer(true));
    new PopupChooserBuilder(list).setTitle(QuickFixBundle.message("static.import.method.choose.method.to.import")).setMovable(true).setItemChoosenCallback(() -> {
        PsiMethod selectedValue = (PsiMethod) list.getSelectedValue();
        if (selectedValue == null)
            return;
        LOG.assertTrue(selectedValue.isValid());
        doImport(selectedValue);
    }).createPopup().showInBestPositionFor(editor);
}
Also used : JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) MethodCellRenderer(com.intellij.ide.util.MethodCellRenderer)

Example 23 with PopupChooserBuilder

use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.

the class GrCreateFromUsageBaseFix method chooseClass.

private void chooseClass(List<PsiClass> classes, Editor editor) {
    final Project project = classes.get(0).getProject();
    final JList list = new JBList(classes);
    PsiElementListCellRenderer renderer = new PsiClassListCellRenderer();
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setCellRenderer(renderer);
    final PopupChooserBuilder builder = new PopupChooserBuilder(list);
    renderer.installSpeedSearch(builder);
    Runnable runnable = () -> {
        int index = list.getSelectedIndex();
        if (index < 0)
            return;
        final PsiClass aClass = (PsiClass) list.getSelectedValue();
        CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> invokeImpl(project, aClass)), getText(), null);
    };
    builder.setTitle(QuickFixBundle.message("target.class.chooser.title")).setItemChoosenCallback(runnable).createPopup().showInBestPositionFor(editor);
}
Also used : Project(com.intellij.openapi.project.Project) JBList(com.intellij.ui.components.JBList) PsiClassListCellRenderer(com.intellij.ide.util.PsiClassListCellRenderer) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) PsiElementListCellRenderer(com.intellij.ide.util.PsiElementListCellRenderer)

Example 24 with PopupChooserBuilder

use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.

the class ExternalProjectPathField method createPanel.

@NotNull
public static MyPathAndProjectButtonPanel createPanel(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) {
    final EditorTextField textField = createTextField(project, externalSystemId);
    final FixedSizeButton selectRegisteredProjectButton = new FixedSizeButton();
    selectRegisteredProjectButton.setIcon(AllIcons.Actions.Module);
    String tooltipText = ExternalSystemBundle.message("run.configuration.tooltip.choose.registered.project", externalSystemId.getReadableName());
    selectRegisteredProjectButton.setToolTipText(tooltipText);
    selectRegisteredProjectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final Ref<JBPopup> popupRef = new Ref<>();
            final Tree tree = buildRegisteredProjectsTree(project, externalSystemId);
            tree.setBorder(IdeBorderFactory.createEmptyBorder(8));
            Runnable treeSelectionCallback = () -> {
                TreePath path = tree.getSelectionPath();
                if (path != null) {
                    Object lastPathComponent = path.getLastPathComponent();
                    if (lastPathComponent instanceof ExternalSystemNode) {
                        Object e1 = ((ExternalSystemNode) lastPathComponent).getDescriptor().getElement();
                        if (e1 instanceof ExternalProjectPojo) {
                            ExternalProjectPojo pojo = (ExternalProjectPojo) e1;
                            textField.setText(pojo.getPath());
                            Editor editor = textField.getEditor();
                            if (editor != null) {
                                collapseIfPossible(editor, externalSystemId, project);
                            }
                        }
                    }
                }
                popupRef.get().closeOk(null);
            };
            JBPopup popup = new PopupChooserBuilder(tree).setTitle(ExternalSystemBundle.message("run.configuration.title.choose.registered.project", externalSystemId.getReadableName())).setResizable(true).setItemChoosenCallback(treeSelectionCallback).setAutoselectOnMouseMove(true).setCloseOnEnter(false).createPopup();
            popupRef.set(popup);
            popup.showUnderneathOf(selectRegisteredProjectButton);
        }
    });
    return new MyPathAndProjectButtonPanel(textField, selectRegisteredProjectButton);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ExternalSystemNode(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemNode) Ref(com.intellij.openapi.util.Ref) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) EditorTextField(com.intellij.ui.EditorTextField) Tree(com.intellij.ui.treeStructure.Tree) ExternalSystemTasksTree(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTree) Editor(com.intellij.openapi.editor.Editor) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with PopupChooserBuilder

use of com.intellij.openapi.ui.popup.PopupChooserBuilder in project intellij-community by JetBrains.

the class ImplementAbstractMethodHandler method invoke.

public void invoke() {
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    final PsiElement[][] result = new PsiElement[1][];
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> {
        final PsiClass psiClass = myMethod.getContainingClass();
        if (!psiClass.isValid())
            return;
        if (!psiClass.isEnum()) {
            result[0] = getClassImplementations(psiClass);
        } else {
            final List<PsiElement> enumConstants = new ArrayList<>();
            for (PsiField field : psiClass.getFields()) {
                if (field instanceof PsiEnumConstant) {
                    final PsiEnumConstantInitializer initializingClass = ((PsiEnumConstant) field).getInitializingClass();
                    if (initializingClass != null) {
                        PsiMethod method = initializingClass.findMethodBySignature(myMethod, true);
                        if (method == null || !method.getContainingClass().equals(initializingClass)) {
                            enumConstants.add(initializingClass);
                        }
                    } else {
                        enumConstants.add(field);
                    }
                }
            }
            result[0] = PsiUtilCore.toPsiElementArray(enumConstants);
        }
    }), CodeInsightBundle.message("intention.implement.abstract.method.searching.for.descendants.progress"), true, myProject);
    if (result[0] == null)
        return;
    if (result[0].length == 0) {
        Messages.showMessageDialog(myProject, CodeInsightBundle.message("intention.implement.abstract.method.error.no.classes.message"), CodeInsightBundle.message("intention.implement.abstract.method.error.no.classes.title"), Messages.getInformationIcon());
        return;
    }
    if (result[0].length == 1) {
        implementInClass(new Object[] { result[0][0] });
        return;
    }
    final MyPsiElementListCellRenderer elementListCellRenderer = new MyPsiElementListCellRenderer();
    elementListCellRenderer.sort(result[0]);
    myList = new JBList(result[0]);
    myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final Runnable runnable = () -> {
        int index = myList.getSelectedIndex();
        if (index < 0)
            return;
        implementInClass(myList.getSelectedValues());
    };
    myList.setCellRenderer(elementListCellRenderer);
    final PopupChooserBuilder builder = new PopupChooserBuilder(myList);
    elementListCellRenderer.installSpeedSearch(builder);
    builder.setTitle(CodeInsightBundle.message("intention.implement.abstract.method.class.chooser.title")).setItemChoosenCallback(runnable).createPopup().showInBestPositionFor(myEditor);
}
Also used : JBList(com.intellij.ui.components.JBList) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Aggregations

PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)31 JBList (com.intellij.ui.components.JBList)24 JBPopup (com.intellij.openapi.ui.popup.JBPopup)15 PsiElementListCellRenderer (com.intellij.ide.util.PsiElementListCellRenderer)5 Project (com.intellij.openapi.project.Project)4 Ref (com.intellij.openapi.util.Ref)4 RelativePoint (com.intellij.ui.awt.RelativePoint)4 NotNull (org.jetbrains.annotations.NotNull)4 MethodCellRenderer (com.intellij.ide.util.MethodCellRenderer)3 PsiClassListCellRenderer (com.intellij.ide.util.PsiClassListCellRenderer)3 PsiElement (com.intellij.psi.PsiElement)3 JBLabel (com.intellij.ui.components.JBLabel)3 Editor (com.intellij.openapi.editor.Editor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)2 TreeTableView (com.intellij.ui.dualView.TreeTableView)2 UsageView (com.intellij.usages.UsageView)2 Alarm (com.intellij.util.Alarm)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 ColumnInfo (com.intellij.util.ui.ColumnInfo)2