package _VisualDVM.ProjectData.SapforData.Arrays.UI;
import Common.MainModule_;
import Common.Visual.ControlForm;
import Common.Visual.Tables.Grid.GridAnchestor;
import Common.Visual.Tables.StyledTable;
import _VisualDVM.Global;
import _VisualDVM.ProjectData.SapforData.Arrays.ProjectArray;
import _VisualDVM.ProjectData.SapforData.Arrays.Templates.TemplateDimension;

import javax.swing.*;
import java.util.Vector;
public class DimensionsTableForm extends ControlForm<StyledTable> {
    public DimensionsTableForm(JPanel mountPanel_in) {
        super(StyledTable.class, mountPanel_in);
    }
    @Override
    protected void createControl() {
        Vector<String> columns = new Vector<>();
        columns.add("шаблон");
        for (int i = 0; i < Global.mainModule.getProject().maxdim; ++i)
            columns.add(ProjectArray.alignNames[i]);
        Vector<Object> dimensions = new Vector<>();
        Global.mainModule.getProject().templates.forEach(t -> dimensions.add(t.CreateTemplateCells()));
        control = new StyledTable(new GridAnchestor(columns, dimensions) {
            @Override
            public Object getValueAt(int rowIndex, int columnIndex) {
                return ((Object[]) data.get(rowIndex))[columnIndex];
            }
            @Override
            public boolean isCellEditable(int row, int col) {
                return (col > 0) && !((TemplateDimension) getValueAt(row, col)).isBlocked();
            }
        }) {
            @Override
            public void Init() {
                setDefaultRenderer(TemplateDimension.class, MainModule_.instance.getUI().getTableRenderer(DimensionRenderer.class));
                setDefaultEditor(TemplateDimension.class, MainModule_.instance.getUI().getTableEditor(DimensionStateChanger.class));
            }
        };
    }
}
