/*
 * 
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: LicenseForm.java,v $
 * Revision 1.1  2006/11/06 10:56:26  korowa
 * Initiale Version
 *
 *
 */
package vkc.administration.form;

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

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;

import vkc.db.serializer.VKCLanguageSerializer;
import vkc.db.serializer.VKCLicenseSerializer;
import vkc.db.serializer.VKCUserSerializer;
import vkc.exception.DBException;
import vkc.view.form.BasicActionForm;

public class LicenseForm extends BasicActionForm {
	List licenses = new ArrayList();

	Integer[] selectedIds = new Integer[0];

	Integer selectedId = new Integer(-1);
	
	Integer[] selectedLanguages = new Integer[0];

	Integer selectedLanguageId= new Integer(-1);

	public void reset(ActionMapping mapping, HttpServletRequest request) {
		super.reset(mapping, request);
		licenses = null;
		selectedIds = new Integer[0];
		selectedId = new Integer(-1);
		selectedLanguages = new Integer[0];
		selectedLanguageId = new Integer(-1);
	}

	public List getLicenses() throws DBException {
		if (licenses == null) {
			licenses = VKCLicenseSerializer.retrieveLicenses();
		}

		return licenses;
	}

	public void setLicenses(List licenses) {
		this.licenses = licenses;
	}

	public String getCreator(String creatorId) {
		try {
			return VKCUserSerializer.retrieveUser(new Integer(creatorId))
					.getFullName();
		} catch (DBException e) {
			e.printStackTrace();
		}
		return null;
	}

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

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

	public Integer getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(Integer selectedId) {
		this.selectedId = selectedId;
	}

	public boolean getShowLicenses(int i) {
		return Arrays.asList(getSelectedIds()).contains(new Integer(i));
	}

	public Integer getSelectedLanguageId() {
		return selectedLanguageId;
	}

	public void setSelectedLanguageId(Integer selectedLanguageId) {
		this.selectedLanguageId = selectedLanguageId;
	}

	public Integer[] getSelectedLanguages() {
		return selectedLanguages;
	}

	public void setSelectedLanguages(Integer[] selectedLanguages) {
		this.selectedLanguages = selectedLanguages;
	}
	
	public boolean getShowLanguage(int i) {
		return Arrays.asList(getSelectedLanguages()).contains(new Integer(i));
	}
	public String getLanguage(int index) {		
		return VKCLanguageSerializer.getLanguage(new Integer(index+1))
		.getName();
	}
}