Skip to content

Commit

Permalink
- code refactor
Browse files Browse the repository at this point in the history
- ensure list model changes will always be emitted on FX thread
  • Loading branch information
derreisende77 committed Oct 27, 2023
1 parent 44da370 commit b51f108
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object SenderFilmlistLoadApprover {
val storedSenderList = config.getList(String::class.java, SENDER_KEY)
if (storedSenderList == null || storedSenderList.isEmpty()) {
//manually approve all of them and store in config :(
senderSet.addAll(SenderListBoxModel.readOnlySenderList)
senderSet.addAll(SenderListBoxModel.providedSenderList)
config.setProperty(SENDER_KEY, senderSet)
} else {
senderSet.addAll(storedSenderList)
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/mediathek/javafx/filterpanel/SenderBoxNode.java

This file was deleted.

45 changes: 45 additions & 0 deletions src/main/java/mediathek/javafx/filterpanel/SenderBoxNode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package mediathek.javafx.filterpanel

import ca.odell.glazedlists.*
import ca.odell.glazedlists.event.ListEvent
import ca.odell.glazedlists.javafx.EventObservableList
import ca.odell.glazedlists.javafx.JavaFxThreadProxyEventList
import javafx.event.EventHandler
import javafx.scene.control.ContextMenu
import javafx.scene.control.MenuItem
import mediathek.controller.SenderFilmlistLoadApprover
import mediathek.tool.GermanStringSorter
import org.controlsfx.control.CheckListView

class SenderBoxNode : CheckListView<String?>() {
internal class ReadOnlyList(val list: EventList<String>) : TransformedList<String, String>(list) {
init {
source.addListEventListener(this)
}

override fun isWritable(): Boolean {
return false
}

override fun listChanged(listChanges: ListEvent<String>?) {
updates.forwardEvent(listChanges)
}
}

init {
//do not display unchecked(unloaded) senders from config...
val filteredSenderList = FilterList(SenderListBoxModel.providedSenderList)
filteredSenderList.setMatcher { SenderFilmlistLoadApprover.isApproved(it) }

val sortedSenderList = SortedList(UniqueList(filteredSenderList))
sortedSenderList.comparator = GermanStringSorter.getInstance()

items = EventObservableList(JavaFxThreadProxyEventList(ReadOnlyList(sortedSenderList)))

val contextMenu = ContextMenu()
val miClearChecks = MenuItem("Alle Senderfilter zurücksetzen")
miClearChecks.onAction = EventHandler { checkModel.clearChecks() }
contextMenu.items.add(miClearChecks)
setContextMenu(contextMenu)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ import mediathek.tool.GermanStringSorter
* The base model object for all available senders that the client can process.
*/
object SenderListBoxModel {
private val providedSenderList: EventList<String> = BasicEventList()
@JvmStatic
val providedSenderList: EventList<String> = BasicEventList()

@JvmStatic
val readOnlySenderList = ReadOnlySenderListBoxModel()

class ReadOnlySenderListBoxModel : TransformedList<String, String>(providedSenderList) {
/*init {
source.addListEventListener(this)
}*/

override fun isWritable(): Boolean {
return false
}

override fun listChanged(listChanges: ListEvent<String>?) {
//updates.forwardEvent(listChanges)
}
}

Expand Down Expand Up @@ -51,7 +57,6 @@ object SenderListBoxModel {
providedSenderList.add("WDR")
providedSenderList.add("ZDF")
providedSenderList.add("ZDF-tivi")

providedSenderList.sortWith(GermanStringSorter.getInstance())
}
}

0 comments on commit b51f108

Please sign in to comment.