final code reorg before attempting to implement a WIT VM table
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
44c64228ce
commit
cec3013b97
72
table.go
72
table.go
|
@ -30,6 +30,25 @@ type modelHandler struct {
|
||||||
setCellValue func(*modelHandler, *ui.TableModel, int, int, ui.TableValue)
|
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 {
|
func standardColumnTypes() []ui.TableValue {
|
||||||
return []ui.TableValue{
|
return []ui.TableValue{
|
||||||
ui.TableColor{}, // row background color
|
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 {
|
func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue {
|
||||||
switch column {
|
switch column {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -58,39 +94,3 @@ func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, va
|
||||||
}
|
}
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue