package com.dev.swms.client.ui.page;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.layout.FitLayout;
import com.gwtext.client.widgets.layout.HorizontalLayout;
import com.dev.swms.client.ui.constant.CT_IV;
import com.dev.swms.client.ui.data.Page_IV_DataAccessor;
import com.dev.energy.client.message.IMessagePage;
import com.dev.energy.client.ui.panel.AbstractSupportPanel;

/**
 *@author  dev
 *@version $Project:swms $Date$Version:V1.1
 */
public class Sub_Navigate_Panel extends AbstractSupportPanel{

	protected final static String DEFAULT_NAME = "navigate_panel";
	
	/** 仓库链接 */
	protected HTML w_HyperLink = new HTML("供应链网络");
	/** 库区链接 */
	protected HTML z_HyperLink = new HTML("");
	/** 库位链接 */
	protected HTML l_HyperLink = new HTML("");
	
	protected HTML firstImg = new HTML("");
	protected HTML secondImg = new HTML("");
	
	protected Panel subPanel;
	
	protected Sub_Abstract_Panel currentPanel;
	
	public Sub_Navigate_Panel(IMessagePage page) {
		super(page, DEFAULT_NAME);
		this.initListener();
		this.drawWidget();
	}
	
	protected void drawWidget(){
		w_HyperLink.setStyleName("iv_navigate");
		z_HyperLink.setStyleName("iv_navigate");
		l_HyperLink.setStyleName("iv_navigate");
		
		subPanel = new Panel();
		subPanel.setLayout(new HorizontalLayout(5));
		subPanel.add(w_HyperLink);
		subPanel.add(firstImg);
		subPanel.add(z_HyperLink);
		subPanel.add(secondImg);
		subPanel.add(l_HyperLink);
		subPanel.setWidth("100%");
		
		this.setBodyBorder(true);
		this.setBorder(true);
		this.setLayout(new FitLayout());
		this.setHeight("30px");
		this.setWidth("100%");
		this.add(subPanel);
	}
	
	protected void removeHistoryPanel(){
		if(this.currentPanel == null) return;
		this.currentPanel.hideCharts();
		page.remove(this.currentPanel);
		
	}
	
	protected void addCenterPanel(Sub_Abstract_Panel newPanel){
		this.currentPanel = newPanel;
		curIvPanel().addCenterPanel(newPanel);
	}
	
	protected void initListener(){
		w_HyperLink.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				getData().sendMessage(Page_IV_DataAccessor.MSG_OPEN_W_IMAGE_PANEL);
			}
		});
		
		z_HyperLink.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				getData().sendMessage(Page_IV_DataAccessor.MSG_OPEN_Z_IMAGE_PANEL);
			}
		});
		
		l_HyperLink.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				getData().sendMessage(Page_IV_DataAccessor.MSG_OPEN_L_IMAGE_PANEL);
			}
		});
	}
	
	private Sub_IV_Panel curIvPanel(){
		return (Sub_IV_Panel)this.page;
	}
	
	protected void refreshNavigatePanel(){
		if(((Page_IV_DataAccessor)page.getData()).current_JB_IV() != null){
			firstImg.setHTML(CT_IV.DEFAULT_ARROW_IMG);
			z_HyperLink.setHTML(((Page_IV_DataAccessor)page.getData()).current_JB_IV().getIv_wh_name());
		}
		if(((Page_IV_DataAccessor)page.getData()).getCur_JB_Zone_IV() != null){
			secondImg.setHTML(CT_IV.DEFAULT_ARROW_IMG);
			l_HyperLink.setHTML(((Page_IV_DataAccessor)page.getData()).getCur_JB_Zone_IV().getLoc_name());
		}
	}
	
	public void doDispath(String message){
		if(Page_IV_DataAccessor.MSG_REFRESH_NAVIGATE_PANEL.equals(message)) {
			this.refreshNavigatePanel();
		}else if(Page_IV_DataAccessor.MSG_OPEN_W_IMAGE_PANEL.equals(message)) {
			this.removeHistoryPanel();
			this.addCenterPanel(new Sub_W_Image_Panel(page));
			DOM.setStyleAttribute(this.w_HyperLink.getElement() , "border" , "1px solid blue");
			DOM.setStyleAttribute(this.z_HyperLink.getElement() , "border" , "none");
			DOM.setStyleAttribute(this.l_HyperLink.getElement() , "border" , "none");
		}else if(Page_IV_DataAccessor.MSG_OPEN_Z_IMAGE_PANEL.equals(message)) {
			this.removeHistoryPanel();
			this.addCenterPanel(new Sub_Z_Image_Panel(page));
			this.refreshNavigatePanel();
			DOM.setStyleAttribute(this.w_HyperLink.getElement() , "border" , "none");
			DOM.setStyleAttribute(this.z_HyperLink.getElement() , "border" , "1px solid blue");
			DOM.setStyleAttribute(this.l_HyperLink.getElement() , "border" , "none");
		}else if(Page_IV_DataAccessor.MSG_OPEN_L_IMAGE_PANEL.equals(message)) {
			this.removeHistoryPanel();
			this.addCenterPanel(new Sub_L_Image_Panel(page));
			this.refreshNavigatePanel();
			DOM.setStyleAttribute(this.w_HyperLink.getElement() , "border" , "none");
			DOM.setStyleAttribute(this.z_HyperLink.getElement() , "border" , "none");
			DOM.setStyleAttribute(this.l_HyperLink.getElement() , "border" , "1px solid blue");
		}
	}
}
