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

import javax.swing.*;
public class UsersForm extends DataSetControlForm<User> {
    public UsersForm(DataSet<?, User> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<User>("Логин") {
                    @Override
                    public Object getFieldAt(User object) {
                        return object.login;
                    }
                },
                new ColumnInfo<User>("Статус") {
                    @Override
                    public Object getFieldAt(User object) {
                        return object.state;
                    }
                    @Override
                    public Class getRendererClass() {
                        return RendererStatusEnum.class;
                    }
                }
        );
    }
    @Override
    protected void ShowCurrentObject() throws Exception {
        super.ShowCurrentObject();
        Global.mainModule.getUI().mainMenuBar.ShowUser(dataSource.getUI().getCurrent());
        //Global.mainModule.getUI().getCredentialsMenuBar().ShowUser();
    }
    @Override
    protected void ShowNoCurrentObject() throws Exception {
        super.ShowNoCurrentObject();
        Global.mainModule.getUI().mainMenuBar.ShowNoUser();
        // Global.mainModule.getUI().getCredentialsMenuBar().ShowNoUser();
    }
    @Override
    public PassCode_ getDeletePassCode() {
        return PassCode.DeleteUser;
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(),
                PassCode.AddUser,
                PassCode.EditUser,
                PassCode.InitialiseUser,
                PassCode.DeleteUser);
    }
    @Override
    public boolean isObjectVisible(User object) {
        return super.isObjectVisible(object) &&
                MainModule_.instance.getDb().getTable(Machine.class).getUI().matchCurrentID(object.machine_id);
    }
    @Override
    protected DBObjectDialog getDialog() {
        return new UserDialog();
    }
}