Search in sources :

Example 11 with BaseListPopupStep

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

the class PluginDescriptorChooser method show.

public static void show(final Project project, final Editor editor, final PsiFile file, final Consumer<DomFileElement<IdeaPlugin>> consumer) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    assert module != null;
    List<DomFileElement<IdeaPlugin>> elements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, module.getModuleWithDependentsScope());
    elements = ContainerUtil.filter(elements, element -> {
        VirtualFile virtualFile = element.getFile().getVirtualFile();
        return virtualFile != null && ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile);
    });
    elements = findAppropriateIntelliJModule(module.getName(), elements);
    if (elements.isEmpty()) {
        HintManager.getInstance().showErrorHint(editor, "Cannot find plugin descriptor");
        return;
    }
    if (elements.size() == 1) {
        consumer.consume(elements.get(0));
        return;
    }
    final BaseListPopupStep<PluginDescriptorCandidate> popupStep = new BaseListPopupStep<PluginDescriptorCandidate>("Choose Plugin Descriptor", createCandidates(module, elements)) {

        @Override
        public boolean isSpeedSearchEnabled() {
            return true;
        }

        @Override
        public Icon getIconFor(PluginDescriptorCandidate candidate) {
            return candidate.getIcon();
        }

        @NotNull
        @Override
        public String getTextFor(PluginDescriptorCandidate candidate) {
            return candidate.getText();
        }

        @Nullable
        @Override
        public ListSeparator getSeparatorAbove(PluginDescriptorCandidate candidate) {
            final String separatorText = candidate.getSeparatorText();
            if (separatorText != null) {
                return new ListSeparator(separatorText);
            }
            return null;
        }

        @Override
        public PopupStep onChosen(PluginDescriptorCandidate selectedValue, boolean finalChoice) {
            consumer.consume(selectedValue.myDomFileElement);
            return FINAL_CHOICE;
        }
    };
    JBPopupFactory.getInstance().createListPopup(popupStep).showInBestPositionFor(editor);
}
Also used : IncludedXmlTag(com.intellij.xml.util.IncludedXmlTag) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) ContainerUtil(com.intellij.util.containers.ContainerUtil) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) Comparing(com.intellij.openapi.util.Comparing) Extensions(org.jetbrains.idea.devkit.dom.Extensions) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) EmptyIcon(com.intellij.util.ui.EmptyIcon) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) DomFileElement(com.intellij.util.xml.DomFileElement) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable) ModulesAlphaComparator(com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator) List(java.util.List) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) DomService(com.intellij.util.xml.DomService) Function(com.intellij.util.Function) PopupStep(com.intellij.openapi.ui.popup.PopupStep) HintManager(com.intellij.codeInsight.hint.HintManager) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) DomFileElement(com.intellij.util.xml.DomFileElement) Module(com.intellij.openapi.module.Module)

Example 12 with BaseListPopupStep

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

the class DetectionExcludesConfigurable method doAddAction.

private void doAddAction(AnActionButton button) {
    final List<FrameworkType> types = new ArrayList<>();
    for (FrameworkType type : FrameworkDetectorRegistry.getInstance().getFrameworkTypes()) {
        if (!isExcluded(type)) {
            types.add(type);
        }
    }
    Collections.sort(types, (o1, o2) -> o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName()));
    types.add(0, null);
    final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<FrameworkType>("Framework to Exclude", types) {

        @Override
        public Icon getIconFor(FrameworkType value) {
            return value != null ? value.getIcon() : null;
        }

        @NotNull
        @Override
        public String getTextFor(FrameworkType value) {
            return value != null ? value.getPresentableName() : "All Frameworks...";
        }

        @Override
        public boolean hasSubstep(FrameworkType selectedValue) {
            return selectedValue != null;
        }

        @Override
        public PopupStep onChosen(final FrameworkType frameworkType, boolean finalChoice) {
            if (frameworkType == null) {
                return doFinalStep(() -> chooseDirectoryAndAdd(null));
            } else {
                return addExcludedFramework(frameworkType);
            }
        }
    });
    final RelativePoint popupPoint = button.getPreferredPopupPoint();
    if (popupPoint != null) {
        popup.show(popupPoint);
    } else {
        popup.showInCenterOf(myMainPanel);
    }
}
Also used : FrameworkType(com.intellij.framework.FrameworkType) ArrayList(java.util.ArrayList) ListPopup(com.intellij.openapi.ui.popup.ListPopup) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Example 13 with BaseListPopupStep

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

the class BaseRunConfigurationAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    final RunnerAndConfigurationSettings existing = context.findExisting();
    if (existing == null) {
        final List<ConfigurationFromContext> producers = getConfigurationsFromContext(context);
        if (producers.isEmpty())
            return;
        if (producers.size() > 1) {
            final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
            Collections.sort(producers, ConfigurationFromContext.NAME_COMPARATOR);
            final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationFromContext>(ExecutionBundle.message("configuration.action.chooser.title"), producers) {

                @Override
                @NotNull
                public String getTextFor(final ConfigurationFromContext producer) {
                    return childActionName(producer.getConfigurationType(), producer.getConfiguration());
                }

                @Override
                public Icon getIconFor(final ConfigurationFromContext producer) {
                    return producer.getConfigurationType().getIcon();
                }

                @Override
                public PopupStep onChosen(final ConfigurationFromContext producer, final boolean finalChoice) {
                    perform(producer, context);
                    return FINAL_CHOICE;
                }
            });
            final InputEvent event = e.getInputEvent();
            if (event instanceof MouseEvent) {
                popup.show(new RelativePoint((MouseEvent) event));
            } else if (editor != null) {
                popup.showInBestPositionFor(editor);
            } else {
                popup.showInBestPositionFor(dataContext);
            }
        } else {
            perform(producers.get(0), context);
        }
        return;
    }
    perform(context);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) InputEvent(java.awt.event.InputEvent) Editor(com.intellij.openapi.editor.Editor)

Example 14 with BaseListPopupStep

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

the class SurroundElementWithAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final LayoutTreeComponent treeComponent = myArtifactEditor.getLayoutTreeComponent();
    final LayoutTreeSelection selection = treeComponent.getSelection();
    final CompositePackagingElement<?> parent = selection.getCommonParentElement();
    if (parent == null)
        return;
    final PackagingElementNode<?> parentNode = selection.getNodes().get(0).getParentNode();
    if (parentNode == null)
        return;
    if (!treeComponent.checkCanModifyChildren(parent, parentNode, selection.getNodes())) {
        return;
    }
    final CompositePackagingElementType<?>[] types = PackagingElementFactory.getInstance().getCompositeElementTypes();
    final List<PackagingElement<?>> selected = selection.getElements();
    if (types.length == 1) {
        surroundWith(types[0], parent, selected, treeComponent);
    } else {
        JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<CompositePackagingElementType>("Surround With...", types) {

            @Override
            public Icon getIconFor(CompositePackagingElementType aValue) {
                return aValue.getCreateElementIcon();
            }

            @NotNull
            @Override
            public String getTextFor(CompositePackagingElementType value) {
                return value.getPresentableName();
            }

            @Override
            public PopupStep onChosen(final CompositePackagingElementType selectedValue, boolean finalChoice) {
                return doFinalStep(() -> surroundWith(selectedValue, parent, selected, treeComponent));
            }
        }).showInBestPositionFor(e.getDataContext());
    }
}
Also used : LayoutTreeSelection(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeSelection) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) CompositePackagingElementType(com.intellij.packaging.elements.CompositePackagingElementType) PackagingElement(com.intellij.packaging.elements.PackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) LayoutTreeComponent(com.intellij.openapi.roots.ui.configuration.artifacts.LayoutTreeComponent)

Example 15 with BaseListPopupStep

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

the class StaticImportMethodQuestionAction method chooseAndImport.

private void chooseAndImport(final Editor editor, final Project project) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        doImport(myCandidates.get(0));
        return;
    }
    final BaseListPopupStep<T> step = new BaseListPopupStep<T>(getPopupTitle(), myCandidates) {

        @Override
        public boolean isAutoSelectionEnabled() {
            return false;
        }

        @Override
        public boolean isSpeedSearchEnabled() {
            return true;
        }

        @Override
        public PopupStep onChosen(T selectedValue, boolean finalChoice) {
            if (selectedValue == null) {
                return FINAL_CHOICE;
            }
            if (finalChoice) {
                return doFinalStep(() -> {
                    PsiDocumentManager.getInstance(project).commitAllDocuments();
                    LOG.assertTrue(selectedValue.isValid());
                    doImport(selectedValue);
                });
            }
            return AddImportAction.getExcludesStep(PsiUtil.getMemberQualifiedName(selectedValue), project);
        }

        @Override
        public boolean hasSubstep(T selectedValue) {
            return true;
        }

        @NotNull
        @Override
        public String getTextFor(T value) {
            return getElementPresentableName(value);
        }

        @Override
        public Icon getIconFor(T aValue) {
            return aValue.getIcon(0);
        }
    };
    final ListPopupImpl popup = new ListPopupImpl(step) {

        final PopupListElementRenderer rightArrow = new PopupListElementRenderer(this);

        @Override
        protected ListCellRenderer getListElementRenderer() {
            return new PsiElementListCellRenderer<T>() {

                public String getElementText(T element) {
                    return getElementPresentableName(element);
                }

                public String getContainerText(final T element, final String name) {
                    return PsiClassListCellRenderer.getContainerTextStatic(element);
                }

                public int getIconFlags() {
                    return 0;
                }

                @Nullable
                @Override
                protected TextAttributes getNavigationItemAttributes(Object value) {
                    TextAttributes attrs = super.getNavigationItemAttributes(value);
                    if (value instanceof PsiDocCommentOwner && !((PsiDocCommentOwner) value).isDeprecated()) {
                        PsiClass psiClass = ((T) value).getContainingClass();
                        if (psiClass != null && psiClass.isDeprecated()) {
                            return TextAttributes.merge(attrs, super.getNavigationItemAttributes(psiClass));
                        }
                    }
                    return attrs;
                }

                @Override
                protected DefaultListCellRenderer getRightCellRenderer(final Object value) {
                    final DefaultListCellRenderer moduleRenderer = super.getRightCellRenderer(value);
                    return new DefaultListCellRenderer() {

                        @Override
                        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                            JPanel panel = new JPanel(new BorderLayout());
                            if (moduleRenderer != null) {
                                Component moduleComponent = moduleRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                                if (!isSelected) {
                                    moduleComponent.setBackground(getBackgroundColor(value));
                                }
                                panel.add(moduleComponent, BorderLayout.CENTER);
                            }
                            rightArrow.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                            Component rightArrowComponent = rightArrow.getNextStepLabel();
                            panel.add(rightArrowComponent, BorderLayout.EAST);
                            return panel;
                        }
                    };
                }
            };
        }
    };
    popup.showInBestPositionFor(editor);
}
Also used : PopupListElementRenderer(com.intellij.ui.popup.list.PopupListElementRenderer) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiElementListCellRenderer(com.intellij.ide.util.PsiElementListCellRenderer)

Aggregations

BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)33 PopupStep (com.intellij.openapi.ui.popup.PopupStep)18 NotNull (org.jetbrains.annotations.NotNull)15 ListPopup (com.intellij.openapi.ui.popup.ListPopup)10 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)10 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Project (com.intellij.openapi.project.Project)7 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)5 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiFile (com.intellij.psi.PsiFile)4 Nullable (org.jetbrains.annotations.Nullable)3 AllIcons (com.intellij.icons.AllIcons)2 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 Editor (com.intellij.openapi.editor.Editor)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2