package _VisualDVM.TestingSystem.DVM.DVMTasks;
import Common.Database.Tables.DataSet;
import Common.Visual.DataSetControlForm;
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
import _VisualDVM.TestingSystem.DVM.DVMTasks.UI.DVMRunTasksForm;

import javax.swing.*;
public class DVMRunTasksSet extends DataSet<Integer, DVMRunTask> {
    DVMPackage target;
    public DVMRunTasksSet() {
        super(Integer.class, DVMRunTask.class);
    }
    @Override
    public String getSingleDescription() {
        return "задача";
    }
    @Override
    public String getPluralDescription() {
        return "задачи";
    }
    @Override
    protected DataSetControlForm createUI(JPanel mountPanel) {
        return new DVMRunTasksForm(this, mountPanel);
    }
    public void ShowDVMPackage(DVMPackage dvmPackage) {
        target = dvmPackage;
        ClearUI();
        Data.clear();
        if (dvmPackage.package_json == null) {
            if (dvmPackage.getJsonFile().exists()) {
                try {
                    dvmPackage.readJson();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
        if (dvmPackage.package_json != null) {
            for (DVMCompilationTask compilationTask : dvmPackage.package_json.compilationTasks) {
                for (DVMRunTask runTask : compilationTask.runTasks) {
                    Data.put(runTask.id, runTask);
                }
            }
            ShowUI();
        }
    }
    public void ShowNoPackage() {
        ClearUI();
        Data.clear();
        target = null;
    }
}
