package de.tvo.workplace;

import java.io.Serializable;

import org.eclnt.editor.annotations.CCGenClass;
import org.eclnt.workplace.IWorkpageDispatcher;
import org.eclnt.workplace.WorkpageDispatchedPageBean;
import org.eclnt.workplace.WorkpageStartInfo;
import org.eclnt.workplace.WorkplaceFunctionTree;
import org.eclnt.workplace.WorkplaceFunctionTreeInfoNode;

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

public class DefaultWorkplaceFunctionsBean
    extends WorkpageDispatchedPageBean 
    implements Serializable
{
    // ------------------------------------------------------------------------
    // inner classes
    // ------------------------------------------------------------------------

    /* Listener to the user of the page bean. */
    public interface IListener extends Serializable
    {
    }

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

    private IListener m_listener;

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

    WorkplaceFunctionTreeInfoNode m_functionTree;
    
    
    public WorkplaceFunctionTreeInfoNode getFunctionTree() {
		return m_functionTree;
	}

	public DefaultWorkplaceFunctionsBean(IWorkpageDispatcher workpageDispatcher)
    {
        super(workpageDispatcher);   
        m_functionTree = buildFunctionTree();
        
        
    }

    public String getPageName() { return "/workplace/defaultWorkplaceFunctions.xml"; }
    public String getRootExpressionUsedInPage() { return "#{d.DefaultWorkplaceFunctionsBean}"; }

    // ------------------------------------------------------------------------
    // 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
    // ------------------------------------------------------------------------
    private WorkplaceFunctionTreeInfoNode buildFunctionTree()
    {
        WorkplaceFunctionTreeInfoNode root = new WorkplaceFunctionTreeInfoNode();
        for (int i=0; i<5; i++)
        {
            WorkplaceFunctionTreeInfoNode top = new WorkplaceFunctionTreeInfoNode();
            top.setText("Top " + i);
            root.getSubNodes().add(top);
            for (int j=0; j<5; j++)
            {
                WorkplaceFunctionTreeInfoNode sub = new WorkplaceFunctionTreeInfoNode();
                sub.setText("Sub " + i);
                top.getSubNodes().add(sub);
                for (int k=0; k<5; k++)
                {
                    WorkplaceFunctionTreeInfoNode node = new WorkplaceFunctionTreeInfoNode();
                    node.setText("Node " + i);
                    WorkpageStartInfo wpsi = new WorkpageStartInfo();
                    node.setWorkpageStartInfo(wpsi);
                    wpsi.setPageBeanName("DemoHelloWorld");
                    sub.getSubNodes().add(node);
                }
            }
        }
        return root;
    }
}
