final code reorg before attempting to implement a WIT VM table

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-07 18:35:58 -07:00
parent 44c64228ce
commit cec3013b97
1 changed files with 36 additions and 36 deletions

View File

@ -30,6 +30,25 @@ type modelHandler struct {
setCellValue func(*modelHandler, *ui.TableModel, int, int, ui.TableValue)
}
func newModelHandler(rows int) *modelHandler {
mh := new(modelHandler)
mh.rows = rows
mh.columnTypes = "standard"
mh.funcColumnTypes = standardColumnTypes
mh.scanCellValue = defaultCellValue
mh.setCellValue = defaultSetCellValue
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 standardColumnTypes() []ui.TableValue {
return []ui.TableValue{
ui.TableColor{}, // row background color
@ -39,6 +58,23 @@ func standardColumnTypes() []ui.TableValue {
}
}
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.TableModelColumnAlwaysEditable, nil)
table.AppendButtonColumn("Details", 3, ui.TableModelColumnAlwaysEditable)
return table, mh, model
}
func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue {
switch column {
case 0:
@ -58,39 +94,3 @@ func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, va
}
return
}
func newModelHandler(rows int) *modelHandler {
mh := new(modelHandler)
mh.rows = rows
mh.columnTypes = "standard"
mh.funcColumnTypes = standardColumnTypes
mh.scanCellValue = defaultCellValue
mh.setCellValue = defaultSetCellValue
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.TableModelColumnAlwaysEditable, nil)
table.AppendButtonColumn("Details", 3, ui.TableModelColumnAlwaysEditable)
return table, mh, model
}