Skip to content

Instantly share code, notes, and snippets.

@bjonnh
Last active January 30, 2019 21:47
Show Gist options
  • Save bjonnh/1a06fa47813d131455c6ae5ab8959079 to your computer and use it in GitHub Desktop.
Save bjonnh/1a06fa47813d131455c6ae5ab8959079 to your computer and use it in GitHub Desktop.
class Query(subject: Resource?, label: String, content: String) {
private val originalSubjectProperty = SimpleStringProperty(subject.toString())
fun originalSubjectProperty() = originalSubjectProperty
var originalSubject by originalSubjectProperty
private val subjectProperty = SimpleStringProperty(subject.toString())
fun subjectProperty() = subjectProperty
var subject by subjectProperty
private val originalLabelProperty = SimpleStringProperty(label)
fun originalLabelProperty() = originalLabelProperty
var originalLabel by originalLabelProperty
private val labelProperty = SimpleStringProperty(label)
fun labelProperty() = labelProperty
var label by labelProperty
private val originalContentProperty = SimpleStringProperty(content)
fun originalContentProperty() = originalContentProperty
var originalContent by originalContentProperty
private val contentProperty = SimpleStringProperty(content)
fun contentProperty() = contentProperty
var content by contentProperty
private val changedProperty = SimpleBooleanProperty(false)
fun changedProperty() = changedProperty
var changed by changedProperty
val result = ResultList()
private val errorProperty = SimpleStringProperty("")
fun errorProperty() = errorProperty
var error by errorProperty
private val insertAtCursorProperty = SimpleStringProperty("")
fun insertAtCursorProperty() = insertAtCursorProperty
var insertAtCursor by insertAtCursorProperty
init {
labelProperty().onChange { changed = true }
contentProperty().onChange { changed = true }
}
override fun toString(): String {
return "QueryModel: $originalSubject->$subject $originalLabel->$label $originalContent->$content $changed $error"
}
}
class QueryModel(query: Query): ItemViewModel<Query>(query) {
val originalSubject = bind(Query::originalSubjectProperty)
val originalLabel = bind(Query::originalLabelProperty)
val originalContent = bind(Query::originalContentProperty)
val subject = bind(Query::subjectProperty)
val label = bind(Query::labelProperty)
val content = bind(Query::contentProperty)
val changed = bind(Query::changedProperty)
val result = bind(Query::result)
val error = bind(Query::errorProperty)
val insertAtCursor = bind(Query::insertAtCursorProperty)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment