/*
 * Created on 30-03-2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package net.sf.hibern8ide;

import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractListModel;
import javax.swing.ListModel;

/**
 * @author max
 *
 */
public class ErrorListModel extends AbstractListModel implements ListModel {

    List errors = new ArrayList();
    
    final static int INFO = 0;
    final static int WARNING = 1;
    final static int ERROR = 2;
    
    static class ErrorItem {
       
        ErrorItem(int lvl,String msg) {
            message = msg;
            level = lvl;
        }
        String message;
        int level;
    }
    
    public void addError(Throwable t) {
        errors.add(new ErrorItem(ERROR,t.getMessage()));
        fireContentsChanged(this, errors.size()-1, errors.size());
    }
    public int getSize() {
        return errors.size();
    }

    /* (non-Javadoc)
     * @see javax.swing.ListModel#getElementAt(int)
     */
    public Object getElementAt(int index) {
        return errors.get(index);
    }
    /**
     * @param string
     */
    public void addInfo(String string) {
        errors.add(new ErrorItem(INFO,string));
        fireContentsChanged(this, errors.size()-1, errors.size());
        
    }

}
