/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.reportgen.mainpanel;
import clips.reportgen.QueryLocal;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import reportgen.factory.ReportVersion;
import reportgen.utils.ReportException;
/**
*
* @author petr
*/
public class TableModelQueryList extends AbstractTableModel {
public static final int COL_ID = 0;
public static final int COL_QUERY = 1;
public static final int COL_VERSION = 2;
public static final int COL_COUNT = 3;
private ArrayList<QueryLocal> cache;
public TableModelQueryList(ArrayList<QueryLocal> list) {
cache = list;
}
@Override
public int getRowCount() {
if (cache == null) {
return 0;
}
return cache.size();
}
@Override
public int getColumnCount() {
return COL_COUNT;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
try {
QueryLocal ql = cache.get(rowIndex);
if (columnIndex == COL_ID){
return ql.getID();
} else if (columnIndex == COL_QUERY) {
return (ql.isWrong() ? "(НЕ КОРРЕКТЕН) ":"") + ql.getTitle();
} else if (columnIndex == COL_VERSION) {
try {
ReportVersion ver = ql.getVersion();
ReportVersion realVer = ver.realVersion();
return realVer.toString()
+ (realVer.isSupported() ? "":" (не поддерживается)")
+ (realVer == ver ? "":"(обновлено)");
} catch (Exception ex) {
return "unknown";
}
} else {
return "";
}
} catch (ReportException ex) {
//todo
return null;
}
}
@Override
public String getColumnName(int column) {
if (column == COL_ID){
return "ID";
}else if (column == COL_QUERY) {
return "Название";
}else{
return "";
}
}
@Override
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == COL_ID){
return Integer.class;
}
return super.getColumnClass(columnIndex);
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
}