package _VisualDVM.GlobalData.Compiler.UI;
import Common.Database.Tables.DataSet;
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.Global;
import _VisualDVM.GlobalData.Compiler.Compiler;
import _VisualDVM.GlobalData.Machine.Machine;
import _VisualDVM.Passes.PassCode;

import javax.swing.*;
public class CompilersForm extends DataSetControlForm<Compiler> {
    public CompilersForm(DataSet<?, Compiler> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<Compiler>("описание") {
                    @Override
                    public Object getFieldAt(Compiler object) {
                        return object.description;
                    }
                },
                new ColumnInfo<Compiler>("команда вызова") {
                    @Override
                    public Object getFieldAt(Compiler object) {
                        return object.call_command;
                    }
                },
                new ColumnInfo<Compiler>("версия") {
                    @Override
                    public Object getFieldAt(Compiler object) {
                        return object.version;
                    }
                },
                new ColumnInfo<Compiler>("ревизия") {
                    @Override
                    public Object getFieldAt(Compiler object) {
                        return object.revision;
                    }
                }
        );
    }
    @Override
    protected void ShowCurrentObject() throws Exception {
        super.ShowCurrentObject();
        Global.mainModule.getUI().getMainWindow().getTestingWindow().ShowCurrentCompiler();
        Global.mainModule.getUI().mainMenuBar.ShowCompiler(dataSource.getUI().getCurrent());
    }
    @Override
    protected void ShowNoCurrentObject() throws Exception {
        super.ShowNoCurrentObject();
        Global.mainModule.getUI().getMainWindow().getTestingWindow().ShowCurrentCompiler();
        Global.mainModule.getUI().mainMenuBar.ShowNoCompiler();
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(), PassCode.AddCompiler,
                PassCode.EditCompiler,
                PassCode.DeleteCompiler,
                PassCode.ShowCompilerVersion,
                PassCode.ShowCompilerHelp);
    }
    @Override
    public boolean isObjectVisible(Compiler object) {
        return super.isObjectVisible(object) &&
                Global.mainModule.getDb().getTable(Machine.class).getUI().matchCurrentID(object.machine_id);
    }
    @Override
    protected DBObjectDialog getDialog() {
        return new CompilerDialog();
    }
    @Override
    public PassCode_ getDeletePassCode() {
        return PassCode.DeleteCompiler;
    }
}
