tornadofx / tornadofx / ViewModel

ViewModel

open class ViewModel : Component, ScopedInstance

Constructors

<init> ViewModel()

Properties

autocommitProperties val autocommitProperties: ObservableList<ObservableValue<out Any>>
dirty open val dirty: BooleanBinding
dirtyListListener val dirtyListListener: ListChangeListener<Any>
dirtyListener val dirtyListener: ChangeListener<Any>
dirtyProperties val dirtyProperties: ObservableList<ObservableValue<*>>
externalChangeListeners val externalChangeListeners: ObservableMap<Property<*>, ChangeListener<Any>>
ignoreDirtyStateProperties val ignoreDirtyStateProperties: ObservableList<ObservableValue<out Any>>
isDirty val isDirty: Boolean
isNotDirty val isNotDirty: Boolean
isValid val isValid: Boolean
propertyCache val propertyCache: ObservableMap<Property<*>, Property<*>>
propertyMap val propertyMap: ObservableMap<Property<*>, () -> Property<*>?>
valid val valid: ReadOnlyBooleanProperty
validationContext val validationContext: ValidationContext

Inherited Properties

app val app: App
clipboard val clipboard: Clipboard
config open val config: ConfigProperties
configCharset open val configCharset: Charset
configPath open val configPath: Path

Path to component specific configuration settings. Defaults to javaClass.properties inside the configured configBasePath of the application (By default conf in the current directory).

hostServices val hostServices: HostServices
log val log: <ERROR CLASS>
messages var messages: ResourceBundle
params val params: Map<String, Any?>
paramsProperty val paramsProperty: SimpleObjectProperty<Map<String, Any?>>
primaryStage val primaryStage: Stage
properties val properties: <ERROR CLASS>
resources val resources: ResourceLookup
scope open val scope: Scope
subscribedEvents val subscribedEvents: HashMap<KClass<out FXEvent>, ArrayList<FXEventRegistration>>
workspace val workspace: Workspace

Functions

addValidator fun <T> addValidator(node: Node, property: ObservableValue<T>, trigger: ValidationTrigger = ValidationTrigger.OnChange(), validator: ValidationContext.(T?) -> ValidationMessage?): Unit
assignValue fun assignValue(facade: Property<*>, prop: Property<*>?, defaultValue: Any? = null): Unit
backingValue fun <T> backingValue(property: Property<T>): Any?

Extract the value of the corresponding source property

bind fun <PropertyType : Property<T>, T : Any, ResultType : PropertyType> bind(autocommit: Boolean = false, forceObjectProperty: Boolean = false, defaultValue: T? = null, propertyProducer: () -> PropertyType?): ResultType

Wrap a JavaFX property and return the ViewModel facade for this property

clearDecorators fun clearDecorators(): Boolean
commit fun commit(vararg fields: ObservableValue<*>, successFn: () -> Unit = {}): Booleanfun commit(force: Boolean = false, focusFirstError: Boolean = true, vararg fields: ObservableValue<*>, successFn: () -> Unit = {}): Boolean

Perform validation and flush the values into the source object if validation passes.

dirtyStateProperty fun dirtyStateProperty(): BooleanBinding
isDirty fun <T> isDirty(property: Property<T>): Boolean
isNotDirty fun <T> isNotDirty(property: Property<T>): Boolean
markDirty fun markDirty(property: ObservableValue<*>): Unit
onCommit open fun onCommit(): Unit
open fun onCommit(commits: List<Commit>): Unit

This function is called after a successful commit, right before the optional successFn call sent to the commit call is invoked.

property fun <T : Any> property(autocommit: Boolean = false, forceObjectProperty: Boolean = false, defaultValue: T? = null, op: () -> Property<T>): PropertyDelegate<T>
rollback fun rollback(vararg fields: Property<*>): Unit

Rollback all or the specified fields

setDecorationProvider fun setDecorationProvider(decorationProvider: (ValidationMessage) -> Decorator?): Unit
valid fun valid(vararg fields: Property<*>): BooleanExpression

Create a boolean binding indicating if the given list of properties are currently valid with regards to the ValidationContext of this ViewModel.

validate fun validate(focusFirstError: Boolean = true, decorateErrors: Boolean = true, failFast: Boolean = false, vararg fields: ObservableValue<*>): Boolean

Inherited Functions

background fun <T> background(func: FXTask<*>.() -> T): Task<T>
di fun <T : Any> di(name: String? = null): ReadOnlyProperty<Component, T>
find fun <T : Component> find(vararg params: Pair<*, Any?>, op: T.() -> Unit = {}): T
fun <T : Component> find(params: Map<*, Any?>? = null, op: T.() -> Unit = {}): T
fun <T : Component> find(type: KClass<T>, params: Map<*, Any?>? = null, op: T.() -> Unit = {}): <ERROR CLASS>
fun <T : Component> find(type: KClass<T>, vararg params: Pair<*, Any?>, op: T.() -> Unit = {}): <ERROR CLASS>
fun <T : Component> find(componentType: Class<T>, params: Map<*, Any?>? = null, scope: Scope = this@Component.scope): T
fire fun <T : FXEvent> fire(event: T): Unit
fragment fun <T : Fragment> fragment(overrideScope: Scope = scope, vararg params: Pair<String, Any?>): ReadOnlyProperty<Component, T>
fun <T : Fragment> fragment(overrideScope: Scope = scope, params: Map<String, Any?>): ReadOnlyProperty<Component, T>
get fun <InjectableType, T> get(prop: KProperty1<InjectableType, T>): T where InjectableType : Component, InjectableType : ScopedInstance

Find the given property inside the given ScopedInstance. Useful for assigning a property from a View or Controller in any Component. Example:

inject fun <T> inject(overrideScope: Scope = scope, vararg params: Pair<String, Any?>): ReadOnlyProperty<Component, T> where T : Component, T : ScopedInstance
fun <T> inject(overrideScope: Scope = scope, params: Map<String, Any?>? = null): ReadOnlyProperty<Component, T> where T : Component, T : ScopedInstance
k fun <T : Any> k(javaClass: Class<T>): KClass<T>
nullableParam fun <T> nullableParam(defaultValue: T? = null): ReadOnlyProperty<Component, T>
param fun <T> param(defaultValue: T? = null): ReadOnlyProperty<Component, T>
preferences fun preferences(nodename: String? = null, op: Preferences.() -> Unit): Unit

Store and retrieve preferences.

runAsync fun <T, R> KClass<T>.runAsync(op: T.() -> R): Task<R> where T : Component, T : ScopedInstance

Perform the given operation on an ScopedInstance of the specified type asynchronousyly.

fun <InjectableType, ReturnType> KFunction1<InjectableType, ReturnType>.runAsync(doOnUi: (ReturnType) -> Unit = {}): Task<ReturnType> where InjectableType : Component, InjectableType : ScopedInstance
fun <InjectableType, P1, ReturnType> KFunction2<InjectableType, P1, ReturnType>.runAsync(p1: P1, doOnUi: (ReturnType) -> Unit = {}): <ERROR CLASS> where InjectableType : Component, InjectableType : ScopedInstance

Perform the given operation on an ScopedInstance class function member asynchronousyly.

fun <InjectableType, P1, P2, ReturnType> KFunction3<InjectableType, P1, P2, ReturnType>.runAsync(p1: P1, p2: P2, doOnUi: (ReturnType) -> Unit = {}): <ERROR CLASS> where InjectableType : Component, InjectableType : ScopedInstance
fun <InjectableType, P1, P2, P3, ReturnType> KFunction4<InjectableType, P1, P2, P3, ReturnType>.runAsync(p1: P1, p2: P2, p3: P3, doOnUi: (ReturnType) -> Unit = {}): <ERROR CLASS> where InjectableType : Component, InjectableType : ScopedInstance
fun <InjectableType, P1, P2, P3, P4, ReturnType> KFunction5<InjectableType, P1, P2, P3, P4, ReturnType>.runAsync(p1: P1, p2: P2, p3: P3, p4: P4, doOnUi: (ReturnType) -> Unit = {}): <ERROR CLASS> where InjectableType : Component, InjectableType : ScopedInstance
fun <T> runAsync(daemon: Boolean = false, status: TaskStatus? = find(scope), func: FXTask<*>.() -> T): Task<T>fun <T> runAsync(status: TaskStatus? = find(scope), func: FXTask<*>.() -> T): Task<T>

Runs task in background. If not set directly, looks for TaskStatus instance in current scope.

set fun <InjectableType, T> set(prop: KMutableProperty1<InjectableType, T>, value: T): Unit where InjectableType : Component, InjectableType : ScopedInstance
setInScope fun <T : ScopedInstance> setInScope(value: T, scope: Scope = this.scope): <ERROR CLASS>
subscribe fun <T : FXEvent> subscribe(times: Number? = null, action: EventContext.(T) -> Unit): FXEventRegistration
ui infix fun <T> Task<T>.ui(func: (T) -> Unit): <ERROR CLASS>
unsubscribe fun <T : FXEvent> unsubscribe(action: EventContext.(T) -> Unit): Unit

Companion Object Properties

propertyToFacade val propertyToFacade: WeakHashMap<Observable, Property<*>>
propertyToViewModel val propertyToViewModel: WeakHashMap<Observable, ViewModel>

Companion Object Functions

getFacadeForProperty fun getFacadeForProperty(property: Observable): Property<*>?
getViewModelForProperty fun getViewModelForProperty(property: Observable): ViewModel?
register fun register(property: ObservableValue<*>, possiblyFacade: ObservableValue<*>?): Unit

Register the combination of a property that has been bound to a property that might be a facade in a ViewModel. This is done to be able to locate the validation context for this binding.

Extension Functions

dirtyStateFor fun <V : ViewModel, T : ObservableValue<X>, X> V.dirtyStateFor(modelField: KProperty1<V, T>): BooleanBinding
getProperty fun <T> Any.getProperty(prop: KMutableProperty1<*, T>): ObjectProperty<T>
observable fun <T : Any> Any.observable(propName: String): ObjectProperty<T>
property fun <T> ViewModel.property(value: T? = null): PropertyDelegate<T>
rebind fun <T : ViewModel> T.rebind(op: T.() -> Unit): Unit
rebindOnChange fun <V : ViewModel, T> V.rebindOnChange(observable: ObservableValue<T>, op: V.(T?) -> Unit = {}): Unit

Listen to changes in the given observable and call the op with the new value on change. After each change the viewmodel is rolled back to reflect the values in the new source object or objects.

fun <V : ViewModel, T> V.rebindOnChange(tableview: TableView<T>, op: V.(T?) -> Unit): Unit
fun <V : ViewModel, T> V.rebindOnChange(listview: ListView<T>, op: V.(T?) -> Unit): Unit
fun <V : ViewModel, T> V.rebindOnChange(treeview: TreeView<T>, op: V.(T?) -> Unit): Unit
fun <V : ViewModel, T> V.rebindOnChange(treetableview: TreeTableView<T>, op: V.(T?) -> Unit): Unit
rebindOnTreeItemChange fun <V : ViewModel, T> V.rebindOnTreeItemChange(observable: ObservableValue<TreeItem<T>>, op: V.(T?) -> Unit): Unit

Inheritors

ItemViewModel open class ItemViewModel<T> : ViewModel