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
|
// a table is a grid with X columns and 1 row of header names
// that means that the toolkits might be able to sort the table
// pushing traditional application development to the display
// is that a good idea?
package gui
import (
"go.wit.com/lib/protobuf/guipb"
"go.wit.com/log"
"go.wit.com/widget"
"google.golang.org/protobuf/types/known/anypb"
)
func (n *Node) findInTablePB(pb *guipb.Table, id int) *guipb.Widget {
if n.tablepb == nil {
log.Info("SOMETHING WAS WRONG. gui.findInTablePB() n.tablepb == nil for widget id", id)
return nil
}
log.Info("SOMETHING WAS WRONG. gui.findInTablePB() didn't find widget id", id)
return nil
}
func (n *Node) isWidgetInTable(id int) (bool, *guipb.Table, *guipb.Widget) {
if n.id == 0 {
return false, nil, nil
}
if n.progname == "gridtablePB" {
w := n.findInTablePB(n.tablepb, id)
return true, n.tablepb, w
}
if n.parent == nil {
return false, nil, nil
}
return n.parent.isWidgetInTable(id)
}
func (parent *Node) ShowTable(pb *guipb.Table) {
// make a new action and populate the current node state
// this should be parent and not rootNode?
a := getNewAction(me.rootNode, widget.Show)
// store the mapping for the grid widget to the parent widget
pb.Parent = new(guipb.Widget)
pb.Parent.Id = int64(parent.id)
pb.Parent.Name = pb.Title
grid := parent.makeTableGrid(pb) // generates the protobuf table
grid.tablepb = pb
nt := guipb.NewTables()
nt.Append(pb)
a.TablePB, err = nt.Marshal()
if err != nil {
log.Info("unmarshal error", err)
return
}
log.Log(INFO, "ShowTable() send action to plugin", "marshal pb data len =", len(a.TablePB))
sendActionToPlugin(a)
}
func (parent *Node) UpdateTable(pb *guipb.Table) {
a := getNewAction(parent, widget.Show)
log.Info("gui.UpdateTable() TODO: move the widget update val logic here instead of tree")
nt := guipb.NewTables()
nt.Append(pb)
a.TablePB, err = nt.Marshal()
if err != nil {
log.Info("unmarshal error", err)
return
}
sendActionToPlugin(a)
}
func (parent *Node) DeleteTable(pb *guipb.Table) {
a := getNewAction(parent, widget.Delete)
log.Info("gui.DeleteTable()")
if pb.Grid == nil {
log.Info("gui.DeleteTable() Error: pb.Grid == nil")
return
}
a.WidgetId = int(pb.Grid.Id)
sendActionToPlugin(a)
}
func (parent *Node) numberTableCol(pb *guipb.Table, name string, w int) bool {
var h int = 0
for _, r := range pb.AnyCols {
if name != r.Header.Name {
// log.Info("skip string row:", r.Header.Name, "!=", name)
continue
}
// log.Info("tree: Add()ing to grid here", r.Header.Id, r.Header.Name, w, h)
r.Header.Location = new(guipb.Location)
r.Header.Location.X = int64(w)
r.Header.Location.Y = int64(h)
h += 1
for _, v := range r.Widgets {
// log.Info("tree: Add()ing to grid here", v.Id, v.Name, w, h)
v.Location = new(guipb.Location)
v.Location.X = int64(w)
v.Location.Y = int64(h)
h += 1
}
return true
}
return false
}
func (parent *Node) makeTableGrid(pb *guipb.Table) *Node {
grid := addNode()
grid.progname = "gridtablePB"
grid.WidgetType = widget.Grid
pb.Grid = new(guipb.Widget)
pb.Grid.Id = int64(grid.id)
pb.Grid.Name = "gridtablePB"
parent.children = append(parent.children, grid)
grid.parent = parent
for _, r := range pb.AnyCols {
// log.Info("gui: got time row:", i, r.Header, r.Vals)
header := addNode()
r.Header.Id = int64(header.id)
for _, v := range r.Vals {
label := addNode()
label.WidgetType = widget.Label
label.parent = grid
label.enabled = true
grid.children = append(grid.children, label)
pbwidget := new(guipb.Widget)
pbwidget.Id = int64(label.id)
anyValue, err := anypb.New(v)
if err != nil {
log.Info("gui: failed to add time", err)
continue
}
pbwidget.Val = anyValue
r.Widgets = append(r.Widgets, pbwidget)
// log.Info("gui: added new val", pbwidget)
}
}
return grid
}
|