List<DefaultMutableTreeNode> (@NotNull final Project project, @NotNull List<? extends VcsFullCommitDetails> commits, int commitsNum) { Function<VcsFullCommitDetails, DefaultMutableTreeNode> commitToNode = commit -> new CommitNode(project, commit); List<DefaultMutableTreeNode> childrenToShown = new ArrayList<>(); for (int i = 0; i < commits.size(); ++i) { if (i >= commitsNum) { @NonNls final VcsLinkedTextComponent moreCommitsLink = new VcsLinkedTextComponent(HtmlChunk.link("loadMore", "...").toString(), (sourceNode, event) -> { TreeNode parent = sourceNode.getParent(); if (parent instanceof RepositoryNode) { addMoreCommits((RepositoryNode)parent); } }); childrenToShown.add(new TextWithLinkNode(moreCommitsLink)); break; } childrenToShown.add(commitToNode.fun(commits.get(i))); } return childrenToShown; }