// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "sync" "go.wit.com/gui" "go.wit.com/lib/gadgets" "go.wit.com/lib/protobuf/virtpb" "go.wit.com/log" ) type stdDropletTableWin struct { sync.Mutex win *gadgets.GenericWindow // the machines gui window box *gui.Node // the machines gui parent box widget TB *virtpb.DropletsTable // the gui table buffer update bool // if the window should be updated } func (w *stdDropletTableWin) Toggle() { if w == nil { return } if w.win == nil { return } w.win.Toggle() } func makeDropletsWin() *stdDropletTableWin { dwin := new(stdDropletTableWin) dwin.win = gadgets.NewGenericWindow("virtigo current droplets", "who is squirreling around?") dwin.win.Custom = func() { log.Info("test delete window here") } grid := dwin.win.Group.RawGrid() grid.NewButton("show droplets", func() { var count int found := virtpb.NewDroplets() all := me.droplets.All() for all.Scan() { e := all.Next() count += 1 found.Append(e) if count > 20 { break } } dwin.doDropletsTable(found) }) /* grid.NewButton("Save Current", func() { log.Info("droplets len =", me.droplets.Len()) me.droplets.Save() }) */ // make a box at the bottom of the window for the protobuf table dwin.box = dwin.win.Bottom.Box().SetProgName("TBOX") // doTable(me.droplets) return dwin } func (dwin *stdDropletTableWin) doDropletsTable(currentDroplets *virtpb.Droplets) { dwin.Lock() defer dwin.Unlock() if dwin.TB != nil { dwin.TB.Delete() dwin.TB = nil } // display the protobuf dwin.TB = AddDropletsPB(dwin.box, currentDroplets) f := func(e *Droplet) { log.Info("Triggered. do something here", e.Hostname) // m.Enabled = true } dwin.TB.Custom(f) } func AddDropletsPB(tbox *gui.Node, pb *virtpb.Droplets) *virtpb.DropletsTable { t := pb.NewTable("DropletsPB") t.NewUuid() t.SetParent(tbox) /* ctimef := func(e *virtpb.Droplet) string { ctime := e.Ctime.AsTime() return ctime.Format("2006/01/02 15:04") } t.AddStringFunc("ctime", ctimef) etimef := func(e *virtpb.Droplet) string { etime := e.Etime.AsTime() s := etime.Format("2006/01/02 15:04") if strings.HasPrefix(s, "1970/") { // just show a blank if it's not set return "" } return s } t.AddStringFunc("etime", etimef) */ t.AddHostname() // t.AddAddress() // t.AddWhere() // t.AddLocalPort() t.ShowTable() return t }