package customformitem.client;

import java.util.HashMap;
import java.util.Map;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.HTMLFlow;
import com.smartgwt.client.widgets.HTMLPane;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.VLayout;

public class GeneralPage extends VLayout  {
    
    final GeneralPage thisPage;

    HLayout body = new HLayout();
    private Layout currentContentArea;
    HLayout adContainer = new HLayout();

    public GeneralPage() {
        thisPage = this;
    }
    
    public GeneralPage(Layout contentArea) {
        thisPage = this;
        this.setContentArea(contentArea);
    }

    public void setContentArea(Layout newContentArea) {
        setContentArea(newContentArea, null);
    }

    public void setContentArea(Layout newContentArea, Map passThrough) {
        setContentArea(newContentArea, passThrough, false);
    }
    
    public void setContentArea(Layout newContentArea, Map passThrough, boolean enteringFromAbove) {
        if (passThrough == null) {
            passThrough = new HashMap();
        }
        
        // remove the current content
        if (currentContentArea != null) {
            body.getMember(currentContentArea.getID()).setVisible(false);
            
        }
        
        // if it is not already there, add the new content panel as a member
        if (body.getMember(newContentArea.getID()) == null) {
            body.addMember(newContentArea,0);
        }
        
        // execute the new panel's showAction
        if (newContentArea instanceof CustomItemPanel) { 
            ((CustomItemPanel) newContentArea).showAction(passThrough, enteringFromAbove);
        }
        
        // turn the new panel visible
        newContentArea.setVisible(true);
        
        currentContentArea = newContentArea;
    }

    public Layout getContentArea() {
        return currentContentArea;
    }
    
    public void init() {
        
        HTMLFlow filler = new HTMLFlow();
        filler.setContents("&nbsp;");
        filler.setWidth("*");
        
        HTMLPane ads = new HTMLPane();
        ads.setWidth("1");
        ads.setHeight("600");
        
        ads.setMargin(3);
        ads.setOverflow(Overflow.VISIBLE);
        adContainer.addMember(ads);
        
        HLayout rightContainer = new HLayout();
        rightContainer.setAlign(Alignment.RIGHT);
        rightContainer.setWidth("*");
        rightContainer.addMember(filler);
        rightContainer.addMember(adContainer);
        
        body.addMember(rightContainer);
        body.setWidth("100%");
        
        this.setBackgroundColor("lightgrey");
        this.addMember(body);
        this.setWidth("100%");
        
    }

    
}
