/**
 * 
 */
package org.concord.otrunk.view;

import javax.swing.JComponent;

import org.concord.framework.otrunk.OTObject;
import org.concord.framework.otrunk.view.AbstractOTJComponentView;
import org.concord.framework.otrunk.view.OTViewEntry;

/**
 * @author scott
 *
 */
public abstract class AbstractOTJComponentContainerView extends AbstractOTJComponentView
{
	private OTJComponentContainerHelper containerHelper;
	protected String myMode;

	/**
	 * @see org.concord.framework.otrunk.view.OTJComponentView#viewClosed()
	 */
	public void viewClosed()
	{
		super.viewClosed();
		removeAllSubViews();
	}
	
	public void setMode(String mode){
		myMode = mode;
	}
	
	public String getMode(){
		return myMode;
	}

	protected OTViewContainerPanel createViewContainerPanel()
    {
	    return getContainerHelper().createViewContainerPanel();
    }

	public JComponent createSubViewComponent(OTObject otObject)
	{
		return createSubViewComponent(otObject, false);
	}
	
	public JComponent createSubViewComponent(OTObject otObject, boolean useScrollPane)
	{
		return createSubViewComponent(otObject, useScrollPane, null);
	}
	
	public JComponent createSubViewComponent(OTObject otObject, boolean useScrollPane, 
		OTViewEntry viewEntry)
	{
		return createSubViewComponent(otObject, useScrollPane, viewEntry, false);
	}
	
	public JComponent createSubViewComponent(OTObject otObject, boolean useScrollPane, 
			OTViewEntry viewEntry, boolean isTopLevelContainer)
		{
			OTViewContainerPanel otObjectPanel = createViewContainerPanel();
			otObjectPanel.setUseScrollPane(useScrollPane);
			otObjectPanel.setTopLevelContainer(isTopLevelContainer);
			
			// The OTViewContainerPanel automatically handles the OTViewChild object
			otObjectPanel.setCurrentObject(otObject, viewEntry);
			
			// set parent of new viewcontainer to this viewcontainer
			otObjectPanel.setParentContainer(viewContainer);
			return otObjectPanel;
		}
	
	protected void removeAllSubViews()
    {
		if(containerHelper != null){
			containerHelper.removeAllSubViews();
		}
    }

	protected OTJComponentContainerHelper getContainerHelper()
	{
		if(containerHelper == null){
			containerHelper = new OTJComponentContainerHelper(getFrameManager(),
					getJComponentService(), getMode());

		}
		return containerHelper;
	}

	protected void setSubViewAutoRequestFocus(boolean autoRequestFocus)
    {
		getContainerHelper().setAutoRequestFocus(autoRequestFocus);
    }

	protected void setSubViewUseScrollPane(boolean useScrollPane)
    {
		getContainerHelper().setUseScrollPane(useScrollPane);
    }

	protected void setSubViewMode(String viewMode)
    {
		getContainerHelper().setViewMode(viewMode);
    }
}

@@ -237,16 +237,72 @@
 ewEntry;
+%0Aimport org.concord.framework.otrunk.view.OTViewFactory;
 %0A%0A/**%0A *
@@ -1351,32 +1351,38 @@
 Entry, false
+, null
 );%0A%09%7D%0A%09%0A
 %09public JCom
@@ -1361,32 +1361,293 @@
 se, null);%0A%09%7D%0A%09%0A
+%09/**%0A%09 * Creates a sub view, and returns the view container JComponent%0A%09 * %0A%09 * If isTopLevelContainer is true and a ViewFactory is passed in, the new view container%0A%09 * will be top level, and so will contain a shared service for all its descendant views.%0A%09 */%0A
 %09public JCompone
@@ -1768,16 +1768,45 @@
 ontainer
+, OTViewFactory otViewFactory
 )%0A%09%09%7B%0A%09%09
@@ -1981,16 +1981,97 @@
 ainer);%0A
+%09%09%09if (otViewFactory != null)%0A%09%09%09%09otObjectPanel.setOTViewFactory(otViewFactory);%0A
 %09%09%09%0A%09%09%09/

Allow subview to be created with a view factory, which will allow new view container to be properly top-level.