package _VisualDVM.GlobalData.Tasks.RunTask;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import Common.Visual.Menus.TableMenu;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.Visual.UI;

import static Common.Visual.Tables.TableRenderers.RendererDate;
import static Common.Visual.Tables.TableRenderers.RendererStatusEnum;
public class RunTasksDBTable extends iDBTable<RunTask> {
    public RunTasksDBTable() {
        super(RunTask.class);
    }
    @Override
    public String getSingleDescription() {
        return "задача на запуск";
    }
    @Override
    public String getPluralDescription() {
        return "задачи на запуск";
    }
    @Override
    protected DataSetControlForm createUI() {
        return new DataSetControlForm(this) {
            @Override
            public boolean hasCheckBox() {
                return true;
            }
            @Override
            protected void AdditionalInitColumns() {
                columns.get(6).setRenderer(RendererDate);
                columns.get(7).setRenderer(RendererStatusEnum);
            }
            @Override
            public void ShowCurrentObject() throws Exception {
                super.ShowCurrentObject();
                UI.getDebugWindow().ShowCurrentRunTask();
            }
            @Override
            public void ShowNoCurrentObject() throws Exception {
                super.ShowNoCurrentObject();
                UI.getDebugWindow().ShowNoCurrentRunTask();
            }
            @Override
            public void CreateControl() {
                super.CreateControl();
                TableMenu dataTableMenu = new TableMenu(control);
                dataTableMenu.add(Global.mainModule.getPass(PassCode.DeleteSelectedRunTasks).createMenuItem());
                control.setComponentPopupMenu(dataTableMenu);
            }
        };
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{
                "Матрица",
                "Лимит(с)",
                "Время(с)",
                "Чистое время",
                "Дата",
                "Статус"};
    }
    @Override
    public Object getFieldAt(RunTask object, int columnIndex) {
        switch (columnIndex) {
            case 2:
                return object.matrix;
            case 3:
                return object.maxtime;
            case 4:
                return object.Time;
            case 5:
                return object.CleanTime;
            case 6:
                return object.getEndDate();
            case 7:
                return object.state;
            default:
                return null;
        }
    }
    @Override
    public Current CurrentName() {
        return Current.RunTask;
    }
    @Override
    public Class getMenuBarClass() {
        return RunTasksMenuBar.class;
    }
}
