Add conversion to ObservableBuffer

This commit is contained in:
Sarah Gerweck 2015-08-15 02:09:45 -07:00
parent b039198d7f
commit 777f6bda28

View File

@ -6,6 +6,7 @@ import scalaz._
import scalafx.beans.property._ import scalafx.beans.property._
import scalafx.beans.value._ import scalafx.beans.value._
import scalafx.collections._
trait ObservableImplicits { trait ObservableImplicits {
/* NOTE: (Sarah) I believe that the synchronization in these helpers is not /* NOTE: (Sarah) I believe that the synchronization in these helpers is not
@ -163,6 +164,14 @@ class RichObservable[A, C](val self: ObservableValue[A, C]) extends AnyVal {
final def [B, B1](fb: ObservableValue[B, B1]) = |@|(fb) final def [B, B1](fb: ObservableValue[B, B1]) = |@|(fb)
} }
class ObservableOfIterable[A](val self: ObservableValue[Iterable[A], Iterable[A]]) extends AnyVal {
def toBuffer: ObservableBuffer[A] = {
val buff = ObservableBuffer(self.value.toSeq)
self onChange { (_, oldV, newV) => fillCollection(buff.delegate, newV) }
buff
}
}
class RichProperty[A, B](val inner: Property[A, B]) extends AnyVal { class RichProperty[A, B](val inner: Property[A, B]) extends AnyVal {
def biMap[B <: AnyRef](push: A => B, pull: B => A): ObjectProperty[B] = { def biMap[B <: AnyRef](push: A => B, pull: B => A): ObjectProperty[B] = {
val original = push(inner.value) val original = push(inner.value)