final List<Pair<PsiFile, BDDFrameworkType>> pairs = ContainerUtil.newArrayList(pairSortedSet);
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(new Runnable() {
public void run() {
createStepOrSteps(step, selectedValue != null ? selectedValue.first : null);
}
});
}
});
if (!ApplicationManager.getApplication().isUnitTestMode()) {
popupStep.showCenteredInCurrentWindow(step.getProject());
} else {
new WriteCommandAction.Simple(step.getProject()) {
@Override
protected void run() throws Throwable {
createStepOrSteps(step, pairs.get(1).getFirst());