package com.gx.obe.management.composite;

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

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.listener.RoundBorderLineListener;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
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 org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;

import com.gx.obe.ColorConstants;
import com.gx.obe.action.bean.Action;
import com.gx.obe.business.enumeration.ExpertEnum;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.common.widget.button.RoundButton;
import com.gx.obe.common.widget.button.StepProgressButton;
import com.gx.obe.common.widget.composite.TipsComposite;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.enumeration.EvaluationFactorEnum;
import com.gx.obe.components.core.enumeration.EvaluationStepEnum;
import com.gx.obe.components.core.enumeration.TenderProjectEnum;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.DateUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.util.utils.StringUtils;
import com.gx.obe.web.entity.evaluation.EvaluationFactor;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.expert.Expert;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.ProjectRuleService;
import com.gx.obe.web.service.TenderProjectService;
import com.gx.obe.web.service.evaluation.EvaluationFactorService;
import com.gx.obe.web.service.evaluation.EvaluationStepService;
import com.gx.obe.web.service.expert.ExpertService;
import com.gx.obe.web.vo.TenderPackOpeningInfo;
import com.gx.utils.NowTimeUtils;
import org.eclipse.swt.core.utils.WidgetUtils;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

public class TenderProjectStatusComposite extends Composite {

	private boolean isDisposite = false;
	private Composite openingInfoComposite;
	private TenderProjectEntity tenderProject;
	private TenderProjectRuleEntity projectRule;
	private TenderProjectService tenderProjectService = new TenderProjectService();
	private ProjectRuleService projectRuleService = new ProjectRuleService();
	private EvaluationFactorService evaluationFactorService = new EvaluationFactorService();
	private ExpertService expertService = new ExpertService();
	private EvaluationStepService evaluationStepService = new EvaluationStepService();
	private Composite factorComposite;
	private Composite expertComposite;
	private Composite stepInfoComposite;
	private CLabel openingStatusValue;
	private Label openingTime;
	private CLabel openingUploadTitle;
	private CLabel evaluationStatusValue;
	private CLabel evaluationUploadTitle;
	private Composite stepProgressComposite;
	private ScrolledComposite scrolledComposite;
	private Composite topComposite;
	private TipsComposite tipsComposite;
	private Composite evaluationCheckComposite;
	private Composite evaluationResultComposite;
	private Composite openingComposite;
	private static final String  FORMAT = "yyyy-MM-dd HH:mm";

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 * @param action 
	 */
	public TenderProjectStatusComposite(Composite parent, int style, Action action) {
		super(parent, style);
		tenderProject = action.getTenderProject();
		setLayout(new GridLayout(1, false));
		
		tipsComposite = new TipsComposite(this, SWT.NONE);
		GridLayout gridLayout = (GridLayout) tipsComposite.getTipsParent().getLayout();
		gridLayout.numColumns = 2;
		tipsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		
		Composite tipsDetailComposite = new Composite(tipsComposite.getTipsParent(), SWT.NONE);
		tipsDetailComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		RowLayout rl_tipsDetailComposite = new RowLayout(SWT.HORIZONTAL);
		rl_tipsDetailComposite.center = true;
		tipsDetailComposite.setLayout(rl_tipsDetailComposite);
		
		Label openingStatusTitles = new Label(tipsDetailComposite, SWT.NONE);
		openingStatusTitles.setText(Messages.EvaluationOperation);
		openingStatusTitles.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		openingStatusTitles.setForeground(SWTResourceManager.getColor(80, 80, 80));
		
		{
			Label stepName = new Label(tipsDetailComposite, SWT.NONE);
			stepName.setText(Messages.BidOpening);
			stepName.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
			stepName.setForeground(SWTResourceManager.getColor(60, 138, 226));
		}
		{
			CLabel sepLabelIco = new CLabel(tipsDetailComposite, SWT.NONE);
			sepLabelIco.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/right_arrow.png"));
		}
		
		{
			Label stepName = new Label(tipsDetailComposite, SWT.NONE);
			stepName.setText(Messages.EvaluationCheck);
			stepName.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
			stepName.setForeground(SWTResourceManager.getColor(60, 138, 226));
		}
		
		{
			Label stepTips = new Label(tipsDetailComposite, SWT.WRAP);
			stepTips.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
			stepTips.setForeground(SWTResourceManager.getColor(100, 100, 100));
//			stepTips.setText("评标办法\r\n评标步骤\r\n评标专家");
		}
		{
			CLabel sepLabelIco = new CLabel(tipsDetailComposite, SWT.NONE);
			sepLabelIco.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/right_arrow.png"));
		}
		
		{
			Label stepName = new Label(tipsDetailComposite, SWT.NONE);
			stepName.setText(Messages.BidEvaluation);
			stepName.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
			stepName.setForeground(SWTResourceManager.getColor(60, 138, 226));
		}
		
		{
			CLabel sepLabelIco = new CLabel(tipsDetailComposite, SWT.NONE);
			sepLabelIco.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/right_arrow.png"));
		}
		
		{
			Label stepName = new Label(tipsDetailComposite, SWT.NONE);
			stepName.setText(Messages.GenerateEvaluationReport);
			stepName.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
			stepName.setForeground(SWTResourceManager.getColor(60, 138, 226));
		}
		
		{
			Label stepTips = new Label(tipsDetailComposite, SWT.WRAP);
			stepTips.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
			stepTips.setForeground(SWTResourceManager.getColor(100, 100, 100));
//			stepTips.setText("生成报告报表\r\n专家签字");
		}
		{
			CLabel sepLabelIco = new CLabel(tipsDetailComposite, SWT.NONE);
			sepLabelIco.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/right_arrow.png"));
		}
		
		{
			Label stepName = new Label(tipsDetailComposite, SWT.NONE);
			stepName.setText(Messages.Button_uploadEvaluationResult);
			stepName.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
			stepName.setForeground(SWTResourceManager.getColor(60, 138, 226));
		}
		
		
		scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL);
		scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		topComposite = new Composite(scrolledComposite, SWT.NONE);
		topComposite.setLayout(new GridLayout(2, false));
		
		RoundButton label_2 = new RoundButton(topComposite, SWT.NONE);
		GridData gd_label_2 = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
		gd_label_2.widthHint = 100;
		label_2.setLayoutData(gd_label_2);
		label_2.setText(Messages.BidOpening);
		label_2.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/evaluaton_step/recommoned.png"));
		label_2.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		label_2.setSurroundMargin(10);
		openingComposite = new Composite(topComposite, SWT.NONE);
		openingComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_openingComposite = new GridLayout(1, false);
		gl_openingComposite.verticalSpacing = 0;
		gl_openingComposite.marginHeight = 0;
		openingComposite.setLayout(gl_openingComposite);
		
		Composite composite_5 = new Composite(openingComposite, SWT.NONE);
		composite_5.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_composite_5 = new GridLayout(5, false);
		gl_composite_5.horizontalSpacing = 0;
		composite_5.setLayout(gl_composite_5);
		
		Label openingStatusTitle = new Label(composite_5, SWT.NONE);
		openingStatusTitle.setText(Messages.BidOpeningStatus + "：");
		openingStatusTitle.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		openingStatusTitle.setForeground(SWTResourceManager.getColor(80, 80, 80));
		openingStatusTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		
		openingStatusValue = new CLabel(composite_5, SWT.NONE);
		openingStatusValue.setText("");
		openingStatusValue.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/decrypt.png"));
		openingStatusValue.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		openingStatusValue.setForeground(SWTResourceManager.getColor(60, 138, 226));
		openingStatusValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		
		Label openingTimeTitle = new Label(composite_5, SWT.NONE);
		openingTimeTitle.setText("  "+Messages.BidOpeningTime +"：");
		openingTimeTitle.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		openingTimeTitle.setForeground(SWTResourceManager.getColor(100, 100, 100));
		openingTimeTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		
		openingTime = new Label(composite_5, SWT.WRAP);
		openingTime.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		openingTime.setForeground(SWTResourceManager.getColor(100, 100, 100));
		openingTime.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		openingTime.setText("");
		
		openingUploadTitle = new CLabel(composite_5, SWT.NONE);
		openingUploadTitle.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/update.png"));
		openingUploadTitle.setLeftMargin(20);
		openingUploadTitle.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		openingUploadTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		openingUploadTitle.setForeground(SWTResourceManager.getColor(60, 138, 226));
		
		openingInfoComposite = new Composite(openingComposite, SWT.NONE);
		openingInfoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_openingInfoComposite = new GridLayout(3, false);
		gl_openingInfoComposite.verticalSpacing = 0;
		gl_openingInfoComposite.marginHeight = 0;
		openingInfoComposite.setLayout(gl_openingInfoComposite);
		
		
		Label label = new Label(openingInfoComposite, SWT.NONE);
		label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 1));
		label.setText(Messages.Tips_loading);
		label.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		label.setForeground(SWTResourceManager.getColor(100, 100, 100));
		
		ProgressBar progressBar = new ProgressBar(openingInfoComposite, SWT.INDETERMINATE);
		GridData gd_progressBar = new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1);
		gd_progressBar.heightHint = 3;
		gd_progressBar.widthHint = 200;
		progressBar.setLayoutData(gd_progressBar);
		new Label(openingInfoComposite, SWT.NONE);
		
		
		{
			ESepator sep = new ESepator(topComposite, SWT.WRAP);
			sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
			sep.setForeground(ColorConstants.SEP_LIGHT_COLOR);
			sep.setLineStyle(SWT.LINE_DOT);
			sep.setLineWidth(3);
		}
		
		RoundButton evaluationCheck = new RoundButton(topComposite, SWT.NONE);
		GridData gd_evaluationCheck = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
		gd_evaluationCheck.widthHint = 100;
		evaluationCheck.setLayoutData(gd_evaluationCheck);
		evaluationCheck.setText(Messages.EvaluationCheck);
		evaluationCheck.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/evaluaton_step/feature_check.png"));
		evaluationCheck.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		evaluationCheck.setSurroundMargin(10);
		
		evaluationCheckComposite = new Composite(topComposite, SWT.NONE);
		evaluationCheckComposite.setLayout(new GridLayout(3, false));
		evaluationCheckComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		
		Composite composite_2 = new Composite(evaluationCheckComposite, SWT.NONE);
		GridData gd_composite_2 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_composite_2.widthHint = 150;
		composite_2.setLayoutData(gd_composite_2);
		GridLayout gl_composite_2 = new GridLayout(2, false);
		gl_composite_2.verticalSpacing = 0;
		composite_2.setLayout(gl_composite_2);
		composite_2.addPaintListener(new RoundBorderLineListener(10));
		
		Label label_1 = new Label(composite_2, SWT.NONE);
		label_1.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		label_1.setText(Messages.EvalFactor);
		label_1.setForeground(SWTResourceManager.getColor(80, 80, 80));
		label_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		
		Label label_3 = new Label(composite_2, SWT.WRAP);
		label_3.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		label_3.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_3.setForeground(SWTResourceManager.getColor(100, 100, 100));
		label_3.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/mouse.png"));
		label_3.setText(Messages.EvalManage + "->"+Messages.EvalMethod);
		
		factorComposite = new Composite(composite_2, SWT.NONE);
		factorComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1));
		GridLayout gl_factorComposite = new GridLayout(3, false);
		gl_factorComposite.marginHeight = 0;
		gl_factorComposite.verticalSpacing = 0;
		factorComposite.setLayout(gl_factorComposite);
		
		
		Composite composite_4 = new Composite(evaluationCheckComposite, SWT.NONE);
		GridData gd_composite_4 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_composite_4.widthHint = 100;
		composite_4.setLayoutData(gd_composite_4);
		composite_4.setLayout(new GridLayout(2, false));
		composite_4.addPaintListener(new RoundBorderLineListener(10));
		
		Label stepTitle = new Label(composite_4, SWT.NONE);
		stepTitle.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		stepTitle.setText(Messages.Step_step);
		stepTitle.setForeground(SWTResourceManager.getColor(80, 80, 80));
		
		Label stepOp = new Label(composite_4, SWT.WRAP);
		stepOp.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1));
		stepOp.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		stepOp.setForeground(SWTResourceManager.getColor(100, 100, 100));
		stepOp.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/mouse.png"));
		stepOp.setText(Messages.EvalManage + "-> "+ Messages.EvalStep);
		
		stepInfoComposite = new Composite(composite_4, SWT.NONE);
		stepInfoComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1));
		stepInfoComposite.setLayout(new GridLayout(3, false));
		
		Composite composite_3 = new Composite(evaluationCheckComposite, SWT.NONE);
		GridData gd_composite_3 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_composite_3.widthHint = 100;
		composite_3.setLayoutData(gd_composite_3);
		composite_3.setLayout(new GridLayout(2, false));
		composite_3.addPaintListener(new RoundBorderLineListener(10));
		
		Label expertTitle = new Label(composite_3, SWT.NONE);
		expertTitle.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		expertTitle.setText(Messages.EvalMember);
		expertTitle.setForeground(SWTResourceManager.getColor(80, 80, 80));
		
		Label expertOp = new Label(composite_3, SWT.WRAP);
		expertOp.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1));
		expertOp.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		expertOp.setForeground(SWTResourceManager.getColor(100, 100, 100));
		expertOp.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/mouse.png"));
		expertOp.setText(Messages.EvalManage + "->" + Messages.EvalExpert);
		
		expertComposite = new Composite(composite_3, SWT.NONE);
		expertComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1));
		expertComposite.setLayout(new GridLayout(3, false));
		
		
		
		{
			ESepator sep = new ESepator(topComposite, SWT.WRAP);
			sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
			sep.setForeground(ColorConstants.SEP_LIGHT_COLOR);
			sep.setLineStyle(SWT.LINE_DOT);
			sep.setLineWidth(3);
		}
		RoundButton evaluationInfo = new RoundButton(topComposite, SWT.NONE);
		evaluationInfo.setText(Messages.BidEvaluation);
		evaluationInfo.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/evaluaton_step/score.png"));
		evaluationInfo.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		GridData gd_evaluationInfo = new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1);
		gd_evaluationInfo.widthHint = 100;
		evaluationInfo.setLayoutData(gd_evaluationInfo);
		evaluationInfo.setSurroundMargin(10);
		
		evaluationResultComposite = new Composite(topComposite, SWT.NONE);
		evaluationResultComposite.setLayout(new GridLayout(1, false));
		evaluationResultComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		Composite composite_7 = new Composite(evaluationResultComposite, SWT.NONE);
		composite_7.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		composite_7.setLayout(new GridLayout(3, false));
		
		Label evaluationStatusTitle = new Label(composite_7, SWT.NONE);
		evaluationStatusTitle.setText(Messages.EvalProgress);
		evaluationStatusTitle.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		evaluationStatusTitle.setForeground(SWTResourceManager.getColor(80, 80, 80));
		evaluationStatusTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		
		evaluationStatusValue = new CLabel(composite_7, SWT.NONE);
		evaluationStatusValue.setText("");
		evaluationStatusValue.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.BOLD));
		evaluationStatusValue.setForeground(SWTResourceManager.getColor(60, 138, 226));
		GridData gd_evaluationStatusValue = new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1);
		gd_evaluationStatusValue.widthHint = 50;
		evaluationStatusValue.setLayoutData(gd_evaluationStatusValue);
		
		Label label_4 = new Label(composite_7, SWT.WRAP);
		label_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		label_4.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_4.setForeground(SWTResourceManager.getColor(100, 100, 100));
		label_4.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/mouse.png"));
		label_4.setText(Messages.EvalManage + "->"+Messages.EvalProgress+"\t" +Messages.Tips_evalProgressOperation);
		
		stepProgressComposite = new Composite(evaluationResultComposite, SWT.NONE);
		RowLayout rl_stepProgressComposite = new RowLayout(SWT.HORIZONTAL);
		rl_stepProgressComposite.marginRight = 0;
		rl_stepProgressComposite.marginLeft = 80;
		rl_stepProgressComposite.spacing = 0;
		stepProgressComposite.setLayout(rl_stepProgressComposite);
		stepProgressComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		
		Composite composite_8 = new Composite(evaluationResultComposite, SWT.NONE);
		composite_8.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		composite_8.setLayout(new GridLayout(3, false));
		
		Label evaluationResultTitle = new Label(composite_8, SWT.NONE);
		evaluationResultTitle.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		evaluationResultTitle.setText(Messages.BidEvaluationResult);
		evaluationResultTitle.setForeground(SWTResourceManager.getColor(80, 80, 80));
		
		Label label_5 = new Label(composite_8, SWT.WRAP);
		label_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		label_5.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_5.setForeground(SWTResourceManager.getColor(100, 100, 100));
		label_5.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/mouse.png"));
		label_5.setText(Messages.EvalManage + "->"+Messages.BidEvaluationResult+"\t" + Messages.Tips_evalResultOperation);
		
		evaluationUploadTitle = new CLabel(composite_8, SWT.NONE);
		evaluationUploadTitle.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		evaluationUploadTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		evaluationUploadTitle.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/update.png"));
		evaluationUploadTitle.setForeground(SWTResourceManager.getColor(60, 138, 226));
		
		scrolledComposite.setContent(topComposite);
		scrolledComposite.setMinSize(topComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		init();
	}
	
	private void init(){
		new Thread(new Runnable(){
			public void run(){
				
				projectRule = projectRuleService.getProjectRule(tenderProject.getId());
				tenderProject = tenderProjectService.getById(tenderProject.getId());
				if(null == projectRule){
					projectRule = new TenderProjectRuleEntity();
				}
				
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(!openingStatusValue.isDisposed()){
							openingTime.setText(ObjectUtils.getObjString(DateUtils.getFormat(projectRule.getBidOpeningStartTime(), FORMAT)));
							if(CommonEnum.COMPLETE.equals(tenderProject.getBidOpeningStatus())){
								openingStatusValue.setEnabled(true);
								openingStatusValue.setText(Messages.OpeningStatus_opend);
							}else {
								openingStatusValue.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
								openingStatusValue.setText(Messages.OpeningStatus_none);
								openingStatusValue.setEnabled(false);
							}
							if(null != tenderProject.getTransactionServerId()){
								if(CommonEnum.COMPLETE.equals(tenderProject.getUploadOpeningResultStatus())){
									openingUploadTitle.setText(MessageFormat.format(Messages.Button_uploadedFormat, Messages.BidOpeningList));
									openingUploadTitle.setEnabled(true);
								}else {
									openingUploadTitle.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
									openingUploadTitle.setText(MessageFormat.format(Messages.Button_notUploadFormat, Messages.BidOpeningList));
									openingUploadTitle.setEnabled(false);
								}
							}else {
								WidgetUtils.setControlVisible(openingUploadTitle, false);
							}
							openingStatusValue.getParent().layout();
							for(Control control : openingInfoComposite.getChildren()){
								control.dispose();
							}
							if(TenderProjectEnum.BID_OPENING_TWO_STAGE.equals(projectRule.getBidOpeningStage())){
								GridLayout gridLayout = ((GridLayout)openingInfoComposite.getLayout());
								int initCoumns = gridLayout.numColumns;
								gridLayout.numColumns = initCoumns * 3 + 1;
								TenderPackOpeningInfo tenderPackOpeningInfo = tenderProjectService.getTenderPackOpeningInfo(tenderProject.getId(), TenderProjectEnum.STAGE_BUS_TEC);
								refreshOpeningInfo(tenderPackOpeningInfo, Messages.BusinessTechnologyBid, true);
								tenderPackOpeningInfo = tenderProjectService.getTenderPackOpeningInfo(tenderProject.getId(), TenderProjectEnum.STAGE_PRICE);
								refreshOpeningInfo(tenderPackOpeningInfo, Messages.EconomicBid, false);
							}else {
								TenderPackOpeningInfo tenderPackOpeningInfo = tenderProjectService.getTenderPackOpeningInfo(tenderProject.getId(), TenderProjectEnum.STAGE_ALL);
								refreshOpeningInfo(tenderPackOpeningInfo, null, true);
							}
							openingInfoComposite.layout();
							((GridData)openingComposite.getLayoutData()).widthHint = tipsComposite.getBounds().width - 120;
							openingComposite.layout();
						}
					}
				});
				
				if(isDisposite){
					return;
				}
				
				final List<EvaluationFactor> evaluationFactorList = evaluationFactorService.getAllEvaluationFactorList(tenderProject.getId(), EvaluationFactorEnum.AUDIT_COMPLIANCE);
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(!factorComposite.isDisposed()){
							createFactorInfo(EvaluationFactorEnum.AUDIT_COMPLIANCE, evaluationFactorList, factorComposite, Messages.Factor_compliance);
							factorComposite.layout();
						}
					}
				});
				final List<EvaluationFactor> scoreEvaluationFactorList = evaluationFactorService.getAllEvaluationFactorList(tenderProject.getId(), EvaluationFactorEnum.AUDIT_SCORE);
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(!factorComposite.isDisposed()){
							createFactorInfo(EvaluationFactorEnum.AUDIT_SCORE, scoreEvaluationFactorList, factorComposite, Messages.Factor_score);
							factorComposite.layout();
						}
					}
				});
				final List<EvaluationFactor> priceEvaluationFactorList = evaluationFactorService.getAllEvaluationFactorList(tenderProject.getId(), EvaluationFactorEnum.AUDIT_PRICE);
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(!factorComposite.isDisposed()){
							createFactorInfo(EvaluationFactorEnum.AUDIT_PRICE, priceEvaluationFactorList, factorComposite, Messages.Factor_price);
							factorComposite.layout();
							factorComposite.getParent().layout();
							
						}
					}
				});
				if(isDisposite){
					return;
				}
				
				final List<EvaluationStep> evaluationStepList = evaluationStepService.getEvaluationStepList(tenderProject.getId());
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(!stepInfoComposite.isDisposed()){
							if(null != evaluationStepList && evaluationStepList.size() > 0){
								boolean hasRecommoned = EvaluationStepEnum.RECOMMONED.equals(evaluationStepList.get(evaluationStepList.size()-1).getStepType());
								int busStep = 0;
								int tecStep = 0;
								for(EvaluationStep step : evaluationStepList){
									if(EvaluationFactorEnum.EVAL_BID_BUS.equals(step.getEvalBidType())){
										busStep ++;
									}else if(EvaluationFactorEnum.EVAL_BID_TEC.equals(step.getEvalBidType())){
										tecStep ++;
									}
								}
								createInfo(stepInfoComposite, Messages.Step_step, evaluationStepList.size()+ Messages.NumCouns, false, "");
								createInfo(stepInfoComposite, Messages.Business, busStep> 0 ? Messages.Setup_yes : Messages.Setup_no, busStep  == 0, "");
								createInfo(stepInfoComposite, Messages.Technology, tecStep> 0 ? Messages.Setup_yes : Messages.Setup_no, busStep  == 0, "");
								if(!hasRecommoned){
									createInfo(stepInfoComposite, "提示", "评标步骤设置不完整", true, "");
								}
							}else {
								createInfo(stepInfoComposite, Messages.Step_step, Messages.Setup_no, true, "");
							}
							stepInfoComposite.layout();
							stepInfoComposite.getParent().layout();
						}
					}
				});
				
				if(isDisposite){
					return;
				}
				final List<Expert> expertList = expertService.getExpertList(tenderProject.getId(), ExpertEnum.ALL);
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(!expertComposite.isDisposed()){
							if(null != expertList && expertList.size() > 0){
								boolean hasExpertLeader = false;
								for(Expert expert : expertList){
									if(ExpertEnum.LEADER_YES.equals(expert.getIsLeader())){
										hasExpertLeader = true;
										break;
									}
								}
								createInfo(expertComposite, Messages.Expert, expertList.size()+ Messages.PeopleCouns, false, "");
								if(hasExpertLeader){
									createInfo(expertComposite, Messages.ExpertLeader, Messages.Setup_yes, false, "");
								}else {
									createInfo(expertComposite, Messages.ExpertLeader, Messages.Setup_no, true, "");
								}
							}else {
								createInfo(expertComposite, Messages.Expert, Messages.Setup_no, true, "");
							}
							expertComposite.layout();
							expertComposite.getParent().layout();
							
							((GridData)evaluationCheckComposite.getLayoutData()).widthHint = tipsComposite.getBounds().width - 120;
							evaluationCheckComposite.layout();
						}
					}
				});
				
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(!stepProgressComposite.isDisposed()){
							int complateCount = 0;
							int totalStepCount = 0;
//							evaluationStepList.addAll(evaluationStepList);
//							evaluationStepList.addAll(evaluationStepList);
							if(null != evaluationStepList && evaluationStepList.size() > 0){
								totalStepCount = evaluationStepList.size() * 2;
								for(Control control : stepProgressComposite.getChildren()){
									control.dispose();
								}
								for(int nodeCount = 0; nodeCount < evaluationStepList.size(); nodeCount ++){
									final EvaluationStep evaluationStep = evaluationStepList.get(nodeCount);
									final StepProgressButton totalProgress = new StepProgressButton(stepProgressComposite, SWT.NONE|SWT.SELECTED);
									totalProgress.setText((nodeCount+1)+"、"+evaluationStep.getStepName()+ (nodeCount != evaluationStepList.size() -1 ? "  >" : ""));
									
									if(ObjectUtils.equals(evaluationStep.getStepStatus(), CommonEnum.COMPLETE)){
										complateCount += 2;
										totalProgress.setBackground(StepProgressButton.COMPLATE_COLOR);
									}else if(ObjectUtils.equals(evaluationStep.getStepStatus(), CommonEnum.RE_OPERATOR)){
										totalProgress.setBackground(StepProgressButton.RE_AUTHORIZATION_COLOR);
										complateCount += 1;
									}else if(ObjectUtils.equals(evaluationStep.getStepStatus(), CommonEnum.IN_PROGRESS)){
										complateCount += 1;
										totalProgress.setBackground(SWTResourceManager.getColor(60, 138, 226));
									}else {
										totalProgress.setBackground(StepProgressButton.NO_START_COLOR);
									}
								}
							}
							if(complateCount > 0){
								evaluationStatusValue.setText((int)(complateCount * 100d/ ((double)(totalStepCount)))+"%");
							}else {
								evaluationStatusValue.setText("0%");
							}
							if(CommonEnum.COMPLETE.equals(tenderProject.getComplateStatus()) || complateCount > 0 && complateCount == totalStepCount){
								evaluationStatusValue.setText("100%");
							}else {
								evaluationStatusValue.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
							}
							
							if(null != tenderProject.getTransactionServerId()){
								if(CommonEnum.COMPLETE.equals(tenderProject.getUploadEvaluationResultStatus())){
									evaluationUploadTitle.setText(MessageFormat.format(Messages.Button_uploadedFormat, Messages.BidEvaluationResult));
									evaluationUploadTitle.setEnabled(true);
								}else {
									evaluationUploadTitle.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
									evaluationUploadTitle.setText(MessageFormat.format(Messages.Button_notUploadFormat, Messages.BidEvaluationResult));
									evaluationUploadTitle.setEnabled(false);
								}
							}else {
								WidgetUtils.setControlVisible(evaluationUploadTitle, false);
							}
							
							evaluationStatusValue.getParent().layout();
							stepProgressComposite.layout();
							stepProgressComposite.getParent().layout();
							
							((GridData)evaluationResultComposite.getLayoutData()).widthHint = tipsComposite.getBounds().width - 120;
							
							topComposite.layout();
							scrolledComposite.setMinSize(topComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
						}
					}
				});
			
			}
		}).start();
	}

	private void refreshOpeningInfo(final TenderPackOpeningInfo tenderPackOpeningInfo, String title, final boolean clear){
		
		if(StringUtils.hasLength(title)) {
			Label titleLabel = new Label(openingInfoComposite, SWT.RIGHT);
			titleLabel.setText(title + "：");
			titleLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
			titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
			titleLabel.setForeground(SWTResourceManager.getColor(100, 100, 100));
		}
		
		boolean isHideSupplierInfo = null != projectRule.getBidOpeningStartTime() && projectRule.getBidOpeningStartTime().after(NowTimeUtils.getNowDate());
		createInfo(openingInfoComposite, Messages.Opening_tendered, (isHideSupplierInfo ?  "*" : tenderPackOpeningInfo.getTenderCount()) +" " + Messages.NumCouns, tenderPackOpeningInfo.getTenderCount() == 0, "使用“开标工具”进入开标大厅后点击“同步最新投标信息”或在“供应商信息->下载供应商”下载最新投标信息");
		
		
		createInfo(openingInfoComposite, Messages.Opening_signedIn, tenderPackOpeningInfo.getSignCount() +" " + Messages.NumCouns, tenderPackOpeningInfo.getSignCount() == 0, "全流程项目请使用“开标工具”进入开标大厅并启动远程开标大厅后，由供应商在线签到，半流程项目请进入“开标管理->供应商签到”根据提示进行补录。");
		
		createInfo(openingInfoComposite, Messages.OpeningStatus_opend, tenderPackOpeningInfo.getDecCount() +" " + Messages.NumCouns, tenderPackOpeningInfo.getDecCount() == 0, "全流程项目请使用“开标工具”进入开标大厅根据提示完成开标流程操作，半流程项目请进入“开标管理->开标结果”根据提示进行补录开标结果。");
	}
	
	
	private void createInfo(Composite parent, String title, String value, boolean isError, final String tips){
		Label titleLabel = new Label(parent, SWT.RIGHT);
		titleLabel.setText(title + "：");
		titleLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		titleLabel.setForeground(SWTResourceManager.getColor(100, 100, 100));
		
		Label valueLabel = new Label(parent, SWT.NONE);
		valueLabel.setText(value);
		valueLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		if(isError){
			valueLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		}else {
			valueLabel.setForeground(SWTResourceManager.getColor(60, 138, 226));
		}
		valueLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		
		CLabel tipsLabel = new CLabel(parent, SWT.WRAP);
		tipsLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		tipsLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		tipsLabel.setForeground(SWTResourceManager.getColor(100, 100, 100));
		if(null != tips && tips.length() > 0){
//			tipsLabel.setText(tips);
			tipsLabel.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/question.png"));
			tipsLabel.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			tipsLabel.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseUp(MouseEvent e) {
					MessageDialog.openShortMessage(tips);
				}
			});
		}
	}
	
	private void createFactorInfo(final String factorType, List<EvaluationFactor> evaluationFactorList, Composite parent, String title){
		Label titleLabel = new Label(parent, SWT.RIGHT);
		titleLabel.setText(title + "：");
		titleLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		titleLabel.setForeground(SWTResourceManager.getColor(100, 100, 100));
		
		final Label valueLabel = new Label(parent, SWT.NONE);
		valueLabel.setText(Messages.Tips_loading);
		valueLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		valueLabel.setForeground(SWTResourceManager.getColor(60, 138, 226));
		valueLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		
		final Label emptyLabel = new Label(parent, SWT.WRAP);
		emptyLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1));
		emptyLabel.setForeground(SWTResourceManager.getColor(100, 100, 100));
		emptyLabel.setText("");
		
		FactorCount factorCount = new FactorCount(){
			int total, busCount, tecCount = 0;
			boolean hasPriceFormula = false;
			final Runnable valueRunnable = new Runnable(){
				public void run(){
					if(!valueLabel.isDisposed()){
						emptyLabel.setForeground(SWTResourceManager.getColor(100, 100, 100));
						valueLabel.setText(total +Messages.ItemCounts);
						if(total > 0){
							if(EvaluationFactorEnum.AUDIT_PRICE.equals(factorType)){
								if(hasPriceFormula){
									emptyLabel.setText(MessageFormat.format(Messages.Setup_yesFormat, Messages.PriceFormula));
								}else {
									emptyLabel.setText(MessageFormat.format(Messages.Setup_noFormat, Messages.PriceFormula));
									emptyLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
								}
							}else {
								if(busCount + tecCount > 0){
									emptyLabel.setText(MessageFormat.format(Messages.Tips_factorsBidTypeCount, busCount, tecCount));
									if(busCount == 0 || tecCount == 0){
										emptyLabel.setForeground(SWTResourceManager.getColor(255, 153, 20));
									}
								}else {
									emptyLabel.setText(Messages.Tips_factorsNoBidType);
									emptyLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
								}
							}
						}else {
							emptyLabel.setText(Messages.Setup_no);
							emptyLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
						}
					
					}
				}
			};
			public synchronized void count(int total, boolean isBus, boolean isTec, boolean hasPriceFormula) {
				this.total += total;
				if(isBus){
					this.busCount += 1;
				}
				if(isTec){
					this.tecCount += 1;
				}
				if(!this.hasPriceFormula){
					this.hasPriceFormula = hasPriceFormula;
				}
				Display.getDefault().syncExec(valueRunnable);
			}
			
		};
		if(null != evaluationFactorList && evaluationFactorList.size() > 0){
			for (EvaluationFactor factor : evaluationFactorList) {
				initChildGridItem(factor, factorCount);
			}
		}else {
			valueLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
			valueLabel.setText(Messages.Setup_no);
		}
		
	}
	
	interface FactorCount{
		public void count(int total, boolean isBus, boolean isTec, boolean hasPriceFormula);
	}
	
	/**
	 * @Description: 递归实现指标树
	 * @author guoyr
	 * @param factor
	 * @param parentGridItem
	 * @param selectId
	 */
	private void initChildGridItem(EvaluationFactor factor, FactorCount factorCount) {
		factorCount.count(1, EvaluationFactorEnum.EVAL_BID_BUS.equals(factor.getEvalBidType()), EvaluationFactorEnum.EVAL_BID_TEC.equals(factor.getEvalBidType()), null != factor.getComputerParams());
		if (null != factor.getChildFactorList() && factor.getChildFactorList().size() > 0) {
			for (EvaluationFactor childFactor : factor.getChildFactorList()) {
				initChildGridItem(childFactor, factorCount);
			}
		}
	}
	
	@Override
	public void dispose() {
		isDisposite = true;
		super.dispose();
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
