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

import javax.swing.*;
public class SubscriberWorkspacesForm extends DataSetControlForm<SubscriberWorkspace> {
    public SubscriberWorkspacesForm(DataSet<?, SubscriberWorkspace> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected boolean isPKVisible() {
        return false;
    }
    @Override
    protected boolean hasCheckBox() {
        return false;
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<SubscriberWorkspace>("URL") {
                    @Override
                    public Object getFieldAt(SubscriberWorkspace object) {
                        return object.URL;
                    }
                },
                new ColumnInfo<SubscriberWorkspace>("пользователь") {
                    @Override
                    public Object getFieldAt(SubscriberWorkspace object) {
                        return object.login;
                    }
                },
                new ColumnInfo<SubscriberWorkspace>("папка") {
                    @Override
                    public Object getFieldAt(SubscriberWorkspace object) {
                        return object.path;
                    }
                }
        );
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(), PassCode.DeleteRemoteWorkspace);
    }
    @Override
    public boolean isObjectVisible(SubscriberWorkspace object) {
        UserAccount account = Global.componentsServer.credentials_db.userAccounts.getUI().getCurrent();
        return super.isObjectVisible(object) && (account != null) && account.email.equals(object.email) &&
                (Global.mainModule.getAccount().isAdmin() || Global.mainModule.getAccount().email.equals(account.email));
    }
}
