/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package reportgen.gui.genepanel.subreportpanel;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import reportgen.utils.ReportException;
import reportgen.prototype.utils.ItemSelectorEditable;
import reportgen.ren.executer.QueryExecuterSub;
import reportgen.utils.Message;
/**
*
* @author axe
*/
class SubReportTableModel extends AbstractTableModel {
public static final int COL_TITLE = 0;
public static final int COL_SELECTROWS = 1;
public static final int COL_SELTITLE = 2;
public static final int COL_SELCOLUMN = 3;
public static final int COL_SELDESCRIPTION = 4;
public static final int COL_DEFAULTCHOICE = 5;
public static final int COL_CONSTANT = 6;
public static final int COL_CANBEOMITTED = 7;
private final ItemSelectorEditable<QueryExecuterSub> reports;
private final JTable table;
public SubReportTableModel(JTable table, ItemSelectorEditable<QueryExecuterSub> reports) {
this.reports = reports;
this.table = table;
}
@Override
public int getColumnCount() {
return COL_CANBEOMITTED+1;
}
@Override
public int getRowCount() {
return reports.size();
}
@Override
public String getColumnName(int column) {
switch(column) {
case COL_TITLE: {
return "Подотчет";
}
case COL_SELECTROWS: {
return "Активных строк";
}
case COL_SELTITLE: {
return "Приглашение выбора";
}
case COL_SELDESCRIPTION: {
return "Описание при выборе";
}
case COL_SELCOLUMN: {
return "Отображаемый столбец";
}
case COL_DEFAULTCHOICE: {
return "Значение по умолчанию";
}
case COL_CONSTANT: {
return "Константа";
}
case COL_CANBEOMITTED: {
return "Опционально";
}
}
return null;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if(columnIndex == COL_TITLE
|| columnIndex == COL_DEFAULTCHOICE) {
return false;
}
return true;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
if(columnIndex == COL_CONSTANT
|| columnIndex == COL_CANBEOMITTED) {
return Boolean.class;
}
return super.getColumnClass(columnIndex);
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
QueryExecuterSub report = reports.get(rowIndex);
switch(columnIndex) {
case COL_TITLE: {
return report.getReportTitle();
}
case COL_SELECTROWS: {
return report.getActiveRows();
}
case COL_SELTITLE: {
return report.getSelectTitle();
}
case COL_SELCOLUMN: {
return report.getColTitle(report.getSelectColumn());
}
case COL_SELDESCRIPTION: {
return report.getSelectDescription();
}
case COL_DEFAULTCHOICE: {
try {
return report.getDefaultValue(report.getSelectColumn());
} catch (ReportException ex) {
return "нет";
}
}
case COL_CONSTANT: {
return report.isConstant();
}
case COL_CANBEOMITTED: {
return report.isCanBeOmitted();
}
}
return null;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
QueryExecuterSub report = reports.get(rowIndex);
switch(columnIndex) {
case COL_SELECTROWS: {
//@TODO
break;
}
case COL_SELTITLE: {
report.setSelectTitle(aValue.toString());
break;
}
case COL_SELCOLUMN: {
int index = -1;
try {
index = report.getColumnIndex(aValue.toString());
} catch (ReportException ex) {
index = -1;
}
if(index != -1) {
report.setSelectColumn(index);
}
break;
}
case COL_SELDESCRIPTION: {
report.setSelectDescription(aValue.toString());
break;
}
case COL_CONSTANT: {
try {
report.setConstant((Boolean) aValue);
} catch (ReportException ex) {
Message.warning(table, ex);
}
break;
}
case COL_CANBEOMITTED: {
report.setCanBeOmitted((Boolean)aValue);
break;
}
}
}
public QueryExecuterSub getField(int row) {
return reports.get(row);
}
}