package _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.UI;
import Common.Database.Tables.DataSet;
import Common.Passes.PassCode_;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Tables.ColumnInfo;
import Common.Visual.Tables.RendererDate;
import Common.Visual.Tables.RendererStatusEnum;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
import _VisualDVM.Visual.RDataSetControlForm;

import javax.swing.*;
import java.util.Comparator;
public class ServerSapforsForm extends RDataSetControlForm<ServerSapfor> {
    public ServerSapforsForm(DataSet<?, ServerSapfor> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<ServerSapfor>("версия") {
                    @Override
                    public Object getFieldAt(ServerSapfor object) {
                        return object.version;
                    }
                },
                new ColumnInfo<ServerSapfor>("автор") {
                    @Override
                    public Object getFieldAt(ServerSapfor object) {
                        return object.sender_name;
                    }
                },
                new ColumnInfo<ServerSapfor>("дата сборки") {
                    @Override
                    public Object getFieldAt(ServerSapfor object) {
                        return object.buildDate;
                    }
                    @Override
                    public Class getRendererClass() {
                        return RendererDate.class;
                    }
                },
                new ColumnInfo<ServerSapfor>("сборка") {
                    @Override
                    public Object getFieldAt(ServerSapfor object) {
                        return object.state;
                    }
                    @Override
                    public Class getRendererClass() {
                        return RendererStatusEnum.class;
                    }
                }
        );
    }
    @Override
    protected void ShowCurrentObject() throws Exception {
        super.ShowCurrentObject();
        Global.mainModule.getUI().getMainWindow().getTestingWindow().ShowCurrentServerSapfor();
    }
    @Override
    protected void ShowNoCurrentObject() throws Exception {
        super.ShowNoCurrentObject();
        Global.mainModule.getUI().getMainWindow().getTestingWindow().ShowNoServerSapfor();
    }
    @Override
    public PassCode_ getDeletePassCode() {
        return PassCode.DeleteServerSapfor;
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(),
                PassCode.CompileServerSapfor,
                PassCode.ShowSapforCompilationOut,
                PassCode.ShowSapforCompilationErr,
                PassCode.DeleteServerSapfor);
    }
    @Override
    protected Comparator<ServerSapfor> getDefaultComparator() {
        return new Comparator<ServerSapfor>() {
            @Override
            public int compare(ServerSapfor o1, ServerSapfor o2) {
                return o2.id - o1.id;
            }
        };
    }
}
