/*
 * $Id: ClusterDocumentViewForm.java,v 1.1 2005/06/23 00:58:31 aram Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: ClusterDocumentViewForm.java,v $
 * Revision 1.1  2005/06/23 00:58:31  aram
 * + Initiale Version
 *
 */

package vkc.view.form;

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

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import vkc.db.entities.VKCDocument;
import vkc.db.serializer.VKCDocumentSerializer;
import vkc.exception.DBException;

public class ClusterDocumentViewForm extends DynaForm {
    private Integer documentId = null;
    private VKCDocument document = null;
	private Integer selectedId = null;

	private Integer[] showDocumentDetails = new Integer[ 0 ];
    
    public void reset(ActionMapping mapping, HttpServletRequest request) {
		super.reset( mapping, request );

	    documentId = null;
	    document = null;
		selectedId = null;

		showDocumentDetails = new Integer[ 0 ];
    }

    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();

		return errors;
    }

    public VKCDocument getDocument() {
        try {
            if (document == null) {
                document = VKCDocumentSerializer.retrieveDocument(getDocumentId());
            }
            
            return document;
        } catch (DBException e) {
            return null;
        }
    }
    
    public Integer getDocumentId() {
        return documentId;
    }

    public void setDocumentId(Integer documentId) {
        this.documentId = documentId;
    }

	public Integer getSelectedId() {
		return selectedId;
	}

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

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

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

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