<commit_before>package nl.mpi.arbil.ui.fieldeditors;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import javax.swing.JComboBox;
import nl.mpi.arbil.ui.DocumentationLanguages;
import nl.mpi.arbil.ui.GuiHelper;
import nl.mpi.arbil.data.ArbilField;
import nl.mpi.arbil.data.ArbilVocabularies;

/**
 *  Document   : LanguageIdBox
 *  Created on : Sep 14, 2010, 3:58:33 PM
 *  Author     : <NAME>
 */
public class LanguageIdBox extends JComboBox {

    public static int languageSelectWidth = 100;
    static String defaultLanguageDropDownValue = "<select>";

    public LanguageIdBox(final ArbilField cellField, Rectangle parentCellRect) {
        String fieldLanguageId = cellField.getLanguageId();
//        if (fieldLanguageId != null) {
        System.out.println("Has LanguageId");
        ArbilVocabularies.VocabularyItem selectedItem = null;
        this.setEditable(false);
        ArbilVocabularies.VocabularyItem[] languageItemArray = new DocumentationLanguages().getLanguageListSubset();
        Arrays.sort(languageItemArray);
        for (ArbilVocabularies.VocabularyItem currentItem : languageItemArray) {
            this.addItem(currentItem);
            if (fieldLanguageId.equals(currentItem.itemCode)) {
                selectedItem = currentItem;
            }
        }
        if (selectedItem != null) {
            System.out.println("selectedItem: " + selectedItem);
            this.setSelectedItem(selectedItem);
        } else {
            this.addItem(defaultLanguageDropDownValue);
            this.setSelectedItem(defaultLanguageDropDownValue);
        }
        this.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
//                        ImdiField cellField = (ImdiField) cellValue[cellFieldIndex];
                    if (LanguageIdBox.this.getSelectedItem() instanceof ArbilVocabularies.VocabularyItem) {
                        cellField.setLanguageId(((ArbilVocabularies.VocabularyItem) LanguageIdBox.this.getSelectedItem()).itemCode, true, false);
                    }<commit_msg>Modified the description language dropdown to handle the changes to the controlled vocabularies see https://trac.mpi.nl/ticket/563#<commit_after>package nl.mpi.arbil.ui.fieldeditors;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import javax.swing.JComboBox;
import nl.mpi.arbil.ui.DocumentationLanguages;
import nl.mpi.arbil.ui.GuiHelper;
import nl.mpi.arbil.data.ArbilField;
import nl.mpi.arbil.data.ArbilVocabularies;

/**
 *  Document   : LanguageIdBox
 *  Created on : Sep 14, 2010, 3:58:33 PM
 *  Author     : <NAME>
 */
public class LanguageIdBox extends JComboBox {

    public static int languageSelectWidth = 100;
    static String defaultLanguageDropDownValue = "<select>";

    public LanguageIdBox(final ArbilField cellField, Rectangle parentCellRect) {
        String fieldLanguageId = cellField.getLanguageId();
//        if (fieldLanguageId != null) {
        System.out.println("Has LanguageId");
        ArbilVocabularies.VocabularyItem selectedItem = null;
        this.setEditable(false);
        ArbilVocabularies.VocabularyItem[] languageItemArray = new DocumentationLanguages().getLanguageListSubset();
        Arrays.sort(languageItemArray);
        for (ArbilVocabularies.VocabularyItem currentItem : languageItemArray) {
            this.addItem(currentItem);
            // the code and description values have become unreliable due to changes to the controlled vocabularies see https://trac.mpi.nl/ticket/563#
            if (fieldLanguageId.equals(currentItem.itemCode) || fieldLanguageId.equals(currentItem.descriptionString)) {
                selectedItem = currentItem;
            }
        }
        if (selectedItem != null) {
            System.out.println("selectedItem: " + selectedItem);
            this.setSelectedItem(selectedItem);
        } else {
            this.addItem(defaultLanguageDropDownValue);
            this.setSelectedItem(defaultLanguageDropDownValue);
        }
        this.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
//                        ImdiField cellField = (ImdiField) cellValue[cellFieldIndex];
                    if (LanguageIdBox.this.getSelectedItem() instanceof ArbilVocabularies.VocabularyItem) {
                        ArbilVocabularies.VocabularyItem selectedLanguage = (ArbilVocabularies.VocabularyItem) LanguageIdBox.this.getSelectedItem();
                        String languageCode = selectedLanguage.itemCode;
                        if (languageCode == null) {
                            // the code and description values have become unreliable due to changes to the controlled vocabularies see https://trac.mpi.nl/ticket/563#
                            languageCode = selectedLanguage.descriptionString;
                        }
                        cellField.setLanguageId(languageCode, true, false);
                    }
{'fraction_non_alphanumeric': 0.08919646289888504, 'fraction_numerical': 0.007112648981161092, 'mean_word_length': 2.78125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5825863', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1397, 'n_words': 274}