Search in sources :

Example 11 with JBPopupFactory

use of com.intellij.openapi.ui.popup.JBPopupFactory in project intellij-plugins by JetBrains.

the class CucumberCreateStepFixBase method applyFix.

public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
    final GherkinStep step = (GherkinStep) descriptor.getPsiElement();
    final GherkinFile featureFile = (GherkinFile) step.getContainingFile();
    // TODO + step defs pairs from other content roots
    final List<Pair<PsiFile, BDDFrameworkType>> pairs = ContainerUtil.newArrayList(getStepDefinitionContainers(featureFile));
    if (!pairs.isEmpty()) {
        pairs.add(0, null);
        final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
        final ListPopup popupStep = popupFactory.createListPopup(new BaseListPopupStep<Pair<PsiFile, BDDFrameworkType>>(CucumberBundle.message("choose.step.definition.file"), ContainerUtil.newArrayList(pairs)) {

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

            @NotNull
            @Override
            public String getTextFor(Pair<PsiFile, BDDFrameworkType> value) {
                if (value == null) {
                    return CucumberBundle.message("create.new.file");
                }
                final VirtualFile file = value.getFirst().getVirtualFile();
                assert file != null;
                CucumberStepsIndex stepsIndex = CucumberStepsIndex.getInstance(value.getFirst().getProject());
                StepDefinitionCreator stepDefinitionCreator = stepsIndex.getExtensionMap().get(value.getSecond()).getStepDefinitionCreator();
                return stepDefinitionCreator.getStepDefinitionFilePath(value.getFirst());
            }

            @Override
            public Icon getIconFor(Pair<PsiFile, BDDFrameworkType> value) {
                return value == null ? AllIcons.Actions.CreateFromUsage : value.getFirst().getIcon(0);
            }

            @Override
            public PopupStep onChosen(final Pair<PsiFile, BDDFrameworkType> selectedValue, boolean finalChoice) {
                return doFinalStep(() -> createStepOrSteps(step, selectedValue));
            }
        });
        if (!ApplicationManager.getApplication().isUnitTestMode()) {
            popupStep.showCenteredInCurrentWindow(step.getProject());
        } else {
            createStepOrSteps(step, pairs.get(1));
        }
    } else {
        createFileOrStepDefinition(step, null);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) ListPopup(com.intellij.openapi.ui.popup.ListPopup) NotNull(org.jetbrains.annotations.NotNull) CucumberStepsIndex(org.jetbrains.plugins.cucumber.steps.CucumberStepsIndex) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) PsiFile(com.intellij.psi.PsiFile) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile) Pair(com.intellij.openapi.util.Pair)

Example 12 with JBPopupFactory

use of com.intellij.openapi.ui.popup.JBPopupFactory in project intellij-plugins by StepicOrg.

the class DownloadSubmission method showPopup.

private void showPopup(@NotNull Project project, @NotNull StepNode stepNode, @NotNull List<Submission> submissions) {
    JBPopupFactory popupFactory = JBPopupFactory.getInstance();
    PopupChooserBuilder builder;
    if (!submissions.isEmpty()) {
        JList<SubmissionDecorator> list;
        List<SubmissionDecorator> submissionDecorators = submissions.stream().map(SubmissionDecorator::new).collect(Collectors.toList());
        list = new JList<>(submissionDecorators.toArray(new SubmissionDecorator[submissionDecorators.size()]));
        builder = popupFactory.createListPopupBuilder(list).addListener(new Listener(list, project, stepNode));
    } else {
        JList<String> emptyList = new JList<>(new String[] { "Empty" });
        builder = popupFactory.createListPopupBuilder(emptyList);
    }
    builder = builder.setTitle("Choose submission");
    JBPopup popup = builder.createPopup();
    popup.showCenteredInCurrentWindow(project);
}
Also used : JBPopupListener(com.intellij.openapi.ui.popup.JBPopupListener) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Aggregations

JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)12 ListPopup (com.intellij.openapi.ui.popup.ListPopup)5 DataContext (com.intellij.openapi.actionSystem.DataContext)3 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)3 Balloon (com.intellij.openapi.ui.popup.Balloon)3 RelativePoint (com.intellij.ui.awt.RelativePoint)3 JBPopupListener (com.intellij.openapi.ui.popup.JBPopupListener)2 NotNull (org.jetbrains.annotations.NotNull)2 BeforeRunTask (com.intellij.execution.BeforeRunTask)1 BeforeRunTaskProvider (com.intellij.execution.BeforeRunTaskProvider)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 UnknownRunConfiguration (com.intellij.execution.configurations.UnknownRunConfiguration)1 Notification (com.intellij.notification.Notification)1 Disposable (com.intellij.openapi.Disposable)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1 BalloonBuilder (com.intellij.openapi.ui.popup.BalloonBuilder)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1