Skip to content

Instantly share code, notes, and snippets.

@3gcodes
Created October 18, 2017 02:44
Show Gist options
  • Select an option

  • Save 3gcodes/2579103f6d5a3176740158b52f1039f6 to your computer and use it in GitHub Desktop.

Select an option

Save 3gcodes/2579103f6d5a3176740158b52f1039f6 to your computer and use it in GitHub Desktop.
First stab at displaying a list of Accounts pulled from a Grails REST API in TornadoFX.
class Account: JsonModel {
var id by property<Long>()
fun idProperty() = getProperty(Account::id)
var name by property<String>()
fun nameProperty() = getProperty(Account::name)
var accountNumber by property<String>()
fun accountNumberProperty() = getProperty(Account::accountNumber)
override fun updateModel(json: JsonObject) {
with(json) {
id = long("id")
name = string("name")
accountNumber = string("accountNumber")
}
}
}
class HelloController : Controller() {
val api: Rest by inject()
init {
api.baseURI = "http://localhost:8080/"
}
fun getAccounts() = api.get("account").list().toModel<Account>()
}
class HelloWorld : View("Hello") {
val helloController: HelloController by inject()
private val accounts = helloController.getAccounts()
override val root = form {
fieldset(labelPosition = Orientation.VERTICAL) {
tableview(accounts) {
column("ID", Account::id)
column("Name", Account::name)
column("Account #", Account::accountNumber)
}
}
}
}
class HelloApp : App(HelloWorld::class, Styles::class) {
class Styles : Stylesheet()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment