package de.tvo.workplace;

import java.io.Serializable;

import org.eclnt.editor.annotations.CCGenClass;
import org.eclnt.jsfserver.elements.util.Trigger;
import org.eclnt.jsfserver.pagebean.IPageBean;
import org.eclnt.jsfserver.util.HttpSessionAccess;
import org.eclnt.workplace.IWorkpageDispatcher;
import org.eclnt.workplace.WorkpageDispatchedPageBean;

import de.tvo.workplace.layout.DefaultLayout;
import de.tvo.workplace.layout.LayoutManager;
import jakarta.servlet.http.HttpSession;

@CCGenClass (expressionBase="#{d.MainPage}")

public class MainPage extends WorkpageDispatchedPageBean implements Serializable {
	
	private boolean DEBUG = false;

	boolean m_mobileDevice = false;

	public boolean getMobileDevice() { return m_mobileDevice; }

	public void setMobileDevice(boolean value) { m_mobileDevice = value; }

	Trigger m_scriptTrigger = new Trigger();

	public Trigger getScriptTrigger() { return m_scriptTrigger; }

	String m_scriptText;

	public String getScriptText() { return m_scriptText; }

	public void setScriptText(String value) { m_scriptText = value; }

	String m_title;

	public String getTitle() { return m_title; }

	public void setTitle(String value) { m_title = value; }

	boolean m_confirmExit = false;

	public boolean getConfirmExit() { return m_confirmExit; }

	public void setConfirmExit(boolean value) { m_confirmExit = value; }

	private static final long serialVersionUID = 2944301072965627253L;

	private IPageBean currentPage = null;

	public IPageBean getCurrentPage() { return currentPage; }

	public void setCurrentPage(IPageBean currentPage) { this.currentPage = currentPage; }

	public DefaultLayout layout = LayoutManager.getLayoutObject();

	public DefaultLayout getLayout() { return layout; }
	
	
    // ------------------------------------------------------------------------
    // inner classes
    // ------------------------------------------------------------------------
    
    /* Listener to the user of the page bean. */
    public interface IListener extends Serializable {
    	

    }
    
    // ------------------------------------------------------------------------
    // members
    // ------------------------------------------------------------------------
    
    private IListener m_listener;
    
    // ------------------------------------------------------------------------
    // constructors & initialization
    // ------------------------------------------------------------------------

    public MainPage(IWorkpageDispatcher workpageDispatcher) {
        super(workpageDispatcher); 
    	showDefaultWorkplace();
    }
    
    
    @SuppressWarnings("unused")
	private void showDefaultWorkplace() {
    	DefaultWorkplaceBean dwp = new DefaultWorkplaceBean(getOwningDispatcher(), layout); //, getSessionVars());

    	DefaultWorkplaceBean.IListener listener = new DefaultWorkplaceBean.IListener() {

			private static final long serialVersionUID = -4934826046496488251L;

			@Override
			public void logout() {
				HttpSession httpSession = HttpSessionAccess.getCurrentHttpSession();
				String sessionID = httpSession.getId();
				//SessionHandler.logoutSession(sessionID);
				
				try {
					//showLogin();
				} catch (IllegalStateException ise) {
					if (!ise.getMessage().equals("getAttribute: Session already invalidated") && !ise.getMessage().equals("getAttribute: Session already invalidated")) {
						ise.printStackTrace();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		};
		dwp.prepare(listener);
		currentPage = dwp;
    }

    public String getPageName() { return "/main.xml"; }
    public String getRootExpressionUsedInPage() { return "#{d.MainPage}"; }

    // ------------------------------------------------------------------------
    // public usage
    // ------------------------------------------------------------------------

    /* Initialization of the bean. Add any parameter that is required within your scenario. */
    public void prepare(IListener listener)
    {
        m_listener = listener;
    }

    // ------------------------------------------------------------------------
    // private usage
    // ------------------------------------------------------------------------
}
