/*
 * Created on 20-04-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;


/**
 * @author max
 *
 */
public class QueryPageModel extends AbstractListModel {

	List pages = new ArrayList();

	public int getSize() {
		return pages.size();
	}

	public Object getElementAt(int index) {
		return pages.get(index);
	}

	/**
	 * @param qp
	 */
	public void add(QueryPage qp) {
	

		for (int i = pages.size() - 1; i >= 0; i--) {
			QueryPage element = (QueryPage) pages.get(i);
			if (!element.isSticky()) {
                pages.remove(i);
			}
		}
        pages.add(qp);
		fireIntervalAdded(this, 0, pages.size());

	}

	/**
	 * @param i
	 */
	protected void remove(int i) {
		QueryPage qp = (QueryPage) pages.get(i);
		qp.release();
		pages.remove(i);
		fireIntervalRemoved(pages, i, i);

	}

	/**
	 * @param i
	 * @return
	 */
	protected QueryPage get(int i) {
		return (QueryPage) getElementAt(i);
	}

	/**
	 * 
	 */
	protected void update(int index) {
		fireContentsChanged(pages, index, index);

	}

}
