Package reportgen.gui.genepanel.formatpanel

Source Code of reportgen.gui.genepanel.formatpanel.FormatTableModel

package reportgen.gui.genepanel.formatpanel;

import reportgen.prototype.utils.ItemSelectorEditable;
import javax.swing.table.AbstractTableModel;
import reportgen.ren.report.extendedformat.table.TableFormat;


/**
*
* @author axe
*/
class FormatTableModel extends AbstractTableModel {

    public static final int COL_TITLE = 0;
    public static final int COL_ENABLED = 1;
    public static final int COL_COUNT = 2;
   
    private ItemSelectorEditable<TableFormat>  tables;

    public FormatTableModel(ItemSelectorEditable<TableFormat>  tables) {
        this.tables = tables;
    }

    public TableFormat getField(int index) {
        return tables.get(index);
    }
   
    @Override
    public int getRowCount() {
        return  tables.size();
    }

    @Override
    public int getColumnCount() {
        return COL_COUNT;
    }

    @Override
    public String getColumnName(int col) {
        switch(col) {
            case COL_TITLE: {
                return "Название результата";
            }
            case COL_ENABLED: {
                return "Включена";
            }
        }
        return super.getColumnName(col);
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if(columnIndex == COL_ENABLED) {
            return Boolean.class;
        }
        return super.getColumnClass(columnIndex);
    }


    @Override
    public Object getValueAt(int row, int col) {
        TableFormat table = tables.get(row);
        switch(col) {
            case COL_TITLE: {
                Object val = table.getTitle();
                if(val != null) {
                    return val;
                }
                break;
            }
            case COL_ENABLED: {
                return table.isEnabled();
            }
        }
        return null;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        TableFormat table = tables.get(rowIndex);
        switch(columnIndex) {
            case COL_TITLE: {
                String newTitle = aValue.toString();
                table.setTitle(newTitle);
                break;
            }
            case COL_ENABLED: {
                table.setEnabled((Boolean)aValue);
                break;
            }
        }
    }
   
   
}
TOP

Related Classes of reportgen.gui.genepanel.formatpanel.FormatTableModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.