001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thierry Delprat 016 */ 017package org.nuxeo.apidoc.api; 018 019import java.util.ArrayList; 020import java.util.Collections; 021import java.util.List; 022 023import org.nuxeo.apidoc.snapshot.DistributionSnapshot; 024 025public class BundleGroupTreeHelper { 026 027 protected final DistributionSnapshot distrib; 028 029 public BundleGroupTreeHelper(DistributionSnapshot distrib) { 030 this.distrib = distrib; 031 } 032 033 protected void browseBundleGroup(BundleGroup group, int level, List<BundleGroupFlatTree> tree) { 034 BundleGroupFlatTree info = new BundleGroupFlatTree(group, level); 035 tree.add(info); 036 List<BundleGroup> subGroups = group.getSubGroups(); 037 Collections.sort(subGroups, new NuxeoArtifactComparator()); 038 for (BundleGroup subGroup : subGroups) { 039 browseBundleGroup(subGroup, level + 1, tree); 040 } 041 } 042 043 public List<BundleGroupFlatTree> getBundleGroupSubTree(String groupId) { 044 BundleGroup group = distrib.getBundleGroup(groupId); 045 List<BundleGroupFlatTree> tree = new ArrayList<BundleGroupFlatTree>(); 046 browseBundleGroup(group, 0, tree); 047 return tree; 048 } 049 050 public List<BundleGroupFlatTree> getBundleGroupTree() { 051 List<BundleGroupFlatTree> tree = new ArrayList<BundleGroupFlatTree>(); 052 053 List<BundleGroup> bgroups = distrib.getBundleGroups(); 054 Collections.sort(bgroups, new NuxeoArtifactComparator()); 055 for (BundleGroup group : bgroups) { 056 browseBundleGroup(group, 0, tree); 057 } 058 return tree; 059 } 060 061}