简体   繁体   English

Scala ScalaFX:如何处理 Observable* 的大量变化

[英]Scala ScalaFX: how to deal with large set of changes of Observable*

I am using a ObservableMap for data modeling, and want to update the whole entry.我正在使用ObservableMap进行数据建模,并且想要更新整个条目。 Initially the ObservableMap is empty, and it is filled asynchronously with lots of elements.最初ObservableMap是空的,它被大量元素异步填充。

Now the problem is that an onChanged event is shot for each and every entry, which creates too many events and a bogging down of the GUI.现在的问题是,每个条目都会触发一个onChanged事件,这会产生过多的事件并导致 GUI 陷入困境。 I used pkgs.clear() ; pkgs ++= newpkgs我使用了pkgs.clear() ; pkgs ++= newpkgs pkgs.clear() ; pkgs ++= newpkgs . pkgs.clear() ; pkgs ++= newpkgs

Is there way to either only trigger one onChanged , either by disabling the handler temporarily, or by having an operation on the map that updates all elements but fires only afterwards.有没有办法只触发一个onChanged ,或者通过暂时禁用处理程序,或者通过在地图上进行更新所有元素但仅在之后触发的操作。

I'm not aware of a mechanism to disable/delay/buffer UI updates.我不知道禁用/延迟/缓冲 UI 更新的机制。

I don't know about other JavaFX view types, but I have experience with this using TableView in a similar situation.我不知道其他 JavaFX 视图类型,但我有在类似情况下使用TableView经验。 I suspect other views may be similar in this regard.我怀疑其他观点在这方面可能是相似的。

At least the TableView has a property called itemsProperty .至少TableView有一个名为itemsProperty的属性。 When data in itemsProperty is updated using setItems (wrapper for itemsProperty.set(value) ), the table tries very hard to update just the minimum slice of it self.当数据itemsProperty使用更新setItems (包装为itemsProperty.set(value) ),该表将尝试很难更新只是它的最低片的自我。

However, for the optimizations to work, the key is that the items must be "value objects" ( hashCode and equals are deep and based on the actual data being displayed and not some random references.)但是,要使优化起作用,关键是项目必须是“值对象”( hashCodeequals很深并且基于显示的实际数据而不是一些随机引用。)

In the case of TableView this may require elaborate rowFactory and cellFactory implementations.TableView的情况下,这可能需要详细的rowFactorycellFactory实现。 The reason is that the data in items can't be "preformatted" in any way or it would spoil the optimizations inside TableView .原因是items中的数据不能以任何方式“预格式化”,否则会破坏TableView内部的优化。

Realizing the above, solved my update churn problems.意识到上述问题,解决了我的更新流失问题。 Maybe other answers can provide other tips.也许其他答案可以提供其他提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM