ServiceViewModel (@NotNull List<ServiceViewItem> items, @Nullable ServiceViewContributor<?> contributor, @NotNull ServiceModel model, @NotNull ServiceModelFilter modelFilter, @Nullable ServiceViewFilter parentFilter) { if (contributor != null && items.size() > 1) { ServiceViewItem contributorRoot = null; for (ServiceViewItem root : model.getRoots()) { if (contributor == root.getContributor()) { contributorRoot = root; break; } } if (contributorRoot != null && contributorRoot.getChildren().equals(items)) { return new ContributorModel(model, modelFilter, contributor, parentFilter); } } if (items.size() == 1) { ServiceViewItem item = items.get(0); if (item instanceof ContributorNode) { return new ContributorModel(model, modelFilter, item.getContributor(), parentFilter); } if (item instanceof ServiceGroupNode) { AtomicReference<ServiceGroupNode> ref = new AtomicReference<>((ServiceGroupNode)item); return new GroupModel(model, modelFilter, ref, parentFilter); } else if (isSingleService(item)) { AtomicReference<ServiceViewItem> ref = new AtomicReference<>(item); return new SingeServiceModel(model, modelFilter, ref, parentFilter); } } return new ServiceListModel(model, modelFilter, items, parentFilter); }