<commit_before>package com.elpassion.intelijidea.task.edit

import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.openapi.ui.ValidationInfo
import javax.swing.JTextField

class TaskEditValidator( val form: TaskEditForm) {

    fun doValidate() =
            when {
                taskFieldIsEmpty() -> ValidationInfo("Task cannot be empty", form.taskField())
                buildCommandIsEmpty() -> ValidationInfo("Build command cannot be empty", form.buildCommandField())
                pathIsEmpty() -> ValidationInfo("Path cannot be empty", form.mainframerToolField())
                else -> null
            }

    private fun taskFieldIsEmpty(): Boolean = form.taskField().text.isBlank()

    private fun buildCommandIsEmpty(): Boolean = form.buildCommandField().text.isBlank()

    private fun pathIsEmpty(): Boolean = form.taskField().text.isBlank()

}

interface TaskEditForm {
    fun taskField(): JTextField
    fun buildCommandField(): JTextField
    fun mainframerToolField(): TextFieldWithBrowseButton

}<commit_msg>[#41] Add file validation to TaskEditDialog<commit_after>package com.elpassion.intelijidea.task.edit

import com.elpassion.intelijidea.util.mfFilename
import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.openapi.ui.ValidationInfo
import java.io.File
import javax.swing.JTextField

class TaskEditValidator(val form: TaskEditForm) {

    fun doValidate() =
            when {
                taskFieldIsEmpty() -> ValidationInfo("Task cannot be empty", form.taskField())
                buildCommandIsEmpty() -> ValidationInfo("Build command cannot be empty", form.buildCommandField())
                pathIsEmpty() -> ValidationInfo("Path cannot be empty", form.mainframerToolField())
                pathIsInvalid() -> ValidationInfo("Path cannot be empty", form.mainframerToolField())
                else -> null
            }

    private fun pathIsInvalid() = !File(form.mainframerToolField().text, mfFilename).exists()

    private fun taskFieldIsEmpty() = form.taskField().text.isBlank()

    private fun buildCommandIsEmpty() = form.buildCommandField().text.isBlank()

    private fun pathIsEmpty() = form.mainframerToolField().text.isBlank()

}

interface TaskEditForm {
    fun taskField(): JTextField
    fun buildCommandField(): JTextField
    fun mainframerToolField(): TextFieldWithBrowseButton

}
{'fraction_non_alphanumeric': 0.10460251046025104, 'fraction_numerical': 0.0008368200836820083, 'mean_word_length': 3.6608187134502925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '2278503', 'n_tokens_mistral': 667, 'n_tokens_neox': 640, 'n_words': 149}