package _VisualDVM.GlobalData.Tasks.CompilationTask;
import Common.Database.Objects.DBObject;
import Common.Database.Tables.FKBehaviour;
import Common.Database.Tables.FKCurrentObjectBehaviuor;
import Common.Database.Tables.FKDataBehaviour;
import Common.Database.Tables.iDBTable;
import Common.Visual.DataSetControlForm;
import Common.Visual.Menus.TableMenu;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.Tasks.RunTask.RunTask;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.Visual.UI;

import java.util.LinkedHashMap;

import static Common.Visual.Tables.TableRenderers.RendererDate;
import static Common.Visual.Tables.TableRenderers.RendererStatusEnum;
public class CompilationTasksDBTable extends iDBTable<CompilationTask> {
    public CompilationTasksDBTable() {
        super(CompilationTask.class);
    }
    @Override
    public String getSingleDescription() {
        return "задача на компиляцию";
    }
    @Override
    public String getPluralDescription() {
        return "задачи на компиляцию";
    }
    @Override
    public LinkedHashMap<Class<? extends DBObject>, FKBehaviour> getFKDependencies() {
        LinkedHashMap<Class<? extends DBObject>, FKBehaviour> res = new LinkedHashMap<>();
        res.put(RunTask.class, new FKBehaviour(FKDataBehaviour.DELETE, FKCurrentObjectBehaviuor.ACTIVE));
        return res;
    }
    @Override
    protected DataSetControlForm createUI() {
        return new DataSetControlForm(this) {
            @Override
            public boolean hasCheckBox() {
                return true;
            }
            @Override
            protected void AdditionalInitColumns() {
                columns.get(12).setRenderer(RendererDate);
                columns.get(13).setRenderer(RendererStatusEnum);
            }
            @Override
            public void ShowCurrentObject() throws Exception {
                super.ShowCurrentObject();
                UI.getDebugWindow().DropRunTasksComparison();
            }
            @Override
            public void ShowNoCurrentObject() throws Exception {
                super.ShowNoCurrentObject();
                UI.getDebugWindow().DropRunTasksComparison();
            }
            @Override
            public void CreateControl() {
                super.CreateControl();
                TableMenu dataTableMenu = new TableMenu(control);
                dataTableMenu.add(Global.mainModule.getPass(PassCode.DeleteSelectedCompilationTasks).createMenuItem());
                control.setComponentPopupMenu(dataTableMenu);
            }
        };
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{
                "сборка",
                "",
                //
                "Fortran",
                "",
                //
                "С",
                "",
                //
                "С++",
                "",
                "Лимит(c)",
                "Время(c)",
                "Дата",
                "Статус"
        };
    }
    @Override
    public Object getFieldAt(CompilationTask object, int columnIndex) {
        switch (columnIndex) {
            case 2:
                return object.linkerDescription;
            case 3:
                return object.linkFlags;
            case 4:
                return object.fortranCompilerDescription;
            case 5:
                return object.fortranFlags;
            case 6:
                return object.cCompilerDescription;
            case 7:
                return object.cFlags;
            case 8:
                return object.cppCompilerDescription;
            case 9:
                return object.cppFlags;
            case 10:
                return object.maxtime;
            case 11:
                return object.Time;
            case 12:
                return object.getEndDate();
            case 13:
                return object.state;
            default:
                return null;
        }
    }
    @Override
    public Current CurrentName() {
        return Current.CompilationTask;
    }
    @Override
    public Class getMenuBarClass() {
        return CompilationTasksMenuBar.class;
    }
}
