package com.gx.obe.management.composite;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.core.widgets.ImageButton;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

import com.gx.obe.ColorConstants;
import com.gx.obe.business.enumeration.ExpertEnum;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.service.TenderProjectService;
import com.swtdesigner.SWTResourceManager;

/**
 * @Description: 评标工作人员管理
 * @author wangxiang
 */
public class EvaluationWorkerManagerComposite extends Composite {
	
	private TenderProjectEntity tenderProjectEntity;
	private TenderProjectService tenderProjectService;
	private ImageButton curEvaluationUser;
	private ImageButton monitor_Btn;
	private ImageButton worker_Btn;
	private Composite load_composite;
	
	{
		LogUtils.logClass(EvaluationWorkerManagerComposite.class);
	}
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public EvaluationWorkerManagerComposite(Composite parent, int style) {
		super(parent, style);
		setBackground(SWTResourceManager.getColor(255, 255, 255));
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
			}
		});
		this.tenderProjectEntity = (TenderProjectEntity)parent.getData("tenderProjectEntity");
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.verticalSpacing = 0;
		gridLayout.horizontalSpacing = 0;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		
		Composite title_composite = new Composite(this, SWT.NONE);
		GridLayout gl_title__composite = new GridLayout(3, false);
		gl_title__composite.marginHeight = 0;
		gl_title__composite.verticalSpacing = 0;
		title_composite.setLayout(gl_title__composite);
		title_composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		monitor_Btn = new ImageButton(title_composite, SWT.NONE);
		monitor_Btn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		monitor_Btn.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
//				worker_Btn.setSelection(false);
//				monitor_Btn.setSelection(true);
				loadEvaluationUser(ExpertEnum.MONITOR);
			}

		});
		curEvaluationUser = monitor_Btn;
		monitor_Btn.setText(Messages.Supervisor);
		setWokerBtnCss(monitor_Btn);
		
		worker_Btn = new ImageButton(title_composite, SWT.NONE);
		worker_Btn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		worker_Btn.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
//				monitor_Btn.setSelection(false);
//				worker_Btn.setSelection(true);
				loadEvaluationUser(ExpertEnum.WORKER);
			}
			
		});
		curEvaluationUser = worker_Btn;
		worker_Btn.setText(Messages.Worker);
		setWokerBtnCss(worker_Btn);
		
		Composite composite = new Composite(title_composite, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
		composite.setLayout(new RowLayout(SWT.HORIZONTAL));
		
		ESepator user_tab = new ESepator(title_composite, SWT.NONE);
		user_tab.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 5, 1));
		user_tab.setLineWidth(2);
		user_tab.setBackground(ColorConstants.SKIN_BG);
		
		Composite content_omposite = new Composite(this, SWT.NONE);
		content_omposite.setBackground(ColorConstants.BORDER_LINE_COLOR);
		content_omposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_content_omposite = new GridLayout(1, false);
		gl_content_omposite.marginHeight = 0;
		gl_content_omposite.marginWidth = 0;
		content_omposite.setLayout(gl_content_omposite);
		load_composite = new Composite(content_omposite, SWT.NONE);
		load_composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		FillLayout fl_load_composite = new FillLayout(SWT.HORIZONTAL);
		fl_load_composite.marginHeight = 5;
		fl_load_composite.marginWidth = 5;
		load_composite.setLayout(fl_load_composite);
		load_composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		init();
	}
	
	/**
	 * @Description: 初始化
	 * @author guoyr 
	 */
	private void init(){
		tenderProjectService = new TenderProjectService();
		loadEvaluationUser(ExpertEnum.MONITOR );
		
	}
		
	/**
	 * @Description: 加载人员面板
	 * @author wangxiang
	 * @param auditType 
	 */
	private void loadEvaluationUser(String auditType){
		load_composite.setData("tenderProjectEntity", tenderProjectEntity);
		for(Control control : load_composite.getChildren()){
			control.dispose();
		}
		if(null != curEvaluationUser && !curEvaluationUser.isDisposed()){
			curEvaluationUser.setSelection(false);
		}
		if(auditType.equals(ExpertEnum.MONITOR)){
//			new WorkerComposite(load_composite,ExpertEnum.MONITOR, SWT.NONE);
			curEvaluationUser = monitor_Btn;
		}else if(auditType.equals(ExpertEnum.WORKER)){
//			new WorkerComposite(load_composite,ExpertEnum.WORKER, SWT.NONE);
			curEvaluationUser = worker_Btn;
		}
		curEvaluationUser.setSelection(true);
		load_composite.layout();
	}
	/**
	 * @Description: 设置指标分类的按钮
	 * @author wangxiang
	 * @param userBtn 
	 */
	private void setWokerBtnCss(ImageButton factorBtn){
		factorBtn.setRightMargin(10);
		factorBtn.setLeftMargin(10);
		factorBtn.setTopMargin(5);
		factorBtn.setBottomMargin(5);
		factorBtn.setRightMargin(20);
		factorBtn.setLeftMargin(20);
		factorBtn.setTopMargin(5);
		factorBtn.setBottomMargin(5);
		factorBtn.setRightMargin(10);
		factorBtn.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		
		factorBtn.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		factorBtn.setBackgroundColor(SWTResourceManager.getColor(245, 245, 245));
		
		factorBtn.setActiveForeground(ColorConstants.SKIN_ACTIVE_FOREGROUND);
		factorBtn.setActiveBackgroundColor(ColorConstants.SKIN_ACTIVE_BG);
		
		factorBtn.setSelectionForeground(ColorConstants.SKIN_SELECTOIN_FOREGROUND);
		factorBtn.setSelectionBgColor(ColorConstants.SKIN_BG);
		
	}
	
	/**
	 * @Description: 验证是否已经进入评标环节
	 * @author wangxiang
	 * @return 
	 */
	private boolean isInEvaluationProgress(){
		boolean isInEvaluationProgress = tenderProjectService.isInProgress(tenderProjectEntity.getId(), null);
		if(isInEvaluationProgress){
			MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_enteredEvaluation);
		}
		return isInEvaluationProgress;
	}
	
	
	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
