ActionCallback (@NotNull RunAnythingGroup group, @NotNull RunAnythingSearchListModel listModel, @NotNull DataContext dataContext, @NotNull String pattern, int index, int itemsNumberToInsert) { ActionCallback callback = new ActionCallback(); ApplicationManager.getApplication().executeOnPooledThread(() -> { List<RunAnythingItem> items = ContainerUtil.filterIsInstance(listModel.getItems(), RunAnythingItem.class); RunAnythingGroup.SearchResult result; try { result = ProgressManager.getInstance().runProcess( () -> group.getItems(dataContext, items, trimHelpPattern(pattern), itemsNumberToInsert == -1 ? group.getMaxItemsToInsert() : itemsNumberToInsert), new EmptyProgressIndicator()); } catch (ProcessCanceledException e) { callback.setRejected(); return; } ApplicationManager.getApplication().invokeLater(() -> { int shift = 0; int i = index + 1; for (Object o : result) { listModel.add(i, o); shift++; i++; } listModel.shiftIndexes(index, shift); if (!result.isNeedMore()) { group.resetMoreIndex(); } callback.setDone(); }); }); return callback; }