scala - Editable Boolean Columns in ScalaFX TableView -


i'm new scalafx , want create tableview containing editable boolean column checkboxs (as editable string , int columns textfields). assume i'll need use checkboxtablecell. i'm using jdk 7u25, scalafx 1.0.0-m4/m5 , scala 2.10.2-final. (i'm not scalafx version, it's definately @ least 1.0.0-m5. in case it's snapshot jarek uploaded on august 1 https://oss.sonatype.org/index.html#nexus-search;quick~scalafx. jarek compiles scala 2.9.x, i've downloaded source code , recompiled it.)

i've managed halfway working based on integer columns in scalafx tableview, http://foofighter2146.blogspot.com/2013/06/tutorial-scalafx-slick.html , scalafx-demo: simpletableview. however, can't use checkbox's in tableview , use values. in stead, can work in such way need type in "true" or "false" edit value in table.

here's have managed working far:

class person(firstname_ : string, age_ : int, cool_ : boolean) {   val name = new stringproperty(this, "name", firstname_)   val age = new integerproperty(this, "age", age_)   val cool = new objectproperty(this, "cool", cool) }  object simpleeditabletableview extends jfxapp {   val characters = observablebuffer[person](     new person("peggy", 45, false),     new person("rocky", 43, true)   )    stage = new primarystage {     title = "simple ediatble table view"     scene = new scene {       content = new tableview[person](characters) {         editable = true         columns ++= list(           new tablecolumn[person, string] {             text = "name"             cellvaluefactory = {_.value.name}             cellfactory = _ => new textfieldtablecell[person, string] (new defaultstringconverter())             oneditcommit = (evt: celleditevent[person, string]) => {               val person = evt.rowvalue               val newname = evt.newvalue               println("here we'll typically save data. new name = "+newname)             }             editable = true             prefwidth = 180           },           new tablecolumn[person, int] {             text = "name"             cellvaluefactory = {_.value.age}             cellfactory = _ => new textfieldtablecell[person, int] (new intstringconverter())             oneditcommit = (evt: celleditevent[person, int]) => {               val person = evt.rowvalue               val newage = evt.newage               println("here we'll typically save data. new age = "+newage)             }             editable = true             prefwidth = 180           },           new tablecolumn[person, boolean] {             text = "cool"             cellvaluefactory = {_.value.cool}             cellfactory = _ => new textfieldtablecell[person, boolean] (new booleanstringconverter())             oneditcommit = (evt: celleditevent[person, boolean]) => {               val person = evt.rowvalue               val newcool = evt.newcool               println("here we'll typically save data. new cool = "+newcool)             }             editable = true             prefwidth = 180           }         )       }     }   } } 

for "cool" tablecolumn, replace

cellfactory = _ => new textfieldtablecell[person, boolean] (new booleanstringconverter()) 

with

val selectedproperty: int => observablevalue[boolean, java.lang.boolean] = {rownum: int => model.characters(rownum).cool} cellfactory = column => checkboxtablecell.fortablecolumn[person, boolean](selectedproperty) 

in order nice checkboxes in tableview (currently, textfields in must type out "true" or "false"). however, gives me (obvious) error:

type mismatch; found : scalafx.beans.property.objectproperty[scala.boolean] required: scalafx.beans.value.observablevalue[scala.boolean,java.lang.boolean] 

and if change

val selectedproperty: int => observablevalue[boolean, java.lang.boolean] = {rownum: int => model.characters(rownum).cool} 

to val selectedproperty = {rownum: int => model.characters(rownum).cool}

i 1 heck of error message, comes down fact checkboxtablecell.fortablecolumn[person, boolean](selectedproperty) requires selectedproperty of type int => observablevalue[boolean, java.lang.boolean], not int => objectproperty[boolean]

basically should use booleanproperty, can find details, including complete example, in answer same question posted scalafx-users discussion group https://groups.google.com/d/msg/scalafx-users/oedbp9ty5ye/csni1qhsnuqj


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -