package _VisualDVM.GlobalData.Tasks.CompilationTask.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.Tasks.CompilationTask.CompilationTask;
import _VisualDVM.GlobalData.User.User;
import _VisualDVM.Passes.PassCode;

import javax.swing.*;
public class CompilationTasksForm extends DataSetControlForm<CompilationTask> {
    public CompilationTasksForm(DataSet<?, CompilationTask> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<CompilationTask>("сборка") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.linkerDescription;
                    }
                },
                new ColumnInfo<CompilationTask>("") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.linkFlags;
                    }
                },
                new ColumnInfo<CompilationTask>("Fortran") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.fortranCompilerDescription;
                    }
                },
                new ColumnInfo<CompilationTask>("") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.fortranFlags;
                    }
                },
                new ColumnInfo<CompilationTask>("С") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.cCompilerDescription;
                    }
                },
                new ColumnInfo<CompilationTask>("") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.cFlags;
                    }
                },
                new ColumnInfo<CompilationTask>("С++") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.cppCompilerDescription;
                    }
                },
                new ColumnInfo<CompilationTask>("") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.cppFlags;
                    }
                },
                new ColumnInfo<CompilationTask>("Лимит(c)") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.maxtime;
                    }
                },
                new ColumnInfo<CompilationTask>("Время(c)") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.Time;
                    }
                },
                new ColumnInfo<CompilationTask>("Дата") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.EndDate;
                    }
                    @Override
                    public Class getRendererClass() {
                        return RendererDate.class;
                    }
                },
                new ColumnInfo<CompilationTask>("Статус") {
                    @Override
                    public Object getFieldAt(CompilationTask object) {
                        return object.state;
                    }
                    @Override
                    public Class getRendererClass() {
                        return RendererStatusEnum.class;
                    }
                }
        );
    }
    @Override
    protected void ShowCurrentObject() throws Exception {
        super.ShowCurrentObject();
        Global.mainModule.getUI().getDebugWindow().DropRunTasksComparison();
    }
    @Override
    protected void ShowNoCurrentObject() throws Exception {
        super.ShowNoCurrentObject();
        Global.mainModule.getUI().getDebugWindow().DropRunTasksComparison();
    }
    @Override
    public PassCode_ getDeletePassCode() {
        return PassCode.DeleteCompilationTasks;
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(), PassCode.DeleteCompilationTasks);
    }
    @Override
    public boolean isObjectVisible(CompilationTask 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) &&
                Global.mainModule.HasProject() &&
                object.belongsToProject(Global.mainModule.getProject());
    }
}
