/**
 * 
 */
package cz.neubauer.tomas.hazardanalysis.model.tablemodels;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerVariant;

/**
 * @author Tomáš Neubauer
 */
public class DangerVariantTableModel extends AbstractTableModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5209175080871047039L;

	private ArrayList<DangerVariant> dangerVariants;

	protected String[] columnNames = new String[] { "Popis nebezpečí",
			"Kritické" };

	/**
	 * @param dangerVariants
	 */
	public DangerVariantTableModel(ArrayList<DangerVariant> variants) {
		dangerVariants = variants;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.table.TableModel#getColumnCount()
	 */
	@Override
	public int getColumnCount() {
		return 2;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.table.TableModel#getRowCount()
	 */
	@Override
	public int getRowCount() {
		return dangerVariants.size();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.table.TableModel#getValueAt(int, int)
	 */
	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		DangerVariant currentVariant = dangerVariants.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return currentVariant.getDescription();
		case 1:
			return currentVariant.isCritical();
		default:
			return null;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
	 */
	@Override
	public Class<?> getColumnClass(int columnIndex) {
		if (columnIndex == 1) {
			return Boolean.class;
		}
		return super.getColumnClass(columnIndex);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.table.AbstractTableModel#getColumnName(int)
	 */
	@Override
	public String getColumnName(int column) {
		return columnNames[column];
	}

	public ArrayList<DangerVariant> getDangerVariants() {
		return dangerVariants;
	}

	public void setDangerVariants(ArrayList<DangerVariant> dangerVariants) {
		this.dangerVariants = dangerVariants;
	}

}
