<commit_before>package uk.co.reecedunn.intellij.plugin.intellij.settings

import com.intellij.openapi.fileChooser.FileTypeDescriptor
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.ComponentWithBrowseButton
import com.intellij.openapi.ui.TextComponentAccessor
import com.intellij.ui.ColoredListCellRenderer
import uk.co.reecedunn.intellij.plugin.core.ui.SettingsUI
import uk.co.reecedunn.intellij.plugin.intellij.resources.XQueryBundle
import uk.co.reecedunn.intellij.plugin.processor.query.ConnectionSettings
import uk.co.reecedunn.intellij.plugin.processor.query.QueryProcessorApi
import uk.co.reecedunn.intellij.plugin.processor.query.QueryProcessorSettings
import javax.swing.*

class QueryProcessorSettingsUI(private val project: Project) : SettingsUI<QueryProcessorSettings> {
    // region Processor APIs

    private var api: JComboBox<QueryProcessorApi>? = null

    private fun createQueryProcessorApiUI() {
        api = ComboBox()
        api!!.renderer = object : ColoredListCellRenderer<QueryProcessorApi>() {
            override fun customizeCellRenderer(
                list: JList<out QueryProcessorApi>,
                value: QueryProcessorApi?,
                index: Int, selected: Boolean, hasFocus: Boolean
            ) {
                if (value != null) {
                    append(value.displayName)
                }
            }
        }

        QueryProcessorApi.values().forEach { value -> api!!.addItem(value) }
    }

    // endregion
    // region Processor APIs

    private var jar: ComponentWithBrowseButton<JTextField>? = null

    private fun createJarUI() {
        jar = ComponentWithBrowseButton(JTextField(), null)
        jar!!.addBrowseFolderListener(
            XQueryBundle.message("browser.choose.implementation-api-jar"), null,
            project,
            FileTypeDescriptor(XQueryBundle.message("browser.choose.implementation-api-jar"), "jar"),
            TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT
        )
    }

    // endregion
    // region Form

    private var name: JTextField? = null
    private var standalone: JCheckBox? = null
    private var hostname: JTextField? = null
    private var serverPort: JTextField? = null
    private var username: JTextField? = null
    private var password: JPasswordField? = null

    private fun createUIComponents() {
        name = JTextField()
        standalone = JCheckBox()
        hostname = JTextField()
        serverPort = JTextField()
        username = JTextField()
        password = <PASSWORD>()
        createQueryProcessorApiUI()
        createJarUI()
    }

    // endregion
    // region SettingsUI

    override var panel: JPanel? = null

    override fun isModified(configuration: QueryProcessorSettings): Boolean {
        return false
    }

    override fun reset(configuration: QueryProcessorSettings) {
        name!!.text = configuration.name
        api!!.selectedItem = configuration.api
        jar!!.childComponent.text = configuration.jar
        if (configuration.connection != null) {
            standalone!!.isSelected = true
            hostname!!.text = configuration.connection!!.hostname
            serverPort!!.text = configuration.connection!!.port.toString()
            username!!.text = configuration.connection!!.username<commit_msg>Enable/disable the connection details depending on whether or not the standalone checkbox is checked or not.<commit_after>package uk.co.reecedunn.intellij.plugin.intellij.settings

import com.intellij.openapi.fileChooser.FileTypeDescriptor
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.ComponentWithBrowseButton
import com.intellij.openapi.ui.TextComponentAccessor
import com.intellij.ui.ColoredListCellRenderer
import uk.co.reecedunn.intellij.plugin.core.ui.SettingsUI
import uk.co.reecedunn.intellij.plugin.intellij.resources.XQueryBundle
import uk.co.reecedunn.intellij.plugin.processor.query.ConnectionSettings
import uk.co.reecedunn.intellij.plugin.processor.query.QueryProcessorApi
import uk.co.reecedunn.intellij.plugin.processor.query.QueryProcessorSettings
import javax.swing.*

class QueryProcessorSettingsUI(private val project: Project) : SettingsUI<QueryProcessorSettings> {
    // region Processor APIs

    private var api: JComboBox<QueryProcessorApi>? = null

    private fun createQueryProcessorApiUI() {
        api = ComboBox()
        api!!.renderer = object : ColoredListCellRenderer<QueryProcessorApi>() {
            override fun customizeCellRenderer(
                list: JList<out QueryProcessorApi>,
                value: QueryProcessorApi?,
                index: Int, selected: Boolean, hasFocus: Boolean
            ) {
                if (value != null) {
                    append(value.displayName)
                }
            }
        }

        QueryProcessorApi.values().forEach { value -> api!!.addItem(value) }
    }

    // endregion
    // region Processor JAR

    private var jar: ComponentWithBrowseButton<JTextField>? = null

    private fun createJarUI() {
        jar = ComponentWithBrowseButton(JTextField(), null)
        jar!!.addBrowseFolderListener(
            XQueryBundle.message("browser.choose.implementation-api-jar"), null,
            project,
            FileTypeDescriptor(XQueryBundle.message("browser.choose.implementation-api-jar"), "jar"),
            TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT
        )
    }

    // endregion
    // region Standalone

    private var standalone: JCheckBox? = null

    private fun createStandaloneUI() {
        standalone = JCheckBox()
        standalone!!.addActionListener { action ->
            val serverEnabled = !standalone!!.isSelected
            hostname!!.isEnabled = serverEnabled
            serverPort!!.isEnabled = serverEnabled
            username!!.isEnabled = serverEnabled
            password!!.isEnabled = serverEnabled
        }
    }

    // endregion
    // region Form

    private var name: JTextField? = null
    private var hostname: JTextField? = null
    private var serverPort: JTextField? = null
    private var username: JTextField? = null
    private var password: JPasswordField? = null

    private fun createUIComponents() {
        name = JTextField()
        hostname = JTextField()
        serverPort = JTextField()
        username = JTextField()
        password = JPasswordField()
        createQueryProcessorApiUI()
        createJarUI()
        createStandaloneUI()
    }

    // endregion
    // region SettingsUI

    override var panel: JPanel? = null

    override fun isModified(configuration: QueryProcessorSettings): Boolean {
        return false
    }

    override fun reset(configuration: QueryProcessorSettings) {
        name!!.text = configuration.name
        api!!.selectedItem = configuration.api
        jar!!.childComponent.text = configuration.jar
        if (configuration.connection != null) {
            standalone!!.isSelected = true
            hostname!!.text = configuration.connection!!.hostname
            serverPort!!.text = configuration.connection!!.port.toString()
            username!!.text = configuration.connection!!.username
{'fraction_non_alphanumeric': 0.09132294109532349, 'fraction_numerical': 0.0, 'mean_word_length': 2.856382978723404, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '264110', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1877, 'n_words': 388}