package _VisualDVM.GlobalData.RunConfiguration.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.Windows.Dialog.DBObjectDialog;
import _VisualDVM.GlobalData.Machine.Machine;
import _VisualDVM.GlobalData.RunConfiguration.RunConfiguration;
import _VisualDVM.Passes.PassCode;

import javax.swing.*;
public class RunConfigurationsForm extends DataSetControlForm<RunConfiguration> {
    public RunConfigurationsForm(DataSet<?, RunConfiguration> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected boolean hasCheckBox() {
        return false;
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<RunConfiguration>("Команда") {
                    @Override
                    public Object getFieldAt(RunConfiguration object) {
                        return object.LauncherCall;
                    }
                },
                new ColumnInfo<RunConfiguration>("Опции") {
                    @Override
                    public Object getFieldAt(RunConfiguration object) {
                        return object.LauncherOptions;
                    }
                },
                new ColumnInfo<RunConfiguration>("Разм.") {
                    @Override
                    public Object getFieldAt(RunConfiguration object) {
                        return object.dim;
                    }
                },
                new ColumnInfo<RunConfiguration>("Куб") {
                    @Override
                    public Object getFieldAt(RunConfiguration object) {
                        return object.printCube();
                    }
                },
                new ColumnInfo<RunConfiguration>("Min") {
                    @Override
                    public Object getFieldAt(RunConfiguration object) {
                        return object.minMatrix;
                    }
                },
                new ColumnInfo<RunConfiguration>("Max") {
                    @Override
                    public Object getFieldAt(RunConfiguration object) {
                        return object.maxMatrix;
                    }
                },
                new ColumnInfo<RunConfiguration>("Аргументы") {
                    @Override
                    public Object getFieldAt(RunConfiguration object) {
                        return object.args;
                    }
                }
        );
    }
    @Override
    public PassCode_ getDeletePassCode() {
        return PassCode.DeleteRunConfiguration;
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(),
                PassCode.Run,
                PassCode.AddRunConfiguration,
                PassCode.EditRunConfiguration,
                PassCode.DeleteRunConfiguration) {
            {
                add(new JSeparator());
                addPasses(PassCode.EditProjectRunMaxtime);
            }
        };
    }
    @Override
    public boolean isObjectVisible(RunConfiguration object) {
        return super.isObjectVisible(object) &&
                MainModule_.instance.getDb().getTable(Machine.class).getUI().matchCurrentID(object.machine_id);
    }
    @Override
    protected DBObjectDialog getDialog() {
        return new RunConfigurationDialog();
    }
}
