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

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

import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.nebula.widgets.grid.listener.GridCheckedListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.core.CallBack;
import org.eclipse.swt.core.ImageResolver;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.listener.RoundBorderLineListener;
import org.eclipse.swt.core.listener.TextHintListener;
import org.eclipse.swt.core.listener.VerifyRequiredListener;
import org.eclipse.swt.core.utils.GridUtils;
import org.eclipse.swt.core.utils.ValidateUtils;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.EButton;
import org.eclipse.swt.core.widgets.EDialog;
import org.eclipse.swt.core.widgets.ELink;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.gx.obe.ColorConstants;
import com.gx.obe.business.enumeration.MenuEnum;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.common.widget.button.Tips;
import com.gx.obe.common.widget.dialog.SelectStepExpertDialog;
import com.gx.obe.common.widget.listener.SelectExpertListener;
import com.gx.obe.common.widget.utils.MenuFunctionUtils;
import com.gx.obe.components.core.I18NEnum;
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.message.Messages;
import com.gx.obe.util.utils.CollectionUtils;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.util.utils.StringUtils;
import com.gx.obe.web.entity.auth.Menu;
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.service.MenuService;
import com.gx.obe.web.service.evaluation.EvaluationFactorService;
import com.gx.obe.web.service.evaluation.EvaluationStepExpertService;
import com.gx.obe.web.service.evaluation.EvaluationStepFactorService;
import com.gx.obe.web.service.evaluation.EvaluationStepService;
import com.gx.obe.web.service.expert.ExpertService;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

/**
 * @Description: 
 * @author guoyr
 */
public class ComplianceEvaluationStepDialog extends EDialog {
	
	private Text stepNameText;
	private Composite roleTypeComposite;
	private Composite customComposite;
	private Composite passTypeComposite;
	private Grid grid;
	private EButton save_btn;
	private GridColumn gridColumn;
	private ImageResolver imageResolver = new ImageResolver();
	private Image menuOpenImage;
	private Image menuImage;
	private EvaluationFactorService evaluationFactorService = new EvaluationFactorService();
	private EvaluationStepService evaluationStepService = new EvaluationStepService();
	private EvaluationStepFactorService evaluationStepFactorService ;
	private ExpertService expertService;
	private MenuService menuService ;
	private TenderProjectEntity tenderProjectEntity;
	private EvaluationStep evaluationStep;
	private List<Object> factorList;
	private Text stepMemoText;
	private Label expertNamesLabel;
	private Composite composite;
	private CallBack callBack;
	private List<Expert> stepExpertUserIdList ;
	private Button button_2;
//	private Button button_3;
	private Button button_4;
	private boolean isInEvaluation = false;// 是否在评审中
	private Button importTypeBtn;
	private Button importHistoryBtn;
	private Button allowEditConclusionBtn;
	private Button showAggregateBtn;
//	private Button param_exper_signature;
	private Button param_sealed_bid;
	private Button param_orderby_sealed_bid_code;
	private Composite sortNoComposite;
	private Button evalBidBusBtn;
	private Button evalBidTecBtn;
	private GridItem topGridItem;
	private Button expertRoleNameBtn;
	private Label evalBidTypeLabel;
	private Composite evalBidTypeComposite;
	private Label customExpertLabel;
	private Button evalBidPriceBtn;
	private Text deviateClauseCountText;
	private Label deviateClauseLabel;
	private Composite deviateClauseComposite;
//	private Composite sealedBidFileTypeComposite;
	private Text filterPriceSortText;
	private Label priceFilterTips;
	private Label deviateClauseTips;
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();
	private Label filterLabel;;
	private Button sameScoreCheckBtn;
	private Button sameScoreFilterBtn;
	private boolean hasNoCheckedFactor = false;
	private Tips tips;
	{
		LogUtils.logClass(ComplianceEvaluationStepDialog.class);
	}

	/**
	 * Create the dialog.
	 * @param parentShell
	 */
	public ComplianceEvaluationStepDialog(Shell parentShell, TenderProjectEntity tenderProjectEntity, EvaluationStep evaluationStep) {
		super(parentShell);
		setTitle(Messages.Step_step);
		this.tenderProjectEntity = tenderProjectEntity;
		this.evaluationStep = evaluationStep;
	}

	/**
	 * Create contents of the dialog.
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite topContainer = (Composite) super.createDialogArea(parent);
		this.setOperator(SWT.MAX|SWT.CLOSE);
		topContainer.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				imageResolver.disposite();
				if(null != stepExpertUserIdList){
					stepExpertUserIdList.clear();
				}
			}
		});
		GridLayout gl_topContainer = new GridLayout(1, false);
		gl_topContainer.marginHeight = 0;
		gl_topContainer.verticalSpacing = 0;
		gl_topContainer.horizontalSpacing = 0;
		gl_topContainer.marginWidth = 0;
		topContainer.setLayout(gl_topContainer);
		
		Composite container = new Composite(topContainer, SWT.NONE);
		container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_container = new GridLayout(2, false);
		gl_container.marginHeight = 10;
		gl_container.marginWidth = 10;
		container.setLayout(gl_container);
		
		
		tips = new Tips(container, SWT.WRAP);
		tips.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
		tips.setText(MessageFormat.format(Messages.Tips_factorStep, Messages.Factor_compliance));
		tips.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, EvaluationStepEnum.getEvaluationStepIco(EvaluationStepEnum.COMPLIANCE)));
		tips.setSurroundColor(SWTResourceManager.getColor(60, 138, 226));
		
		composite = new Composite(container, SWT.NONE);
		GridLayout gl_composite = new GridLayout(2, false);
		gl_composite.verticalSpacing = 10;
		composite.setLayout(gl_composite);
		GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_composite.widthHint = 400;
		composite.setLayoutData(gd_composite);
		
		Label step_name = new Label(composite, SWT.NONE);
		step_name.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		step_name.setAlignment(SWT.RIGHT);
		step_name.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		step_name.setText(Messages.StepName + ": ");
		
		Composite composite_2 = new Composite(composite, SWT.NONE);
		composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		GridLayout gl_composite_2 = new GridLayout(1, false);
		gl_composite_2.marginWidth = 0;
		gl_composite_2.verticalSpacing = 1;
		gl_composite_2.marginHeight = 0;
		composite_2.setLayout(gl_composite_2);
		
		stepNameText = new Text(composite_2, SWT.NONE);
		stepNameText.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		stepNameText.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1));
		stepNameText.addPaintListener(new TextHintListener(Messages.Tips_EnterEvaluationStepName));
		stepNameText.addVerifyListener(new VerifyRequiredListener(stepNameText, MessageFormat.format(Messages.Tips_required, Messages.StepName)));
		stepNameText.setTextLimit(20);
		stepNameText.setText("");
		
		ESepator label = new ESepator(composite_2, SWT.NONE);
		label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		label.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		Label label_1 = new Label(composite, SWT.NONE);
		label_1.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_1.setText(Messages.EvalExpert + "：");
		
		roleTypeComposite = new Composite(composite, SWT.NONE);
		RowLayout rl_roleTypeComposite = new RowLayout(SWT.HORIZONTAL);
		rl_roleTypeComposite.marginLeft = 0;
		roleTypeComposite.setLayout(rl_roleTypeComposite);
		roleTypeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		
		button_2 = new Button(roleTypeComposite, SWT.RADIO);
		button_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				selectRoleTypeAction(EvaluationStepEnum.EXPERT);
			}
		});
		button_2.setSelection(true);
		button_2.setText(Messages.AllExperts);
		button_2.setData("roleType", EvaluationStepEnum.EXPERT);
		
//		button_3 = new Button(roleTypeComposite, SWT.RADIO);
//		button_3.addSelectionListener(new SelectionAdapter() {
//			@Override
//			public void widgetSelected(SelectionEvent e) {
//				selectRoleTypeAction(EvaluationStepEnum.EXPERT_LEADER);
//			}
//		});
//		button_3.setText(Messages.ExpertLeader);
//		button_3.setData("roleType", EvaluationStepEnum.EXPERT_LEADER);
		
		expertRoleNameBtn = new Button(roleTypeComposite, SWT.RADIO);
		expertRoleNameBtn.setData("roleType", EvaluationStepEnum.EVAL_BID_TYPE);
		expertRoleNameBtn.setText(Messages.Business + "、" + Messages.Technology + Messages.Expert);
		expertRoleNameBtn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				selectRoleTypeAction(EvaluationStepEnum.EVAL_BID_TYPE);
			}
		});
		
		
		button_4 = new Button(roleTypeComposite, SWT.RADIO);
		button_4.setData("roleType", EvaluationStepEnum.CUSTOM);
		button_4.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				selectRoleTypeAction(EvaluationStepEnum.CUSTOM);
			}
		});
		button_4.setText(Messages.SpecifyExpert);
		
		customExpertLabel = new Label(composite, SWT.NONE);
		customExpertLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		
		customComposite = new Composite(composite, SWT.NONE);
		customComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_customComposite = new GridLayout(2, false);
		gl_customComposite.verticalSpacing = 0;
		gl_customComposite.horizontalSpacing = 0;
		gl_customComposite.marginHeight = 0;
		gl_customComposite.marginWidth = 0;
		customComposite.setLayout(gl_customComposite);
		
		expertNamesLabel = new Label(customComposite, SWT.WRAP);
		expertNamesLabel.setLayoutData(new GridData(SWT.CENTER, SWT.BOTTOM, true, true, 1, 1));
		expertNamesLabel.setText("郭永荣");
		
		ELink selectExpertLabel = new ELink(customComposite, SWT.NONE);
		selectExpertLabel.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/search.png"));
		selectExpertLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				selectStepExpert();
			}
		});
		selectExpertLabel.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, true, 1, 2));
		selectExpertLabel.setText(MessageFormat.format(Messages.Button_selectFormat, Messages.Expert));
		
		ESepator expert_sep = new ESepator(customComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
		expert_sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		expert_sep.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		evalBidTypeLabel = new Label(composite, SWT.NONE);
		evalBidTypeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		evalBidTypeLabel.setText(Messages.EvalType + "：");
		evalBidTypeLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		
		evalBidTypeComposite = new Composite(composite, SWT.NONE);
		evalBidTypeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		GridLayout gl_evalBidTypeComposite = new GridLayout(3, false);
		gl_evalBidTypeComposite.marginHeight = 0;
		gl_evalBidTypeComposite.marginWidth = 0;
		evalBidTypeComposite.setLayout(gl_evalBidTypeComposite);
		
		evalBidBusBtn = new Button(evalBidTypeComposite, SWT.CHECK);
		evalBidBusBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		evalBidBusBtn.setText(Messages.BusinessBid);
		
		evalBidTecBtn = new Button(evalBidTypeComposite, SWT.CHECK);
		evalBidTecBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		evalBidTecBtn.setText(Messages.TechnologyBid);
		
		evalBidPriceBtn = new Button(evalBidTypeComposite, SWT.CHECK);
		evalBidPriceBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		evalBidPriceBtn.setText(Messages.EconomicBid);
		
		Label label_11 = new Label(composite, SWT.NONE);
		label_11.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		label_11.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_11.setText(Messages.EvaluationSet + "：");
		
		Composite composite_import = new Composite(composite, SWT.NONE);
		composite_import.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		RowLayout rl_composite_import = new RowLayout(SWT.HORIZONTAL);
		rl_composite_import.marginRight = 0;
		rl_composite_import.marginBottom = 0;
		rl_composite_import.marginTop = 0;
		rl_composite_import.marginLeft = 0;
		composite_import.setLayout(rl_composite_import);
		
		importTypeBtn = new Button(composite_import, SWT.CHECK);
		importTypeBtn.setText(Messages.Tips_allowedImportOtherResult);
		
		importHistoryBtn = new Button(composite_import, SWT.CHECK);
		importHistoryBtn.setText(Messages.Tips_allowedImportHisResult);
		
		allowEditConclusionBtn = new Button(composite_import, SWT.CHECK);
		allowEditConclusionBtn.setText(Messages.Tips_allowEditConclusion);
		
		showAggregateBtn = new Button(composite_import, SWT.CHECK);
		showAggregateBtn.setText(Messages.Tips_allowedViewConclusion);
		
		sameScoreCheckBtn = new Button(composite_import, SWT.CHECK | SWT.WRAP);
		sameScoreCheckBtn.setText(Messages.Tips_inconsistentEarlyWarning);
		sameScoreFilterBtn = new Button(composite_import, SWT.CHECK | SWT.WRAP);
		sameScoreFilterBtn.setText(Messages.Tips_inconsistentNotAllowed);
		
		filterLabel = new Label(composite, SWT.NONE);
		filterLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		filterLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		filterLabel.setText(Messages.FilterFinalists + "：");
		menuFunctionUtils.addFunction(filterLabel, "FILTER_FINALISTS");
		
		Composite enterEvalPriceSortComposite = new Composite(composite, SWT.NONE);
		enterEvalPriceSortComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		GridLayout gl_enterEvalPriceSortComposite = new GridLayout(2, false);
		gl_enterEvalPriceSortComposite.verticalSpacing = 0;
		gl_enterEvalPriceSortComposite.marginHeight = 0;
		gl_enterEvalPriceSortComposite.marginWidth = 0;
		enterEvalPriceSortComposite.setLayout(gl_enterEvalPriceSortComposite);
		menuFunctionUtils.addFunction(enterEvalPriceSortComposite, "FILTER_FINALISTS");
		
		filterPriceSortText = new Text(enterEvalPriceSortComposite, SWT.CENTER);
		GridData gd_filterPriceSortText = new GridData(SWT.FILL, SWT.BOTTOM, false, true, 1, 1);
		gd_filterPriceSortText.widthHint = 30;
		filterPriceSortText.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
		filterPriceSortText.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.BOLD));
		filterPriceSortText.setLayoutData(gd_filterPriceSortText);
		filterPriceSortText.setTextLimit(3);
		
		priceFilterTips = new Label(enterEvalPriceSortComposite, SWT.WRAP);
		priceFilterTips.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 2));
		priceFilterTips.setText("");
		
		ESepator subLine = new ESepator(enterEvalPriceSortComposite, SWT.NONE);
		subLine.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1));
		subLine.setBackground(ColorConstants.BORDER_LINE_COLOR);
		
		deviateClauseLabel = new Label(composite, SWT.WRAP);
		deviateClauseLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		deviateClauseLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		deviateClauseLabel.setText(Messages.VetoBid + "：");
		
		deviateClauseComposite = new Composite(composite, SWT.NONE);
		GridLayout gl_deviateClauseComposite = new GridLayout(2, false);
		gl_deviateClauseComposite.verticalSpacing = 0;
		gl_deviateClauseComposite.marginHeight = 0;
		gl_deviateClauseComposite.marginWidth = 0;
		deviateClauseComposite.setLayout(gl_deviateClauseComposite);
		deviateClauseComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		deviateClauseCountText = new Text(deviateClauseComposite, SWT.CENTER);
		GridData gd_deviateClauseCountText = new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1);
		gd_deviateClauseCountText.widthHint = 30;
		deviateClauseCountText.setLayoutData(gd_deviateClauseCountText);
		deviateClauseCountText.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
		deviateClauseCountText.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.BOLD));
		deviateClauseCountText.setTextLimit(3);
		
		deviateClauseTips = new Label(deviateClauseComposite, SWT.WRAP);
		deviateClauseTips.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 2));
		deviateClauseTips.setText("");
		
		ESepator deviateClauseSubLine = new ESepator(deviateClauseComposite, SWT.NONE);
		deviateClauseSubLine.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1));
		deviateClauseSubLine.setBackground(ColorConstants.BORDER_LINE_COLOR);
		
		
		Label label_in = new Label(composite, SWT.NONE);
		label_in.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		label_in.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_in.setText(Messages.ShortlistedRules + "：");
		
		passTypeComposite = new Composite(composite, SWT.NONE);
		passTypeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		GridLayout gl_passTypeComposite = new GridLayout(2, false);
		gl_passTypeComposite.marginHeight = 0;
		gl_passTypeComposite.marginWidth = 0;
		passTypeComposite.setLayout(gl_passTypeComposite);
		
		Button button_1 = new Button(passTypeComposite, SWT.RADIO);
		button_1.setData("passType",EvaluationStepEnum.PASS_ALL);
		button_1.setSelection(true);
		button_1.setText(Messages.OneTicketVeto);
		
		Button button_5 = new Button(passTypeComposite, SWT.RADIO);
		button_5.setData("passType",EvaluationStepEnum.PASS_MORE);
		button_5.setText(Messages.MinorityObeyMajority);
		
//		Label evalTypeLabel = new Label(composite, SWT.NONE);
//		evalTypeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
//		evalTypeLabel.setText("评审视图：");
//		
//		evalTypeComposite = new Composite(composite, SWT.NONE);
//		evalTypeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
//		GridLayout gl_evalTypeComposite = new GridLayout(3, false);
//		gl_evalTypeComposite.marginHeight = 0;
//		gl_evalTypeComposite.marginWidth = 0;
//		evalTypeComposite.setLayout(gl_evalTypeComposite);
//		
//		Button evalTypeDefault = new Button(evalTypeComposite, SWT.RADIO);
//		evalTypeDefault.setSelection(true);
//		evalTypeDefault.setText(Messages.CentralizedReview);
//		evalTypeDefault.setData(EvaluationStepEnum.EVALUATION_TYPE_COLLECT);
//		
//		Button evalTypeSingle = new Button(evalTypeComposite, SWT.RADIO);
//		evalTypeSingle.setText(Messages.IndividualReview);
//		evalTypeSingle.setData(EvaluationStepEnum.EVALUATION_TYPE_SINGLE);
//		
//		Button evalTypeAI = new Button(evalTypeComposite, SWT.RADIO);
//		evalTypeAI.setText(Messages.SmartReview);
//		evalTypeAI.setData(EvaluationStepEnum.EVALUATION_TYPE_AI);
		
		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_3.setText(Messages.DartBid + "：");
		menuFunctionUtils.addFunction(label_3, "DART_BID");
		
		Composite composite_3 = new Composite(composite, SWT.NONE);
		composite_3.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_sealedbidcomposite_3 = new GridLayout(2, false);
		gl_sealedbidcomposite_3.marginHeight = 0;
		gl_sealedbidcomposite_3.marginWidth = 0;
		composite_3.setLayout(gl_sealedbidcomposite_3);
		menuFunctionUtils.addFunction(composite_3, "DART_BID");
		
		param_sealed_bid = new Button(composite_3, SWT.CHECK);
		param_sealed_bid.setText(Messages.DartBid);
		param_sealed_bid.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				checkSealedBidAction();
			}
		});
		
		param_orderby_sealed_bid_code = new Button(composite_3, SWT.CHECK);
		param_orderby_sealed_bid_code.setText(Messages.SortByDarkCode);
		
//		sealedBidFileTypeComposite = new Composite(composite_3, SWT.NONE);
//		sealedBidFileTypeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
//		GridLayout gl_sealedBidFileType = new GridLayout(4, false);
//		gl_sealedBidFileType.marginHeight = 0;
//		gl_sealedBidFileType.marginWidth = 0;
//		sealedBidFileTypeComposite.setLayout(gl_sealedBidFileType);
//		
//		Label sealedBidFileType = new Label(sealedBidFileTypeComposite, SWT.NONE);
//		sealedBidFileType.setForeground(ColorConstants.FONT_BLACK_COLOR);
//		sealedBidFileType.setText("暗标文件为：");
//		sealedBidFileType.setToolTipText("当标识暗标文件后，仅能看到已标识为暗标类型的文件（不标识时以专家权限为准）。");
//		
//		Button busFileBtn = new Button(sealedBidFileTypeComposite, SWT.CHECK);
//		busFileBtn.setText(Messages.BusinessBid);
//		busFileBtn.setData("evalBidType", ExpertEnum.EXPERT_BUS);
//		
//		Button tecFileBtn = new Button(sealedBidFileTypeComposite, SWT.CHECK);
//		tecFileBtn.setText(Messages.TechnologyBid);
//		tecFileBtn.setData("evalBidType", ExpertEnum.EXPERT_TEC);
//		
//		Button priceFileBtn = new Button(sealedBidFileTypeComposite, SWT.CHECK);
//		priceFileBtn.setText(Messages.EconomicBid);
//		priceFileBtn.setData("evalBidType", ExpertEnum.EXPERT_PRICE);
//		
//		Label label_2 = new Label(composite, SWT.NONE);
//		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
//		label_2.setText(Messages.Esignature + "：");
		
//		param_exper_signature = new Button(composite, SWT.CHECK);
//		param_exper_signature.setText(Messages.Tips_signatureBeforeSubmit);
		
		Label label_4 = new Label(composite, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_4.setText(Messages.ListNum + "：");
		menuFunctionUtils.addFunction(label_4, "LIST_NUM");
		
		sortNoComposite = new Composite(composite, SWT.NONE);
		sortNoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_compositea_4 = new GridLayout(2, false);
		gl_compositea_4.verticalSpacing = 0;
		gl_compositea_4.horizontalSpacing = 0;
		gl_compositea_4.marginHeight = 0;
		gl_compositea_4.marginWidth = 0;
		sortNoComposite.setLayout(gl_compositea_4);
		menuFunctionUtils.addFunction(sortNoComposite, "LIST_NUM");
		
		Button button = new Button(sortNoComposite, SWT.RADIO);
		button.setData("indexIsBidNumber", CommonEnum.NO);
		button.setText(Messages.Num);
		
		Button button_3 = new Button(sortNoComposite, SWT.RADIO);
		button_3.setData("indexIsBidNumber", CommonEnum.YES);
		button_3.setText(Messages.TenderNumber);
		
		Label label_5 = new Label(composite, SWT.NONE);
		label_5.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, true, 1, 1));
		label_5.setText(Messages.Note + ": ");
		
		stepMemoText = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
		stepMemoText.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		stepMemoText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		stepMemoText.setTextLimit(100);
		
		Composite table_composite = new Composite(container, SWT.NONE);
		table_composite.setBackground(SWTResourceManager.getColor(255, 255, 255));
		table_composite.addPaintListener(new RoundBorderLineListener(ColorConstants.BORDER_LINE_COLOR));
		GridData gd_table_composite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_table_composite.widthHint = 200;
		table_composite.setLayoutData(gd_table_composite);
		GridLayout gl_composite_table = new GridLayout(1, false);
		gl_composite_table.marginWidth = 1;
		gl_composite_table.marginBottom = 1;
		gl_composite_table.marginHeight = 1;
		gl_composite_table.verticalSpacing = 0;
		table_composite.setLayout(gl_composite_table);
		
		grid = new Grid(table_composite, SWT.H_SCROLL | SWT.V_SCROLL);
		grid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		gridColumn = new GridColumn(grid, SWT.CHECK);
		gridColumn.setText("New Column");
		gridColumn.setWidth(200);
		
		GridItem topGridItem = new GridItem(grid, SWT.NONE);
		topGridItem.setText(Messages.Factor_compliance);
		topGridItem.setImage(0, menuOpenImage);
		topGridItem.setExpanded(true);
		
		ESepator but_sep = new ESepator(topContainer, SWT.SEPARATOR | SWT.HORIZONTAL);
		but_sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		but_sep.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		Composite composite_1 = new Composite(topContainer, SWT.NONE);
		composite_1.setBackgroundMode(SWT.INHERIT_FORCE);
		composite_1.setBackgroundImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/fill_bg.png"));
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		GridLayout gl_composite_1 = new GridLayout(2, false);
		composite_1.setLayout(gl_composite_1);
		
		save_btn = new EButton(composite_1, SWT.NONE);
		save_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/save.png"));
		GridData gd_confirmBtn = new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1);
		gd_confirmBtn.widthHint = 90;
		save_btn.setLayoutData(gd_confirmBtn);
		save_btn.setText(Messages.Button_save);
		save_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				saveEvaluationStepAction();
			}
		});
		EButton cancel_btn = new EButton(composite_1, SWT.NONE);
		cancel_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/close.png"));
		cancel_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				cancelAction();
			}
		});
		GridData gd_button = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
		gd_button.widthHint = 90;
		cancel_btn.setLayoutData(gd_button);
		cancel_btn.setText(Messages.Button_close);

		init();
		return container;
	}

	/**
	 * @Description: 初始化
	 * @author guoyr
	 */
	private void init(){
		final String SUPPLIER_NAME = com.gx.obe.components.core.I18N.getString(I18NEnum.SUPPLIERNAME, tenderProjectEntity.getTenderType());
		expertService = new ExpertService();
		menuService = new MenuService();
		evaluationStepFactorService = new EvaluationStepFactorService();
		new EvaluationStepExpertService();
		if(null == evaluationStep){
			evaluationStep = new EvaluationStep();
			evaluationStep.setFilterType(EvaluationStepEnum.FILTER_YES);
			evaluationStep.setPassType(EvaluationStepEnum.PASS_ALL);
			evaluationStep.setRoleType(EvaluationStepEnum.EXPERT);
			evaluationStep.setStepStatus(CommonEnum.NOT_START);
			int maxSortNo = evaluationStepService.getMaxEvaluationStepSortNo(tenderProjectEntity.getId());
			evaluationStep.setSortNo(maxSortNo + 1);
			this.setTitle(MessageFormat.format(Messages.Title_create, Messages.Step_step));
		}else {
			this.setTitle(MessageFormat.format(Messages.Title_edit, Messages.Step_step));
			if(ObjectUtils.equals(evaluationStep.getStepStatus(), CommonEnum.COMPLETE)){
				save_btn.setEnabled(false);
				isInEvaluation = true;
			}else {
				isInEvaluation = evaluationStepService.isInEvaluationStep(tenderProjectEntity.getId(), evaluationStep.getId());
				if(isInEvaluation){
					for(Control control : roleTypeComposite.getChildren()){
						control.setEnabled(false);
					}
				}
			}
		}
		final ModifyListener filterListener = new ModifyListener() {
			public void modifyText(ModifyEvent arg0) {
				int value = ObjectUtils.getIntValue(filterPriceSortText.getText().trim(), 0);
				if(value < 1){
					filterPriceSortText.removeModifyListener(this);
					filterPriceSortText.setText("");
					filterPriceSortText.addModifyListener(this);
				}
				priceFilterTips.setText(MessageFormat.format(Messages.Tips_filterPriceSort, Messages.EvaluationPrice, (value > 0 ? value : "__"), SUPPLIER_NAME));
				composite.layout();
			}
		};
		filterPriceSortText.addModifyListener(filterListener);
		final ModifyListener deviateClauseListener = new ModifyListener() {
			public void modifyText(ModifyEvent arg0) {
				int value = ObjectUtils.getIntValue(deviateClauseCountText.getText().trim(), 0);
				if(value < 1){
					deviateClauseCountText.removeModifyListener(this);
					deviateClauseCountText.setText("");
					deviateClauseCountText.addModifyListener(this);
				}
				deviateClauseTips.setText(MessageFormat.format(Messages.Tips_filterDeviateclause, (value > 0 ? value : "__")));
				composite.layout();
			}
		};
		deviateClauseCountText.addModifyListener(deviateClauseListener);
		
		
//		WidgetUtils.setRadioChecked(evalTypeComposite, PropertiesUtils.getProperty(ConfigConstants.DEFAULT_EVALUATION_TYPE, EvaluationStepEnum.EVALUATION_TYPE_COLLECT));
		
		// 不显示评标步骤的类型
		WidgetUtils.setControlVisible(evalBidTypeLabel, false);
		WidgetUtils.setControlVisible(evalBidTypeComposite, false);
		
		gridColumn.setShowTreeTogglePic(true);
		grid.setAutoHeight(true);
		gridColumn.setWordWrap(true);
		gridColumn.setTreeTogglePic(ImageResolver.RESOLVER_INSTANCE.loadImage(IconsActivator.PLUGIN_ID,"icons/tree_expend.png"), ImageResolver.RESOLVER_INSTANCE.loadImage(IconsActivator.PLUGIN_ID,"icons/tree_close.png"));
		gridColumn.setTree(true);
		menuOpenImage = imageResolver.loadImage(IconsActivator.PLUGIN_ID,"icons/tree_parent.png");
		menuImage = imageResolver.loadImage(IconsActivator.PLUGIN_ID,"icons/tree_item.png");
		
		refreshFactorTree();
		// 添加选中监听事件
		grid.addListener(SWT.Selection, new GridCheckedListener(false));
		GridUtils.refreshGridCheckedStatus(grid, 0);
		grid.addListener(SWT.Selection, new Listener(){
			public void handleEvent(Event event) {
				// 选中了复选框事件
				if(event.detail == SWT.CHECK){
					checkFactorItemAction();
				}
			}
		});
		
		refreshEvaluationStepForm();
		
		Menu menu = menuService.getMenutByMenuCode(MenuEnum.EVALUATION_STEP_RULE);
		menuFunctionUtils.initFunctionAuthority(menu);
		
	}
	
	
	/**
	 * @Description: 刷新指标树
	 * @author guoyr
	 * @param factorId
	 */
	public void refreshFactorTree(){
		grid.removeAll();
		List<EvaluationFactor> evaluationFactorList = evaluationFactorService.getFactorListOfEvaluationStep(tenderProjectEntity.getId(), EvaluationFactorEnum.AUDIT_COMPLIANCE, evaluationStep.getId());
		if(null != evaluationFactorList && evaluationFactorList.size() > 0){
			
			if(StringUtils.isNotEmpty(evaluationStep.getId())){
 
				factorList = evaluationStepFactorService.getFactorIdLsitByStepId(evaluationStep.getId());
			}
			topGridItem = new GridItem(grid, SWT.NONE);
			topGridItem.setText(Messages.Factor_compliance);
			topGridItem.setImage(0, menuOpenImage);
			topGridItem.setExpanded(true);
			if(isInEvaluation){
//				topGridItem.setCheckVisible(0, false);
				topGridItem.setCheckable(0, false);
				topGridItem.setGrayed(0, true);
			}
			for(EvaluationFactor factor : evaluationFactorList){
				GridItem gridItem = new GridItem(topGridItem, SWT.NONE);
				gridItem.setText(0, factor.getFactorName());
				gridItem.setData("evaluationFactor", factor);
				if(isInEvaluation){
//					gridItem.setCheckVisible(0, false);
					gridItem.setCheckable(0, false);
					gridItem.setGrayed(0, true);
				}
//				gridItem.setCheckable(0, true);
				initChildGridItem(factor, gridItem);
			}
		}else {
			save_btn.setEnabled(false);
		}
		if(StringUtils.isNotEmpty(evaluationStep.getId())){
			GridUtils.refreshGridCheckedStatus(grid, 0);
			refreshEviateClause();
			
			hasNoCheckedFactor = false;
			getCheckedEvaluationFactorList(topGridItem.getItems());
			if(hasNoCheckedFactor) {
				tips.setText(tips.getText()+"当前步骤存在部分未选择的子级指标！");
				tips.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
			}
			
		}else {
			GridUtils.checkAll(grid, 0, true);
			checkFactorItemAction();
		}
	}
	
	/**
	 * @Description: 递归实现指标树
	 * @author guoyr
	 * @param factor
	 * @param parentGridItem
	 * @param selectId
	 */
	private void initChildGridItem(EvaluationFactor factor, GridItem parentGridItem){
		if(null != factor.getChildFactorList() && factor.getChildFactorList().size() > 0){
			for(EvaluationFactor childFactor : factor.getChildFactorList()){
				GridItem gridItem = new GridItem(parentGridItem, SWT.NONE);
				gridItem.setText(0, childFactor.getFactorName());
				gridItem.setData("evaluationFactor", childFactor);
				gridItem.setGrayed(0, true);
				gridItem.setCheckable(0, false);
				gridItem.setCheckVisible(0, false);
				
				initChildGridItem(childFactor, gridItem);
			}
			parentGridItem.setExpanded(true);
			parentGridItem.setImage(0, menuOpenImage);
		}else {
			parentGridItem.setImage(0, menuImage);
		}
//		parentGridItem.setCheckable(0, false);
//		parentGridItem.setGrayed(0, true);
		if(null != factorList && factorList.contains(factor.getId())){
			parentGridItem.setChecked(0, true);
		}
		parentGridItem.setToolTipText(0, parentGridItem.getText());
	}
	

	/**
	 * @Description: 刷新评标步骤表单
	 * @author guoyr
	 */
	private void refreshEvaluationStepForm(){
		
		stepNameText.setText(ObjectUtils.getObjString(evaluationStep.getStepName()));
		stepMemoText.setText(ObjectUtils.getObjString(evaluationStep.getStepMemo()));
		
		WidgetUtils.setRadioChecked(roleTypeComposite, ObjectUtils.getObjString(evaluationStep.getRoleType()), "roleType");
		WidgetUtils.setRadioChecked(passTypeComposite, ObjectUtils.getObjString(evaluationStep.getPassType()), "passType");
		
		Object indexIsBidNumber = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_INDEX_IS_BIDNUMBER);
		WidgetUtils.setRadioChecked(sortNoComposite, null != indexIsBidNumber && indexIsBidNumber.equals(CommonEnum.YES) ? CommonEnum.YES : CommonEnum.NO, "indexIsBidNumber");
//		WidgetUtils.setRadioChecked(evalTypeComposite, evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.EVALUATION_TYPE, String.class));
		
		int evalBidBusCount = 0;
		int evalBidTecCount = 0;
		int evalBidPriceCount = 0;
		if(null != evaluationStep.getEvalBidType() && evaluationStep.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_BUS)){
			evalBidBusCount ++;
		}else if(null != evaluationStep.getEvalBidType() && evaluationStep.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_TEC)){
			evalBidTecCount ++;
		}else if(null != evaluationStep.getEvalBidType() && evaluationStep.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_PRICE)){
			evalBidPriceCount ++;
		}else if(null != evaluationStep.getEvalBidType() && evaluationStep.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_DETAIL)){
			evalBidBusCount ++;
			evalBidTecCount ++;
		}
		if(evalBidBusCount > 0){
			evalBidBusBtn.setSelection(true);
		}
		if(evalBidTecCount > 0){
			evalBidTecBtn.setSelection(true);
		}
		if(evalBidPriceCount > 0){
			evalBidPriceBtn.setSelection(true);
		}
		refreshRoleType(evalBidBusCount, evalBidTecCount, evalBidPriceCount, false);
		if(StringUtils.isNotEmpty(evaluationStep.getId()) && ObjectUtils.equals(evaluationStep.getRoleType(), EvaluationStepEnum.CUSTOM)){
			stepExpertUserIdList = expertService.getEvaluationStepExpertList(tenderProjectEntity.getId(), evaluationStep);
//			if(null == stepExpertUserIdList){
//				stepExpertUserIdList = new ArrayList<Expert>();
//			}else {
//				stepExpertUserIdList.clear();
//			}
//			if(null != userIdsList){
//				for(Expert userId : userIdsList){
//					stepExpertUserIdList.add(userId);
//				}
//			}
		}
		
		boolean importExpertResult = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_IMPORT_OTHERE_EXPERT_RESULT, Boolean.class, false);
		if(importExpertResult){
			importTypeBtn.setSelection(true);
		}else {
			importTypeBtn.setSelection(false);
		}
		boolean importHistoryResult = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_IMPORT_HISTORY_RESULT, Boolean.class, false);
		if(importHistoryResult){
			importHistoryBtn.setSelection(true);
		}else {
			importHistoryBtn.setSelection(false);
		}
		boolean allowEditConclusion = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_ALLOW_EDIT_CONCLUSION, Boolean.class, false);
		if(allowEditConclusion){
			allowEditConclusionBtn.setSelection(true);
		}else {
			allowEditConclusionBtn.setSelection(false);
		}
		
		showAggregateBtn.setSelection("01".equals(evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.SHOW_SUMMARY_RESULT)));
		
		boolean sameScoreCheck = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.CHECK_SAME_EVALUATION, Boolean.class, true);
		sameScoreCheckBtn.setSelection(sameScoreCheck);
		boolean sameScoreFilter = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.CHECK_SAME_EVALUATION_FILTER, Boolean.class, true);
		sameScoreFilterBtn.setSelection(sameScoreFilter);
		
		int filterPriceSort = ObjectUtils.getIntValue(evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_FILTER_PRICE_SORT), 0);
		if(filterPriceSort > 0){
			filterPriceSortText.setText(filterPriceSort +"");
		}else {
			filterPriceSortText.setText("");
		}
		
//		boolean experSignature = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_EXPER_SIGNATURE, Boolean.class, false);
//		if(experSignature){
//			param_exper_signature.setSelection(true);
//		}else {
//			param_exper_signature.setSelection(false);
//		}
		boolean sealedBid = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_SEALED_BID, Boolean.class, false);
		if(sealedBid){
			param_sealed_bid.setSelection(true);
		}else {
			param_sealed_bid.setSelection(false);
		}
		boolean orderbySealedBidCode = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_ORDERBY_SEALED_BID_CODE, Boolean.class, false);
		if(orderbySealedBidCode){
			param_orderby_sealed_bid_code.setSelection(true);
		}else {
			param_orderby_sealed_bid_code.setSelection(false);
		}
		checkSealedBidAction();
		Integer unqualifiedDeviateClauseCountObj = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.UNQUALIFIED_DEVIATE_CLAUSE_COUNT, Integer.class, 1);
		if(null != deviateClauseCountText && null != unqualifiedDeviateClauseCountObj){
			deviateClauseCountText.setText(unqualifiedDeviateClauseCountObj.toString());
		}

//		BigDecimal floatingEvaluationPricePercent = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.FLOATING_EVALUATION_PRICE_PERCENT, BigDecimal.class);
//		if (null != floatingEvaluationPricePercent && floatingEvaluationPricePercent.compareTo(BigDecimal.ZERO) != 0) {
//			floatingPercentText.setText(floatingEvaluationPricePercent.toString());
//		}
		
		selectRoleTypeAction(evaluationStep.getRoleType());
	}
	
	private void checkFactorItemAction(){
		List<EvaluationFactor> checkedTopFactorList = new ArrayList<EvaluationFactor>();
		for(GridItem topItem : topGridItem.getItems()){
			if(topItem.getCheckVisible(0) && topItem.getChecked(0)){
				EvaluationFactor topFactor = (EvaluationFactor)topItem.getData("evaluationFactor");
				checkedTopFactorList.add(topFactor);
			}
		}
		int evalBidBusCount = 0;
		int evalBidTecCount = 0;
		int evalBidPriceCount = 0;
		if(checkedTopFactorList.size() > 0){
			
			if(stepNameText.getText().length() == 0){
				
				if(checkedTopFactorList.size() == 1){
					String firstFactorName = checkedTopFactorList.get(0).getFactorName();
					stepNameText.setText(firstFactorName.length() > 9 ? firstFactorName.substring(0,9):firstFactorName);
				}else {
					stepNameText.setText(com.gx.obe.components.core.I18N.getString(I18NEnum.COMPLIANCE_EVALUATION));
				}
				
			}
			for(EvaluationFactor topFactor : checkedTopFactorList){
				if(null != topFactor.getEvalBidType() && topFactor.getEvalBidType().length() > 0){
					if(topFactor.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_DETAIL)){
						evalBidBusCount ++;
						evalBidTecCount ++;
					}else if(topFactor.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_BUS)){
						evalBidBusCount ++;
					}else if(topFactor.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_TEC)){
						evalBidTecCount ++;
					}else if(topFactor.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_PRICE)){
						evalBidPriceCount ++;
					}
				}
			}
		}
		evalBidBusBtn.setSelection(evalBidBusCount > 0);
		evalBidTecBtn.setSelection(evalBidTecCount > 0);
		evalBidPriceBtn.setSelection(evalBidPriceCount > 0);
		refreshRoleType(evalBidBusCount, evalBidTecCount, evalBidPriceCount, true);
		refreshEviateClause();
		
		refreshEvalType();
	}
	
	private void refreshRoleType(int evalBidBusCount, int evalBidTecCount, int evalBidPriceCount, boolean setEnable){
		if(evalBidBusCount + evalBidTecCount + evalBidPriceCount > 0){
			if(setEnable){
				expertRoleNameBtn.setEnabled(true);
			}
			if(null == evaluationStep.getId() || "".equals(ObjectUtils.getObjString(WidgetUtils.getRadioVal(roleTypeComposite,"roleType")))){
				evaluationStep.setRoleType(EvaluationStepEnum.EVAL_BID_TYPE);
				WidgetUtils.setRadioChecked(roleTypeComposite, EvaluationStepEnum.EVAL_BID_TYPE, "roleType");
			}
			StringBuilder expertTypeName = new StringBuilder();
			if(evalBidBusCount > 0 || evalBidPriceCount > 0){
				expertTypeName.append(Messages.Business);
			}
			if(evalBidTecCount > 0){
				if(expertTypeName.length() > 0){
					expertTypeName.append("、");
				}
				expertTypeName.append(Messages.Concat).append(Messages.Technology);
			}
			expertTypeName.append(Messages.Expert);
			expertRoleNameBtn.setText(expertTypeName.toString());
		}else {
			Messages.BusinessTechnology.concat(Messages.Concat).concat(Messages.Expert);
			if(setEnable){
				expertRoleNameBtn.setEnabled(false);
			}
			expertRoleNameBtn.setSelection(false);
		}
		roleTypeComposite.layout();
	}
	
	/**
	 * @Description: 刷新偏移评审配置
	 * @author guoyr 
	 */
	private void refreshEviateClause(){
		boolean existDeviateClause = false;
		for(GridItem topItem : grid.getItems()){
			if(topItem.getChecked(0) && topItem.getItemCount() == 0){
				EvaluationFactor evaluationFactor = (EvaluationFactor)topItem.getData("evaluationFactor");
				if(EvaluationFactorEnum.CLAUSE_TYPE_DEVIATE.equals(evaluationFactor.getClauseType())){
					existDeviateClause = true;
					break;
				}
			}
		}
		WidgetUtils.setControlVisible(deviateClauseComposite, existDeviateClause);
		WidgetUtils.setControlVisible(deviateClauseLabel, existDeviateClause);
		composite.layout();
	}
	
	/**
	 * @Description: 刷新偏移评审配置
	 * @author guoyr 
	 */
	private void refreshEvalType(){
		boolean existAIFactor = false;
		for(GridItem topItem : grid.getItems()){
			if(topItem.getChecked(0) && topItem.getItemCount() == 0){
				EvaluationFactor evaluationFactor = (EvaluationFactor)topItem.getData("evaluationFactor");
				if(EvaluationFactorEnum.SCORE_TYPE_AI.equals(evaluationFactor.getScoreType())){
					existAIFactor = true;
					break;
				}
			}
		}
		if(existAIFactor){
//			WidgetUtils.setRadioChecked(evalTypeComposite, EvaluationStepEnum.EVALUATION_TYPE_AI);
		}
	}
	
	private List<EvaluationFactor> getCheckedEvaluationFactorList(GridItem[] gridItems){
		List<EvaluationFactor> checkedValuesList = new ArrayList<EvaluationFactor>();
		if(null != gridItems) {
			for(GridItem item : gridItems){
				if(item.getChecked(0)) {
					EvaluationFactor evaluationFactor = (EvaluationFactor)item.getData("evaluationFactor");
					EvaluationFactor checkFactor = new EvaluationFactor();
					checkFactor.setId(evaluationFactor.getId());
					checkFactor.setFactorName(evaluationFactor.getFactorName());
					checkFactor.setTenderId(evaluationFactor.getTenderId());
					checkedValuesList.add(checkFactor);
					
					if(item.getItemCount() > 0) {
						List<EvaluationFactor> subCheckedValuesList = getCheckedEvaluationFactorList(item.getItems());
						if(null != subCheckedValuesList && subCheckedValuesList.size() > 0) {
							checkedValuesList.addAll(subCheckedValuesList);
							for(GridItem subItem : item.getItems()) {
								if(!subItem.getChecked(0)) {
									hasNoCheckedFactor = true; 
									if(!isInEvaluation){
										subItem.setCheckable(0, true);
									}
									subItem.setCheckVisible(0, true);
									subItem.setForeground(0, SWTResourceManager.getColor(SWT.COLOR_RED));
								}
							}
						}
					}
				}
				
			}
		}
		return checkedValuesList;
	}
	
	/**
	 * @Description: 确定
	 * @author guoyr
	 */
	private void saveEvaluationStepAction(){
		if(save_btn.getEnabled()){
			if(!ValidateUtils.checkInput(stepNameText.getParent())){
				return;
			}
			
			evaluationStep.setStepName(stepNameText.getText().trim());
			evaluationStep.setStepType(EvaluationStepEnum.COMPLIANCE);//符合性评审
			evaluationStep.setStepMemo(stepMemoText.getText().trim());
			evaluationStep.setTenderId(tenderProjectEntity.getId());
			evaluationStep.setRoleType(ObjectUtils.getObjString(WidgetUtils.getRadioVal(roleTypeComposite,"roleType")));
			
			Object indexIsBidNumber = ObjectUtils.getObjString(WidgetUtils.getRadioVal(sortNoComposite,"indexIsBidNumber"));
			evaluationStep.setEvaluationParam(EvaluationStepEnum.PARAM_INDEX_IS_BIDNUMBER, null != indexIsBidNumber && indexIsBidNumber.equals(CommonEnum.YES) ? CommonEnum.YES : CommonEnum.NO);
			evaluationStep.setPassType(ObjectUtils.getObjString(WidgetUtils.getRadioVal(passTypeComposite,"passType")));
			evaluationStep.setEvaluationParam(EvaluationStepEnum.PARAM_IMPORT_OTHERE_EXPERT_RESULT, importTypeBtn.getSelection());
			evaluationStep.setEvaluationParam(EvaluationStepEnum.PARAM_IMPORT_HISTORY_RESULT, importHistoryBtn.getSelection());
			evaluationStep.setEvaluationParam(EvaluationStepEnum.PARAM_ALLOW_EDIT_CONCLUSION, allowEditConclusionBtn.getSelection());
			evaluationStep.setEvaluationParam(EvaluationStepEnum.CHECK_SAME_EVALUATION, sameScoreCheckBtn.getSelection());
			evaluationStep.setEvaluationParam(EvaluationStepEnum.CHECK_SAME_EVALUATION_FILTER, sameScoreFilterBtn.getSelection());
//			evaluationStep.setEvaluationParam(EvaluationStepEnum.PARAM_EXPER_SIGNATURE, param_exper_signature.getSelection());
			evaluationStep.setEvaluationParam(EvaluationStepEnum.PARAM_SEALED_BID, param_sealed_bid.getSelection());
			evaluationStep.setEvaluationParam(EvaluationStepEnum.PARAM_ORDERBY_SEALED_BID_CODE, param_orderby_sealed_bid_code.getSelection());
//			int PARAM_SEALED_BID_FILE_ROLE = 0;
//			if(param_sealed_bid.getSelection()){
//				for(Control button : sealedBidFileTypeComposite.getChildren()){
//					if(button instanceof Button){
//						if(null != button.getData("evalBidType")){
//							if(((Button)button).getSelection()){
//								try {
//									int evalBidType = Integer.parseInt(button.getData("evalBidType").toString());
//									PARAM_SEALED_BID_FILE_ROLE = PARAM_SEALED_BID_FILE_ROLE | evalBidType;
//								} catch (NumberFormatException e) {
//								}
//							}
//						}
//					}
//				}
//			}
//			evaluationStep.setEvaluationParam(EvaluationStepEnum.PARAM_SEALED_BID_FILE_ROLE, PARAM_SEALED_BID_FILE_ROLE);
//			evaluationStep.setEvaluationParam(EvaluationStepEnum.EVALUATION_TYPE, ObjectUtils.getObjString(WidgetUtils.getRadioVal(evalTypeComposite)));
			
			if((evalBidBusBtn.getSelection() && evalBidTecBtn.getSelection())){
				evaluationStep.setEvalBidType(EvaluationFactorEnum.EVAL_BID_DETAIL);
			}else if(evalBidBusBtn.getSelection()){
				evaluationStep.setEvalBidType(EvaluationFactorEnum.EVAL_BID_BUS);
			}else if(evalBidTecBtn.getSelection()){
				evaluationStep.setEvalBidType(EvaluationFactorEnum.EVAL_BID_TEC);
			}else if(evalBidPriceBtn.getSelection()){
				evaluationStep.setEvalBidType(EvaluationFactorEnum.EVAL_BID_PRICE);
			}
			
			if(deviateClauseComposite.getVisible()){
				if(!ValidateUtils.checkInput(deviateClauseComposite)){
					return;
				}
				evaluationStep.setEvaluationParam(EvaluationStepEnum.UNQUALIFIED_DEVIATE_CLAUSE_COUNT, ObjectUtils.getIntValue(deviateClauseCountText.getText(), 1));
//				evaluationStep.setEvaluationParam(EvaluationStepEnum.FLOATING_EVALUATION_PRICE_PERCENT, ObjectUtils.getObjBigDecimal(floatingPercentText.getText()));
			}else {
				evaluationStep.setEvaluationParam(EvaluationStepEnum.UNQUALIFIED_DEVIATE_CLAUSE_COUNT, 1);
			}
			
			evaluationStep.setEvaluationParam(EvaluationStepEnum.PARAM_FILTER_PRICE_SORT, ObjectUtils.getIntValue(filterPriceSortText.getText().trim(), 0));
			
			if(isInEvaluation){
				evaluationStepService.updateAssignProperty(evaluationStep, new String[]{"stepName", "importType", "darkEvaluation", "stepMemo", "roleType", "evalBidType", "params"});
				if(null != callBack){
					callBack.callBackObject(evaluationStep);
				}
				this.getShell().close();
				return;
			}
			
			// 如果选择的是自定义专家类型
			if(ObjectUtils.equals(evaluationStep.getRoleType(), EvaluationStepEnum.CUSTOM) && (null == stepExpertUserIdList || stepExpertUserIdList.size() == 0)){
				MessageDialog.openWarning(getShell(), Messages.Tips_SelcetExpert);
				return;
			}
			
			hasNoCheckedFactor = false;
			List<EvaluationFactor> checkedEvaluationFactorList = getCheckedEvaluationFactorList(topGridItem.getItems());//GridUtils.getRealCheckedValues(grid, 0, "evaluationFactor");
			if(hasNoCheckedFactor) {
				MessageDialog.openWarning(getShell(), "当前步骤存在部分未选择的子级指标！");
				return;
			}
			if(null == checkedEvaluationFactorList || checkedEvaluationFactorList.size() == 0){
				MessageDialog.openWarning(getShell(), Messages.Tips_select+stepNameText.getText().trim()+"的评审指标！");
				return;
			}
			
			if(null == evaluationStep.getRoleType() || evaluationStep.getRoleType().length() == 0){
				MessageDialog.openWarning(getShell(), "请选择评标专家！");
				return;
			}
			
			// 验证评标步骤名称是否已经存在
			if(evaluationStepService.valEvaluationStepNameExist(tenderProjectEntity.getId(), evaluationStep.getId(), stepNameText.getText().trim())){
				MessageDialog.openWarning(getShell(), Messages.Step_step +"["+stepNameText.getText().trim()+"]" + Messages.Tips_AlreadyExistsPleaseRetype);
				stepNameText.setFocus();
				stepNameText.setSelection(stepNameText.getText().length());
				return;
			}
			evaluationStep.setEvaluationParam(EvaluationStepEnum.SHOW_SUMMARY_RESULT, showAggregateBtn.getSelection() ? "01" : "00");
			List<String> expertIdList = new ArrayList<String>();
			if (CollectionUtils.isNotNull(stepExpertUserIdList)){
				for(Expert expert : stepExpertUserIdList){
					expertIdList.add(expert.getUserId());
				}
			} 
			EvaluationStep evalStep = evaluationStepService.saveEvaluationStepAndFactors(evaluationStep, checkedEvaluationFactorList, null, expertIdList);
			if(null != evalStep && null != callBack){
				if(null != callBack){
					callBack.callBackObject(evalStep);
				}
				this.getShell().close();
			}else {
				MessageDialog.openWarning(getShell(), stepNameText.getText()+Messages.Tips_saveFail);
			}
		}
	}
	
	/**
	 * @Description: 取消
	 * @author guoyr
	 */
	private void cancelAction(){
		this.getShell().close();
	}

	/**
	 * @Description: 选择评审成员类型
	 * @author guoyr
	 * @param roleType
	 */
	private void selectRoleTypeAction(String roleType){
		// 如果选择的是自定义专家类型
		if(ObjectUtils.equals(roleType, EvaluationStepEnum.CUSTOM)){
			StringBuilder memberName = new StringBuilder("");
 			if(null != stepExpertUserIdList && stepExpertUserIdList.size() > 0){
				int memberCount = 0;
				for(Expert expert : stepExpertUserIdList){
					if(null != expert && null != expert.getUser()){
						if(memberCount > 0){
							memberName.append("；");
						}
						memberName.append(ObjectUtils.getObjString(expert.getUser().getUserName()));
						memberCount ++;
					}
				}
			}
		
			expertNamesLabel.setText(memberName.toString());
			customComposite.layout();
			((GridData)customExpertLabel.getLayoutData()).exclude = false;
			customExpertLabel.setVisible(true);
			((GridData)customComposite.getLayoutData()).exclude = false;
			customComposite.setVisible(true);
//			((GridData)customComposite.getLayoutData()).heightHint = customComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
		}else {
			((GridData)customComposite.getLayoutData()).exclude = true;
			customComposite.setVisible(false);
			((GridData)customExpertLabel.getLayoutData()).exclude = true;
			customExpertLabel.setVisible(false);
//			((GridData)customComposite.getLayoutData()).heightHint = 0;
		}
		composite.layout();
	}
	
	 
	
	/**
	 * @Description: 选择自定义专家
	 * @author guoyr
	 */
	private void selectStepExpert(){
		SelectStepExpertDialog dialog = new SelectStepExpertDialog(getShell(), tenderProjectEntity.getId(), stepExpertUserIdList, new SelectExpertListener(){
			public void setExpertList(List<Expert> expertList){
				if(null != expertList){
					stepExpertUserIdList = expertList;
					selectRoleTypeAction(EvaluationStepEnum.CUSTOM);
				}
			}
			
		});
		dialog.open();
	}
	
	/**
	 * @Description: 设置暗标文件类型
	 * @author guoyr 
	 */
	private void checkSealedBidAction(){
		if(param_sealed_bid.getSelection()){
			WidgetUtils.setControlVisible(param_orderby_sealed_bid_code, true);
		}else {
			param_sealed_bid.setSelection(false);
			WidgetUtils.setControlVisible(param_orderby_sealed_bid_code, false);
			param_orderby_sealed_bid_code.setSelection(false);
		}
		composite.layout();
	}
	
	public CallBack getCallBack() {
		return callBack;
	}

	public void setCallBack(CallBack callBack) {
		this.callBack = callBack;
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(800, 600);
	}
}
