Skip to content

Commit

Permalink
Correct fix for Issue #169 - do not assume that "update" event contai…
Browse files Browse the repository at this point in the history
…ns full information about the changes.

The documentation for the "update" event does not state that there is information about the content that changes, only its location (from, to).
It cannot be assumed that `getAddedSubList` contains the update. The behaviour changed between JavaFX 2 and 8.
Provide fix that is in line with JavaFX 2 documantation but also works in JavaFX 8, so there are no uncessary diferences between versions.
  • Loading branch information
jpsacha committed Jan 8, 2015
1 parent fa433fc commit dc972da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2014, ScalaFX Project
* Copyright (c) 2011-2015, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -134,13 +134,13 @@ object ObservableBuffer extends SeqFactory[ObservableBuffer] {
/**
* Indicates an Update in an $OB.
*
* @param position Position from where new elements were updated
* @param updated elements updated
* @param from Position from where elements were updated
* @param to Position to where elements were updated (exclusive)
* @see [[http://docs.oracle.com/javafx/2/api/javafx/collections/ListChangeListener.Change.html#wasUpdated() `ListChangeListener.Change.wasUpdated()`]]
* @see [[http://docs.oracle.com/javafx/2/api/javafx/collections/ListChangeListener.Change.html#getFrom() `ListChangeListener.Change.getFrom()`]]
* @see [[http://docs.oracle.com/javafx/2/api/javafx/collections/ListChangeListener.Change.html#getAddedSubList() `ListChangeListener.Change.getAddedSubList()`]]
* @see [[http://docs.oracle.com/javafx/2/api/javafx/collections/ListChangeListener.Change.html#getTo() `ListChangeListener.Change.getTo()`]]
*/
case class Update[T](position: Int, updated: Traversable[T]) extends Change
case class Update[T](from: Int, to: Int) extends Change


// CHANGING INDICATORS - END
Expand Down Expand Up @@ -567,7 +567,7 @@ class ObservableBuffer[T](override val delegate: jfxc.ObservableList[T] = jfxc.F
x => c.getPermutation(x)
})
} else if (c.wasUpdated()) {
changes += Update(c.getFrom, c.getAddedSubList)
changes += Update(c.getFrom, c.getTo)
} else {
if (c.wasRemoved()) {
changes += Remove(c.getFrom, c.getRemoved)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2014, ScalaFX Project
* Copyright (c) 2011-2015, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -642,34 +642,25 @@ class ObservableBufferSpec[T]

items.append(jfxc.FXCollections.observableArrayList("test"))

var expectedPosition = -1
var actualFrom = -1
var actualTo = -1
var changed = false
items.onChange((obs, changes) => {
changed = true
for (change <- changes)
change match {
case ObservableBuffer.Update(position, update) =>
position should be(expectedPosition)
val list = update.toList
list.length should equal(1)
list(0) match {
case e: ElementType =>
e.length should equal(2)
e(0) should equal("test")
e(1) should equal("update")
case _@t => fail("Wrong list type: " + t)
}

case ObservableBuffer.Update(from, to) =>
actualFrom = from
actualTo = to
case _@otherChange => fail("Wrong change: " + otherChange.toString)
}
})

expectedPosition = 0
items(0) += "update"

changed should be(true)


actualFrom should be(0)
actualTo should be(1)
}

}

0 comments on commit dc972da

Please sign in to comment.