package realcix20.guis.models;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import realcix20.classes.basic.BaseClass;
import realcix20.classes.basic.Cell;
import realcix20.classes.basic.Column;
import realcix20.classes.basic.Row;
import realcix20.classes.plugins.CurrencyPlugin;
import realcix20.guis.utils.I18NManager;
import realcix20.utils.GlobalValueManager;
import realcix20.utils.ObjectUtil;
public class IndexTableModel extends DefaultTableModel {
private BaseClass object;
private Vector names;
private Vector dataValues;
public IndexTableModel(BaseClass object) {
this.object = object;
names = new Vector();
dataValues = new Vector();
Iterator columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Column column = (Column)columnIter.next();
if (column.isIndexField())
names.add(column);
}
names.add("row");
Iterator rowIter = object.getRows().iterator();
while (rowIter.hasNext()) {
Row row = (Row)rowIter.next();
Vector rowDatas = new Vector();
columnIter = object.getColumns().iterator();
while (columnIter.hasNext()) {
Column column = (Column)columnIter.next();
if (column.isIndexField()) {
Cell newCell = ObjectUtil.findNewCell(row, column.getTableName(), column.getColumnName());
if (column.getInputType() == 4) {
rowDatas.add("*****");
}
else if (column.isI18N()) {
String i18nString = null;
if (newCell.getColumnValue() != null)
i18nString = I18NManager.getI18NString(column.getI18nPrefix(), newCell.getColumnValue());
if (i18nString != null) {
if (GlobalValueManager.getValue("APPLICATION.ZIC").equals("1")) {
rowDatas.add(i18nString);
} else if (GlobalValueManager.getValue("APPLICATION.ZIC").equals("2")) {
rowDatas.add(newCell.getColumnValue());
} else if (GlobalValueManager.getValue("APPLICATION.ZIC").equals("3")) {
rowDatas.add(newCell.getColumnValue() + " - " + i18nString);
}
}
else {
if (newCell.getColumnValue() instanceof Double) {
rowDatas.add(CurrencyPlugin.getFormatedDouble((Double)newCell.getColumnValue()));
} else
rowDatas.add(newCell.getColumnValue());
}
} else {
if (newCell.getColumnValue() instanceof Double) {
rowDatas.add(CurrencyPlugin.getFormatedDouble((Double)newCell.getColumnValue()));
} else
rowDatas.add(newCell.getColumnValue());
}
}
}
rowDatas.add(row);
dataValues.add(rowDatas);
}
setDataVector(dataValues, names);
}
}