package _VisualDVM.GlobalData.Tasks.RunTask.UI;
import Common.Database.Tables.DataSet;
import Common.MainModule_;
import Common.Passes.PassCode_;
import Common.Visual.DataSetControlForm;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Tables.ColumnInfo;
import Common.Visual.Tables.RendererDate;
import Common.Visual.Tables.RendererStatusEnum;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.Machine.Machine;
import _VisualDVM.GlobalData.RunConfiguration.RunConfiguration;
import _VisualDVM.GlobalData.Tasks.CompilationTask.CompilationTask;
import _VisualDVM.GlobalData.Tasks.RunTask.RunTask;
import _VisualDVM.GlobalData.User.User;
import _VisualDVM.Passes.PassCode;

import javax.swing.*;
public class RunTasksForm extends DataSetControlForm<RunTask> {
    public RunTasksForm(DataSet<?, RunTask> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<RunTask>("Матрица") {
                    @Override
                    public Object getFieldAt(RunTask object) {
                        return object.matrix;
                    }
                },
                new ColumnInfo<RunTask>("Лимит(с)") {
                    @Override
                    public Object getFieldAt(RunTask object) {
                        return object.maxtime;
                    }
                },
                new ColumnInfo<RunTask>("Время(с)") {
                    @Override
                    public Object getFieldAt(RunTask object) {
                        return object.Time;
                    }
                },
                new ColumnInfo<RunTask>("Чистое время") {
                    @Override
                    public Object getFieldAt(RunTask object) {
                        return object.CleanTime;
                    }
                },
                new ColumnInfo<RunTask>("Дата") {
                    @Override
                    public Object getFieldAt(RunTask object) {
                        return object.EndDate;
                    }
                    @Override
                    public Class getRendererClass() {
                        return RendererDate.class;
                    }
                },
                new ColumnInfo<RunTask>("Статус") {
                    @Override
                    public Object getFieldAt(RunTask object) {
                        return object.state;
                    }
                    @Override
                    public Class getRendererClass() {
                        return RendererStatusEnum.class;
                    }
                }
        );
    }
    @Override
    protected void ShowCurrentObject() throws Exception {
        super.ShowCurrentObject();
        Global.mainModule.getUI().getDebugWindow().ShowCurrentRunTask();
    }
    @Override
    protected void ShowNoCurrentObject() throws Exception {
        super.ShowNoCurrentObject();
        Global.mainModule.getUI().getDebugWindow().ShowNoCurrentRunTask();
    }
    @Override
    public PassCode_ getDeletePassCode() {
        return PassCode.DeleteRunTasks;
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(), PassCode.DeleteRunTasks);
    }
    @Override
    public boolean isObjectVisible(RunTask object) {
        return super.isObjectVisible(object) &&
                MainModule_.instance.getDb().getTable(Machine.class).getUI().matchCurrentID(object.machine_id) &&
                MainModule_.instance.getDb().getTable(User.class).getUI().matchCurrentID(object.user_id) &&
                MainModule_.instance.getDb().getTable(RunConfiguration.class).getUI().matchCurrentID(object.run_configuration_id) &&
                Global.mainModule.HasProject() &&
                object.belongsToProject(Global.mainModule.getProject()) &&
                MainModule_.instance.getDb().getTable(CompilationTask.class).getUI().matchCurrentID(object.compilation_task_id);
    }
}
