package _VisualDVM.GlobalData.Makefile.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.Makefile.Makefile;
import _VisualDVM.GlobalData.Module.UI.ModuleAnchestorFields;
import _VisualDVM.GlobalData.Module.UI.ModuleAnchestorForm;
import _VisualDVM.Passes.PassCode;

import javax.swing.*;
public class MakefilesForm extends DataSetControlForm<Makefile> {
    public MakefilesForm(DataSet<?, Makefile> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<Makefile>("Линковщик") {
                    @Override
                    public Object getFieldAt(Makefile object) {
                        return object.getCompilerDescription();
                    }
                },
                new ColumnInfo<Makefile>("Команда") {
                    @Override
                    public Object getFieldAt(Makefile object) {
                        return object.command;
                    }
                },
                new ColumnInfo<Makefile>("Флаги") {
                    @Override
                    public Object getFieldAt(Makefile object) {
                        return object.flags;
                    }
                }
        );
    }
    @Override
    public PassCode_ getDeletePassCode() {
        return PassCode.DeleteMakefile;
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(),
                PassCode.Compile,
                PassCode.AddMakefile,
                PassCode.EditMakefile,
                PassCode.DeleteMakefile) {
            {
                addSeparator();
                addPasses(PassCode.ShowMakefilePreview, PassCode.EditProjectCompilationMaxtime);
            }
        };
    }
    @Override
    public boolean isObjectVisible(Makefile object) {
        return super.isObjectVisible(object) &&
                MainModule_.instance.getDb().getTable(Machine.class).getUI().matchCurrentID(object.machine_id);
    }
    @Override
    protected DBObjectDialog<Makefile, ModuleAnchestorFields> getDialog() {
        return new ModuleAnchestorForm<>();
    }
}
