package org.gcube.portlets.user.workspace.client.view.panels;

import org.gcube.portlets.user.workspace.client.ConstantsPortlet.ViewSwitchTypeInResult;
import org.gcube.portlets.user.workspace.client.view.GxtDetailsContainer;
import org.gcube.portlets.user.workspace.client.view.GxtListView;
import org.gcube.portlets.user.workspace.client.view.grids.GxtGridFilterGroupPanel;
import org.gcube.portlets.user.workspace.client.view.toolbars.GxtToolBarItem;

import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.CardLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.Element;

/**
 * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
 *
 */
public class GxtCardLayoutResultPanel extends LayoutContainer{

	private CardLayout cardLayout = new CardLayout();
	private GxtItemsPanel itemPanel;
	private GxtGridFilterGroupPanel gridFilterViewContainer;
	private GxtListView iconsViewContainer;
	private GxtGridFilterGroupPanel gridGroupViewContainer;
	private ContentPanel activePanel = null;
	private GxtToolBarItem toolBarItem;

	public GxtCardLayoutResultPanel(
			GxtGridFilterGroupPanel gridFilterContainer,
			GxtGridFilterGroupPanel gridFilterGroupContainer,
			GxtListView listViewContainer,
			GxtDetailsContainer detailsContainer) {

		this.gridFilterViewContainer = gridFilterContainer;
		this.iconsViewContainer = listViewContainer;
		this.gridGroupViewContainer = gridFilterGroupContainer;
	

		instanceItemsPanel();

	}

	private void instanceItemsPanel(){
		this.toolBarItem = new GxtToolBarItem(gridGroupViewContainer); //instance toolbar
		this.itemPanel = new GxtItemsPanel(gridFilterViewContainer, iconsViewContainer, gridGroupViewContainer, toolBarItem);
	}


	@Override
	protected void onRender(Element parent, int pos) {
		super.onRender(parent, pos);
		setLayout(new FitLayout());

		ContentPanel cp = new ContentPanel();
		cp.setHeaderVisible(false);
		cp.setLayout(cardLayout);

		cp.add(itemPanel);

		cardLayout.setActiveItem(itemPanel);
		activePanel = itemPanel;

		add(cp);

	};

	public void setActivePanel(ViewSwitchTypeInResult type){


		if(type.equals(ViewSwitchTypeInResult.Group) ){
			cardLayout.setActiveItem(itemPanel);
			activePanel = itemPanel;
			//			  toolBar.setEnabled(true);
		}

	}

	//	  public GxtGridMessagesFilterPanel getMessagesPanelContainer() {
	//			return messagesPanelContainer;
	//		}

	public GxtItemsPanel getItemPanel() {
		return itemPanel;
	}

	public void setItemPanel(GxtItemsPanel itemPanel) {
		this.itemPanel = itemPanel;
	}


	public GxtToolBarItem getToolBarItem() {
		return toolBarItem;
	}

	public ContentPanel getActivePanel(){
		return activePanel;
	}

}
