package _VisualDVM.ComponentsServer.Recipient.UI;
import Common.Database.Tables.DataSet;
import Common.Visual.DataSetControlForm;
import Common.Visual.Menus.DataMenuBar;
import Common.Visual.Tables.ColumnInfo;
import _VisualDVM.ComponentsServer.Recipient.Recipient;
import _VisualDVM.ComponentsServer.UserAccount.AccountRole;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;

import javax.swing.*;
public class RecipientsForm extends DataSetControlForm<Recipient> {
    public RecipientsForm(DataSet<?, Recipient> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<Recipient>("Имя") {
                    @Override
                    public Object getFieldAt(Recipient object) {
                        return object.name;
                    }
                }
        );
    }
    @Override
    protected DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(), PassCode.SaveBugReportExecutor, PassCode.SaveBugReportRecipients);
    }
    @Override
    protected ColumnInfo<Recipient> createPKColumn() {
        return new ColumnInfo<Recipient>(dataSource.getPKName()) {
            @Override
            public Object getFieldAt(Recipient object) {
                return object.getPK();
            }
            @Override
            public boolean isVisible() {
                return Global.mainModule.getAccount().role.equals(AccountRole.Admin);
            }
        };
    }
}
