successfully add 2 tabs dynamically

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-07 16:42:16 -07:00
parent dc3f440e47
commit 369a8941a8
3 changed files with 45 additions and 11 deletions

4
gui.go
View File

@ -271,8 +271,8 @@ func setupUI() {
mainwin.Show()
}
func addTableTab(name string) {
table, mh, model := makeJcarrtable(name)
func addTableTab(name string, rows int, row1name string) {
table, mh, model := makeTable(name, rows, row1name)
log.Println(table, mh, model)
tabcount += 1

View File

@ -86,7 +86,7 @@ func main() {
proto := config.String("cloud." + account + ".proto")
hostname := config.String("cloud." + account + ".hostname")
fmt.Println(hostname, port, proto)
addTableTab(account)
addTableTab(account, 4, hostname)
}
for {

View File

@ -46,7 +46,7 @@ func newDefaultModelHandler() *modelHandler {
mh.vms[8].hostname = "fire"
mh.vms[9].hostname = "librem15.this.is.a.really.long.string.test"
mh.yellowRow = -1
log.Println("Called newModelhandler() with mh=", mh)
log.Println("Called newDefaultModelhandler() with mh=", mh)
spew.Dump(mh)
return mh
}
@ -60,15 +60,12 @@ func newJcarrModelHandler() *modelHandler {
mh.vms[8].hostname = "jcarr"
mh.vms[9].hostname = "jcarr2"
mh.yellowRow = -1
log.Println("Called newModelhandler() with mh=", mh)
log.Println("Called newJcarrModelhandler() with mh=", mh)
spew.Dump(mh)
return mh
}
func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
// log.Println("ColumnTypes() with m=", m, "mh=", mh)
if (mh.name == "jcarrTable") {
// log.Println("ColumnTypes() with m=", m, "mh=", mh)
func standardColumnTypes() []ui.TableValue {
return []ui.TableValue{
ui.TableColor{}, // row background color
ui.TableString(""), // column 0 text
@ -76,6 +73,13 @@ func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
ui.TableString("test"), // column 1 button text
}
}
func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
// log.Println("ColumnTypes() with m=", m, "mh=", mh)
if (mh.name == "jcarrTable") {
// log.Println("ColumnTypes() with m=", m, "mh=", mh)
return standardColumnTypes()
}
return []ui.TableValue{
ui.TableString(""), // column 0 text
ui.TableString(""), // column 1 text
@ -229,3 +233,33 @@ func makeJcarrtable(name string) (*ui.Table, *modelHandler, *ui.TableModel) {
return table, mh, model
}
func newModelHandler(rows int) *modelHandler {
mh := new(modelHandler)
mh.rows = rows
mh.bgcolorColumn = 0
mh.checkStates = make([]int, mh.rows)
mh.vms = make([]vmRowData, mh.rows)
mh.vms[1].hostname = "jcarr"
mh.yellowRow = -1
log.Println("Called newModelhandler() with mh=", mh)
spew.Dump(mh)
return mh
}
func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler, *ui.TableModel) {
mh := newModelHandler(rows)
mh.name = name
model := ui.NewTableModel(mh)
table := ui.NewTable(
&ui.TableParams{
Model: model,
RowBackgroundColorModelColumn: mh.bgcolorColumn,
})
table.AppendTextColumn(row1Name, 1, ui.TableModelColumnNeverEditable, nil)
table.AppendButtonColumn("Details", 3, ui.TableModelColumnAlwaysEditable)
return table, mh, model
}