Add observeFiltered methods on ObserableBuffer

These are convenience methods for constructing a `FilteredBuffer` with
either a static or dynamic filter.
This commit is contained in:
Sarah Gerweck 2016-06-12 08:11:24 -07:00
parent 99ed345be5
commit c525330b08
2 changed files with 35 additions and 13 deletions

View File

@ -220,6 +220,7 @@ object Dependencies {
final val commonsIoVersion = "2.4"
final val spireVersion = "0.11.0"
final val groovyVersion = "2.4.4"
final val scalaJava8Version = "0.7.0"
final val scalaParserVersion = "1.0.4"
final val scalaXmlVersion = "1.0.5"
final val gerweckUtilVersion = "2.0.0"
@ -227,19 +228,20 @@ object Dependencies {
final val shapelessVersion = "2.3.1"
final val scallopVersion = "1.0.1"
val log4s = "org.log4s" %% "log4s" % log4sVersion
val slf4j = "org.slf4j" % "slf4j-api" % slf4jVersion
val jclBridge = "org.slf4j" % "jcl-over-slf4j" % slf4jVersion
val log4jBridge = "org.slf4j" % "log4j-over-slf4j" % slf4jVersion
val logback = "ch.qos.logback" % "logback-classic" % logbackVersion
val spire = "org.spire-math" %% "spire" % spireVersion
val commonsIo = "commons-io" % "commons-io" % commonsIoVersion
val groovy = "org.codehaus.groovy" % "groovy-all" % groovyVersion
val gerweckUtil = "org.gerweck.scala" %% "gerweck-utils" % gerweckUtilVersion
val gerweckUtilAkka = "org.gerweck.scala" %% "gerweck-utils-akka" % gerweckUtilVersion
val scalaz = "org.scalaz" %% "scalaz-core" % scalazVersion
val shapeless = "com.chuusai" %% "shapeless" % shapelessVersion
val scallop = "org.rogach" %% "scallop" % scallopVersion
val log4s = "org.log4s" %% "log4s" % log4sVersion
val slf4j = "org.slf4j" % "slf4j-api" % slf4jVersion
val jclBridge = "org.slf4j" % "jcl-over-slf4j" % slf4jVersion
val log4jBridge = "org.slf4j" % "log4j-over-slf4j" % slf4jVersion
val logback = "ch.qos.logback" % "logback-classic" % logbackVersion
val spire = "org.spire-math" %% "spire" % spireVersion
val commonsIo = "commons-io" % "commons-io" % commonsIoVersion
val groovy = "org.codehaus.groovy" % "groovy-all" % groovyVersion
val gerweckUtil = "org.gerweck.scala" %% "gerweck-utils" % gerweckUtilVersion
val gerweckUtilAkka = "org.gerweck.scala" %% "gerweck-utils-akka" % gerweckUtilVersion
val scalaJava8 = "org.scala-lang.modules" %% "scala-java8-compat" % scalaJava8Version
val scalaz = "org.scalaz" %% "scalaz-core" % scalazVersion
val shapeless = "com.chuusai" %% "shapeless" % shapelessVersion
val scallop = "org.rogach" %% "scallop" % scallopVersion
val commonsVfs = {
val base = "org.apache.commons" % "commons-vfs2" % commonsVfsVersion
@ -325,6 +327,7 @@ object UtilsBuild extends Build {
log4jBridge % "runtime,optional",
logback % "runtime,optional",
gerweckUtil,
scalaJava8,
scalaFx,
scalaz,
shapeless

View File

@ -2,8 +2,14 @@ package org.gerweck.scalafx.util
import language.implicitConversions
import scala.compat.java8.FunctionConverters._
import java.util.function.{ Predicate => JPredicate }
import scalafx.beans.property._
import scalafx.beans.value._
import scalafx.collections._
import scalafx.collections.transformation._
sealed trait ToFlatObservable[-A, +B] extends Calculable[A, B]
object ToFlatObservable extends CalculableObservable[ToFlatObservable[_, _]] {
@ -39,6 +45,19 @@ sealed trait RichObservableSeqLike[A] extends Any {
final class RichObservableBuffer[A](val obs: ObservableBuffer[A]) extends AnyVal with RichObservableSeqLike[A] {
def observableSeqValue: ReadOnlyObjectProperty[Seq[A]] = ToFlatObservable.toObservable(obs)
def observableSize = ObservableSized.toObservable(obs)
def observeFiltered(predicate: A => Boolean) = {
new transformation.FilteredBuffer(obs, predicate)
}
/* The dummy implicit is here to ensure the `observeFiltered` methods all have different post-erasure types */
def observeFiltered[B >: A](predicate: ObservableValue[JPredicate[B], JPredicate[B]])(implicit dummy: DummyImplicit): FilteredBuffer[A] = {
val fb = new transformation.FilteredBuffer(obs)
fb.predicate <== predicate
fb
}
def observeFiltered[B >: A](predicate: Observable[B => Boolean]): FilteredBuffer[A] = {
observeFiltered(predicate.map[JPredicate[A]](asJavaPredicate))
}
}
final class RichObservableArray[A, B <: ObservableArray[A, B, C], C <: javafx.collections.ObservableArray[C]](val oaa: ObservableArray[A, B, C]) extends AnyVal with RichObservableSeqLike[A] {