DefaultTreeModel (@NotNull ChangesGroupingPolicyFactory grouping) { MultiMap<ChangesBrowserNode.Tag, GenericChangesBrowserNode> groups = MultiMap.createLinked(); for (int i = 0; i < myChanges.size(); i++) { PresentableChange change = getPresentation(myChanges.get(i)); if (change == null) continue; FilePath filePath = change.getFilePath(); FileStatus fileStatus = change.getFileStatus(); ChangesBrowserNode.Tag tag = change.getTag(); groups.putValue(tag, new GenericChangesBrowserNode(filePath, fileStatus, i)); } MyTreeModelBuilder builder = new MyTreeModelBuilder(myProject, grouping); for (ChangesBrowserNode.Tag tag : groups.keySet()) { builder.setGenericNodes(groups.get(tag), tag); } return builder.build(); }