-
Notifications
You must be signed in to change notification settings - Fork 0
/
fill_up_tree.go
195 lines (163 loc) · 6.43 KB
/
fill_up_tree.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package probe
import (
"fmt"
"sort"
"strings"
gongtree_buttons "github.com/fullstack-lang/gongtree/go/buttons"
tree "github.com/fullstack-lang/gongtree/go/models"
gong_models "github.com/fullstack-lang/gong/go/models"
"github.com/fullstack-lang/gongfly/go/models"
)
func fillUpTree(
probe *Probe,
) {
// keep in memory which nodes have been unfolded / folded
expandedNodesSet := make(map[string]any, 0)
var _sidebar *tree.Tree
for __sidebar := range probe.treeStage.Trees {
_sidebar = __sidebar
}
if _sidebar != nil {
for _, node := range _sidebar.RootNodes {
if node.IsExpanded {
expandedNodesSet[strings.Fields(node.Name)[0]] = true
}
}
}
probe.treeStage.Reset()
// create tree
sidebar := (&tree.Tree{Name: "gong"}).Stage(probe.treeStage)
// collect all gong struct to construe the true
setOfGongStructs := *gong_models.GetGongstructInstancesSet[gong_models.GongStruct](probe.gongStage)
sliceOfGongStructsSorted := make([]*gong_models.GongStruct, len(setOfGongStructs))
i := 0
for k := range setOfGongStructs {
sliceOfGongStructsSorted[i] = k
i++
}
sort.Slice(sliceOfGongStructsSorted, func(i, j int) bool {
return sliceOfGongStructsSorted[i].Name < sliceOfGongStructsSorted[j].Name
})
for _, gongStruct := range sliceOfGongStructsSorted {
name := gongStruct.Name + " (" +
fmt.Sprintf("%d", probe.stageOfInterest.Map_GongStructName_InstancesNb[gongStruct.Name]) + ")"
nodeGongstruct := (&tree.Node{Name: name}).Stage(probe.treeStage)
nodeGongstruct.IsExpanded = false
if _, ok := expandedNodesSet[strings.Fields(name)[0]]; ok {
nodeGongstruct.IsExpanded = true
}
switch gongStruct.Name {
// insertion point
case "CivilianAirport":
nodeGongstruct.Name = name
set := *models.GetGongstructInstancesSet[models.CivilianAirport](probe.stageOfInterest)
for _civilianairport := range set {
nodeInstance := (&tree.Node{Name: _civilianairport.GetName()}).Stage(probe.treeStage)
nodeInstance.IsNodeClickable = true
nodeInstance.Impl = NewInstanceNodeCallback(_civilianairport, "CivilianAirport", probe)
nodeGongstruct.Children = append(nodeGongstruct.Children, nodeInstance)
}
case "Liner":
nodeGongstruct.Name = name
set := *models.GetGongstructInstancesSet[models.Liner](probe.stageOfInterest)
for _liner := range set {
nodeInstance := (&tree.Node{Name: _liner.GetName()}).Stage(probe.treeStage)
nodeInstance.IsNodeClickable = true
nodeInstance.Impl = NewInstanceNodeCallback(_liner, "Liner", probe)
nodeGongstruct.Children = append(nodeGongstruct.Children, nodeInstance)
}
case "Message":
nodeGongstruct.Name = name
set := *models.GetGongstructInstancesSet[models.Message](probe.stageOfInterest)
for _message := range set {
nodeInstance := (&tree.Node{Name: _message.GetName()}).Stage(probe.treeStage)
nodeInstance.IsNodeClickable = true
nodeInstance.Impl = NewInstanceNodeCallback(_message, "Message", probe)
nodeGongstruct.Children = append(nodeGongstruct.Children, nodeInstance)
}
case "OpsLine":
nodeGongstruct.Name = name
set := *models.GetGongstructInstancesSet[models.OpsLine](probe.stageOfInterest)
for _opsline := range set {
nodeInstance := (&tree.Node{Name: _opsline.GetName()}).Stage(probe.treeStage)
nodeInstance.IsNodeClickable = true
nodeInstance.Impl = NewInstanceNodeCallback(_opsline, "OpsLine", probe)
nodeGongstruct.Children = append(nodeGongstruct.Children, nodeInstance)
}
case "Radar":
nodeGongstruct.Name = name
set := *models.GetGongstructInstancesSet[models.Radar](probe.stageOfInterest)
for _radar := range set {
nodeInstance := (&tree.Node{Name: _radar.GetName()}).Stage(probe.treeStage)
nodeInstance.IsNodeClickable = true
nodeInstance.Impl = NewInstanceNodeCallback(_radar, "Radar", probe)
nodeGongstruct.Children = append(nodeGongstruct.Children, nodeInstance)
}
case "Satellite":
nodeGongstruct.Name = name
set := *models.GetGongstructInstancesSet[models.Satellite](probe.stageOfInterest)
for _satellite := range set {
nodeInstance := (&tree.Node{Name: _satellite.GetName()}).Stage(probe.treeStage)
nodeInstance.IsNodeClickable = true
nodeInstance.Impl = NewInstanceNodeCallback(_satellite, "Satellite", probe)
nodeGongstruct.Children = append(nodeGongstruct.Children, nodeInstance)
}
case "Scenario":
nodeGongstruct.Name = name
set := *models.GetGongstructInstancesSet[models.Scenario](probe.stageOfInterest)
for _scenario := range set {
nodeInstance := (&tree.Node{Name: _scenario.GetName()}).Stage(probe.treeStage)
nodeInstance.IsNodeClickable = true
nodeInstance.Impl = NewInstanceNodeCallback(_scenario, "Scenario", probe)
nodeGongstruct.Children = append(nodeGongstruct.Children, nodeInstance)
}
}
nodeGongstruct.IsNodeClickable = true
nodeGongstruct.Impl = NewTreeNodeImplGongstruct(gongStruct, probe)
// add add button
addButton := (&tree.Button{
Name: gongStruct.Name + " " + string(gongtree_buttons.BUTTON_add),
Icon: string(gongtree_buttons.BUTTON_add)}).Stage(probe.treeStage)
nodeGongstruct.Buttons = append(nodeGongstruct.Buttons, addButton)
addButton.Impl = NewButtonImplGongstruct(
gongStruct,
gongtree_buttons.BUTTON_add,
probe,
)
sidebar.RootNodes = append(sidebar.RootNodes, nodeGongstruct)
}
// Add a refresh button
nodeRefreshButton := (&tree.Node{Name: ""}).Stage(probe.treeStage)
sidebar.RootNodes = append(sidebar.RootNodes, nodeRefreshButton)
refreshButton := (&tree.Button{
Name: "RefreshButton" + " " + string(gongtree_buttons.BUTTON_refresh),
Icon: string(gongtree_buttons.BUTTON_refresh)}).Stage(probe.treeStage)
nodeRefreshButton.Buttons = append(nodeRefreshButton.Buttons, refreshButton)
refreshButton.Impl = NewButtonImplRefresh(probe)
probe.treeStage.Commit()
}
type InstanceNodeCallback[T models.Gongstruct] struct {
Instance *T
gongstructName string
probe *Probe
}
func NewInstanceNodeCallback[T models.Gongstruct](
instance *T,
gongstructName string,
probe *Probe) (
instanceNodeCallback *InstanceNodeCallback[T],
) {
instanceNodeCallback = new(InstanceNodeCallback[T])
instanceNodeCallback.probe = probe
instanceNodeCallback.gongstructName = gongstructName
instanceNodeCallback.Instance = instance
return
}
func (instanceNodeCallback *InstanceNodeCallback[T]) OnAfterUpdate(
gongtreeStage *tree.StageStruct,
stagedNode, frontNode *tree.Node) {
FillUpFormFromGongstruct(
instanceNodeCallback.Instance,
instanceNodeCallback.probe,
)
}