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

import javax.swing.*;
public class EnvironmentsLinesSet extends DataSet<Integer, EnvironmentsLine> {
    public int maxId = 1;
    public EnvironmentsLinesSet() {
        super(Integer.class, EnvironmentsLine.class);
    }
    public EnvironmentsLinesSet(EnvironmentsSetJson json) {
        super(Integer.class, EnvironmentsLine.class);
        for (EnvironmentsJson environmentsJson : json.values) {
            EnvironmentsLine environmentsLine = new EnvironmentsLine(environmentsJson);
            environmentsLine.id = maxId++;
            put(environmentsLine.id, environmentsLine);
        }
    }
    @Override
    public String getSingleDescription() {
        return "набор переменных окружения";
    }
    @Override
    public String getPluralDescription() {
        return "наборы переменных окружения";
    }
    @Override
    protected DataSetControlForm createUI(JPanel mountPanel) {
        return new EnvironmentsLinesForm(this, mountPanel);
    }
    public EnvironmentsSetJson toJson() {
        EnvironmentsSetJson res = new EnvironmentsSetJson();
        for (EnvironmentsLine environmentsLine : Data.values()) {
            res.values.add(environmentsLine.json);
        }
        return res;
    }
}
