Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLassCastException when binding in ItemViewModel #54

Open
tyb51 opened this issue Aug 17, 2022 · 1 comment
Open

CLassCastException when binding in ItemViewModel #54

tyb51 opened this issue Aug 17, 2022 · 1 comment

Comments

@tyb51
Copy link

tyb51 commented Aug 17, 2022

I have been working on an application for use during brainsurgery using this amazing framework for about a year now. BUt I have now encountered an issue that I have not been able to solve.

I made this custom implementation of an ObservableMapProperty which is backed by a reversed map (value,keys) with some custom impelmentations
class ReversableObservableMapProperty<K, V?> (map: ObservableMap<K,V?> = FXCollections.observableMap<K,V?>(hashMapOf())) : SimpleMapProperty<K, V?>(map)

I have a Model :
class MappingModel() {
val parcelHexagonMapProperty = ReversableObservableMapProperty<ParcelPoint,Hexagon?>()
val parcelHexagonMap by parcelHexagonMapProperty
}

And and ItemViewModel:
class MappingModelView: ItemViewModel<MappingModel>() {
val parcelHexagonMap = bind(MappingModel::parcelHexagonMapProperty)
}

On build however it throws the following error:
java.lang.ClassCastException: class tornadofx.BindingAwareSimpleMapProperty cannot be cast to class com.sasdashboard.ui.utils.ReversableObservableMap (tornadofx.BindingAwareSimpleMapProperty and com.sasdashboard.ui.utils.ReversableObservableMap are in unnamed module of loader 'app')
at line val parcelHexagonMap = bind(MappingModel::parcelHexagonMapProperty)

Any idea what causes the issue? Is it due to my custom MapProperty not being accessible by TornadoFx? Might it be due to kotlin version (as I saw in another similar issue #12 . Any ideas on how to resolve it. I rely a lot on this easy binding of properties and delegation of Mapfunctions.

@tyb51
Copy link
Author

tyb51 commented Aug 17, 2022

I currently fixed it by creating a custom:
class BindingAwareReversableObservableMapProperty<S, T>(viewModel: ViewModel, name: String?) : ReversableObservableMap<S, T>(viewModel, name) {

and

inline fun <reified PropertyType : T, reified T: ReversableObservableMap<*,*>,reified V: ItemViewModel<M>, reified M : Any, ResultType : PropertyType> V.bindReversableMap(property: KProperty1<M, PropertyType>, autocommit: Boolean = false, forceObjectProperty: Boolean = false, defaultValue: T? = null): ResultType {

But its really just a lot of boiler plate. Any other ideas on how a neater implementation would look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant