As the discussion over JavaFX grows both in the forums and wiki I start to get a better sense of what binding requires from the Java objects. The problem with the simple case (of getters and setters) is not much different than the Java/Swing binding problem. That problem was solved by creating the JavaBeans standard, which in turn was so complex to implement that people started forgetting what it was and regarded it as a standard for properties alone, which is obviously not true.
With today’s tools things can get much simpler. Recently, Ben Galbraith posted about his use of @AspectJ to easily create JavaBeans property events. At the end of his post he even shows how, using load-time weaving, there was no need to change the code of the original class to get it JavaBeans’ events compliant. And this is the direction the Java/JFX binding should go to: Easy, no brainer binding with older code.
But this only solves the replace trigger problem – What about the insert and delete triggers for collections of items? The difficulty with collections is with the many ways they can be exposed, with the two main methods of either exposing the collection instance itself, using a method such as getAnimals() method, or using two methods for manipulating the collection’s contents, such as addAnimal(Animal a) and removeAnimal(Animal a). To reduce the amount of trouble this might cause, I would suggest using some code changes, to maybe wrap the collection in question with something like Apache’s ObservableCollection or its subclasses. Then, using another aspect-oriented solution, create JFX-supported binding for the collection’s manipulations.
To make everything slightly more tricky, the replace trigger on an instance of a collection (the trigger on arr[oldValue] = newValue one) is there too. Again, the simple solution is to have all elements of the collection supporting the aforementioned binding scheme. The JFX framework could either listen to each individual element, or the collection could be implemented to listen to all its contained elements and aggregate changes to JFX.
Any suggestions or comments? Post them here, or on the relevant discussion in the wiki!
Liked Chaotic Java? It's free! But I also make some other things that aren't, which you might like. Like Firewall, a rule changing, turn based strategy game for iOS.