-
-
Save NikkyAI/aad9fa2d4fb47f7e2b0e1c5459591d5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.threelite.scraper.gui.view | |
| import com.threelite.scraper.gui.controller.TabController | |
| import javafx.collections.ObservableList | |
| import javafx.scene.control.Tab | |
| import kfoenix.jfxtabpane | |
| import tornadofx.* | |
| class DriverTabPane : View() { | |
| private val controller: TabController by inject() | |
| override val root = jfxtabpane { | |
| // tabClosingPolicy = TabPane.TabClosingPolicy.SELECTED_TAB //TODO: do cleanup on close of tab | |
| controller.selectionModel = selectionModel | |
| bindTabs(tabs, controller.list) { | |
| Tab(it).apply { | |
| //TODO: add real UI | |
| vbox { | |
| label(it) | |
| } | |
| } | |
| } | |
| } | |
| private inline fun <reified T> bindTabs(into: ObservableList<Tab>, list: ObservableList<T>, crossinline conversion: (T) -> Tab) { | |
| list.forEach { t -> | |
| val existing = into.find { it.properties["tracker"] == t } | |
| if (existing == null) | |
| into.add( | |
| conversion(t).apply { | |
| tag = t | |
| properties["tracker"] = t | |
| } | |
| ) | |
| } | |
| list.onChange { c -> | |
| while (c.next()) { | |
| if (c.wasAdded()) { | |
| c.addedSubList.forEach { t -> | |
| val existing = into.find { it.properties["tracker"] == t } | |
| if (existing == null) | |
| into.add( | |
| conversion(t).apply { | |
| tag = t | |
| properties["tracker"] = t | |
| } | |
| ) | |
| } | |
| } | |
| if (c.wasRemoved()) { | |
| c.removed.forEach { t -> | |
| into.removeIf { it.properties["tracker"] == t } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment