/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.renatofreitas.rtmclient;
import com.google.common.collect.Lists;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.swing.table.AbstractTableModel;
/**
 *
 * @author Renato
 */
public class RTMTableModel extends AbstractTableModel {
    
    private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
    private List<RTMTask> tasks;
    public RTMTableModel() {
        this.tasks = Lists.newArrayList();
    }
    
    public RTMTableModel(List<RTMTask> tasks) {
        this.tasks = tasks;
    }
    
    public List<RTMTask> getTasks() {
        return tasks;
    }
    public void setTasks(List<RTMTask> tasks) {
        this.tasks = tasks;
    }
    
    public int getRowCount() {
        return tasks.size();
    }
    public int getColumnCount() {
        return 3;
    }
    
    public boolean shouldHighlightRow(int rowIndex) {
        return tasks.get(rowIndex).isOverdue();
    }
    public Object getValueAt(int rowIndex, int columnIndex) {
        RTMTask task = tasks.get(rowIndex);
        if (columnIndex == 0) {
            if (task.isOverdue()) {
                return "!";
            } else {
                return "";
            }
        } else if (columnIndex == 1) {
            if (task.getDueDate() == null) {
                return null;
            }
            return sdf.format(task.getDueDate());
        } else {
            return task.getName();
        }
    }
    
}

Comentários