void (@NotNull final AbstractTreeStructure treeStructure, @NotNull final Runnable finish) { final SliceRootNode root = (SliceRootNode)treeStructure.getRootElement(); final Ref<Collection<PsiElement>> leafExpressions = Ref.create(null); final Map<SliceNode, Collection<PsiElement>> map = createMap(); String encouragementPiece = " " + LangBundle.message("progress.title.may.very.well.take.whole.day"); ProgressManager.getInstance().run(new Task.Backgroundable( root.getProject(), LangBundle.message("progress.title.expanding.all.nodes", encouragementPiece), true) { @Override public void run(@NotNull final ProgressIndicator indicator) { Collection<PsiElement> l = calcLeafExpressions(root, treeStructure, map); leafExpressions.set(l); } @Override public void onCancel() { finish.run(); } @Override public void onSuccess() { try { Collection<PsiElement> leaves = leafExpressions.get(); if (leaves == null) return; //cancelled if (leaves.isEmpty()) { Messages.showErrorDialog(LangBundle.message("dialog.message.unable.to.find.leaf.expressions.to.group.by"), LangBundle.message("dialog.title.cannot.group")); return; } groupByValues(leaves, root, map); } finally { finish.run(); } } }); }