package _VisualDVM.GlobalData.CompilerEnvironment;
import Common.Database.Tables.DataSet;
import Common.Visual.DataSetControlForm;
import _VisualDVM.GlobalData.CompilerEnvironment.Json.EnvironmentJson;
import _VisualDVM.GlobalData.CompilerEnvironment.Json.EnvironmentsJson;
import _VisualDVM.GlobalData.CompilerEnvironment.UI.CompilerEnvironmentsForm;

import javax.swing.*;
public class RawCompilerEnvironmentsSet extends DataSet<String, CompilerEnvironment> {
    public RawCompilerEnvironmentsSet() {
        super(String.class, CompilerEnvironment.class);
    }
    @Override
    protected DataSetControlForm createUI(JPanel mountPanel) {
        return new CompilerEnvironmentsForm(this, mountPanel);
    }
    @Override
    public String getPluralDescription() {
        return "переменные окружения";
    }
    @Override
    public String getSingleDescription() {
        return "переменная окружения";
    }
    public CompilerEnvironment findByJson(EnvironmentJson json) {
        for (CompilerEnvironment compilerEnvironment : Data.values()) {
            if (json.name.equals(compilerEnvironment.name))
                return compilerEnvironment;
        }
        return null;
    }
    public void Reset() {
        for (CompilerEnvironment environment : Data.values()) {
            environment.select(false);
            environment.value = "";
        }
    }
    public void Synchronize(EnvironmentsJson json) {
        for (EnvironmentJson environmentJson : json.values) {
            CompilerEnvironment compilerEnvironment = findByJson(environmentJson);
            if (compilerEnvironment != null) {
                compilerEnvironment.select(true);
                compilerEnvironment.value = environmentJson.value;
            }
        }
    }
}
