Leder
Leder

Reputation: 392

Guide from TornadoFX: how to implement Customer class

I am following TornadoFX Guide from here, trying to run the sample wizard: Wizard

and have implemented additional class Customer as follows, which is not running:

package com.example.demo.app

import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty
import java.time.LocalDate
import java.time.Period
import tornadofx.*

class Customer(name: String, zip: Int, city: String, type: String) {
    val zipProperty = SimpleIntegerProperty(zip)
    var zip by zipProperty

    val nameProperty = SimpleStringProperty(name)
    var name by nameProperty

    val cityProperty = SimpleStringProperty(city)
    var city by cityProperty

    val typeProperty = SimpleStringProperty(type)
    var type by typeProperty

}

How can I add Customer.Type as referenced here, these classes are taken from the Guide:

package com.example.demo.view

import com.example.demo.app.Customer
import com.example.demo.app.CustomerModel
import tornadofx.*
class CustomerWizard : Wizard() {
    val customer: CustomerModel by inject()

    override val canGoNext = currentPageComplete
    override val canFinish = allPagesComplete

    init {
        add(BasicData::class)
        add(AddressInput::class)
    }
}

class BasicData : View("Basic Data") {
    val customer: CustomerModel by inject()

    override val complete = customer.valid(customer.name)

    override val root = form {
        fieldset(title) {
            field("Type") {
                combobox(customer.type, Customer.Type.values().toList()) //Customer.Type, what is it?
            }
            field("Name") {
                textfield(customer.name).required()
            }
        }
    }
}

class AddressInput : View("Address") {
    val customer: CustomerModel by inject()

    override val complete = customer.valid(customer.zip, customer.city)

    override val root = form {
        fieldset(title) {
            field("Zip/City") {
                textfield(customer.zip) {
                    prefColumnCount = 5
                    required()
                }
                textfield(customer.city).required()
            }
        }
    }
}

Error is as follows, leaving me to wonder what Type is? Enum, Class, ...? Error:(26, 50) Kotlin: Unresolved reference: Type

Upvotes: 1

Views: 361

Answers (1)

Edvin Syse
Edvin Syse

Reputation: 7297

In the example above, Type is an enum, defined inside the Customer class, for example like this:

class Customer(name: String, zip: Int, city: String, type: Customer.Type) {
    enum class Type {
        Private, Company
    }

    val zipProperty = SimpleIntegerProperty(zip)
    var zip by zipProperty

    val nameProperty = SimpleStringProperty(name)
    var name by nameProperty

    val cityProperty = SimpleStringProperty(city)
    var city by cityProperty

    val typeProperty = SimpleObjectProperty<Type>(type)
    var type by typeProperty

}

Note that typeProperty was changed to SimpleObjectProperty<Type> as well.

Upvotes: 1

Related Questions