<commit_before>package de.pbauerochse.worklogviewer.favourites.fx

import de.pbauerochse.worklogviewer.favourites.issue.FavouriteIssue
import de.pbauerochse.worklogviewer.favourites.searches.FavouriteSearch
import de.pbauerochse.worklogviewer.fx.components.ComponentStyleClasses
import de.pbauerochse.worklogviewer.fx.issuesearch.SavedSearchContextMenu
import de.pbauerochse.worklogviewer.search.fx.SearchTabModel
import de.pbauerochse.worklogviewer.timereport.Issue
import de.pbauerochse.worklogviewer.timereport.fx.table.columns.context.IssueCellContextMenu
import de.pbauerochse.worklogviewer.util.FormattingUtil
import javafx.collections.ListChangeListener
import javafx.fxml.Initializable
import javafx.scene.control.TreeItem
import javafx.scene.control.TreeView
import org.slf4j.LoggerFactory
import java.net.URL
import java.util.*

/**
 * FX Controller for managing the users [de.pbauerochse.worklogviewer.favourites.issue.FavouriteIssue]s
 * and [de.pbauerochse.worklogviewer.favourites.searches.FavouriteSearch]es.
 */
class FavouritesController : Initializable {

    lateinit var favouritesTreeView: TreeView<IssueSearchTreeItem>

    private lateinit var favouriteSearchesTreeItem: TreeItem<IssueSearchTreeItem>
    private lateinit var favouriteIssuesTreeItem: TreeItem<IssueSearchTreeItem>
    private lateinit var searchResultsTreeItem: TreeItem<IssueSearchTreeItem>

    override fun initialize(url: URL?, resourceBundle: ResourceBundle?) {
        // FavouriteSearches
        favouriteSearchesTreeItem = TreeItem(IssueSearchTreeItem.labelledNoopItem(FormattingUtil.getFormatted("dialog.issuesearch.groups.favourites.searches"))).apply {
            isExpanded = true
        }

        // FavouriteIssues
        favouriteIssuesTreeItem = TreeItem(IssueSearchTreeItem.labelledNoopItem(FormattingUtil.getFormatted("dialog.issuesearch.groups.favourites.issues"))).apply {
            isExpanded = true
        }


        // SearchResults (will be removed later)
        searchResultsTreeItem = TreeItem(IssueSearchTreeItem.labelledNoopItem(FormattingUtil.getFormatted("dialog.issuesearch.groups.searchresult"))).apply {
            isExpanded = true
        }

        // Tree View
        favouritesTreeView.apply {
            cellFactory = IssueSearchTreeItemCell.cellFactory()
            isShowRoot = false
            isEditable = false
            selectionModel.selectedItemProperty().addListener { _, _, selectedItem -> selectedItem?.let { selectIssue(it.value) } }
            root = TreeItem<IssueSearchTreeItem>().apply {
                children.addAll(favouriteSearchesTreeItem, favouriteIssuesTreeItem, searchResultsTreeItem)
            }
        }

        initializeFavourites()
        initializeSearchResults()<commit_msg>preventing selection, hence loading WorkItems, when right clicking favourite<commit_after>package de.pbauerochse.worklogviewer.favourites.fx

import de.pbauerochse.worklogviewer.favourites.issue.FavouriteIssue
import de.pbauerochse.worklogviewer.favourites.searches.FavouriteSearch
import de.pbauerochse.worklogviewer.fx.components.ComponentStyleClasses
import de.pbauerochse.worklogviewer.fx.issuesearch.SavedSearchContextMenu
import de.pbauerochse.worklogviewer.search.fx.SearchTabModel
import de.pbauerochse.worklogviewer.timereport.Issue
import de.pbauerochse.worklogviewer.timereport.fx.table.columns.context.IssueCellContextMenu
import de.pbauerochse.worklogviewer.util.FormattingUtil
import javafx.collections.ListChangeListener
import javafx.fxml.Initializable
import javafx.scene.Node
import javafx.scene.control.TreeCell
import javafx.scene.control.TreeItem
import javafx.scene.control.TreeView
import javafx.scene.input.MouseEvent.MOUSE_PRESSED
import javafx.scene.text.Text
import org.slf4j.LoggerFactory
import java.net.URL
import java.util.*

/**
 * FX Controller for managing the users [de.pbauerochse.worklogviewer.favourites.issue.FavouriteIssue]s
 * and [de.pbauerochse.worklogviewer.favourites.searches.FavouriteSearch]es.
 */
class FavouritesController : Initializable {

    lateinit var favouritesTreeView: TreeView<IssueSearchTreeItem>

    private lateinit var favouriteSearchesTreeItem: TreeItem<IssueSearchTreeItem>
    private lateinit var favouriteIssuesTreeItem: TreeItem<IssueSearchTreeItem>
    private lateinit var searchResultsTreeItem: TreeItem<IssueSearchTreeItem>

    override fun initialize(url: URL?, resourceBundle: ResourceBundle?) {
        // FavouriteSearches
        favouriteSearchesTreeItem = TreeItem(IssueSearchTreeItem.labelledNoopItem(FormattingUtil.getFormatted("dialog.issuesearch.groups.favourites.searches"))).apply {
            isExpanded = true
        }

        // FavouriteIssues
        favouriteIssuesTreeItem = TreeItem(IssueSearchTreeItem.labelledNoopItem(FormattingUtil.getFormatted("dialog.issuesearch.groups.favourites.issues"))).apply {
            isExpanded = true
        }


        // SearchResults (will be removed later)
        searchResultsTreeItem = TreeItem(IssueSearchTreeItem.labelledNoopItem(FormattingUtil.getFormatted("dialog.issuesearch.groups.searchresult"))).apply {
            isExpanded = true
        }

        // Tree View

        favouritesTreeView.addEventFilter(MOUSE_PRESSED) { event ->
            // prevent selection on right click, but still show context menu
            // see https://stackoverflow.com/a/61779016
            if (event.isSecondaryButtonDown) {
                val node = event.target as Node
                val treeCell: TreeCell<*>? = when (node) {
                    is TreeCell<*> -> node
                    is Text -> node.parent as TreeCell<*>
                    else -> null
                }

                treeCell?.let {
                    it.contextMenu?.show(treeCell, 0.0, 0.0)
                    event.consume()
                }
            }
        }
        favouritesTreeView.apply {
            cellFactory = IssueSearchTreeItemCell.cellFactory()
            isShowRoot = false
            isEditable = false
            selectionModel.selectedItemProperty().addListener { _, _, selectedItem -> selectedItem?.let { selectIssue(it.value) } }
            root = TreeItem<IssueSearchTreeItem>().apply {
                children.addAll(favouriteSearchesTreeItem, favouriteIssuesTreeItem, searchResultsTreeItem)
            }
        }

        initializeFavourites()
        initializeSearchResults()
{'fraction_non_alphanumeric': 0.08026233603997501, 'fraction_numerical': 0.0021861336664584633, 'mean_word_length': 3.5587188612099645, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 22, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6821160', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1807, 'n_words': 272}