package de.tvo.workplace;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.eclnt.editor.annotations.CCGenClass;
import org.eclnt.jsfserver.util.HttpSessionAccess;
import org.eclnt.workplace.IWorkpageDispatcher;
import org.eclnt.workplace.WorkpageDispatchedPageBean;
import org.eclnt.workplace.WorkpageStarterFactory;

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

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

public class DefaultWorkplaceBean
    extends WorkpageDispatchedPageBean 
    implements Serializable
{
    public void onMenuToggleAction(org.eclnt.jsfserver.base.faces.event.ActionEvent event) {
    	if (getMenuToggle()) {
    		m_menuPageBean = new MenuPageBean();
    	} else {
    		m_menuPageBean = null;
    	}
    }

    boolean m_menuToggle = false;
    public boolean getMenuToggle() { return m_menuToggle; }
    public void setMenuToggle(boolean value) { this.m_menuToggle = value; }
    
    MenuPageBean m_menuPageBean = null;
    public MenuPageBean getMenuPageBean() { return m_menuPageBean; }

    public static DefaultWorkplaceBean findWorkplaceUIOfSession() {
        HttpSession hs = HttpSessionAccess.getCurrentHttpSession();
        return (DefaultWorkplaceBean)hs.getAttribute(DefaultWorkplaceBean.class.getName());
    }
    
    public void hideNavigation() {
//    	if (!navigationFixed) {
//    		m_navigationWidth = 0;
//    	}
//    	closePopup(m_favorits);
    }
    
	// ------------------------------------------------------------------------
    // inner classes
    // ------------------------------------------------------------------------
	private DefaultLayout m_layout;
	public DefaultLayout getLayout() { return m_layout; }

	/* Listener to the user of the page bean. */
    public interface IListener extends Serializable {
    	public void logout();
    }

    // ------------------------------------------------------------------------
    // members
    // ------------------------------------------------------------------------

    private IListener m_listener;

    // ------------------------------------------------------------------------
    // constructors & initialization
    // ------------------------------------------------------------------------

    public DefaultWorkplaceBean(IWorkpageDispatcher workpageDispatcher, DefaultLayout defaultLayout)
    {
        super(workpageDispatcher);   
        m_layout = defaultLayout;
        init();
    }

    private void init() {
    	HttpSession hs = HttpSessionAccess.getCurrentHttpSession();
        hs.setAttribute(DefaultWorkplaceBean.class.getName(),this);
        
//        m_menuBean = m_functionsBean;
//      
//        loadTree(true);
//      
//        showNavigation();
//        
//        m_searchBean = new FunctionSearchUI();
        
//        if (getTest()) {
//        	setRenderTest(true);
//        }
        
        //System.out.println(this.getClass().getSimpleName() + " init: " + m_favorits);
        
        //MK: Deaktivieren von Drag n Drop im Workplace selbst
        getWorkpageContainer().setWithWorkpageDragDrop(false);
        
        //MK: Hinzufuegen der Home Seite die nicht geschlossen werden kann
        DefaultWorkpageStarterInfo wpsi = new DefaultWorkpageStarterInfo();
        //wpsi.setSessionVars(this.sessionVars);
        wpsi.setCloseSupported(false);
		wpsi.setComment("Home");
		wpsi.setDecorated(false);
		wpsi.setId("HOME");
		//MK: Auskommenteirt weil er sonst die JSP callen möchte, er soll jedoch ueber Klasse callen
//		wpsi.setJspPage("/portal/workplace/favorits.jsp");
		wpsi.setOpenAsPopupByDefault(false);
		wpsi.setOpenMultipleInstances(false);
		wpsi.setPageBeanName("HomeBean");
		wpsi.setPopupSupported(false);
		wpsi.setSelectorTitle("Home");
		wpsi.setText("Home");
		wpsi.setWindowTitle("Home");
		Map<String, String> param = new HashMap<>();
//		param.put(StarterInfoParm.MANDANTID.name(), "0");
//		param.put(StarterInfoParm.NODEKNID.name(), "0");
//		wpsi.setParamMap(param);
		
        WorkpageStarterFactory.getWorkpageStarter().startWorkpage(getOwningDispatcher(), getWorkpageContainer(), wpsi);
		
	}
    
    @Override
	public String getPageName() { return "/workplace/defaultWorkplace.xml"; }
    @Override
    public String getRootExpressionUsedInPage() { return "#{d.DefaultWorkplaceBean}"; }

    // ------------------------------------------------------------------------
    // 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
    // ------------------------------------------------------------------------
}
