FXBean Adapter

FXBeanAdapter reflects changes of bean properties to the UI and vice versa.

It automatically creates bidirectional bindings to any bean.On bean update old bindings are cleared and new bindings for the new bean are created.

Example

Define Adapter

source@FXML
var personBox: VBox = _

Add Bindings and Converter

sourceoverride def didGainVisibilityFirstTime(): Unit = {
  super.didGainVisibilityFirstTime()

  // Bindings lookup by id or fx:id in fxml
  val bindings = SFXKeyBindings("id", "name", "age")
  // Expression Binding Example
  bindings.add("person", "${sfx:i18n('personText', _self.name(), _self.age())}")

  adapter.addBindings(bindings)

  adapter.addIntConverter("age")

  personBox.visibleProperty().bind(adapter.hasBeanProperty)
}

def items: ObservableList[SFXBean[Person]] = PersonFactory.personList

Change Adapter items

sourcedef selectPerson(person: SFXBean[Person]): Unit = {
  adapter.set(person)
}

def actionRevert(event: ActionEvent): Unit =
  adapter.revert()