// 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" ) // makes a grid inside an existing Widget func (n *Node) NewTable(title string) *NodeTable { t := new(NodeTable) t.grid = n.RawGrid().SetProgName("PB GRID") t.tb = t.grid.newNode(title, widget.Table) t.tb.label = title return t } type NodeColumn struct { Title string Vals []string } type NodeTable struct { grid *Node tb *Node Custom func() } 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) pb.Parent = new(guipb.Widget) pb.Parent.Id = int64(parent.id) pb.Parent.Name = pb.Title makeTableGrid(pb) nt := guipb.NewTables() nt.Append(pb) a.TablePB, err = nt.Marshal() if err != nil { log.Info("unmarshal error", err) return } log.Info("NewStable() send action to plugin", "pb 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 makeTableGrid(pb *guipb.Table) { grid := addNode() pb.Grid = new(guipb.Widget) pb.Grid.Id = int64(grid.id) pb.Grid.Name = "gridtablePB" /* // get unique widget ID numbers for the headers for i, r := range pb.Order { n := addNode() r.Id = int64(n.id) } */ for _, r := range pb.StringRows { // log.Info("gui: got string row:", pb.Title, i, r.Header, r.Vals) header := addNode() r.Header.Id = int64(header.id) for _, v := range r.Vals { label := addNode() pbwidget := new(guipb.Widget) pbwidget.Id = int64(label.id) pbwidget.Name = v r.Widgets = append(r.Widgets, pbwidget) // log.Info("gui: added new string", pbwidget) } } for _, r := range pb.IntRows { // log.Info("gui: got int row:", i, r.Header, r.Vals) header := addNode() r.Header.Id = int64(header.id) for _, v := range r.Vals { label := addNode() pbwidget := new(guipb.Widget) pbwidget.Id = int64(label.id) pbwidget.Size = v r.Widgets = append(r.Widgets, pbwidget) // log.Info("gui: added new int", pbwidget) } } for _, r := range pb.TimeRows { // 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() 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) } } }