package _VisualDVM.GlobalData.Module.UI;
import Common.Database.Tables.DataSet;
import Common.MainModule_;
import Common.Visual.DataSetControlForm;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Tables.ColumnInfo;
import Common.Visual.Windows.Dialog.DBObjectDialog;
import Common.Visual.Windows.Dialog.DialogFields;
import _VisualDVM.GlobalData.Makefile.Makefile;
import _VisualDVM.GlobalData.Module.Module;
import _VisualDVM.Passes.PassCode;

import javax.swing.*;
public class ModulesForm extends DataSetControlForm<Module> {
    public ModulesForm(DataSet<?, Module> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected boolean isPKVisible() {
        return false;
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<Module>("Язык") {
                    @Override
                    public Object getFieldAt(Module object) {
                        return object.language.getDescription();
                    }
                },
                new ColumnInfo<Module>("Компилятор") {
                    @Override
                    public Object getFieldAt(Module object) {
                        return object.getCompilerDescription();
                    }
                },
                new ColumnInfo<Module>("Команда") {
                    @Override
                    public Object getFieldAt(Module object) {
                        return object.command;
                    }
                },
                new ColumnInfo<Module>("Флаги") {
                    @Override
                    public Object getFieldAt(Module object) {
                        return object.flags;
                    }
                }
        );
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(), PassCode.EditModule);
    }
    @Override
    public boolean isObjectVisible(Module object) {
        return super.isObjectVisible(object) &&
                MainModule_.instance.getDb().getTable(Makefile.class).getUI().matchCurrentID(object.makefile_id);
    }
    @Override
    protected DBObjectDialog<Module, ? extends DialogFields> getDialog() {
        return new ModuleAnchestorForm<>();
    }
}
