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

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.widgets.EDialog;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

import com.gx.obe.action.bean.Action;
import com.gx.obe.action.listener.ActionListener;
import com.gx.obe.action.utils.ActionUtil;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.enumeration.EvaluationStepEnum;
import com.gx.obe.evaluation.step.resutl.action.ComplianceEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.ScoreEvaluationResultAction;
import com.gx.obe.util.utils.ScreenUtils;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.expert.Expert;
import com.gx.obe.web.entity.tender.TenderProjectEntity;

public class ViewEvaluationResultDialog extends EDialog implements ActionListener{

	
	private TenderProjectEntity tenderProjectEntity;
//	private TenderProjectRuleEntity tenderProjectRuleEntity;
	private EvaluationStep evaluationStep;
	private Expert CURRENT_EXPERT;
	private Composite container;
	/**
	 * Create the dialog.
	 * @param parentShell
	 */
	public ViewEvaluationResultDialog(Shell parentShell, TenderProjectEntity tenderProjectEntity, EvaluationStep evaluationStep, Expert CURRENT_EXPERT) {
		super(parentShell);
		this.tenderProjectEntity = tenderProjectEntity;
		this.evaluationStep = evaluationStep;
		this.CURRENT_EXPERT = CURRENT_EXPERT;
	}

	/**
	 * Create contents of the dialog.
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		container = (Composite) super.createDialogArea(parent);
		container.setLayout(new FillLayout(SWT.HORIZONTAL));

		init();
		return container;
	}

	private void init(){
		Action action = null;
		if (evaluationStep.getStepType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.COMPLIANCE)) {
			action = (Action) ActionUtil.getAction(ComplianceEvaluationResultAction.class.getName());
		} else if (EvaluationStepEnum.DETAIL.equals(evaluationStep.getStepType()) || EvaluationStepEnum.FIXED_FACTOR.equals(evaluationStep.getStepType())) {
			action = (Action) ActionUtil.getAction(ScoreEvaluationResultAction.class.getName());
		}
		evaluationStep.setEvaluationParam(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SHOW_SUMMARY_RESULT, "00");
		action.setTenderProject(tenderProjectEntity);
		action.setData("evaluationStep", evaluationStep);
//		action.setData("tenderProjectRuleEntity", tenderProjectRuleEntity);
		action.setData(Constants.CUR_EXPERT, CURRENT_EXPERT);
		action.setData(Constants.OPERATOR_USERID, Constants.USER.getId());
		action.addActionListener(this);
		action.run();
	}

	public void onLoad(Action action) {
		for (Control control : container.getChildren()) {
			control.dispose();
		}
		
	}
	
	public void loadComposite(Action action, Composite composite) {
		container.layout();
	}
	
	public Composite getParentComposite() {
		return container;
	}
	
	/**
	 * 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.7));
	}
}
