package com.gx.obe.evaluation.step.dialog;

import java.text.MessageFormat;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.CallBack;
import org.eclipse.swt.core.ImageResolver;
import org.eclipse.swt.core.widgets.EDialog;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

import com.gx.obe.evaluation.step.composite.FactorEvaluationOpinionComposite;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.util.utils.ScreenUtils;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.auth.AuthUser;
import com.gx.obe.web.entity.evaluation.EvaluationFactor;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.service.SupplierService;
import com.gx.obe.web.service.evaluation.EvaluationFactorService;

/**
 * @Description: 查看指标评审意见
 * @author guoyr
 */
public class FactorOpinionDialog extends EDialog {
	
	private ImageResolver imageResolver = new ImageResolver();
	private CallBack callBack;
	private Composite container;
	private TenderProjectEntity tenderProjectEntity;
	private SupplierService supplierService = new SupplierService();
	private EvaluationFactorService evaluationFactorService = new EvaluationFactorService();
	private List<Supplier> supplierList;
	private List<EvaluationFactor> evaluationFactorTreeList;
	private EvaluationFactor curEvaluationFactor;
	private EvaluationStep evaluationStep;
	private AuthUser curUser;
	private FactorEvaluationOpinionComposite factorEvaluationOpinionComposite;
	{
		LogUtils.logClass(FactorOpinionDialog.class);
	}
	
	/**
	 * Create the dialog.
	 * @param parentShell
	 */
	public FactorOpinionDialog(Shell parentShell, TenderProjectEntity tenderProjectEntity, EvaluationStep evaluationStep, AuthUser curUser, List<Supplier> supplierList, List<EvaluationFactor> evaluationFactorTreeList, EvaluationFactor curEvaluationFactor) {
		super(parentShell);
		this.setShellTrim();
		setShellStyle(SWT.MODELESS);
		this.supplierList = supplierList;
		this.tenderProjectEntity = tenderProjectEntity;
		this.evaluationFactorTreeList = evaluationFactorTreeList;
		this.curEvaluationFactor = curEvaluationFactor;
		this.curUser = curUser;
		this.evaluationStep = evaluationStep;
		this.setOperator(SWT.MAX);
		setTitle(MessageFormat.format(Messages.Title_view, Messages.Button_factorOpinion));
	}

	/**
	 * Create contents of the dialog.
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite topContainer = (Composite) super.createDialogArea(parent);
		topContainer.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				imageResolver.disposite();
			}
		});
		GridLayout gl_topContainer = new GridLayout(1, false);
		gl_topContainer.verticalSpacing = 0;
		gl_topContainer.horizontalSpacing = 0;
		gl_topContainer.marginHeight = 0;
		gl_topContainer.marginWidth = 0;
		topContainer.setLayout(gl_topContainer);
		
		container = new Composite(topContainer, SWT.NONE);
		container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_container = new GridLayout(1, false);
		gl_container.verticalSpacing = 0;
		gl_container.horizontalSpacing = 0;
		gl_container.marginHeight = 0;
		gl_container.marginWidth = 0;
		container.setLayout(gl_container);
		this.setOperator(SWT.MAX|SWT.CLOSE);
		
		factorEvaluationOpinionComposite = new FactorEvaluationOpinionComposite(container, SWT.NONE);
		factorEvaluationOpinionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		init();
		return container;
	}

	/**
	 * @Description: 初始化
	 * @author guoyr
	 */
	private void init() {
		
		if(null == supplierList) {
			supplierList = supplierService.getEvaluationStepSupplierList(tenderProjectEntity.getId(), evaluationStep);
		}
		if(null == evaluationFactorTreeList) {
			evaluationFactorTreeList = evaluationFactorService.getEvaluationStepFactorTreeList(tenderProjectEntity.getId(), evaluationStep);
		}
		factorEvaluationOpinionComposite.refresh(tenderProjectEntity, evaluationStep, curUser.getId(), supplierList, evaluationFactorTreeList, curEvaluationFactor);
	}
	
	
	
	
	
	
//	/**
//	 * @Description: 取消
//	 * @author guoyr
//	 */
//	private void cancelAction(){
//		this.getShell().close();
//	}

	
	public CallBack getCallBack() {
		return callBack;
	}

	public void setCallBack(CallBack callBack) {
		this.callBack = callBack;
	}
	
	
	
	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		ScreenUtils util = new ScreenUtils();
		return new Point((int)(util.getScreenWight() * 0.8), (int)(util.getScreenHight() * 0.8));
	}
}
