package TestingSystem.DVM.DVMPackage;
import Common.Current;
import Common.Database.*;
import Common.Global;
import Common.UI.DataSetControlForm;
import Common.UI.UI;

import java.util.Date;

import static Common.UI.Tables.TableRenderers.*;
public class DVMPackageDBTable extends iDBTable<DVMPackage> {
    public DVMPackageDBTable() {
        super(DVMPackage.class);
    }
    @Override
    public Current CurrentName() {
        return Current.DVMPackage;
    }
    @Override
    public String getSingleDescription() {
        return "пакет задач DVM";
    }
    @Override
    public String getPluralDescription() {
        return "пакеты задач DVM";
    }
    @Override
    protected DataSetControlForm createUI() {
        return new DataSetControlForm(this) {
            @Override
            public boolean hasCheckBox() {
                return true;
            }
            @Override
            protected void AdditionalInitColumns() {
                columns.get(8).setRenderer(RendererProgress);
                columns.get(9).setRenderer(RendererDate);
                columns.get(10).setRenderer(RendererDate);
                columns.get(11).setRenderer(RendererStatusEnum);
            }
            @Override
            public void ShowCurrentObject() throws Exception {
                super.ShowCurrentObject();
                Global.testingServer.db.dvmRunTasks.ShowDVMPackage(getCurrent());
                UI.getMainWindow().getTestingWindow().DropTestRunTasksComparison();
            }
            @Override
            public void ShowNoCurrentObject() throws Exception {
                super.ShowNoCurrentObject();
                Global.testingServer.db.dvmRunTasks.ShowNoPackage();
                UI.getMainWindow().getTestingWindow().DropTestRunTasksComparison();
            }
        };
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{
                "Автор",

                "Машина",
                "Пользователь",
                "DVM",
                "Задач",

                "Ядер",
                "Прогресс",
                "Начало",
                "Изменено",
                "Статус"
        };
    }
    @Override
    public Object getFieldAt(DVMPackage object, int columnIndex) {
        switch (columnIndex) {
            case 2:
                return object.sender_name;
            case 3:
                return object.machine_address + ":" + object.machine_port;
            case 4:
                return object.user_name;
            case 5:
                return object.version;
            case 6:
                return object.tasksCount;
            case 7:
                return object.kernels;
            case 8:
                return object.progress;
            case 9:
                return new Date(object.StartDate);
            case 10:
                return new Date(object.ChangeDate);
            case 11:
                return object.state;
            default:
                return null;
        }
    }
}
