All demo table code is now seperate
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
96348bc86d
commit
44c64228ce
61
table.go
61
table.go
|
@ -27,22 +27,7 @@ type modelHandler struct {
|
|||
columnTypes string
|
||||
funcColumnTypes func() []ui.TableValue
|
||||
scanCellValue func(*modelHandler, int, int) ui.TableValue
|
||||
setCellValue func(*modelHandler, int, int) ui.TableValue
|
||||
}
|
||||
|
||||
func newDemoModelHandler() *modelHandler {
|
||||
mh := new(modelHandler)
|
||||
mh.rows = 20
|
||||
mh.funcColumnTypes = demoColumnTypes
|
||||
mh.scanCellValue = demoCellValue
|
||||
mh.checkStates = make([]int, mh.rows)
|
||||
mh.vms = make([]vmRowData, mh.rows)
|
||||
mh.vms[8].hostname = "fire"
|
||||
mh.vms[9].hostname = "librem15.this.is.a.really.long.string.test"
|
||||
mh.yellowRow = -1
|
||||
log.Println("Called newDemoModelhandler() with mh=", mh)
|
||||
spew.Dump(mh)
|
||||
return mh
|
||||
setCellValue func(*modelHandler, *ui.TableModel, int, int, ui.TableValue)
|
||||
}
|
||||
|
||||
func standardColumnTypes() []ui.TableValue {
|
||||
|
@ -67,45 +52,27 @@ func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue {
|
|||
return ui.TableString(fmt.Sprintf("jcarrbad %d", row))
|
||||
}
|
||||
|
||||
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.columnTypes == "standard") {
|
||||
if column == 3 { // button row (?)
|
||||
log.Println("Button was pressed START", row, column)
|
||||
}
|
||||
return
|
||||
func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) {
|
||||
if column == 3 { // button row (?)
|
||||
log.Println("Button was pressed START", row, column)
|
||||
}
|
||||
if column == 2 {
|
||||
mh.vms[row].hostname = string(value.(ui.TableString))
|
||||
}
|
||||
if column == 6 { // row background color
|
||||
prevYellowRow := mh.yellowRow
|
||||
mh.yellowRow = row
|
||||
if prevYellowRow != -1 {
|
||||
m.RowChanged(prevYellowRow)
|
||||
}
|
||||
m.RowChanged(mh.yellowRow)
|
||||
}
|
||||
if column == 7 { // checkboxes
|
||||
mh.checkStates[row] = int(value.(ui.TableInt))
|
||||
}
|
||||
log.Println("SetCallValue() END")
|
||||
spew.Dump(m)
|
||||
return
|
||||
}
|
||||
|
||||
func newModelHandler(rows int) *modelHandler {
|
||||
mh := new(modelHandler)
|
||||
mh.rows = rows
|
||||
mh.columnTypes = "standard"
|
||||
|
||||
mh.rows = rows
|
||||
mh.columnTypes = "standard"
|
||||
mh.funcColumnTypes = standardColumnTypes
|
||||
mh.scanCellValue = defaultCellValue
|
||||
mh.bgcolorColumn = 0
|
||||
mh.checkStates = make([]int, mh.rows)
|
||||
mh.vms = make([]vmRowData, mh.rows)
|
||||
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
|
||||
mh.yellowRow = -1
|
||||
|
||||
log.Println("Called newModelhandler() with mh=", mh)
|
||||
spew.Dump(mh)
|
||||
return mh
|
||||
|
|
|
@ -6,6 +6,8 @@ import "log"
|
|||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
func (mh *modelHandler) NumRows(m *ui.TableModel) int {
|
||||
// log.Println("NumRows() with m=", m)
|
||||
return mh.rows
|
||||
|
@ -28,3 +30,16 @@ func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableVal
|
|||
}
|
||||
return mh.scanCellValue(mh, row, column)
|
||||
}
|
||||
|
||||
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.columnTypes == "standard") {
|
||||
defaultSetCellValue(mh, m, row, column, value)
|
||||
return
|
||||
}
|
||||
demoSetCellValue(mh, m, row, column, value)
|
||||
log.Println("SetCallValue() END")
|
||||
spew.Dump(m)
|
||||
}
|
||||
|
|
35
tableDemo.go
35
tableDemo.go
|
@ -3,14 +3,28 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
/*
|
||||
import "log"
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
*/
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
func newDemoModelHandler() *modelHandler {
|
||||
mh := new(modelHandler)
|
||||
mh.rows = 20
|
||||
mh.funcColumnTypes = demoColumnTypes
|
||||
mh.scanCellValue = demoCellValue
|
||||
mh.setCellValue = demoSetCellValue
|
||||
mh.checkStates = make([]int, mh.rows)
|
||||
mh.vms = make([]vmRowData, mh.rows)
|
||||
mh.vms[8].hostname = "fire"
|
||||
mh.vms[9].hostname = "librem15.this.is.a.really.long.string.test"
|
||||
mh.yellowRow = -1
|
||||
log.Println("Called newDemoModelhandler() with mh=", mh)
|
||||
spew.Dump(mh)
|
||||
return mh
|
||||
}
|
||||
|
||||
func demoColumnTypes() []ui.TableValue {
|
||||
return []ui.TableValue{
|
||||
ui.TableString(""), // column 0 text
|
||||
|
@ -105,3 +119,20 @@ func makeDemotable(name string) *ui.Table {
|
|||
|
||||
return table
|
||||
}
|
||||
|
||||
func demoSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) {
|
||||
if column == 2 {
|
||||
mh.vms[row].hostname = string(value.(ui.TableString))
|
||||
}
|
||||
if column == 6 { // row background color
|
||||
prevYellowRow := mh.yellowRow
|
||||
mh.yellowRow = row
|
||||
if prevYellowRow != -1 {
|
||||
m.RowChanged(prevYellowRow)
|
||||
}
|
||||
m.RowChanged(mh.yellowRow)
|
||||
}
|
||||
if column == 7 { // checkboxes
|
||||
mh.checkStates[row] = int(value.(ui.TableInt))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue