diff --git a/gui.go b/gui.go index 1e21e10..374fa43 100644 --- a/gui.go +++ b/gui.go @@ -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 diff --git a/main.go b/main.go index b8bd66d..0e972b5 100644 --- a/main.go +++ b/main.go @@ -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 { diff --git a/table.go b/table.go index 2313525..8ef7b1d 100644 --- a/table.go +++ b/table.go @@ -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,21 +60,25 @@ 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 standardColumnTypes() []ui.TableValue { + return []ui.TableValue{ + ui.TableColor{}, // row background color + ui.TableString(""), // column 0 text + ui.TableColor{}, // column 0 text color + 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 []ui.TableValue{ - ui.TableColor{}, // row background color - ui.TableString(""), // column 0 text - ui.TableColor{}, // column 0 text color - ui.TableString("test"), // column 1 button text - } + return standardColumnTypes() } return []ui.TableValue{ ui.TableString(""), // column 0 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 +}