2

I'd like to bind two properties of different types to each other bidirectionally.

I have an interface:

interface Gateway<F, T> {
    T to(F item);
    F from(T item);
}

which allows me to convert an object of one type, to an object of another type.

Optimally, I'd have a function:

void bindBidirectional(Property<F> first, Gateway<F, T> converter, Property<T> second) {
   ...
}

which would allow me to easily bidirectionally bind two properties, so long as I have an object that can map values of one type to values of another, and back.

How would I implement binding like this?

Note: There are already convenience methods for this kind of binding as long as one of the Property's types is a String. I'd like a more generic method, similar to this, that will allow me to convert between any two types.

Kröw
  • 504
  • 2
  • 13
  • 31
  • P.S., I found [this](https://bugs.openjdk.java.net/browse/JDK-8101274), in case it interests anyone. – Kröw Jun 16 '19 at 20:37
  • You could study [the implementation](https://github.com/javafxports/openjdk-jfx/blob/jfx-12/modules/javafx.base/src/main/java/com/sun/javafx/binding/BidirectionalBinding.java) for inspiration. Note the source file is 827 lines of code; however, you'll probably be most interested in lines [723-785](https://github.com/javafxports/openjdk-jfx/blob/jfx-12/modules/javafx.base/src/main/java/com/sun/javafx/binding/BidirectionalBinding.java#L723-L785) and 808-827. – Slaw Jun 16 '19 at 23:12

0 Answers0