}
}
for (Iterator itItems = getModel().getItems(itemType); itItems.hasNext();)
{
Item item = (Item) itItems.next();
if (filterMgr == null || filterMgr.acceptsItem(item))
{
if (ungroupedItems == null)
ungroupedItems = new ArrayList();
ungroupedItems.add(item);
}
}
if (ungroupedItems != null)
{
if (showGroups)
{
// Iterate the items and store the grouped one in the group table
for (Iterator it = ungroupedItems.iterator(); it.hasNext();)
{
Item item = (Item) it.next();
String group = item.getFunctionalGroup();
if (group != null)
{
// Remove the item from the lis of ungrouped items
it.remove();
if (groupTable == null)
{
groupTable = new HashMap();
}
List items = (List) groupTable.get(group);
if (items == null)
{
items = new ArrayList();
groupTable.put(group, items);
}
items.add(item);
}
}
}
}
}
if (ungroupedItems != null && ungroupedItems.size() > 0)
{
// Add the ungrouped items to the model node first
// Sort
Collections.sort(ungroupedItems, itemComparator);
// Recurse down
int nItems = ungroupedItems.size();
for (int iItems = 0; iItems < nItems; ++iItems)
{
Item item = (Item) ungroupedItems.get(iItems);
ItemNode itemNode = new ItemNode(item, this);
addChild(itemNode);
itemNode.addChildObjects();
}
}
if (groupTable != null)
{
// Add the item groups
// Sort the groups
List groups = CollectionUtil.iteratorToArrayList(groupTable.keySet().iterator());
Collections.sort(groups);
// Add the groups to the model node in sorted order
int nGroups = groups.size();
for (int iGroups = 0; iGroups < nGroups; ++iGroups)
{
String group = (String) groups.get(iGroups);
List items = (List) groupTable.get(group);
GroupNode groupNode = new GroupNode(group, this);
addChild(groupNode);
Collections.sort(items, itemComparator);
int nItems = items.size();
for (int iItems = 0; iItems < nItems; ++iItems)
{
Item item = (Item) items.get(iItems);
ItemNode itemNode = new ItemNode(item, groupNode);
groupNode.addChild(itemNode);
itemNode.addChildObjects();