0

How do I make a scala.collection.mutable.ObservableBuffer publish swing events so that I can update my components when a buffer changes?

The confusing thing is that scala has two implementations of Publisher. One is scala.collection.mutable.Publisher and the second is scala.swing.Publisher. It's unfortunate that ObservableBuffer only extends the first type of Publisher.

Jean-Philippe Pellet
  • 59,296
  • 21
  • 173
  • 234
dsg
  • 12,924
  • 21
  • 67
  • 111

1 Answers1

2

You can write a subclass of ObservableBuffer that translates the events from the Scala way to the Swing way. I did that to turn an ObservableBuffer into a Eclipse IObservableList, you can check it out here: https://gist.github.com/951288

Note that it is a fast copy-paste, not everything may compile, but you get the idea.

Jean-Philippe Pellet
  • 59,296
  • 21
  • 173
  • 234
  • Alright. I guess I was hoping for a slick way, but perhaps it's impossible. – dsg May 02 '11 at 09:33
  • My code is probably more complex than necessary for a Swing publisher; much of it is for dealing with the `ListDiffEvent` of `IObservableList` correctly. Don't forget the `override def ++=` though because of this bug: https://lampsvn.epfl.ch/trac/scala/ticket/4461 – Jean-Philippe Pellet May 02 '11 at 09:40
  • Philippe -- I am planning to just copy the source code of `ObservableBuffer` and modify all of the calls to `publish`. – dsg May 02 '11 at 09:43
  • @dsg Cool, so you can directly avoid reproducing bug 4461 linked above, then. – Jean-Philippe Pellet May 02 '11 at 10:04