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

import javax.swing.*;
public class EnvironmentsValuesForm extends DataSetControlForm<EnvironmentValue> {
    public EnvironmentsValuesForm(DataSet<?, EnvironmentValue> dataSource_in, JPanel mountPanel_in) {
        super(dataSource_in, mountPanel_in);
    }
    @Override
    protected boolean hasCheckBox() {
        return false;
    }
    @Override
    protected void createColumns() {
        AddColumns(
                new ColumnInfo<EnvironmentValue>("имя") {
                    @Override
                    public Object getFieldAt(EnvironmentValue object) {
                        return object.name;
                    }
                },
                new ColumnInfo<EnvironmentValue>("значение") {
                    @Override
                    public Object getFieldAt(EnvironmentValue object) {
                        return object.value;
                    }
                }
        );
    }
    @Override
    public PassCode_ getDeletePassCode() {
        return PassCode.DeleteEnvironmentValue;
    }
    @Override
    public DataMenuBar createMenuBar() {
        return new DataMenuBar(dataSource.getPluralDescription(),
                PassCode.AddEnvironmentValue,
                PassCode.EditEnvironmentValue,
                PassCode.DeleteEnvironmentValue,
                PassCode.PickCompilerEnvironments);
    }
    @Override
    public boolean isObjectVisible(EnvironmentValue object) {
        return super.isObjectVisible(object) &&
                MainModule_.instance.getDb().getTable(RunConfiguration.class).getUI().matchCurrentID(object.run_configuration_id);
    }
    @Override
    protected DBObjectDialog<EnvironmentValue, ? extends DialogFields> getDialog() {
        return new EnvironmentValueDialog();
    }
}
