/*
 * $Id: ShowDocumentFavoritesForm.java,v 1.4 2006/03/27 15:24:15 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: ShowDocumentFavoritesForm.java,v $
 * Revision 1.4  2006/03/27 15:24:15  marbobo
 * + Bugfix
 *
 * Revision 1.3  2005/08/09 19:50:38  marbobo
 * + Alternative-Sicht implementiert
 *
 * Revision 1.2  2004/08/18 13:41:08  marbobo
 * +Umgeschrieben und Bugfix
 *
 * Revision 1.1  2004/05/06 15:10:09  jonyp
 * first strike
 *
 */
package vkc.profile.form;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;

import vkc.db.serializer.VKCDocumentFavoritesSerializer;
import vkc.exception.DBException;
import vkc.view.form.BasicActionForm;

public final class ShowDocumentFavoritesForm extends BasicActionForm {
	private Integer   selectedId = null;
	private Integer[] selectedIds = new Integer[0];
	private Integer[] showDocumentDetails = new Integer[0];
	private Integer[] showDocuments = new Integer[0];

	private List documents = null;
		
	/**
	 * Reset all properties to their default values.
	 *
	 * @param mapping The mapping used to select this instance
	 * @param request The servlet request we are processing
	 */
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		super.reset(mapping, request);

		selectedId = null;
		selectedIds = new Integer[0];
		showDocumentDetails = new Integer[0];
		showDocuments = new Integer[0];

		documents = null;
	}	

	public List getDocuments() throws DBException {
		if (documents == null) {
		    documents = VKCDocumentFavoritesSerializer.retrieveDocumentFavorites(getUser().getUserId());
		}
		
	    return documents;
	}

	public Integer getSelectedId() {
		return selectedId;
	}

	public Integer[] getSelectedIds() {
		return selectedIds;
	}

	public boolean getShowDocDetails(int i ) {
		List ids = Arrays.asList(getShowDocumentDetails());
		
		return ids.contains(new Integer(i));
	}

	public Integer[] getShowDocumentDetails() {
		return showDocumentDetails;
	}

	public void setDocuments(List list) {
		documents = list;
	}

	public void setSelectedId(Integer integer) {
		selectedId = integer;
	}

	public void setSelectedIds(Integer[] integers) {
		selectedIds = integers;
	}

	public void setShowDocumentDetails(Integer[] list) {
		showDocumentDetails = list;
	}

	public Integer[] getShowDocuments() {
		return showDocuments;
	}

	public void setShowDocuments(Integer[] list) {
		showDocuments = list;
	}

	public boolean getShowDocs(int i) {
		List ids = Arrays.asList(getShowDocuments());

		return ids.contains(new Integer(i));
	}
}