package _VisualDVM.GlobalData.Machine.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 Common.Visual.Windows.Dialog.DialogFields;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.Machine.Machine;
import _VisualDVM.Passes.PassCode;

import javax.swing.*;
public class MachinesForm extends DataSetControlForm<Machine> {
    public MachinesForm(DataSet<?, Machine> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<Machine>("имя") {
                    @Override
                    public Object getFieldAt(Machine object) {
                        return object.name;
                    }
                },
                new ColumnInfo<Machine>("URL") {
                    @Override
                    public Object getFieldAt(Machine object) {
                        return object.getURL();
                    }
                }
        );
    }
    @Override
    protected void ShowCurrentObject() throws Exception {
        super.ShowCurrentObject();
        Global.mainModule.getUI().getMainWindow().getTestingWindow().ShowCurrentCompiler();
        Global.mainModule.getUI().mainMenuBar.ShowMachine(dataSource.getUI().getCurrent());
    }
    @Override
    protected void ShowNoCurrentObject() throws Exception {
        super.ShowNoCurrentObject();
        Global.mainModule.getUI().getMainWindow().getTestingWindow().ShowCurrentCompiler();
        Global.mainModule.getUI().mainMenuBar.ShowNoMachine();
    }
    @Override
    public PassCode_ getDeletePassCode() {
        return PassCode.DeleteMachine;
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(),
                PassCode.AddMachine,
                PassCode.EditMachine,
                PassCode.DeleteMachine);
    }
    @Override
    protected DBObjectDialog<Machine, ? extends DialogFields> getDialog() {
        return new MachineDialog();
    }
}
