/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package clips.job;
import clips.delegate.job.DangerExamChunk;
import clips.delegate.directory.complex.DirectoryDanger;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.job.JobLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ErrorValue;
import cli_fmw.utils.MessageBox;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;
/**
*
* @author petr
*/
public class TableModelDangers extends AbstractTableModel {
public static final int CL_DANGER =0;
public static final int CL_LAST_EXAM = 1;
private JobLocal jobLocal;
TableModelDangers(JobLocal jobLocal) throws ClipsException {
this.jobLocal = jobLocal;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == CL_LAST_EXAM){
return Date.class;
}
return super.getColumnClass(columnIndex);
}
@Override
public String getColumnName(int column) {
if (column == CL_DANGER){
return "Вредный фактор";
}else if (column == CL_LAST_EXAM){
return "Дата последнего осмотра";
}else{
return null;
}
}
@Override
public int getRowCount() {
try {
return jobLocal.dangerFactors().size();
} catch (ClipsException ex) {
ex.getStackTrace();
return 0;
}
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
try {
DangerExamChunk chunk = jobLocal.dangerFactors().get(rowIndex);
if (columnIndex == CL_DANGER) {
try {
return chunk.getDanger();
} catch (ClipsException ex) {
return new ErrorValue(ex);
}
} else if (columnIndex == CL_LAST_EXAM) {
return chunk.getLastExam();
} else {
return null;
}
} catch (ClipsException ex) {
return new ErrorValue(ex);
}
}
/**
*
* @param row
* @return
*/
public boolean isManually(int row){
try {
return jobLocal.dangerFactors().get(row).isLastExamManually();
} catch (ClipsException ex) {
ex.getStackTrace();
return false;
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == CL_LAST_EXAM;
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
try {
DangerExamChunk chunk = jobLocal.dangerFactors().get(rowIndex);
chunk.setLastExam((Date) aValue);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}