package TestingSystem.Common.Test;
import Common.Current;
import Common.Database.iDBTable;
import Common.UI.DataSetControlForm;
import Common.UI.Windows.Dialog.DBObjectDialog;
import TestingSystem.Common.Test.UI.TestFields;
public class TestDBTable extends iDBTable<Test> {
    public TestDBTable() {
        super(Test.class);
    }
    @Override
    public String getSingleDescription() {
        return "тест DVM";
    }
    @Override
    public String getPluralDescription() {
        return "тесты";
    }
    @Override
    protected DataSetControlForm createUI() {
        return new DataSetControlForm(this) {
            @Override
            protected void AdditionalInitColumns() {
                //columns.get(0).setVisible(false);
            }
            @Override
            public boolean hasCheckBox() {
                return true;
            }
        };
    }
    @Override
    public Object getFieldAt(Test object, int columnIndex) {
        switch (columnIndex) {
            case 2:
                return object.description;
            case 3:
                return object.min_dim;
            case 4:
                return object.max_dim;
            case 5:
                return object.getFilesForTable();
            default:
                return null;
        }
    }
    @Override
    public String[] getUIColumnNames() {
        return new String[]{
                "имя",
                "min_dim",
                "max_dim",
                "файлы"
        };
    }
    @Override
    public Current CurrentName() {
        return Current.Test;
    }
    @Override
    public DBObjectDialog<Test, TestFields> getDialog() {
        return new DBObjectDialog<Test, TestFields>(TestFields.class) {
            @Override
            public int getDefaultHeight() {
                return 200;
            }
            @Override
            public int getDefaultWidth() {
                return 400;
            }
            @Override
            public void validateFields() {
                if (!edit) {
                    if (!Current.getGroup().language.equals(Current.getProject().languageName))
                        Log.Writeln_("В текущую группу могут войти только тесты на языке " + Current.getGroup().language);
                }
            }
            @Override
            public void fillFields() {
                fields.tfName.setText(Result.description);
                fields.sMinDim.setValue(Result.min_dim);
                fields.sMaxDim.setValue(Result.max_dim);
            }
            @Override
            public void ProcessResult() {
                Result.description = fields.tfName.getText();
                Result.min_dim = (int) fields.sMinDim.getValue();
                Result.max_dim = (int) fields.sMaxDim.getValue();
                if (!edit) {
                    Result.sender_name = Current.getAccount().name;
                    Result.sender_address = Current.getAccount().email;
                }
            }
        };
    }
}