Sub convertToHierarchy(data As List) As Map
Dim rootNode As Map
rootNode.Initialize
rootNode.Put("root",CreateMap())
For Each path As String In data
buildNodeRecursive(rootNode, Regex.Split("\.",path), 0)
Next
Return rootNode
End Sub
Sub buildNodeRecursive(node As Map, path As List, idx As Int)
If idx < path.Size Then
Dim item As String = path.Get(idx)
If node.ContainsKey(item) = False Then node.Put(item,CreateMap())
buildNodeRecursive(node.Get(item), path, idx + 1)
End If
End Sub
Sub PopulateTreeview()
vwTree.ClearSelection
vwTree.Root.Children.Clear
Dim data As List
data.Initialize
Dim Cursor1 As ResultSet
Cursor1 = DB.ExecQuery("select path from series")
Do While Cursor1.NextRow
data.Add(Cursor1.GetString2(0))
Loop
data.Sort(True)
Dim nodes As Map = convertToHierarchy(data)
Dim Parent As TreeItem
Parent = vwTree.Root
Dim t1 As Long = DateTime.Now
For Each k As String In nodes.Keys
Dim tti As TreeItem
tti.Initialize("tti", k)
Parent.Children.Add(tti)
BuildTree(nodes.Get(k),tti)
Next
Dim t2 As Long = DateTime.Now
Dim d As Long = t2-t1
Log("Response time: " & d )
Cursor1.Close
End Sub
Sub BuildTree(m As Map, parent As TreeItem)
For Each k As String In m.Keys
Dim ti As TreeItem
ti.Initialize("", k)
parent.Children.Add(ti)
BuildTree(m.Get(k), ti)
Next
End Sub