/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cli_fmw.directory.editors.kladr;
import cli_fmw.delegate.directory.complex.DirectoryCountry;
import cli_fmw.delegate.directory.complex.DirectoryCountryItem;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import javax.swing.table.AbstractTableModel;
/**
*
* @author petr
*/
public class DirectoryCountryTableModel extends AbstractTableModel {
private DirectoryCountry country;
public DirectoryCountryTableModel(DirectoryCountry country) {
this.country = country;
}
@Override
public String getColumnName(int column) {
switch(column){
case 0: return "Страна";
case 1: return "Код по ОКСМ";
}
return null;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (country.getItems().get(rowIndex).isRussia()){
return false;
}else{
return true;
}
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
DirectoryCountryItem item = country.getItems().get(rowIndex);
try {
if (columnIndex == 0) {
item.setTitle((String) aValue);
} else if (columnIndex == 1) {
item.setCode((String) aValue);
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
@Override
public int getRowCount() {
return country.getItems().size();
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
DirectoryCountryItem item = country.getItems().get(rowIndex);
if (columnIndex == 0){
return item.getTitle();
}else if (columnIndex == 1){
try {
return item.getCode();
} catch (ClipsException ex) {
return new ErrorValue(ex);
}
}else{
return null;
}
}
}