Search in sources :

Example 6 with PopupStep

use of com.intellij.openapi.ui.popup.PopupStep 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 7 with PopupStep

use of com.intellij.openapi.ui.popup.PopupStep 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 8 with PopupStep

use of com.intellij.openapi.ui.popup.PopupStep in project android by JetBrains.

the class ModuleDependenciesPanel method createTableWithButtons.

@NotNull
private JComponent createTableWithButtons() {
    myEntryTable.getSelectionModel().addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            return;
        }
        updateButtons();
    });
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable);
    decorator.setAddAction(button -> {
        ImmutableList<PopupAction> popupActions = ImmutableList.of(new PopupAction(AndroidIcons.MavenLogo, 1, "Library dependency") {

            @Override
            public void run() {
                addExternalDependency();
            }
        }, new PopupAction(PlatformIcons.LIBRARY_ICON, 2, "Jar dependency") {

            @Override
            public void run() {
                addFileDependency();
            }
        }, new PopupAction(AllIcons.Nodes.Module, 3, "Module dependency") {

            @Override
            public void run() {
                addModuleDependency();
            }
        });
        final JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<PopupAction>(null, popupActions) {

            @Override
            public Icon getIconFor(PopupAction value) {
                return value.myIcon;
            }

            @Override
            public boolean hasSubstep(PopupAction value) {
                return false;
            }

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

            @Override
            public PopupStep onChosen(final PopupAction value, final boolean finalChoice) {
                return doFinalStep(value);
            }

            @Override
            @NotNull
            public String getTextFor(PopupAction value) {
                return "&" + value.myIndex + "  " + value.myTitle;
            }
        });
        popup.show(button.getPreferredPopupPoint());
    });
    decorator.setRemoveAction(button -> removeSelectedItems());
    decorator.setMoveUpAction(button -> moveSelectedRows(-1));
    decorator.setMoveDownAction(button -> moveSelectedRows(+1));
    final JPanel panel = decorator.createPanel();
    myRemoveButton = ToolbarDecorator.findRemoveButton(panel);
    return panel;
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PopupStep

use of com.intellij.openapi.ui.popup.PopupStep 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 10 with PopupStep

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

the class DependenciesConfigurable method addItem.

private void addItem(AnActionButton button) {
    initPopupActions();
    final JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AddItemPopupAction>(FlexBundle.message("add.dependency.popup.title"), myPopupActions) {

        @Override
        public Icon getIconFor(AddItemPopupAction aValue) {
            return aValue.getIcon();
        }

        @Override
        public boolean hasSubstep(AddItemPopupAction selectedValue) {
            return selectedValue.hasSubStep();
        }

        public boolean isMnemonicsNavigationEnabled() {
            return true;
        }

        public PopupStep onChosen(final AddItemPopupAction selectedValue, final boolean finalChoice) {
            if (selectedValue.hasSubStep()) {
                return selectedValue.createSubStep();
            }
            return doFinalStep(() -> selectedValue.run());
        }

        @NotNull
        public String getTextFor(AddItemPopupAction value) {
            return "&" + value.getIndex() + "  " + value.getTitle();
        }
    });
    popup.show(button.getPreferredPopupPoint());
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Aggregations

PopupStep (com.intellij.openapi.ui.popup.PopupStep)19 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)18 NotNull (org.jetbrains.annotations.NotNull)14 ListPopup (com.intellij.openapi.ui.popup.ListPopup)7 RelativePoint (com.intellij.ui.awt.RelativePoint)6 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)5 Project (com.intellij.openapi.project.Project)4 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiFile (com.intellij.psi.PsiFile)3 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)3 Nullable (org.jetbrains.annotations.Nullable)3 AllIcons (com.intellij.icons.AllIcons)2 Editor (com.intellij.openapi.editor.Editor)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 javax.swing (javax.swing)2 HintManager (com.intellij.codeInsight.hint.HintManager)1