pass the name into the handler. start seperating the ui table callbacks
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
85956b4020
commit
229b470935
6
main.go
6
main.go
|
@ -263,10 +263,12 @@ func setupUI() {
|
|||
mainwin.SetChild(tab)
|
||||
mainwin.SetMargined(true)
|
||||
|
||||
tab.Append("v000185.testing.com.customers.wprod.wit.com", makeDemotable())
|
||||
name := "v000185.testing.com.customers.wprod.wit.com"
|
||||
tab.Append(name, makeDemotable(name))
|
||||
tab.SetMargined(0, true)
|
||||
|
||||
tab.Append("jcarrtest", makeJcarrtable())
|
||||
name = "jcarrTable"
|
||||
tab.Append(name, makeJcarrtable(name))
|
||||
tab.SetMargined(1, true)
|
||||
|
||||
tab.Append("List examples", makeNumbersPage())
|
||||
|
|
48
table.go
48
table.go
|
@ -19,12 +19,13 @@ type vmRowData struct {
|
|||
}
|
||||
|
||||
type modelHandler struct {
|
||||
name string
|
||||
yellowRow int
|
||||
checkStates [rows]int
|
||||
vms [rows]vmRowData
|
||||
}
|
||||
|
||||
func newModelHandler() *modelHandler {
|
||||
func newDefaultModelHandler() *modelHandler {
|
||||
mh := new(modelHandler)
|
||||
mh.vms[8].hostname = "fire"
|
||||
mh.vms[9].hostname = "librem15.this.is.a.really.long.string.test"
|
||||
|
@ -34,8 +35,26 @@ func newModelHandler() *modelHandler {
|
|||
return mh
|
||||
}
|
||||
|
||||
func newJcarrModelHandler() *modelHandler {
|
||||
mh := new(modelHandler)
|
||||
mh.vms[8].hostname = "jcarr"
|
||||
mh.vms[9].hostname = "jcarr2"
|
||||
mh.yellowRow = -1
|
||||
log.Println("Called newModelhandler() with mh=", mh)
|
||||
spew.Dump(mh)
|
||||
return mh
|
||||
}
|
||||
|
||||
func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
|
||||
// log.Println("ColumnTypes() with m=", m)
|
||||
// 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
|
||||
}
|
||||
}
|
||||
return []ui.TableValue{
|
||||
ui.TableString(""), // column 0 text
|
||||
ui.TableString(""), // column 1 text
|
||||
|
@ -59,6 +78,14 @@ var img [2]*ui.Image
|
|||
func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
|
||||
// TODO: Figure out why this is being called 1000 times a second (10 times for each row & column)
|
||||
// log.Println("CallValue() row=", row, "column=", column)
|
||||
if (mh.name == "jcarrTable") {
|
||||
switch column {
|
||||
case 1:
|
||||
return ui.TableString(fmt.Sprintf("jcarrgood %d", row))
|
||||
}
|
||||
return ui.TableString(fmt.Sprintf("jcarrbad %d", row))
|
||||
// panic("unreachable")
|
||||
}
|
||||
switch column {
|
||||
case 0:
|
||||
return ui.TableString(fmt.Sprintf("Row %d", row))
|
||||
|
@ -111,6 +138,10 @@ func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableVal
|
|||
func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
|
||||
log.Println("SetCallValue() START")
|
||||
spew.Dump(m)
|
||||
spew.Dump(mh)
|
||||
if (mh.name == "jcarrTable") {
|
||||
return
|
||||
}
|
||||
if column == 2 {
|
||||
mh.vms[row].hostname = string(value.(ui.TableString))
|
||||
}
|
||||
|
@ -129,11 +160,12 @@ func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui
|
|||
spew.Dump(m)
|
||||
}
|
||||
|
||||
func makeDemotable() *ui.Table {
|
||||
func makeDemotable(name string) *ui.Table {
|
||||
img[0] = ui.NewImage(16, 16)
|
||||
img[1] = ui.NewImage(16, 16)
|
||||
|
||||
mh := newModelHandler()
|
||||
mh := newDefaultModelHandler()
|
||||
mh.name = name
|
||||
model := ui.NewTableModel(mh)
|
||||
|
||||
table := ui.NewTable(
|
||||
|
@ -157,16 +189,18 @@ func makeDemotable() *ui.Table {
|
|||
return table
|
||||
}
|
||||
|
||||
func makeJcarrtable() *ui.Table {
|
||||
mh := newModelHandler()
|
||||
func makeJcarrtable(name string) *ui.Table {
|
||||
mh := newJcarrModelHandler()
|
||||
mh.name = name
|
||||
model := ui.NewTableModel(mh)
|
||||
|
||||
table := ui.NewTable(
|
||||
&ui.TableParams{
|
||||
Model: model,
|
||||
RowBackgroundColorModelColumn: 0,
|
||||
})
|
||||
|
||||
table.AppendTextColumn("hostname", 0, ui.TableModelColumnNeverEditable, nil)
|
||||
table.AppendTextColumn("hostname", 1, ui.TableModelColumnNeverEditable, nil)
|
||||
|
||||
return table
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue