package com.gx.obe.management.composite;

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.GridSelectionListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.core.ImageResolver;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.BigButton;
import org.eclipse.swt.core.widgets.ELink;
import org.eclipse.swt.core.widgets.EMenu;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.gx.obe.ColorConstants;
import com.gx.obe.action.bean.Action;
import com.gx.obe.business.entity.MenuFunction;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.common.widget.thread.SyncThread;
import com.gx.obe.common.widget.utils.MenuFunctionUtils;
import com.gx.obe.components.core.Constants;
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.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.tender.TenderProjectEntity;
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.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

/**
 * @Description:
 * @author guoyr
 */
public class ComplianceFactorsComposite extends Composite {

	private BigButton save_btn;
	private Grid factors_grid;
	private GridColumn gridColumn;
	private Text factor_name_text;
	private Text factor_memo_text;
	private ELink add_btn;
	private ELink add_sub_btn;
	private ELink del_btn;
	private ImageResolver imageResolver = new ImageResolver();
	private Image menuOpenImage;
	private Image menuImage;
	private Composite kgxParentComposite;
	private EvaluationFactor curFactor;
//	private TenderProjectEntity tenderProjectEntity;
	private TenderProjectEntity tenderProject;
	private ScrolledComposite scrolledComposite;
	private Composite scroContentComposite;
	private Composite composite_1;
	private Composite composite_3;
	private ELink download_btn;
	private ELink up_btn;
	private Label label_4;
	
	private boolean isExistEvaluationStep = false;
	private Label label_6;
	private Label label_8;
	private Text compliance_content_text;
	private Composite composite_4;
//	private EvaluationFactorService evaluationFactorService = new EvaluationFactorService();
 	private Composite composite_6;
	private Composite composite_7;
	private Composite composite_8;
	private Label evalBidTypeTitle;
	private Combo evalBidTypeCombo;
	private Composite factorComposite;
	private Label clauseTypeLabel;
	private Composite clauseTypeComposite;
	private Label clauseTypeDescLabel;
	private Menu menu;
	private TenderProjectService tenderProjectService ;
	private EvaluationFactorService evaluationFactorService;
	private EvaluationStepService evaluationStepService;
	private Action projectAction;
	
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();
	{
		LogUtils.logClass(ComplianceFactorsComposite.class);
	}

	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public ComplianceFactorsComposite(Composite parent, Action projectAction, int style) {
		super(parent, style);
		GridLayout gridLayout = new GridLayout(2, false);
		gridLayout.verticalSpacing = 0;
		gridLayout.horizontalSpacing = 10;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				imageResolver.disposite();
			}
		});
		this.projectAction = projectAction;

		composite_1 = new Composite(this, SWT.NONE);
		GridData gd_composite_1 = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
		gd_composite_1.widthHint = 300;
		composite_1.setLayoutData(gd_composite_1);
		GridLayout gl_composite_1 = new GridLayout(1, false);
		gl_composite_1.verticalSpacing = 0;
		gl_composite_1.marginHeight = 0;
		gl_composite_1.marginWidth = 0;
		composite_1.setLayout(gl_composite_1);

		composite_8 = new Composite(composite_1, SWT.NONE);
		composite_8.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_composite_8 = new GridLayout(1, false);
		gl_composite_8.verticalSpacing = 1;
		gl_composite_8.marginHeight = 1;
		gl_composite_8.marginWidth = 1;
		composite_8.setLayout(gl_composite_8);
		composite_8.setBackground(ColorConstants.BORDER_LINE_COLOR);

		composite_3 = new Composite(composite_8, SWT.NONE);
		composite_3.setBackgroundMode(SWT.INHERIT_FORCE);
		composite_3.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		composite_3.setLayout(new GridLayout(5, false));

		up_btn = new ELink(composite_3, SWT.NONE);
		up_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
		up_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/up.png"));
		up_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				moveFactorAction(-1);
			}
		});
		up_btn.setText(Messages.Button_moveUp);

		download_btn = new ELink(composite_3, SWT.NONE);
		download_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		download_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/down.png"));
		download_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				moveFactorAction(1);
			}
		});
		download_btn.setText(Messages.Button_moveDown);

		add_btn = new ELink(composite_3, SWT.NONE);
		add_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/add.png"));
		add_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				addFctorAction();
			}
		});
		add_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		add_btn.setText(Messages.Button_add);
		add_btn.setToolTipText(Messages.Button_addSibling);
		menuFunctionUtils.addFunction(add_btn, "ADD");

		add_sub_btn = new ELink(composite_3, SWT.NONE);
		add_sub_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/add_sub.png"));
		add_sub_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				addSubFctorAction();
			}
		});
		add_sub_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		add_sub_btn.setText(Messages.Button_add);
		add_sub_btn.setToolTipText(Messages.Button_addChildSibling);
		menuFunctionUtils.addFunction(add_sub_btn, "ADD_SUB");

		del_btn = new ELink(composite_3, SWT.NONE);
		del_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/delete.png"));
		del_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				delFactorAction();
			}
		});
		del_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		del_btn.setText(Messages.Button_delete);
		menuFunctionUtils.addFunction(del_btn, "DELETE");

		composite_7 = new Composite(composite_8, SWT.NONE);
		composite_7.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_7.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_composite_7 = new GridLayout(1, false);
		gl_composite_7.marginHeight = 0;
		gl_composite_7.marginWidth = 0;
		composite_7.setLayout(gl_composite_7);

		factors_grid = new Grid(composite_7, SWT.V_SCROLL);
		factors_grid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

		gridColumn = new GridColumn(factors_grid, SWT.NONE);
		gridColumn.setText(Messages.Factor_compliance);
		gridColumn.setWidth(200);

		Composite composite = new Composite(this, SWT.NONE);
		GridLayout gl_composite = new GridLayout(1, false);
		gl_composite.verticalSpacing = 0;
		gl_composite.marginHeight = 0;
		gl_composite.marginWidth = 0;
		composite.setLayout(gl_composite);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

		scrolledComposite = new ScrolledComposite(composite, SWT.V_SCROLL);
		scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);

		scroContentComposite = new Composite(scrolledComposite, SWT.NONE);
		GridLayout gl_scroContentComposite = new GridLayout(1, false);
		gl_scroContentComposite.verticalSpacing = 0;
		gl_scroContentComposite.marginHeight = 0;
		gl_scroContentComposite.marginWidth = 0;
		scroContentComposite.setLayout(gl_scroContentComposite);

		factorComposite = new Composite(scroContentComposite, SWT.NONE);
		GridData gc_factorComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gc_factorComposite.heightHint = 200;
		gc_factorComposite.widthHint = 300;
		factorComposite.setLayoutData(gc_factorComposite);
		GridLayout gl_composite_5 = new GridLayout(2, false);
		gl_composite_5.marginWidth = 10;
		gl_composite_5.verticalSpacing = 20;
		gl_composite_5.marginTop = 5;
		factorComposite.setLayout(gl_composite_5);

		Label label = new Label(factorComposite, SWT.NONE);
		label.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText(Messages.FactorName + "：");

		composite_6 = new Composite(factorComposite, SWT.NONE);
		composite_6.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		GridLayout gl_composite_6 = new GridLayout(1, false);
		gl_composite_6.verticalSpacing = 0;
		gl_composite_6.horizontalSpacing = 0;
		gl_composite_6.marginHeight = 0;
		gl_composite_6.marginWidth = 0;
		composite_6.setLayout(gl_composite_6);

		factor_name_text = new Text(composite_6, SWT.WRAP | SWT.MULTI);
		factor_name_text.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		factor_name_text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		factor_name_text.setTextLimit(500);

		ESepator label_sep2 = new ESepator(composite_6, SWT.HORIZONTAL);
		label_sep2.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		label_sep2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

		clauseTypeLabel = new Label(factorComposite, SWT.NONE);
		clauseTypeLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		clauseTypeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		clauseTypeLabel.setText(Messages.ClauseType +"：");

		clauseTypeComposite = new Composite(factorComposite, SWT.NONE);
		GridData gd_clauseTypeComposite = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
		gd_clauseTypeComposite.widthHint = 300;
		clauseTypeComposite.setLayoutData(gd_clauseTypeComposite);
		GridLayout gl_clauseTypeComposite = new GridLayout(2, false);
		gl_clauseTypeComposite.verticalSpacing = 0;
		gl_clauseTypeComposite.horizontalSpacing = 0;
		gl_clauseTypeComposite.marginHeight = 0;
		gl_clauseTypeComposite.marginWidth = 0;
		clauseTypeComposite.setLayout(gl_clauseTypeComposite);

		Button clauseTypeStar = new Button(clauseTypeComposite, SWT.RADIO);
		clauseTypeStar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				changeClauseType(EvaluationFactorEnum.CLAUSE_TYPE_STAR);
			}
		});
		clauseTypeStar.setData(EvaluationFactorEnum.CLAUSE_TYPE_STAR);
		clauseTypeStar.setText(Messages.ClauseTypeStar);
		clauseTypeStar.setSelection(true);

		clauseTypeDescLabel = new Label(clauseTypeComposite, SWT.WRAP);
		clauseTypeDescLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		clauseTypeDescLabel.setText(Messages.ClauseTypeStar +"："+Messages.Tips_clauseTypeStar);
		clauseTypeDescLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
		clauseTypeDescLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NONE));

		Button clauseTypeDeviate = new Button(clauseTypeComposite, SWT.RADIO);
		clauseTypeDeviate.setData(EvaluationFactorEnum.CLAUSE_TYPE_DEVIATE);
		clauseTypeDeviate.setText(Messages.ClauseTypeDeviate);
		clauseTypeDeviate.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				changeClauseType(EvaluationFactorEnum.CLAUSE_TYPE_DEVIATE);
			}
		});

		Label clauseTypeDeviateLabel = new Label(clauseTypeComposite, SWT.WRAP);
		clauseTypeDeviateLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		clauseTypeDeviateLabel.setText(Messages.ClauseTypeDeviate+"："+ Messages.Tips_clauseTypeDeviate);
		clauseTypeDeviateLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
		clauseTypeDeviateLabel.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NONE));

		label_8 = new Label(factorComposite, SWT.NONE);
		label_8.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_8.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_8.setText(Messages.EvalOptions+"：");

		composite_4 = new Composite(factorComposite, SWT.NONE);
		composite_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		GridLayout gl_composite_4 = new GridLayout(2, false);
		gl_composite_4.verticalSpacing = 0;
		gl_composite_4.horizontalSpacing = 5;
		gl_composite_4.marginHeight = 0;
		gl_composite_4.marginWidth = 0;
		composite_4.setLayout(gl_composite_4);

		compliance_content_text = new Text(composite_4, SWT.NONE);
		GridData gd_evalContentText = new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1);
		gd_evalContentText.widthHint = 100;
		compliance_content_text.setLayoutData(gd_evalContentText);
		compliance_content_text.setTextLimit(10);

		Label label_2 = new Label(composite_4, SWT.WRAP);
		label_2.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 2));
		label_2.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		label_2.setText(Messages.Tips_evalOptionsEg);

		ESepator label_sep7 = new ESepator(composite_4, SWT.HORIZONTAL);
		label_sep7.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		label_sep7.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

		evalBidTypeTitle = new Label(factorComposite, SWT.NONE);
		evalBidTypeTitle.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		evalBidTypeTitle.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		evalBidTypeTitle.setText(Messages.EvalType+"：");

		evalBidTypeCombo = new Combo(factorComposite, SWT.READ_ONLY);
		GridData gd_combo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_combo.widthHint = 100;
		evalBidTypeCombo.setLayoutData(gd_combo);

		label_6 = new Label(factorComposite, SWT.NONE);
		label_6.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_6.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_6.setText(Messages.ConsistencyCheck+"：");

		kgxParentComposite = new Composite(factorComposite, SWT.NONE);
		kgxParentComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_kgxParentComposite = new GridLayout(3, false);
		gl_kgxParentComposite.marginHeight = 0;
		kgxParentComposite.setLayout(gl_kgxParentComposite);

		Button button_1 = new Button(kgxParentComposite, SWT.RADIO);
		button_1.setData(EvaluationFactorEnum.OBJECTIVE_YES);
		button_1.setText(Messages.Yes);
		button_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				changeObjective(EvaluationFactorEnum.OBJECTIVE_YES);
			}
		});

		Button button_2 = new Button(kgxParentComposite, SWT.RADIO);
		button_2.setData(EvaluationFactorEnum.OBJECTIVE_NO);
		button_2.setSelection(true);
		button_2.setText(Messages.No);
		button_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				changeObjective(EvaluationFactorEnum.OBJECTIVE_NO);
			}
		});

		label_4 = new Label(kgxParentComposite, SWT.WRAP);
		label_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		label_4.setText(Messages.Tips_consistencyCheck);
		label_4.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
		label_4.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NONE));

		Label label_1 = new Label(factorComposite, SWT.NONE);
		label_1.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_1.setText(Messages.EvalExplain + "：");

		factor_memo_text = new Text(factorComposite, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
		GridData gd_factorMemoText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_factorMemoText.widthHint = 200;
		gd_factorMemoText.heightHint = 100;
		factor_memo_text.setLayoutData(gd_factorMemoText);
		factor_memo_text.setTextLimit(1000);

		Composite composite_2 = new Composite(composite, SWT.NONE);
		composite_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		GridLayout gl_composite_2 = new GridLayout(1, false);
		composite_2.setLayout(gl_composite_2);
		
		save_btn = new BigButton(composite_2, SWT.NONE);
		save_btn.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				saveEvaluationFactorAction();
			}
		});
		save_btn.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		save_btn.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true, 1, 1));
		save_btn.setText(Messages.Button_save);
		menuFunctionUtils.addFunction(composite_2, "SAVE" +	"");
		scrolledComposite.setContent(scroContentComposite);
		scrolledComposite.setMinSize(scroContentComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		tenderProjectService = new TenderProjectService();
		evaluationFactorService = new EvaluationFactorService();
		init();
	}

	/**
	 * @Description: 初始化
	 * @author guoyr
	 */
	private void init() {
		this.tenderProject = projectAction.getTenderProject();
		this.menu = projectAction.getMenu();
		
		factors_grid.setItemHeight(Constants.ROW_HIGHT);
		factors_grid.setLinesVisible(false);
		gridColumn.setShowTreeTogglePic(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");

		evalBidTypeCombo.add(EvaluationFactorEnum.getEvalBidTypeCN(EvaluationFactorEnum.EVAL_BID_DETAIL), 0);
		evalBidTypeCombo.setData("0", EvaluationFactorEnum.EVAL_BID_DETAIL);
		evalBidTypeCombo.add(EvaluationFactorEnum.getEvalBidTypeCN(EvaluationFactorEnum.EVAL_BID_BUS), 1);
		evalBidTypeCombo.setData("1", EvaluationFactorEnum.EVAL_BID_BUS);
		evalBidTypeCombo.add(EvaluationFactorEnum.getEvalBidTypeCN(EvaluationFactorEnum.EVAL_BID_TEC), 2);
		evalBidTypeCombo.setData("2", EvaluationFactorEnum.EVAL_BID_TEC);
		evalBidTypeCombo.add(EvaluationFactorEnum.getEvalBidTypeCN(EvaluationFactorEnum.EVAL_BID_PRICE), 3);
		evalBidTypeCombo.setData("3", EvaluationFactorEnum.EVAL_BID_PRICE);
		new SyncThread("获取项目进度", new SyncThread.Runnable() {
			public void run(){
				if (tenderProjectService.isInProgress(tenderProject.getId(), EvaluationStepEnum.COMPLIANCE)) {
					Display.getDefault().syncExec(new Runnable(){
						public void run(){
							if(evalBidTypeCombo.isDisposed()){
								return ;
							}
							evalBidTypeCombo.setEnabled(false);
						} 
					});
				}
			}
		}).start();
		

		refreshFactorTree(null);
		// 添选中事件和右键菜单事件
		factors_grid.addListener(SWT.Selection, new GridSelectionListener() {
			@Override
			public void leftMouseButtonDown(GridItem item) {
				selectionFactorAction();
			}

			@Override
			public void rightMouseButtonDown(GridItem item) {
				mouseRightClickAction();
			}
		});
		
		if (TenderProjectEnum.REMOTE.equals(tenderProject.getRemoteStatus())) {
//			WidgetUtils.setControlVisible(add_btn, false);
//			WidgetUtils.setControlVisible(add_sub_btn, false);
//			WidgetUtils.setControlVisible(del_btn, false);
		}else if (TenderProjectEnum.LOCAL.equals(tenderProject.getRemoteStatus())) {
			WidgetUtils.setControlVisible(add_btn, true);
			WidgetUtils.setControlVisible(add_sub_btn, true);
			WidgetUtils.setControlVisible(del_btn, true);
		}
		menuFunctionUtils.initFunctionAuthority(menu);
	}

	/**
	 * @Description: 刷新指标树
	 * @author guoyr
	 * @param factorId
	 */
	public void refreshFactorTree(final String factorId) {
		factors_grid.removeAll();
		new SyncThread("加载符合性指标", new SyncThread.Runnable() {
			public void run(){
				final List<EvaluationFactor> evaluationFactorList = evaluationFactorService.getAllEvaluationFactorList(tenderProject.getId(), EvaluationFactorEnum.AUDIT_COMPLIANCE);
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(factors_grid.isDisposed())return;
						if (null != evaluationFactorList && evaluationFactorList.size() > 0) {
							for (EvaluationFactor factor : evaluationFactorList) {
								GridItem gridItem = new GridItem(factors_grid, SWT.NONE);
								initChildGridItem(factor, gridItem, factorId);
							}
						}
						if(factors_grid.isDisposed())return;
						if (factors_grid.getSelectionCount() == 0) {
							if (factors_grid.getItemCount() > 0) {
								factors_grid.select(0);
							}
						}
						selectionFactorAction();
						Rectangle rectangle = factors_grid.getBounds();
						factors_grid.scroll(0, 0, 0, 0, rectangle.width, rectangle.height, true);
						factors_grid.getVerticalBar().setSelection(factors_grid.getSelectionIndex() - 5);
						factors_grid.getVerticalBar().notifyListeners(SWT.Selection, null);
					}
				});
			}
		}).start();
		
	}

	/**
	 * @Description: 递归实现指标树
	 * @author guoyr
	 * @param factor
	 * @param parentGridItem
	 * @param selectId
	 */
	private void initChildGridItem(EvaluationFactor factor, GridItem parentGridItem, String selectId) {
		if (null != factor.getChildFactorList() && factor.getChildFactorList().size() > 0) {
			for (EvaluationFactor childFactor : factor.getChildFactorList()) {
				GridItem gridItem = new GridItem(parentGridItem, SWT.NONE);
				initChildGridItem(childFactor, gridItem, selectId);
			}
			parentGridItem.setExpanded(true);
			parentGridItem.setImage(0, menuOpenImage);
		} else {
			parentGridItem.setImage(0, menuImage);
		}
		setFactorItemContent(factor, parentGridItem, false);
		parentGridItem.setToolTipText(0, parentGridItem.getText());
		if (null != selectId && selectId.equals(factor.getId())) {
			factors_grid.setSelection(new GridItem[] { parentGridItem });
		}
	}

	/**
	 * @Description: 选中指标
	 * @author guoyr
	 */
	private void selectionFactorAction() {

		EvaluationFactor factor = getSelectionEvaluationFactor();
		add_btn.setEnabled(true);
		add_sub_btn.setEnabled(false);
		kgxParentComposite.setEnabled(true);
		if (null != factor) {
			add_sub_btn.setEnabled(true);
			del_btn.setEnabled(true);
			// 如果选中的是父级
			if (factors_grid.getSelectionCount() > 0 && factors_grid.getSelection()[0].getItemCount() > 0) {
				del_btn.setEnabled(false);
				//				kgxParentComposite.setEnabled(false);// 父级指标不允许设置为客观项
			}
			// 如果是基础指标或浮动指标，则不可以新增下级指标
			if (null != factor.getContainId() && !"".equals(factor.getContainId())) {
				add_sub_btn.setEnabled(false);
			}
		} else {
			del_btn.setEnabled(false);
		}
		refreshFactorTreeBtn();
		refreshFactorInfo(factor);
	}

	/**
	 * @Description: 刷新指标
	 * @author guoyr
	 * @param factor
	 */
	private void refreshFactorInfo(EvaluationFactor factor) {
		if (null == factor) {
			factor = new EvaluationFactor();
			factor.setObjective(EvaluationFactorEnum.OBJECTIVE_NO);
		}
		curFactor = factor;
		factor_name_text.forceFocus();
		// 设置当前指标的信息
		factor_name_text.setText(ObjectUtils.getObjString(factor.getFactorName()));
		factor_memo_text.setText(ObjectUtils.getObjString(factor.getMemo()));
		compliance_content_text.setText(ObjectUtils.getObjString(factor.getEvalContent()));

		// 设置是否客观项
		if (StringUtils.isNotEmpty(factor.getObjective()) && factor.getObjective().equals(EvaluationFactorEnum.OBJECTIVE_YES)) {
		} else {
			curFactor.setObjective(EvaluationFactorEnum.OBJECTIVE_NO);
		}
		WidgetUtils.setRadioChecked(kgxParentComposite, factor.getObjective());
		WidgetUtils.setRadioChecked(clauseTypeComposite, factor.getClauseType());

		evalBidTypeTitle.setVisible(null == curFactor.getParentId());
		((GridData) evalBidTypeTitle.getLayoutData()).exclude = null != curFactor.getParentId();
		evalBidTypeCombo.setVisible(null == curFactor.getParentId());
		((GridData) evalBidTypeCombo.getLayoutData()).exclude = null != curFactor.getParentId();
		evalBidTypeCombo.select(0);
		if (evalBidTypeCombo.getVisible()) {
			WidgetUtils.setComboSelection(evalBidTypeCombo, curFactor.getEvalBidType());
		}
		factorComposite.layout();
	}

	/**
	 * @Description: 新增指标
	 * @author guoyr
	 */
	private void addFctorAction() {
		if (isInEvaluationProgress()) {
			return;
		}
		if (add_btn.getEnabled()) {
			EvaluationFactor newFactor = new EvaluationFactor();
			newFactor.setObjective(EvaluationFactorEnum.OBJECTIVE_NO);
			EvaluationFactor selectFactor = getSelectionEvaluationFactor();
			if (null != selectFactor) {
				newFactor.setParentId(selectFactor.getParentId());
			}
			refreshFactorInfo(newFactor);
		} 
	
	
	}

	/**
	 * @Description: 新增下级指标
	 * @author guoyr
	 */
	private void addSubFctorAction() {
		if (isInEvaluationProgress()) {
			return;
		}
		EvaluationFactor selectFactor = getSelectionEvaluationFactor();
		if(add_sub_btn.isDisposed()){
			return ;
		}
		if (add_sub_btn.getEnabled() && null != selectFactor) {
			EvaluationFactor newFactor = new EvaluationFactor();
			newFactor.setObjective(EvaluationFactorEnum.OBJECTIVE_NO);
			newFactor.setEvalBidType(selectFactor.getEvalBidType());
			newFactor.setClauseType(selectFactor.getClauseType());
			newFactor.setParentId(selectFactor.getId());
			refreshFactorInfo(newFactor);
		}
	
		
	}

	/**
	 * @Description: 切换条款类型
	 * @author guoyr
	 * @param clauseType
	 */
	private void changeClauseType(String clauseType) {
		if (factors_grid.getSelectionCount() > 0 && factors_grid.getSelection()[0].getItemCount() > 0) {
			if (MessageDialog.openConfirm(getShell(), Messages.Dialog_warmTips, Messages.Tips_applyToAllChildSiblingFactor, new String[] {Messages.Button_confirm, Messages.Button_cancel})) {
				String clauseTypeValue = ObjectUtils.getObjString(WidgetUtils.getRadioVal(clauseTypeComposite));
				List<EvaluationFactor> childFactorLis = new ArrayList<EvaluationFactor>();
				setSubChildFactorProperty(childFactorLis, "clauseType", clauseTypeValue, curFactor);

		 	if (evaluationFactorService.batchUpdateProperty(childFactorLis, new String[] { "id","clauseType" })) {
					MessageDialog.openShortMessage(Messages.Tips_operateSuccess);
					refreshFactorTree(curFactor.getId());
				} else {
					MessageDialog.openError(getShell(), Messages.Tips_operateFail);
				}
			}
		}
	}

	/**
	 * @Description: 切换一致性检查
	 * @author wangxiang
	 * @param Objective
	 */
	private void changeObjective(String objective) {
		if (factors_grid.getSelectionCount() > 0 && factors_grid.getSelection()[0].getItemCount() > 0) {
			if (MessageDialog.openConfirm(getShell(), Messages.Dialog_warmTips, Messages.Tips_applyToAllChildSiblingFactor, new String[] {Messages.Button_confirm, Messages.Button_cancel})) {
				String objectValue = ObjectUtils.getObjString(WidgetUtils.getRadioVal(kgxParentComposite));
				List<EvaluationFactor> childFactorLis = new ArrayList<EvaluationFactor>();
				setSubChildFactorProperty(childFactorLis, "objective", objectValue, curFactor);

				if (evaluationFactorService.batchUpdateProperty(childFactorLis, new String[] {"id", "objective" })) {
					MessageDialog.openShortMessage(Messages.Tips_operateSuccess);
					refreshFactorTree(curFactor.getId());
				} else {
					MessageDialog.openError(getShell(), Messages.Tips_operateFail);
				}

			}
		}
	}

	/**
	 * @Description: 递归循环添加
	 * @author wangxiang
	 * @param nowFactor
	 * @param childFactorLis
	 * @param value
	 */
	private void setSubChildFactorProperty(List<EvaluationFactor> childFactorLis, String property, String value, EvaluationFactor evalFactor) {
		List<EvaluationFactor> curChildFactorLis = evalFactor.getChildFactorList();
		if("objective".equals(property)){
			evalFactor.setObjective(value);
		}else{
			evalFactor.setClauseType(value);
		}
		childFactorLis.add(evalFactor);
		if (null != curChildFactorLis && curChildFactorLis.size() > 0) {
			for (EvaluationFactor childFactor : curChildFactorLis) {
				if("objective".equals(property)){
					childFactor.setObjective(value);
				}else{
					childFactor.setClauseType(value);
				}
				childFactorLis.add(childFactor);
				if (null != childFactor.getChildFactorList() && childFactor.getChildFactorList().size() > 0) {
					setSubChildFactorProperty(childFactorLis, property, value, childFactor);
				}
			}
		}
	}

	/**
	 * @Description: 右键菜单
	 * @author guoyr
	 */
	private void mouseRightClickAction() {

		final EMenu gmenu = new EMenu(getShell());
		gmenu.addMenuItem(up_btn);
		gmenu.addMenuItem(download_btn);
		gmenu.addSeparator();
		gmenu.addMenuItem(add_btn);
		gmenu.addMenuItem(add_sub_btn);
		gmenu.addMenuItem(del_btn);
		if(MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority("DELETE_ALL"))) {
			gmenu.addMenuItem(Messages.Button_deleteAll, del_btn.getImage(), factors_grid.getItemCount() > 1, new EMenu.ClickListener() {
				public void click() {
					delAllFactorAction();
				}
			});
		}

		gmenu.open();
	}

	/**
	 * @Description: 获得当前选中的指标
	 * @author guoyr
	 * @return
	 */
	private EvaluationFactor getSelectionEvaluationFactor() {
		EvaluationFactor factor = null;
		if (factors_grid.getSelectionCount() > 0) {
			factor = (EvaluationFactor) factors_grid.getSelection()[0].getData("evaluationFactor");
		}
		return factor;
	}

	/**
	 * @Description: 保存或修改指标
	 * @author guoyr
	 */
	private void saveEvaluationFactorAction() {
		if (!save_btn.getEnabled())
			return;
		final boolean isNew = StringUtils.isEmpty(curFactor.getId());
		Thread thread = new Thread(new Runnable() {	
			@Override
			public void run() {
				if (isNew) {
					boolean isInEvaluationProgress = tenderProjectService.isInProgress(tenderProject.getId(), EvaluationStepEnum.COMPLIANCE);
					if (isInEvaluationProgress) {
						Display.getDefault().syncExec(new Runnable(){
							public void run(){
								MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_enteredEvaluation);
								return;
							} 
						});
					}
				} else {
					if (isInEvaluationStepProgress(curFactor.getId())) {
						Display.getDefault().syncExec(new Runnable(){
							public void run(){
								MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_enteredEvaluation);
							} 
						});
						return;
					}
				}	
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(null == factor_name_text  && factor_name_text.isDisposed()){
							return;
						}
						if (factor_name_text.getText().trim().length() == 0) {
							MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_required, Messages.FactorName));
							return;
						}
						String evalContent = compliance_content_text.getText().trim();
						if (null != compliance_content_text && evalContent.length() > 0) {
							evalContent = evalContent.replace("，", ",");
							if (evalContent.indexOf(",") <= 0 || evalContent.split(",").length != 2) {
								MessageDialog.openWarning(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_incorrectFormat, Messages.EvalOptions));
								compliance_content_text.forceFocus();
								return;
							}
						}
						curFactor.setEvalContent(evalContent);
						curFactor.setTenderId(tenderProject.getId());
						curFactor.setFactorName(factor_name_text.getText().trim());
						curFactor.setMemo(factor_memo_text.getText().trim());
						curFactor.setAuditType(EvaluationFactorEnum.AUDIT_COMPLIANCE);
						curFactor.setObjective(ObjectUtils.getObjString(WidgetUtils.getRadioVal(kgxParentComposite)));
						curFactor.setClauseType(ObjectUtils.getObjString(WidgetUtils.getRadioVal(clauseTypeComposite)));

						if (curFactor.getSortNo() == 0) {
		 					int sortNo = evaluationFactorService.getMaxEvaluationFactorSortNo(tenderProject.getId(), EvaluationFactorEnum.AUDIT_COMPLIANCE, curFactor.getParentId());
							curFactor.setSortNo(sortNo + 1);
						}
						if (evalBidTypeCombo.getVisible()) {
							curFactor.setEvalBidType((String) WidgetUtils.getComboSelection(evalBidTypeCombo));
						}
			 			curFactor = evaluationFactorService.saveOrUpdateComplianceEvaluationFactor(curFactor);

						if (null != curFactor) {
							MessageDialog.openShortMessage(Messages.Tips_saveSuccess);
							refreshFactorTree(curFactor.getId());
							if (isNew) {
								checkEvaluationStepAfterChangeFactor();
							}
						} else {
							MessageDialog.openError(getShell(), Messages.Dialog_warmTips, Messages.Tips_saveFail);
						}
					} 
				});
			}
		});
		thread.start();		
	}

	/**
	 * @Description: 设置指标树的内容
	 * @author guoyr
	 * @param factor
	 * @param gridItem
	 * @param refresh
	 */
	private void setFactorItemContent(EvaluationFactor factor, GridItem gridItem, boolean refresh) {
		gridItem.setData("evaluationFactor", factor);
		gridItem.setText(0, factor.getFactorName());
		// 如果是客观项指标
		if (ObjectUtils.equals(factor.getObjective(), EvaluationFactorEnum.OBJECTIVE_YES)) {
			// 如果即是客观项指标，又是浮动指标
			if (null != factor.getContainFactor()) {
				gridItem.setForeground(0, SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
			} else {
				gridItem.setForeground(0, SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN));
			}
		} else if (null != factor.getContainFactor()) {
			// 如果是浮动指标
			gridItem.setForeground(0, SWTResourceManager.getColor(SWT.COLOR_DARK_MAGENTA));
		} else if (refresh) {
			gridItem.setForeground(0, null);
		}
	}

	/**
	 * @Description: 删除指标
	 * @author guoyr
	 */
	private void delFactorAction() {
		if (!del_btn.getEnabled())
			return;
		if (isInEvaluationProgress()) {
			return;
		}
		Thread thread = new Thread(new Runnable() {	
			@Override
			public void run() {
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						EvaluationFactor factor = getSelectionEvaluationFactor();
						if (null != factor) {
							if (MessageDialog.openConfirm(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_deleteObj, ObjectUtils.getObjString(factor.getFactorName())))) {
								int selectIndex = factors_grid.getSelectionIndex();
								String preFactorId = null;
								if (selectIndex > 1) {
									EvaluationFactor preFactor = (EvaluationFactor) factors_grid.getItem(selectIndex - 1).getData("evaluationFactor");
									if (null != preFactor) {
										preFactorId = preFactor.getId();
									}
								}
			 					int delCount = evaluationFactorService.deleteEvaluationFactor(factor);
								if (delCount > 0) {
									refreshFactorTree(preFactorId);
									checkEvaluationStepAfterChangeFactor();
								}
							}
						}
					} 
				});
			}
		});
		thread.start();		
		
	}

	/**
	 * @Description: 删除全部指标
	 * @author guoyr
	 */
	private void delAllFactorAction() {
		if(isInEvaluationProgress()){return;}
		if(MessageDialog.openConfirm(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_deleteAllObject, Messages.Factor_compliance))){
			new SyncThread(new SyncThread.Runnable() {
				public void run() {
					evaluationFactorService.delEvaluationFactorByType(tenderProject.getId(), EvaluationFactorEnum.AUDIT_COMPLIANCE);
					Display.getDefault().syncExec(new Runnable(){
						public void run(){
							if (!factors_grid.isDisposed()) {
								refreshFactorTree(null);
								checkEvaluationStepAfterChangeFactor();
							} 
						} 
					});
				}
			}).start();;
		}
	}


	/**
	 * @Description: 移动指标
	 * @author guoyr
	 * @param upOrDown
	 *            -1：上移；1：下移
	 */
	private void moveFactorAction(int upOrDown) {
		if (upOrDown == 1 && !download_btn.getEnabled()) {
			return;
		} else if (upOrDown == -1 && !up_btn.getEnabled()) {
			return;
		}
		if (factors_grid.getSelectionCount() > 0) {
			GridItem selectGridItem = factors_grid.getSelection()[0];
			if (null != selectGridItem.getData("evaluationFactor")) {
				EvaluationFactor selectResource = (EvaluationFactor) selectGridItem.getData("evaluationFactor");
				GridItem selectParentGridItem = selectGridItem.getParentItem();
				GridItem targetItem = null;
				// 将当前要进行上移的资源信息记录
				// 获取目标资源
				GridItem[] tempGridItems = selectGridItem.getItems();
				boolean tempExpanded = selectGridItem.isExpanded();
				if (null == selectParentGridItem) {
					int index = factors_grid.indexOf(selectGridItem);
					if (upOrDown == 1) {
						targetItem = factors_grid.getItem(index + findNextItemIndex(selectGridItem));
					} else {
						targetItem = findRootItem(factors_grid.getItem(index + upOrDown));
					}
				} else {
					int index = selectParentGridItem.indexOf(selectGridItem);
					// 获取目标资源
					targetItem = selectParentGridItem.getItem(index + upOrDown);
				}

				EvaluationFactor targetResource = (EvaluationFactor) targetItem.getData("evaluationFactor");
				//		
				// 将目录资源换到当前资源
				selectGridItem.setText(targetItem.getText());
				selectGridItem.setData("evaluationFactor", targetItem.getData("evaluationFactor"));
				// 递归将目录的下级资源移动到当前资源
				moveSubResourceItem(targetItem.getItems(), targetItem.isExpanded(), selectGridItem);

				// 将当前资源换到目录资源
				targetItem.setText(selectResource.getFactorName());
				targetItem.setData("evaluationFactor", selectResource);
				// 递归将当前的下级资源移动目标资源
				moveSubResourceItem(tempGridItems, tempExpanded, targetItem);

				factors_grid.setSelection(new GridItem[] { targetItem });
				refreshFactorTreeBtn();
		  	 	evaluationFactorService.changeEvaluationFactorSortNo(selectResource, targetResource);
		  		int targetSortNO = targetResource.getSortNo();
		  		targetResource.setSortNo(selectResource.getSortNo());
		  		selectResource.setSortNo(targetSortNO);
		  	 	if(null != curFactor) {
		  	 		curFactor.setSortNo(selectResource.getSortNo());
		  	 	}
			}

		}
	}

	/**
	 * @Description: 获取目标节点
	 * @author guoyr
	 * @param item
	 * @return
	 */
	private GridItem findRootItem(GridItem item) {
		if (null != item.getParentItem()) {
			return findRootItem(item.getParentItem());
		} else {
			return item;
		}
	}

	/**
	 * @Description: 下移：统计当前节点的子节点个数
	 * @author guoyr
	 * @param gridItem
	 * @param num
	 * @return
	 */
	private int findNextItemIndex(GridItem gridItem) {
		int num = 1;
		GridItem[] gridItems = gridItem.getItems();
		for (GridItem item : gridItems) {
			num += findNextItemIndex(item);
		}
		return num;
	}

	/**
	 * @Description: 递归移动当前指标及其所有子指标
	 * @author guoyr
	 * @param items
	 * @param isExpanded
	 * @param parentItem
	 */
	private void moveSubResourceItem(GridItem[] items, boolean isExpanded, GridItem parentItem) {
		if (items.length > 0) {
			for (GridItem item : items) {
				GridItem newItem = new GridItem(parentItem, SWT.NONE);
				newItem.setText(0, item.getText());
				newItem.setData("evaluationFactor", item.getData("evaluationFactor"));
				moveSubResourceItem(item.getItems(), item.isExpanded(), newItem);
				item.dispose();
			}
			parentItem.setImage(0, menuOpenImage);
			parentItem.setExpanded(isExpanded);
		} else {
			parentItem.setImage(0, menuImage);
		}
	}

	/**
	 * @Description: 刷新移动按钮
	 * @author guoyr
	 */
	private void refreshFactorTreeBtn() {

		if (factors_grid.getSelectionCount() > 0) {
			GridItem selectGridItem = factors_grid.getSelection()[0];
			GridItem selectParentGridItem = selectGridItem.getParentItem();
			if (null != selectParentGridItem) {
				if (selectParentGridItem.getItemCount() > 0) {
					int index = selectParentGridItem.indexOf(selectGridItem);
					if (index > 0) {
						up_btn.setEnabled(true);
					} else {
						up_btn.setEnabled(false);
					}
					if (index < selectParentGridItem.getItemCount() - 1) {
						download_btn.setEnabled(true);
					} else {
						download_btn.setEnabled(false);
					}
				} else {
					up_btn.setEnabled(false);
					download_btn.setEnabled(false);
				}
			} else {
				int index = factors_grid.indexOf(selectGridItem);
				if ((index + findNextItemIndex(selectGridItem) >= factors_grid.getItemCount())) {
					download_btn.setEnabled(false);
				} else {
					download_btn.setEnabled(true);
				}
				if (index - 1 < 0) {
					up_btn.setEnabled(false);
				} else {
					up_btn.setEnabled(true);
				}
			}
		} else {
			up_btn.setEnabled(false);
			download_btn.setEnabled(false);
		}
	}

	/**
	 * @Description: 验证是否已经进入评标环节
	 * @author guoyr
	 * @return
	 */
	private boolean isInEvaluationProgress(){
		boolean isInEvaluationProgress = tenderProjectService.isInProgress(tenderProject.getId(), EvaluationStepEnum.COMPLIANCE);
		if(isInEvaluationProgress){
			MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_enteredEvaluation);
		}
		return isInEvaluationProgress;
	}

	/**
	 * @Description: 验证当前评审指标的是不是已经在评审中的评审步骤中
	 * @author guoyr
	 * @param factorId
	 * @return
	 */
	private boolean isInEvaluationStepProgress(String factorId) {
		if (null == evaluationStepService) {
			evaluationStepService = new EvaluationStepService();
		}
		EvaluationStep evaluatoinNode = evaluationStepService.getEvaluationStepByFactor(tenderProject.getId(), factorId);
		if (null != evaluatoinNode && (ObjectUtils.equals(evaluatoinNode.getStepStatus(), CommonEnum.IN_PROGRESS) || ObjectUtils.equals(evaluatoinNode.getStepStatus(), CommonEnum.COMPLETE))) {
			return true;
		} else {
			return false;
		}
	}

	
	/**
	 * @Description: 验证是否在已设置评标步骤后，又进行了指标的新增或删除操作
	 * @author guoyr
	 * @param opName
	 */
	private void checkEvaluationStepAfterChangeFactor() {

		if (null == evaluationStepService) {
			if (null == evaluationStepService) {
				evaluationStepService = new EvaluationStepService();
			}
//			QueryWrapper queryWrapper = new QueryWrapper(EvaluationStep.class);
//			queryWrapper.setQueryParm("id");
//			queryWrapper.setWhereParam("tenderId", tenderProjectEntity.getId());
//	 		List<Object> nodeList = evaluationStepService.queryColumnList(queryWrapper);
			List<String> nodeList = evaluationStepService.getIdByTenderIdCount(tenderProject.getId());
			if (null != nodeList && nodeList.size() > 0) {
				isExistEvaluationStep = true;
			}
		}
		if (isExistEvaluationStep) {
			MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_pleaseResetEvalStep);
		}
	}

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