package com.gx.obe.management.composite;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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.CallBack;
import org.eclipse.swt.core.ImageResolver;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.utils.FileDialogUtils;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.ELabel;
import org.eclipse.swt.core.widgets.ELink;
import org.eclipse.swt.core.widgets.EMenu;
import org.eclipse.swt.core.widgets.ImageButton;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.SashForm;
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.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
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.ExpertEvaluationStep;
import com.gx.obe.business.entity.ExpertLibrary;
import com.gx.obe.business.entity.Machine;
import com.gx.obe.business.entity.MenuFunction;
import com.gx.obe.business.enumeration.ExpertEnum;
import com.gx.obe.business.enumeration.MenuFunctionEnum;
import com.gx.obe.business.enumeration.UserEnum;
import com.gx.obe.business.http.HttpUtils;
import com.gx.obe.common.dialog.AssignEvalGroupDialog;
import com.gx.obe.common.dialog.CABindingDialog;
import com.gx.obe.common.dialog.ResetPasswordDialog;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.common.widget.composite.TitleComposite;
import com.gx.obe.common.widget.dialog.MessageViewDialog;
import com.gx.obe.common.widget.utils.MenuFunctionUtils;
import com.gx.obe.components.core.Constants;
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.components.core.enumeration.TenderProjectEnum;
import com.gx.obe.config.ConfigConstants;
import com.gx.obe.config.utils.PropertiesUtils;
import com.gx.obe.http.util.Base64;
import com.gx.obe.management.Lisener.AddTempExperCallBack;
import com.gx.obe.management.action.DownloadExpertAction;
import com.gx.obe.management.dialog.AddTempExpertNumDialog;
import com.gx.obe.management.dialog.ApplyToOtherTenderPackExpertDialog;
import com.gx.obe.management.dialog.CheckExpertDialog;
import com.gx.obe.management.dialog.EditExpertDialog;
import com.gx.obe.management.dialog.ExpertAvoidDialog;
import com.gx.obe.management.dialog.ImportExpertFromTenderProjectDialog;
import com.gx.obe.management.dialog.UpdateExpertDialog;
import com.gx.obe.management.thread.ExporExpertThread;
import com.gx.obe.message.Messages;
import com.gx.obe.message.menu.MenuMessages;
import com.gx.obe.util.utils.DateUtils;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.util.utils.MD5Utils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.util.utils.StringUtils;
import com.gx.obe.util.utils.UuidUtils;
import com.gx.obe.web.entity.TransactionServer;
import com.gx.obe.web.entity.auth.AuthLoginRecordEntity;
import com.gx.obe.web.entity.auth.AuthRole;
import com.gx.obe.web.entity.auth.AuthUser;
import com.gx.obe.web.entity.auth.AuthUserRole;
import com.gx.obe.web.entity.auth.Menu;
import com.gx.obe.web.entity.evaluation.EvaluationRoom;
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.MachineService;
import com.gx.obe.web.service.RoleService;
import com.gx.obe.web.service.TenderProjectService;
import com.gx.obe.web.service.TransactionServerService;
import com.gx.obe.web.service.UserLoginRecordService;
import com.gx.obe.web.service.evaluation.EvaluationStepService;
import com.gx.obe.web.service.expert.ExpertEvaluationStepService;
import com.gx.obe.web.service.expert.ExpertService;
import com.gx.utils.NowTimeUtils;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

/**
 * @Description: 评标专家小组管理
 * @author guoyr
 */
public class EvaluationExpertManagerComposite extends Composite {
	
	private SashForm sashForm;
	private ELink addNewExpertBtn;
	private ELink importExpertBtn;
	private ELink applyToOtherPackBtn;
	private ELink synchronousExpertBtn;
	private ELink updateExpertBtn;
	private ELink delExpertBtn;
	private Label accountLabel;
	private Label expertNameLabel;
	private ImageButton userAvatorLabel;
	private Label genderLabel;
	private Label idCardLabel;
	private Label phoneLabel;
	private Text professionalTitleLabel;
	private Text specialityLabel;
	private Text companyNameLabel;
	private ELabel machineLabel;
	private Label ipLabel;
	private Label loginTimeLabel;
	private Label signTimeLabel;
	private Label isLeaderLabel;
	private ELink logOutBtn;
	private ELink configLeaderBtn;
	private ELink configCaBtn;
	private ELink signBtn;
	private ELink button;
	private Label signTypeLabel;
//	private Composite caComposite;
	private Composite caContentComposite;
	private TenderProjectEntity tenderProjectEntity;
	private ImageResolver imageResolver = new ImageResolver();
	private Image defaultAvatorImage;
	private List<Expert> expertList;
	private Grid expertGrid;
	private EvaluationStep signEvaluationStep;
	private UserLoginRecordService loginRecordService;
	private MachineService machineService ;
	private ExpertService expertService ;
	private TenderProjectService tenderProjectService ;
	private EvaluationStepService evaluationStepService = new EvaluationStepService();
//	private ExpertEvaluationStepService expertEvaluationStepService ;
	private boolean isExistExpertLeader = false;
	private Map<String, AuthLoginRecordEntity> loginRecordMap = new HashMap<String, AuthLoginRecordEntity>();
	private Map<String, Machine> machineMap = new HashMap<String, Machine>();
	private boolean initLoad = true;
	private ELink add_temp_expert;
	private ELink checkDownExpertBtn;
	private Composite compositeScrolle;
	private ScrolledComposite scrolledComposite;
	private ELink assignEvalGroupLink;
	private Menu menu;
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();
	private TitleComposite titleComposite;
	private GridColumn evalGroupColumn;
	private Action projectAction;
	
	private ExpertEvaluationStepService expertEvaluationStepService = new ExpertEvaluationStepService();
//	private UserRoleService userRoleService ;
	private GridColumn evalRoomColumn;
	
	{
		LogUtils.logClass(EvaluationExpertManagerComposite.class);
	}
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public EvaluationExpertManagerComposite(Composite parent, Action projectAction, int style) {
		super(parent, style);
		setBackground(SWTResourceManager.getColor(255, 255, 255));
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				imageResolver.disposite();
				machineMap.clear();
				loginRecordMap.clear();
			}
		});
		this.projectAction = projectAction;
		
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.verticalSpacing = 0;
		gridLayout.horizontalSpacing = 0;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		
		titleComposite = new TitleComposite(this, SWT.NONE);
		titleComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		applyToOtherPackBtn = titleComposite.addELink("BATCH_APPLY");
		applyToOtherPackBtn.setText(Messages.Button_applyToOthers);
		applyToOtherPackBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/copy.png"));
		applyToOtherPackBtn.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				applyToOtherPackAction();
			}
		});
		
		assignEvalGroupLink = titleComposite.addELink("ASSIGN_EVAL_GROUP");
		assignEvalGroupLink.setText(Messages.Button_assignEvalGroup);
		assignEvalGroupLink.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/config.png"));
		assignEvalGroupLink.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				assignEvalGroupAction();
			}
		});
		
		ELink button_1 = titleComposite.addELink("REFRESH");
		button_1.setText(Messages.Button_refresh);
		button_1.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/refresh.png"));
		button_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				refreshAllExpert();
			}
		});

		synchronousExpertBtn = titleComposite.addELink("DOWNLOAD");
		synchronousExpertBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				synchronousExpertAction();
			}
		});
		synchronousExpertBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/download.png"));
		synchronousExpertBtn.setText(Messages.Button_download);
		
		importExpertBtn = titleComposite.addELink("IMPORT");
		importExpertBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				importExpertFromProjectAction();
			}
		});
		importExpertBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/import.png"));
		importExpertBtn.setText(Messages.Button_import);
		
		checkDownExpertBtn = titleComposite.addELink("CHECK");
		checkDownExpertBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				checkDownExpertAction();
			}
		});
		checkDownExpertBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/batch_signature.png"));
		checkDownExpertBtn.setText(Messages.Button_validateExpert);
		
		addNewExpertBtn = titleComposite.addELink("ADD");
		addNewExpertBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				createExpertAction();
			}
		});
		addNewExpertBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/add.png"));
		addNewExpertBtn.setText(Messages.Button_add);
		
		add_temp_expert = titleComposite.addELink("ADD_DEFAULT");
		add_temp_expert.setText(Messages.Button_createTempAccount);
		add_temp_expert.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/add.png"));
		add_temp_expert.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				addTempExpert();
			}
		});
		
		
		updateExpertBtn = titleComposite.addELink("EDIT");
		updateExpertBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/edit.png"));
		updateExpertBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				updateExpertAction();
			}
		});
		updateExpertBtn.setText(Messages.Button_modify);
		
		delExpertBtn = titleComposite.addELink("DELETE");
		delExpertBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/delete.png"));
		delExpertBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				delExpertAction();
			}
		});
		delExpertBtn.setText(Messages.Button_delete);
		
		Composite composite_8 = new Composite(this, SWT.NONE);
		composite_8.setBackground(SWTResourceManager.getColor(211, 211, 211));
		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.horizontalSpacing = 1;
		gl_composite_8.marginHeight = 1;
		gl_composite_8.marginWidth = 1;
		composite_8.setLayout(gl_composite_8);
		
		sashForm = new SashForm(composite_8, SWT.VERTICAL);
		sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		sashForm.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
		Composite composite = new Composite(sashForm, SWT.NONE);
		composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		GridLayout gl_composite = new GridLayout(1, false);
		gl_composite.verticalSpacing = 0;
		gl_composite.horizontalSpacing = 1;
		gl_composite.marginHeight = 1;
		gl_composite.marginWidth = 1;
		composite.setLayout(gl_composite);
		Composite composite_1 = new Composite(composite, SWT.NONE);
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_composite_1 = new GridLayout(1, false);
		gl_composite_1.marginHeight = 0;
		gl_composite_1.marginWidth = 0;
		composite_1.setLayout(gl_composite_1);
		
		expertGrid = new Grid(composite_1, SWT.H_SCROLL | SWT.V_SCROLL);
		expertGrid.setHeaderVisible(true);
		expertGrid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		GridColumn gridNumColumn = new GridColumn(expertGrid, SWT.CENTER);
		gridNumColumn.setText(Messages.Num);
		gridNumColumn.setWidth(40);
		gridNumColumn.setMaxmumWidth(50);
		
		GridColumn gridColumn = new GridColumn(expertGrid, SWT.CENTER);
		gridColumn.setText(Messages.FullName);
		gridColumn.setWidth(80);
		
		GridColumn accountColumn = new GridColumn(expertGrid, SWT.CENTER);
		accountColumn.setText(Messages.Account);
		accountColumn.setWidth(80);
		
		GridColumn categoryColumn = new GridColumn(expertGrid, SWT.CENTER);
		categoryColumn.setText(Messages.ExpertType);
		categoryColumn.setWidth(80);
		
		GridColumn checkInStatusColumn = new GridColumn(expertGrid, SWT.CENTER);
		checkInStatusColumn.setText(Messages.CheckInStatus);
		checkInStatusColumn.setWidth(80);
		
		evalGroupColumn = new GridColumn(expertGrid, SWT.CENTER);
		evalGroupColumn.setText(Messages.EvalGroup);
		evalGroupColumn.setWidth(80);
		
		evalRoomColumn = new GridColumn(expertGrid, SWT.CENTER);
		evalRoomColumn.setText(Messages.EvaluationRoom);
		evalRoomColumn.setWidth(150);
		
		GridColumn ipColumn = new GridColumn(expertGrid, SWT.CENTER);
		ipColumn.setText(Messages.Login_ip);
		ipColumn.setWidth(80);
		
		GridColumn macColumn = new GridColumn(expertGrid, SWT.CENTER);
		macColumn.setText(Messages.MachineMark);
		macColumn.setWidth(100);
		macColumn.setVisible(false);
		
		GridColumn loginStatusColumn = new GridColumn(expertGrid, SWT.CENTER);
		loginStatusColumn.setText(Messages.Login_status);
		loginStatusColumn.setWidth(55);
		
		Composite composite_6 = new Composite(sashForm, SWT.NONE);
		composite_6.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_6.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_composite_6 = new GridLayout(1, false);
		gl_composite_6.verticalSpacing = 0;
		gl_composite_6.marginHeight = 0;
		gl_composite_6.marginWidth = 0;
		composite_6.setLayout(gl_composite_6);
		composite_6.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		
		scrolledComposite = new ScrolledComposite(composite_6, SWT.H_SCROLL | SWT.V_SCROLL);
		GridData gd_scrolledComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_scrolledComposite.widthHint = 850;
		scrolledComposite.setLayoutData(gd_scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		compositeScrolle = new Composite(scrolledComposite, SWT.NONE);
		GridLayout gl_compositeScrolle = new GridLayout(2, false);
		gl_compositeScrolle.marginHeight = 10;
		gl_compositeScrolle.marginWidth = 10;
		compositeScrolle.setLayout(gl_compositeScrolle);
		
		Group composite_3 = new Group(compositeScrolle, SWT.NONE);
		composite_3.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		composite_3.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		composite_3.setText(Messages.Title_expertInfo);
		GridData gd_composite_3 = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
		gd_composite_3.widthHint = 400;
		composite_3.setLayoutData(gd_composite_3);
		GridLayout gl_composite_3 = new GridLayout(5, false);
		gl_composite_3.marginHeight = 10;
		gl_composite_3.verticalSpacing = 8;
		composite_3.setLayout(gl_composite_3);
		
		Composite composite_4 = new Composite(composite_3, SWT.NONE);
		GridLayout gl_composite_4 = new GridLayout(1, false);
		gl_composite_4.marginHeight = 0;
		gl_composite_4.marginWidth = 0;
		composite_4.setLayout(gl_composite_4);
		composite_4.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 7));
		
		userAvatorLabel = new ImageButton(composite_4, SWT.SELECTED);
		userAvatorLabel.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/male_96.png"));
		userAvatorLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		
		Label label_1 = new Label(composite_3, SWT.NONE);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_1.setText(Messages.FullName+"：");
		
		expertNameLabel = new Label(composite_3, SWT.NONE);
		GridData gd_expertNameLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_expertNameLabel.widthHint = 150;
		expertNameLabel.setLayoutData(gd_expertNameLabel);
		expertNameLabel.setText("郭永荣");
		
		Label label_2 = new Label(composite_3, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_2.setText(Messages.Account+"：");
		
		accountLabel = new Label(composite_3, SWT.NONE);
		GridData gd_accountLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_accountLabel.widthHint = 150;
		accountLabel.setLayoutData(gd_accountLabel);
		accountLabel.setText("admin");
		
		Label phoneL = new Label(composite_3, SWT.NONE);
		phoneL.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		phoneL.setText(Messages.LinkerTel+"：");
		
		phoneLabel = new Label(composite_3, SWT.NONE);
		GridData gd_phoneLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_phoneLabel.widthHint = 100;
		phoneLabel.setLayoutData(gd_phoneLabel);
		phoneLabel.setText("13720010710");
		
		Label label_3 = new Label(composite_3, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_3.setText(Messages.Gender+"：");
		
		genderLabel = new Label(composite_3, SWT.NONE);
		genderLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		genderLabel.setText("男");
		
		Label label_4 = new Label(composite_3, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_4.setText(Messages.IDCard+"：");
		
		idCardLabel = new Label(composite_3, SWT.WRAP);
		GridData gd_idCardLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
		gd_idCardLabel.widthHint = 150;
		idCardLabel.setLayoutData(gd_idCardLabel);
		idCardLabel.setText("622224198703024013");
		
		Label label_6 = new Label(composite_3, SWT.NONE);
		label_6.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_6.setText(Messages.ProfessionalTitle+"：");
		
		professionalTitleLabel = new Text(composite_3, SWT.READ_ONLY);
		GridData gd_professionalTitleLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
		gd_professionalTitleLabel.widthHint = 100;
		professionalTitleLabel.setLayoutData(gd_professionalTitleLabel);
		professionalTitleLabel.setText("软件工程师");
		
		
		Label label_7 = new Label(composite_3, SWT.NONE);
		label_7.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_7.setText(Messages.Specialty+"：");
		
		specialityLabel = new Text(composite_3, SWT.READ_ONLY);
		GridData gd_specialityLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
		gd_specialityLabel.widthHint = 300;
		specialityLabel.setLayoutData(gd_specialityLabel);
		specialityLabel.setText("");
		
		Label label_8 = new Label(composite_3, SWT.NONE);
		label_8.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_8.setText(Messages.WorkCompany+"：");
		
		companyNameLabel = new Text(composite_3, SWT.WRAP | SWT.READ_ONLY | SWT.MULTI);
		GridData gd_companyNameLabel = new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1);
		gd_companyNameLabel.widthHint = 300;
		companyNameLabel.setLayoutData(gd_companyNameLabel);
		companyNameLabel.setText("");
		
		CLabel label_10 = new CLabel(composite_3, SWT.NONE);
		label_10.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_10.setText(Messages.ExpertType+"：");
		
		isLeaderLabel = new Label(composite_3, SWT.WRAP);
		GridData gd_isLeaderLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		gd_isLeaderLabel.widthHint = 150;
		isLeaderLabel.setLayoutData(gd_isLeaderLabel);
		isLeaderLabel.setText("组员");
		
		configLeaderBtn = new ELink(composite_3, SWT.NONE);
		configLeaderBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				configLeaderAction();
			}
		});
		GridData gd_configLeaderBtn = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		configLeaderBtn.setLayoutData(gd_configLeaderBtn);
		configLeaderBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/loginTray.png"));
		configLeaderBtn.setText(Messages.SetLeader);
		
		CLabel lblca = new CLabel(composite_3, SWT.NONE);
		lblca.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblca.setText("CA：");
		menuFunctionUtils.addFunction(lblca, "CA");
		
		caContentComposite = new Composite(composite_3, SWT.NONE);
		RowLayout rl_caContentComposite = new RowLayout(SWT.HORIZONTAL);
		rl_caContentComposite.marginBottom = 0;
		rl_caContentComposite.marginTop = 0;
		caContentComposite.setLayout(rl_caContentComposite);
		GridData gd_caContentComposite = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
		gd_caContentComposite.widthHint = 200;
		caContentComposite.setLayoutData(gd_caContentComposite);
		menuFunctionUtils.addFunction(caContentComposite, "CA");
		
		ELabel caLabel = new ELabel(caContentComposite, SWT.NONE);
		caLabel.setText("北京CA");
		
		configCaBtn = new ELink(composite_3, SWT.NONE);
		configCaBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				configCaAction();
			}
		});
		configCaBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/key.png"));
		GridData gd_configCaBtn = new GridData(SWT.CENTER, SWT.CENTER, true, false, 2, 1);
		gd_configCaBtn.widthHint = 90;
		configCaBtn.setLayoutData(gd_configCaBtn);
		configCaBtn.setText(Messages.BiddingCa);
		menuFunctionUtils.addFunction(configCaBtn, "CA");
		
		Group machine_composite = new Group(compositeScrolle, SWT.NONE);
		machine_composite.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		machine_composite.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		machine_composite.setText(Messages.Title_loginInfo);
		GridData gd_machine_composite = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
		gd_machine_composite.widthHint = 400;
		machine_composite.setLayoutData(gd_machine_composite);
		GridLayout gl_composite_machine = new GridLayout(5, false);
		gl_composite_machine.marginHeight = 10;
		gl_composite_machine.verticalSpacing = 8;
		machine_composite.setLayout(gl_composite_machine);
		
		
		Composite composite_9 = new Composite(machine_composite, SWT.NONE);
		GridLayout gl_composite_9 = new GridLayout(1, false);
		gl_composite_9.marginHeight = 0;
		gl_composite_9.marginWidth = 0;
		composite_9.setLayout(gl_composite_9);
		composite_9.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false, 1, 5));
		
		machineLabel = new ELabel(composite_9, SWT.BOTTOM);
		machineLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		machineLabel.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/computer.png"));
		
		logOutBtn = new ELink(composite_9, SWT.NONE);
		logOutBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				loginOutExpert();
			}
		});
		logOutBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/exit.png"));
		logOutBtn.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
		logOutBtn.setText(Messages.LogOff);
		
//		Label label_14 = new Label(machine_composite, SWT.NONE);
//		label_14.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
//		label_14.setText(Messages.EvaluationRoom + "：");
//		
//		evalRoomLabel = new Label(machine_composite, SWT.WRAP);
//		evalRoomLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
		
		Label lblip = new Label(machine_composite, SWT.NONE);
		lblip.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblip.setText(Messages.Login_ip+"：");
		
		ipLabel = new Label(machine_composite, SWT.NONE);
		GridData gd_ipLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
		gd_ipLabel.widthHint = 100;
		ipLabel.setLayoutData(gd_ipLabel);
		ipLabel.setText("");
		
//		Label lblMac = new Label(machine_composite, SWT.NONE);
//		lblMac.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
//		lblMac.setText(Messages.MachineMark+"：");
//		
//		macLabel = new Label(machine_composite, SWT.NONE);
//		GridData gd_macLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
//		gd_macLabel.widthHint = 100;
//		macLabel.setLayoutData(gd_macLabel);
//		macLabel.setText("");
		
		Label label_12 = new Label(machine_composite, SWT.NONE);
		label_12.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_12.setText(Messages.Login_time+"：");
		
		loginTimeLabel = new Label(machine_composite, SWT.NONE);
		loginTimeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
//		new Label(machine_composite, SWT.NONE);
//		new Label(machine_composite, SWT.NONE);
		
		Label label_13 = new Label(machine_composite, SWT.NONE);
		label_13.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_13.setText(Messages.CheckInTime+"：");
		
		signTimeLabel = new Label(machine_composite, SWT.NONE);
		signTimeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
		signTimeLabel.setText("");
		
		CLabel label_9 = new CLabel(machine_composite, SWT.NONE);
		label_9.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_9.setText(Messages.CheckInStatus + "：");
		
		signTypeLabel = new Label(machine_composite, SWT.NONE);
		GridData gd_signTypeLabel = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
		gd_signTypeLabel.widthHint = 100;
		signTypeLabel.setLayoutData(gd_signTypeLabel);
		signTypeLabel.setText(Messages.SignInStatus_yes);
		
		Composite composite_7 = new Composite(machine_composite, SWT.NONE);
		composite_7.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
		GridLayout gl_composite_7 = new GridLayout(3, false);
		gl_composite_7.marginHeight = 0;
		gl_composite_7.marginWidth = 0;
		composite_7.setLayout(gl_composite_7);
		
		signBtn = new ELink(composite_7, SWT.NONE);
		GridData gd_signBtn = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_signBtn.widthHint = 90;
		signBtn.setLayoutData(gd_signBtn);
		signBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				signAction();
			}
		});
		signBtn.setText(Messages.Step_signIn);
		signBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/edit.png"));
		menuFunctionUtils.addFunction(signBtn, "SIGNIN");
		
		button = new ELink(composite_7, SWT.NONE);
		GridData gd_button = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
		gd_button.widthHint = 90;
		button.setLayoutData(gd_button);
		button.setText(Messages.Button_avoid);
		button.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				avoidAction();
			}
		});
		button.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/waste.png"));
		menuFunctionUtils.addFunction(button, "AVOID");
		
		new Label(composite_7, SWT.NONE);
		
		scrolledComposite.setContent(compositeScrolle);
		scrolledComposite.setMinSize(compositeScrolle.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		sashForm.setWeights(new int[] {4, 6});
		
		init();
	}
	
	/**
	 * @Description: 初始化
	 * @author guoyr 
	 */
	private void init(){
		expertService = new ExpertService();
		machineService = new MachineService();
//		userRoleService = new UserRoleService();
		this.tenderProjectEntity = projectAction.getTenderProject();
		this.menu = projectAction.getMenu();
		titleComposite.setTitle(Messages.Expert);
		titleComposite.setTitle(ObjectUtils.getObjString(MenuMessages.getValue(menu.getLanguageCode(), menu.getMenuShortName())));
		loginRecordService = new UserLoginRecordService();
		tenderProjectService = new TenderProjectService();
		defaultAvatorImage = ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/male_96.png");
		expertGrid.setItemHeight(Constants.ROW_HIGHT);
		signEvaluationStep = evaluationStepService.getEvaluationStepBySortNo(tenderProjectEntity.getId(), 1);
		// 添选中事件和右键菜单事件
		expertGrid.addListener(SWT.Selection, new GridSelectionListener(){
			@Override
			public void leftMouseButtonDown(GridItem item) {
				selectExpertAction();
			}
			@Override
			public void rightMouseButtonDown(GridItem item) {
				mouseRightClickAction();
			}
		});
		List<Machine> machineList = machineService.getProjectMachineList(tenderProjectEntity.getId(), null, null);
		if(null != machineList && machineList.size() > 0){
			for(Machine machine : machineList){
				machineMap.put(machine.getMachineMac(), machine);
			}
		}
		applyToOtherPackBtn.setText(MessageFormat.format(Messages.Button_applyToOthers, com.gx.obe.components.core.I18N.getString(I18NEnum.SUBPACKAGE, tenderProjectEntity.getTenderType())));
		WidgetUtils.setControlVisible(applyToOtherPackBtn, null != tenderProjectEntity.getParentId());
		
		menuFunctionUtils.initFunctionAuthority(menu, titleComposite.getFunctionComposite());
		if(MenuFunction.HIDE.equals(menuFunctionUtils.getAuthority("EVAL_GROUP"))){
			evalGroupColumn.setVisible(false);
		}
		if(!MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority("EVAL_ROOM"))){
			evalRoomColumn.setVisible(false);
		}
		if (TenderProjectEnum.LOCAL.equals(tenderProjectEntity.getRemoteStatus())) {
			WidgetUtils.setControlVisible(addNewExpertBtn, true);
			WidgetUtils.setControlVisible(updateExpertBtn, true);
			WidgetUtils.setControlVisible(add_temp_expert, true);
			WidgetUtils.setControlVisible(delExpertBtn, true);
		}
		refreshAllExpert();
		titleComposite.layout();
		expertGrid.resizeColumnWidth();
	}

	/**
	 * @Description: 分配评审要素单元
	 * @author guoyr 
	 */
	private void assignEvalGroupAction(){
		AssignEvalGroupDialog assignEvalGroupDialog = new AssignEvalGroupDialog(getShell(), tenderProjectEntity,new CallBack() {
			public void callBack() {
				refreshAllExpert();
			}
		});
		assignEvalGroupDialog.setTitle(Messages.Button_assignEvalGroup);
		assignEvalGroupDialog.open();
	}
	
	/**
	 * @Description: 显示所有评标专家成员列表
	 * @author guoyr 
	 */
	private void refreshAllExpert(){
		expertGrid.removeAll();
		expertList = expertService.getExpertList(tenderProjectEntity.getId(), ExpertEnum.ALL);
		
		if(null != expertList && expertList.size() >0){
			initLoginRecord(expertList);
			int index = 1;
			for(Expert member : expertList){
				AuthUser user = member.getUser();
				if(null == user)continue;
				GridItem gridItem = new GridItem(expertGrid, SWT.NONE);
				gridItem.setText(0, (index ++) + "");
				setExpertItemInfo(gridItem, member);
			}
		}
		if(expertGrid.getItemCount() > 0 && expertGrid.getSelectionCount() == 0){
			expertGrid.setSelection(0);
		}
		selectExpertAction();
		expertGrid.resizeColumnWidth();
	}
	
	private void initLoginRecord(List<Expert> expertList){
		loginRecordMap.clear();
		List<AuthLoginRecordEntity> loginRecordList = loginRecordService.getLoginRecordByEvalBidRoomId(null);
		if(null == loginRecordList || loginRecordList.size() == 0){
			loginRecordList = loginRecordService.getLoginRecordAllList();
		}
		
		List<String> userIdList = new ArrayList<String>();
		for(Expert member : expertList){
			userIdList.add(member.getUserId());
		}
		if(null != loginRecordList && loginRecordList.size() > 0){
			Date effectiveTime = DateUtils.add(NowTimeUtils.getNowDate(), DateUtils.DAY, -1);
			if(null != loginRecordList && loginRecordList.size() > 0){
				for(AuthLoginRecordEntity authLoginRecordEntity : loginRecordList){
					if(null!= authLoginRecordEntity.getUserId() && authLoginRecordEntity.getLoginTime().after(effectiveTime)){
						loginRecordMap.put(authLoginRecordEntity.getUserId(), authLoginRecordEntity);
					}
				}
			}
		}
	}
	
	/**
	 * @Description: 设置专家的信息
	 * @author guoyr
	 * @param gridItem
	 * @param expert 
	 */
	private void setExpertItemInfo(GridItem gridItem, Expert expert){
		AuthUser user = expert.getUser();
		gridItem.setText(1,user.getUserName());
		gridItem.setText(2,user.getUserAccount());
		if(!isExistExpertLeader && ObjectUtils.equals(expert.getIsLeader(), ExpertEnum.LEADER_YES)){
			isExistExpertLeader = true;
		}
		gridItem.setText(3, expert.getExpertTypeAndRole());// 招标代表/组长（专家）
		gridItem.setText(4, expert.getSignTypeCN());
		String[] evalGroupArray = EvaluationFactorEnum.getEvalGroup(expert.getEvalGroup());
		if(null != evalGroupArray[0]){
			gridItem.setText(5, ObjectUtils.getObjString(evalGroupArray[1]));
		}else {
			gridItem.setText(5, "");
		}
		AuthLoginRecordEntity authLoginRecordEntity = loginRecordMap.get(expert.getUserId());
		if(null != authLoginRecordEntity){
			EvaluationRoom evalBidRool = authLoginRecordEntity.getEvaluationRoom();
			if(null != evalBidRool){
				gridItem.setText(6, ObjectUtils.getObjString(evalBidRool.getEvalRoomName()));
			}
			gridItem.setText(7, ObjectUtils.getObjString(authLoginRecordEntity.getIp()));
			gridItem.setText(8, ObjectUtils.getObjString(authLoginRecordEntity.getMac()));
			gridItem.setText(9, Messages.Logged_in);
		}else {
			gridItem.setText(6, "");
			gridItem.setText(7, "");
			gridItem.setText(8, "");
			gridItem.setText(9, Messages.NotLogged_in);
		}
		gridItem.setData("expert", expert);
	}

	/**
	 * @Description: 刷新评标专家信息
	 * @author guoyr 
	 */
	private void selectExpertAction(){
		boolean hasAllSign = false;
		Expert expert = new Expert();
		AuthUser user = new AuthUser();
		Expert selectExpert = getSelectionExpert();
		if(null != selectExpert){
			expert = selectExpert;
			if(null != selectExpert.getUser()){
				user = selectExpert.getUser();
				user.setId(selectExpert.getUserId());
			}
			updateExpertBtn.setEnabled(!CommonEnum.TEMP_STATUS.equals(user.getUseStatus()));
			delExpertBtn.setEnabled(true);
			configLeaderBtn.setEnabled(true);
			configCaBtn.setEnabled(true);
		}else {
			selectExpert = new Expert();
			updateExpertBtn.setEnabled(false);
			delExpertBtn.setEnabled(false);
			configLeaderBtn.setEnabled(false);
			configCaBtn.setEnabled(false);
		}
		accountLabel.setText(ObjectUtils.getObjString(user.getUserAccount()));
		expertNameLabel.setText(ObjectUtils.getObjString(user.getUserName()));
		idCardLabel.setText(ObjectUtils.getObjString(user.getUserIdcard()));
		phoneLabel.setText(ObjectUtils.getObjString(user.getPhone()));
		professionalTitleLabel.setText(ObjectUtils.getObjString(user.getProfessionalTitle()));
		specialityLabel.setText(ObjectUtils.getObjString(user.getSpecialty()));
		companyNameLabel.setText(ObjectUtils.getObjString(user.getCompany()));
		companyNameLabel.setToolTipText(ObjectUtils.getObjString(user.getCompany()));
		signTypeLabel.setText(ObjectUtils.getObjString(expert.getSignTypeCN()));
		genderLabel.setText(ObjectUtils.getObjString(user.getUserGenderCN()));
		Image image = imageResolver.getImage(Base64.decode(user.getAvatar()));
		if(null !=image){
			userAvatorLabel.setImage(image, defaultAvatorImage.getBounds().width, defaultAvatorImage.getBounds().height);
		}else {
			userAvatorLabel.setImage(defaultAvatorImage);
		}
		if(null != selectExpert.getUser() &&CommonEnum.TEMP_STATUS.equals(selectExpert.getUser().getUseStatus())){
			configLeaderBtn.setEnabled(false);
		}else{
			configLeaderBtn.setEnabled(true);
			if(ObjectUtils.equals(expert.getIsLeader(),ExpertEnum.LEADER_YES)){
//				isLeaderLabel.setImage(imageResolver.loadImage(IconsActivator.PLUGIN_ID, "icons/loginTray.png"));
				configLeaderBtn.setText(Messages.UndoLeader);
			}else {
				configLeaderBtn.setText(Messages.SetLeader);
//				isLeaderLabel.setImage(null);
			}
		}
		isLeaderLabel.setText(ObjectUtils.getObjString(expert.getExpertTypeAndRole()));
		signBtn.setEnabled(false);
		button.setEnabled(false);
		refreshExpertBindCALabel(user);
		if(!hasAllSign){
			if(null != signEvaluationStep && EvaluationStepEnum.SIGIN.equals(signEvaluationStep.getStepType())){
				
				if(ObjectUtils.equals(signEvaluationStep.getStepStatus(), CommonEnum.COMPLETE)){
					hasAllSign = true;
					signBtn.setEnabled(false);
				}else {
					ExpertEvaluationStep memberEvaluationStep = expertEvaluationStepService.getExpertEvaluationStep(tenderProjectEntity.getId(), signEvaluationStep.getId(), selectExpert.getUserId());
					if(null == memberEvaluationStep || !ObjectUtils.equals(memberEvaluationStep.getStepStatus(), CommonEnum.COMPLETE)){
						signBtn.setEnabled(true);
						button.setEnabled(true);
					}
				}
			}else {
				List<Object> objIdsList = expertService.getExpertIdListByTenderIdAndSignTypeisNull(tenderProjectEntity.getId());
				if(null != objIdsList && objIdsList.size() > 0){
					signBtn.setEnabled(true);
					button.setEnabled(true);
				}else {
					hasAllSign = true;
				}
			}
			if(ObjectUtils.equals(expert.getSignType(), ExpertEnum.AVOID)){
				button.setEnabled(false);
				signBtn.setEnabled(true);
			}
		}
		
		AuthLoginRecordEntity authLoginRecordEntity = loginRecordMap.get(expert.getUserId());
		EvaluationRoom evaluationRoom = null;
		if(null != authLoginRecordEntity){
			logOutBtn.setData("loginRecord", authLoginRecordEntity);
			evaluationRoom = authLoginRecordEntity.getEvaluationRoom();
			logOutBtn.setEnabled(true);
			Machine machine = (null != authLoginRecordEntity.getMac())?machineMap.get(authLoginRecordEntity.getMac()):null;
			if(null != machine){
//				machineLabel.setText(ObjectUtils.getObjString(machine.getMachineName()));
				
				// 如果都存在ip，则验证登录的IP与评标室机位指定的IP是否一致
				if(!initLoad && StringUtils.isNotEmpty(authLoginRecordEntity.getIp()) && StringUtils.isNotEmpty(machine.getMachineIp()) && !authLoginRecordEntity.getIp().equals(machine.getMachineIp())){
					initLoad = false;// 初始化加载的时候不弹出提示消息
					MessageDialog.openWarning(getShell(), expertNameLabel.getText() + "登录的IP与评标室机位指定的IP不一致！");
				}
			}else {
//				machineLabel.setText("已登录");
			}
			machineLabel.setEnabled(true);
		}else {
			logOutBtn.setData("loginRecord", null);
//			machineLabel.setText("未登录");
			machineLabel.setEnabled(false);
			logOutBtn.setEnabled(false);
			authLoginRecordEntity = new AuthLoginRecordEntity();
		}
		if(null == evaluationRoom){
			evaluationRoom = new EvaluationRoom();
		}
//		evalRoomLabel.setText(ObjectUtils.getObjString(evaluationRoom.getEvalRoomName()));
		ipLabel.setText(ObjectUtils.getObjString(authLoginRecordEntity.getIp()));
//		macLabel.setText(ObjectUtils.getObjString(authLoginRecordEntity.getMac()));
		loginTimeLabel.setText(ObjectUtils.getObjString(DateUtils.getTimestampFormat(authLoginRecordEntity.getLoginTime())));
		signTimeLabel.setText(ObjectUtils.getObjString(DateUtils.getTimestampFormat(expert.getSignTime())));
		expertNameLabel.getParent().layout();
		if(expertGrid.getSelectionCount() > 0){
			setExpertItemInfo(expertGrid.getSelection()[0], expert);
		}
		machineLabel.getParent().layout();
		compositeScrolle.layout();
		scrolledComposite.setMinSize(compositeScrolle.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	}
	
	/**
	 * @Description: 获得选中的评标专家
	 * @author guoyr
	 * @return 
	 */
	private Expert getSelectionExpert(){
		Expert selectExpert = null;
		if(expertGrid.getSelectionCount() >0){
			selectExpert = (Expert)expertGrid.getSelection()[0].getData("expert");
		}
		return selectExpert;
	}
	
	/**
	 * @Description: 应用到其他包件
	 * @author guoyr 
	 */
	private void applyToOtherPackAction(){
		if(null != expertList && expertList.size() > 0){
			ApplyToOtherTenderPackExpertDialog applyToOtherTenderPackDialog = new ApplyToOtherTenderPackExpertDialog(getShell(), tenderProjectEntity);
			applyToOtherTenderPackDialog.open();
		}else {
			MessageDialog.openShortMessage(Messages.Tips_please_add_expert);
		}
	}
	
	/**
	 * @Description: 设置组长
	 * @author guoyr 
	 */
	private void configLeaderAction(){
		if(configLeaderBtn.getEnabled()){
			
			boolean isInEvaluationProgress = tenderProjectService.isInProgress(tenderProjectEntity.getId(), null);
			if(isInEvaluationProgress){
				MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_enteredEvaluation);
				return;
			}
			Expert selectExpert = getSelectionExpert();
			if(null != selectExpert){
				GridItem selectItem = expertGrid.getSelection()[0];
				// 撤销组长
				if(ObjectUtils.getObjString(selectExpert.getIsLeader()).equals(ExpertEnum.LEADER_YES)){
					if (!MessageDialog.openConfirm(getShell(), "撤销组长提示", "撤销组长将会清空[" + selectExpert.getUser().getUserName() + "]作为组长评审的结果信息，是否确认撤销", "确认撤销组长", Messages.Button_cancel)) {
						return;
					}
					selectExpert.setIsLeader(ExpertEnum.LEADER_NO);
					if(expertService.updateAssignProperty(selectExpert, new String[]{"id","isLeader"})){
						evaluationStepService.deleteExpertLeaderEvaluationStepResult(tenderProjectEntity.getId());
						selectItem.setData("expert", selectExpert);
						selectItem.setText(3, selectExpert.getExpertTypeAndRole());
						isLeaderLabel.setText(ObjectUtils.getObjString(selectExpert.getExpertTypeAndRole()));
						configLeaderBtn.setText(Messages.SetLeader);
						isLeaderLabel.setImage(null);
					}
				}else {// 设为组长
//					// 先将原来的组长撤销
					for(GridItem gridItem : expertGrid.getItems()){
						Expert member = (Expert)gridItem.getData("expert");
						if(null != member && ObjectUtils.getObjString(member.getIsLeader()).equals(ExpertEnum.LEADER_YES)){
							if (!MessageDialog.openConfirm(getShell(), "更换组长提示", "更换组长将会清空[" + member.getUser().getUserName() + "]作为原组长评审的结果信息，是否确认更换", "确认更换组长", Messages.Button_cancel)) {
								return;
							}
							member.setIsLeader(ExpertEnum.LEADER_NO);
							if(expertService.updateAssignProperty(member, new String[]{"id","isLeader"})){
								evaluationStepService.deleteExpertLeaderEvaluationStepResult(tenderProjectEntity.getId());
								gridItem.setData("expert", member);
								gridItem.setText(3, member.getExpertTypeAndRole());
								isLeaderLabel.setText(ObjectUtils.getObjString(selectExpert.getExpertTypeAndRole()));
								break;
							}
						}
					}
					// 设置当前评标专家为组长
					selectExpert.setIsLeader(ExpertEnum.LEADER_YES);
					isLeaderLabel.setImage(imageResolver.loadImage(IconsActivator.PLUGIN_ID, "icons/loginTray.png"));
					if (expertService.updateAssignProperty(selectExpert, new String[] {"id" ,"isLeader" })) {
						selectItem.setData("expert", selectExpert);
						isLeaderLabel.setText(ObjectUtils.getObjString(selectExpert.getExpertTypeAndRole()));
						selectItem.setText(3, selectExpert.getExpertTypeAndRole());
						configLeaderBtn.setText(Messages.UndoLeader);
					}
				}
				// 通过直接设置或撤销组长时，将之前已推荐的记录清空
				expertService.updateVotesAndVotesNumByTenderId(0 ,0 ,tenderProjectEntity.getId());
			}
		}
	}
	
	/**
	 * @Description: 删除专家
	 * @author guoyr 
	 */
	private void delExpertAction(){
//		if(isInEvaluationProgress(delExpertBtn.getText())){return;}
		if(isInEvaluationProgress()){return;}
		if(delExpertBtn.getEnabled()){
			Expert selectExpert = getSelectionExpert();
			if(null != selectExpert && MessageDialog.openConfirm(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_deleteObj, ObjectUtils.getObjString(selectExpert.getUser().getUserName())), new String[]{Messages.Button_confirm, Messages.Button_cancel})){
				if(expertService.deleteExpert(tenderProjectEntity.getId(), selectExpert.getUserId())){
					
					int selectIndex = expertGrid.getSelectionIndex();
					expertGrid.getSelection()[0].dispose();
					if(expertGrid.getItemCount() > 0){
						if(expertGrid.getItemCount() > selectIndex){
							expertGrid.setSelection(selectIndex);
							for(int i = selectIndex; i < expertGrid.getItemCount(); i ++){
								GridItem gridItem = expertGrid.getItem(i);
								gridItem.setText(0, (i + 1) + "");
							}
						}else {
							expertGrid.setSelection(selectIndex - 1);
						}
					}
					selectExpertAction();
				}else {
					MessageDialog.openWarning(getShell(), Messages.Tips_deleteFail);
				}
			}
		}
	}
	
	/**
	 * @Description: 重置密码
	 * @author wangx
	 */
	private void reSetPassWordAction(){
		Expert selectExpert = getSelectionExpert();
		if(null != selectExpert){
			AuthUser user = selectExpert.getUser();
			ResetPasswordDialog resetPasswordDialog = new ResetPasswordDialog(getShell(), user.getUserName(), user.getId());
			resetPasswordDialog.open();
		}
	}
	
//	/**
//	 * @Description: 验证专家
//	 * @author wangxiang
//	 */
//	private void checkDownExpertAction(){
//		if(isInEvaluationProgress()){return;}
//		if(checkDownExpertBtn.getEnabled()){
//			final CheckExpertDialog dialog = new CheckExpertDialog(getShell(), tenderProjectEntity,new CallBack(){
//				public void callBackObject(Object obj) {
//					Expert selectEvalExpert = null != obj ? (Expert)obj : null;
//					if(null != selectEvalExpert){
//						if(ObjectUtils.equals(ExpertEnum.LEADER_YES, selectEvalExpert.getIsLeader())){
//							isExistExpertLeader = true;
//						}
//						GridItem gridItem = new GridItem(expertGrid, SWT.NONE);
//						gridItem.setText(0, ObjectUtils.getObjString(expertGrid.getItemCount()));
//						gridItem.setData("expert", selectEvalExpert);
//						expertGrid.setSelection(new GridItem[]{gridItem});
//					}
//					selectExpertAction();
//				}
//			
//			});
//			dialog.open();
//		}
//	}
	
	/**
	 * @Description: 新增专家
	 * @author guoyr 
	 */
	private void createExpertAction() {
		if (!addNewExpertBtn.getEnabled()) {
			return;
		}
		if (isInEvaluationProgress()) {
			return;
		}
		EditExpertDialog dialog = new EditExpertDialog(getShell(), tenderProjectEntity, null);
		dialog.setCallBack(new CallBack() {
			public void callBackObject(Object obj) {
				if (obj == null) {
					return;
				}
				Expert selectEvalExpert = (Expert) obj;
				if (ObjectUtils.equals(ExpertEnum.LEADER_YES, selectEvalExpert.getIsLeader())) {
					isExistExpertLeader = true;
				}
				GridItem gridItem = new GridItem(expertGrid, SWT.NONE);
				gridItem.setText(0, ObjectUtils.getObjString(expertGrid.getItemCount()));
				gridItem.setData("expert", selectEvalExpert);
				expertGrid.setSelection(new GridItem[] { gridItem });
				selectExpertAction();
			}
		});
		dialog.open();
	}
	
	/**
	 * @Description: 修改专家
	 * @author guoyr 
	 */
	private void updateExpertAction(){
//		if(isInEvaluationProgress()){return;}
		if(updateExpertBtn.getEnabled()){
			final Expert selectExpert = getSelectionExpert();
			if(null != selectExpert.getUser() && CommonEnum.TEMP_STATUS.equals(selectExpert.getUser().getUseStatus())){
				MessageDialog.openInformation(getShell(), "临时专家不能修改！请专家登陆完善信息");
				return;
			}
			final EditExpertDialog dialog = new EditExpertDialog(getShell(), tenderProjectEntity, selectExpert);
			dialog.setCallBack(new CallBack(){
				public void callBackObject(Object obj) {
					Expert selectEvalExpert = null != obj ? (Expert) obj : null;
					if(null != selectEvalExpert){
						GridItem selectItem = expertGrid.getSelection()[0];
						selectItem.setData("expert", selectEvalExpert);
					}
					selectExpertAction();
				}
			});
			dialog.open();
		}
	}
	
	/**
	 * @Description: 签到
	 * @author guoyr 
	 */
	private void signAction(){
		if(signBtn.getEnabled()){
			saveSignAction(ExpertEnum.SIGN, null);
		}
	}
	
	/**
	 * @Description: 回避
	 * @author guoyr 
	 */
	private void avoidAction(){
		if(button.getEnabled()){
			Expert selectExpert = getSelectionExpert();
			if(null != selectExpert && null != selectExpert.getUser()){
				if(ObjectUtils.equals(selectExpert.getIsLeader(), ExpertEnum.LEADER_YES)){
					MessageDialog.openInformation(getShell(), selectExpert.getUser().getUserName() + "是专家组长，不能回避，请先另指定组长！");
					return;
				}
				ExpertAvoidDialog dialog = new ExpertAvoidDialog(getShell(), selectExpert.getUser());
				dialog.open();
				if(dialog.isAvoidYes()){
					saveSignAction(ExpertEnum.AVOID, dialog.getAvoidReason());
				}
			}
				
		}
	}
	
	/**
	 * @Description: 保存签到
	 * @author guoyr
	 * @param signType
	 * @param signResult
	 * @return 
	 */
	private boolean saveSignAction(String signType, String signResult){
		// 验证是否有评标步骤，没有则跳转到"评标步骤管理"界面。
		boolean hasNode = evaluationStepService.isHasEvaluationStep(tenderProjectEntity.getId());
		if(!hasNode){
			MessageDialog.openWarning(getShell(), Messages.Tips_creatEvalStep);
			return false;
		}
		
		// 项目经理为专家签到操作
		Expert selectExpert = getSelectionExpert();
		if(null != selectExpert && null != selectExpert.getUser()){
			
			// 如果是签到，并且是已经回避的
			if(ObjectUtils.equals(signType, ExpertEnum.SIGN) && ObjectUtils.equals(selectExpert.getSignType(), ExpertEnum.AVOID)){
				if(!MessageDialog.openConfirm(getShell(), selectExpert.getUser().getUserName() +"已经回避，回避原因如下：\r\n"+ObjectUtils.getObjString(selectExpert.getSignResult())+"\r\n确认要重新进行签到吗？")){
					return false;
				}
			}
			GridItem selectItem = expertGrid.getSelection()[0];
			selectExpert.setSignType(signType);
			selectExpert.setSignResult(signResult);
			selectExpert.setSignTime(NowTimeUtils.getNowDate());
			if(expertService.updateAssignProperty(selectExpert, new String[]{"id","signType", "signResult", "signTime"})){
				selectItem.setData("expert", selectExpert);
				
				// 如果存在签到节点，则修改签到节点
				if(null != signEvaluationStep && ObjectUtils.equals(signEvaluationStep.getStepType(), EvaluationStepEnum.SIGIN)){
					
					ExpertEvaluationStep memberEvaluationStep = expertEvaluationStepService.getExpertEvaluationStep(tenderProjectEntity.getId(), signEvaluationStep.getId(), selectExpert.getUserId());
					if(null == memberEvaluationStep){
						memberEvaluationStep = new ExpertEvaluationStep();
						memberEvaluationStep.setStepId(signEvaluationStep.getId());
						memberEvaluationStep.setTenderId(tenderProjectEntity.getId());
						memberEvaluationStep.setUserId(selectExpert.getUserId());
						memberEvaluationStep.setStartTime(NowTimeUtils.getNowDate());
					}
					memberEvaluationStep.setStepStatus(CommonEnum.COMPLETE);
					expertEvaluationStepService.saveOrUpdateNoEmpty(memberEvaluationStep);
			 
//					queryWrapper.setWhereParam("signType", ExpertEnum.AVOID+","+ExpertEnum.SIGN, WhereParam.OP_NOT_IN);
					List<Object> objIdsList = expertService.getExpertIdListByTenderIdAndSignTypeisNull(tenderProjectEntity.getId());
					if(null == objIdsList || objIdsList.size() == 0){
						signEvaluationStep.setStepStatus(CommonEnum.COMPLETE);
						evaluationStepService.updateAssignProperty(signEvaluationStep, new String[]{"stepStatus"});
					}else if(!ObjectUtils.equals(signEvaluationStep.getStepStatus(), CommonEnum.COMPLETE) && !ObjectUtils.equals(signEvaluationStep.getStepStatus(), CommonEnum.IN_PROGRESS)){
						signEvaluationStep.setStepStatus(CommonEnum.IN_PROGRESS);
						evaluationStepService.updateAssignProperty(signEvaluationStep, new String[]{"stepStatus"});
					}
				}
				selectExpertAction();
				return true;
			}
		}
		return false;
	}
	
//	/**
//	 * @Description: 验证是否已经进入评分环节
//	 * @author guoyr
//	 * @param operatorName
//	 * @return 
//	 */
//	private boolean isInEvaluationProgress(String operatorName){
//		boolean isInEvaluationProgress = tenderProjectService.isInProgress(tenderProjectEntity.getId(), null);
//		isInEvaluationProgress = false;
//		if(isInEvaluationProgress){
//			MessageDialog.openWarning(getShell(), Messages.Dialog_warmTips, Messages.Tips_enteredEvaluation);
//		}
//		return isInEvaluationProgress;
//	}
	
	/**
	 * @Description: 右键菜单
	 * @author guoyr 
	 */
	private void mouseRightClickAction(){
		final EMenu gmenu = new EMenu(getShell());
		if(addNewExpertBtn.getVisible()){
			// 新增
			gmenu.addMenuItem(addNewExpertBtn);
		}
		if(updateExpertBtn.getVisible()){
			// 修改
			gmenu.addMenuItem(updateExpertBtn);
		}
		if(delExpertBtn.getVisible()){
			// 删除
			gmenu.addMenuItem(delExpertBtn);
		}
		
		if(MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority("DELETE_ALL"))){
			// 全部删除
			gmenu.addMenuItem(Messages.Button_deleteAll, ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/delete.png"), true, new EMenu.ClickListener() {
				public void click() { 
					delAllExpertAction();
				}
			});
		}
		
		if(MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority("RESET_PASSWORD"))){
			Expert selectExpert = getSelectionExpert();
			if(null != selectExpert && null != selectExpert.getUser()) {
				AuthUser user = selectExpert.getUser();
				if(UserEnum.USER_SOURCE_LOCAL.equals(user.getSource())){
					//重置密码
					gmenu.addMenuItem(Messages.PasswordReset, ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/reStart.png"), true, new EMenu.ClickListener() {
						public void click() { 
							reSetPassWordAction();
						}
					});
				}
			}
		}
		
		if(MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority("UPDATE_EXPERT"))){
			//更新专家
			gmenu.addMenuItem("更新专家", ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/download.png"), true, new EMenu.ClickListener() {
				public void click() { 
					updateExpertListAction();
				}
			});
		}
		
		gmenu.addSeparator();
		
		if(synchronousExpertBtn.getVisible()){
			// 下载
			gmenu.addMenuItem(synchronousExpertBtn);
		}
		
		if(MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority("IMPORT"))){
			// 导入
			gmenu.addMenuItem(importExpertBtn);
		}
		
		// 导出
		if(MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority("EXPORT"))){
			gmenu.addMenuItem(Messages.Button_export, ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/export.png"), true, new EMenu.ClickListener() {
				public void click() { 
					exportExpertAction();
				}
			});
		}
		gmenu.addSeparator();
		if(signBtn.getVisible()){
			// 签到
			gmenu.addMenuItem(signBtn);
		}
		if(configLeaderBtn.getVisible()){
			gmenu.addMenuItem(configLeaderBtn);
		}
		if(configCaBtn.getVisible()){
			gmenu.addMenuItem(configCaBtn);
		}
		if(button.getVisible()){
			// 回避
			gmenu.addMenuItem(button);
		}
		if(logOutBtn.getVisible()){
			// 注销
			gmenu.addMenuItem(logOutBtn);
		}
		if(add_temp_expert.getVisible()){
			//新增临时专家
			gmenu.addMenuItem(add_temp_expert);
		}
//		gmenu.addMenuItem("新增临时专家", ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/add.png"), true, new EMenu.ClickListener() {
//			public void click() { 
//				addTempExpert();
////				addTempExpert();
////				delAllExpertAction();
//			}
//		});
		
		gmenu.open();
	}
	
	/**
	 * @Description: 更新专家
	 * @author wangx
	 */
	private void updateExpertListAction(){
		Expert selectExpert = getSelectionExpert();
		if(synchronousExpertBtn.isEnabled()){
			//获得签到步骤
			List<EvaluationStep> evaluationStepList = evaluationStepService.getEvaluationStepListByType(tenderProjectEntity.getId(), EvaluationStepEnum.SIGIN);
			EvaluationStep signStep = null;
			if(null != evaluationStepList && evaluationStepList.size() > 0) {
				signStep = evaluationStepList.get(0);
			}
			if(null != signStep) {
				ExpertEvaluationStep expertEvaluationStep = expertEvaluationStepService.getExpertEvaluationStep(tenderProjectEntity.getId(),signStep.getId(),selectExpert.getUserId());
				if(CommonEnum.COMPLETE.equals(expertEvaluationStep.getStepStatus())) {
					MessageDialog.openInformation(getShell(), "当前专家已签到，不能修改！");
					return;
				}
			}
			
//			if(isInEvaluationProgress()){return;}
		}
		
		ExpertLibrary expertLibrary = new ExpertLibrary();
		TransactionServerService transactionServerService = new TransactionServerService();
		TransactionServer transactionServer = transactionServerService.findById(tenderProjectEntity.getTransactionServerId());
		if(null != transactionServer){
			expertLibrary.setExpertLibAddress(transactionServer.getServerAddress());
		} else {
			MessageDialog.openWarning(getShell(), "请配置需下载的服务器地址！");
			return;
		}
		
		if(null != selectExpert){
			UpdateExpertDialog   dialog = new UpdateExpertDialog(getShell(),tenderProjectEntity, expertLibrary,selectExpert,new CallBack(){
				public void after() {
					refreshAllExpert();
				}
			});
			dialog.open();
		}
	}
	
	/**
	 * @Description: 导入专家
	 * @author guoyr 
	 */
	private void importExpertFromProjectAction() {
		if(importExpertBtn.isEnabled()){
			if(isInEvaluationProgress()){return;}
			ImportExpertFromTenderProjectDialog importExpertFromTenderProjectDialog = new ImportExpertFromTenderProjectDialog(getShell(), tenderProjectEntity);
			importExpertFromTenderProjectDialog.open();
			refreshAllExpert();
		}
	}
	
	/**
	 * @Description: 验证专家
	 * @author wangxiang
	 */
	private void checkDownExpertAction(){
		if(isInEvaluationProgress()){return;}
		if(checkDownExpertBtn.getEnabled()){
			final CheckExpertDialog dialog = new CheckExpertDialog(getShell(), tenderProjectEntity,new CallBack(){
				public void callBack(final boolean isExistExpert, final Object expert) {
					Display.getDefault().syncExec(new Runnable(){
						public void run(){
							if(!expertGrid.isDisposed()){
								Expert selectEvalExpert = null != expert ? (Expert)expert : null;
								if(null != selectEvalExpert){
									if(isExistExpert){
										refreshAllExpert();
									}else {
										if(ObjectUtils.equals(ExpertEnum.LEADER_YES, selectEvalExpert.getIsLeader())){
											isExistExpertLeader = true;
										}
										GridItem gridItem = new GridItem(expertGrid, SWT.NONE);
										gridItem.setText(0, ObjectUtils.getObjString(expertGrid.getItemCount()));
										gridItem.setData("expert", selectEvalExpert);
										expertGrid.setSelection(new GridItem[]{gridItem});
									}
									MessageDialog.openShortMessage(Messages.Tips_operateSuccess);
								}else {
									MessageDialog.openShortMessage(Messages.Tips_operateFail);
								}
								selectExpertAction();
							}
						}
					});
				}
				
			});
			dialog.open();
		}
	}	
	
	/**
	 * @Description: 下载专家
	 * @author guoyr 
	 */
	private void synchronousExpertAction() {
		if(synchronousExpertBtn.isEnabled()){
			if(isInEvaluationProgress()){return;}
			
			//京能要求上传开标结果才能下载专家
			if(MenuFunction.HIDE.equals(menuFunctionUtils.getAuthority(MenuFunctionEnum.HAS_UPLOAD_OPEN_RESULT))){
				if(!CommonEnum.COMPLETE.equals(tenderProjectEntity.getUploadOpeningResultStatus())){
					MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, "请上传开标结果后再下载专家！");
					return;
				}
			}
			
//			EOp op = new EOp(getShell());
//			op.addOpItem("从平台下载", ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/download.png"), null != tenderProjectEntity.getServerId() && tenderProjectEntity.getServerId().length() > 0, new EOp.ClickListener() {
//				public void click() {
					downExpertFormProject();
//				}
//			});
//			op.addOpItem("从专家库下载", ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/download.png"), true, new EOp.ClickListener() {
//				public void click() {
//					downExpertFormExpertLib();
//				}
//			});
			
//			op.setForeground(SWTResourceManager.getColor(80, 80, 80));
//			op.setBackground(SWTResourceManager.getColor(60, 138, 226));
//			op.setAlpha(200);
//			op.open(synchronousExpertBtn);
		
			
		}
	}
	
	/**
	 * @Description: 项目专家
	 * @author guoyr
	 * @param transactionServer 
	 */
	private void downExpertFormProject(){
		ExpertLibrary expertLibrary = new ExpertLibrary();
		TransactionServer transactionServer = HttpUtils.getTransactionServer(tenderProjectEntity.getTransactionServerId());
		if(null != transactionServer){
			expertLibrary.setExpertLibAddress(transactionServer.getServerAddress());
			downLoadExpertAtion(expertLibrary);
		} else {
			MessageDialog.openWarning(getShell(), "请配置需下载的服务器地址！");
		}
//		transactionServer.set
	}
	
	/**
	 * @Description: 从专家库下载
	 * @author guoyr 
	 */
//	private void downExpertFormExpertLib(){
//		SelectExpertLibraryDialog expertLibDialog = new SelectExpertLibraryDialog(getParent().getShell(), tenderProjectEntity.getExpertLibId());
//		expertLibDialog.setTitle("请选择专家库");
//		expertLibDialog.open();
//		ExpertLibrary expertLibrary = expertLibDialog.getExpertLibrary();
//		if(null != expertLibrary){
//			downLoadExpertAtion(expertLibrary);			
//		}
//		
//	}
	
	/**
	 * @Description: 从平台下载项目专家
	 * @author guoyr
	 * @param expertLibrary 
	 */
	private void downLoadExpertAtion(ExpertLibrary expertLibrary){
		DownloadExpertAction downloadExpertAction = new DownloadExpertAction();
		downloadExpertAction.setParent(this);
		downloadExpertAction.setTenderProject(tenderProjectEntity);
		downloadExpertAction.setData("expertLibrary", expertLibrary);
		downloadExpertAction.setCallBack(new CallBack(){
			public void after() {
				refreshAllExpert();
			}
		});
		downloadExpertAction.run();
	}
	/**
	 * @Description: 绑定CA
	 */
	private void configCaAction(){
		if(configCaBtn.isEnabled()){
			Expert expert = getSelectionExpert();
			if(null != expert && null != expert.getUser()){
				CABindingDialog dialog = new CABindingDialog(getShell(), expert.getUser());
				dialog.open();
			}
		}
	}
	
	/**
	 * @Description: 刷新显示专家绑定CA控件
	 * @param user
	 */
	private void refreshExpertBindCALabel(AuthUser user){
		if(null != caContentComposite && !caContentComposite.isDisposed()){
			for(Control control : caContentComposite.getChildren()){
				control.dispose();
			}
		}
		String caKeys = user.getBindingCa();
//		caKeys = "北京CA_bj;安徽CA_AH";
		if(null != caKeys && StringUtils.isNotEmpty(caKeys)){
			for(String str : caKeys.split(";")){
				if(null != str && StringUtils.isNotEmpty(str)){
					CLabel caLabel = new CLabel(caContentComposite, SWT.NONE);
					caLabel.setText(null != str.split("_")[0] ? str.split("_")[0] : "");
					caLabel.setData("caType", str);
				}
			}
		}else {
			ELabel caLabel = new ELabel(caContentComposite, SWT.NONE);
			caLabel.setText(Messages.Unbounded +"CA");
		}
		caContentComposite.layout();
		caContentComposite.getParent().layout();
	}
	
	/**
	 * @Description: 注销专家
	 * @author guoyr
	 */
	private void loginOutExpert(){
		if(logOutBtn.getEnabled() && null != logOutBtn.getData("loginRecord")){
			AuthLoginRecordEntity authLoginRecordEntity = (AuthLoginRecordEntity)logOutBtn.getData("loginRecord");
			if(loginRecordService.deleteById(authLoginRecordEntity.getId())){
				loginRecordMap.remove(authLoginRecordEntity.getUserId());
				selectExpertAction();
			}
			
		}
	}
	
	/**
	 * @Description: 导出专家
	 * @author guoyr
	 */
	private void exportExpertAction(){
		if(expertGrid.getItemCount() > 0){
			String projName = "["+tenderProjectEntity.getTenderNo()+"]" + tenderProjectEntity.getTenderName()+"_"+Messages.Expert;
			String saveFilePath = FileDialogUtils.getFileSavePath(projName, Messages.Button_export, new String[]{"*.xml"}, new String[]{"XML(*.xml)"});
			if(StringUtils.isNotEmpty(saveFilePath)){
				MessageViewDialog dialog = new MessageViewDialog(getShell(), -1);
				new ExporExpertThread(tenderProjectEntity, saveFilePath, dialog.getCallBack()).start();
				dialog.setTitle(Messages.Button_export);
				dialog.open();
			}
		}else {
			MessageDialog.openInformation(getShell(), Messages.Tips_operateFail);
		}
	}
	
	/**
	 * @Description: 删除专家
	 * @author guoyr
	 */
	private void delAllExpertAction(){
		if(isInEvaluationProgress()){
			return;
		}
		
		if(MessageDialog.openConfirm(getShell(), "确定要删除全部专家吗？")){
			if(expertService.deleteAllExperts(tenderProjectEntity.getId())){
				expertGrid.removeAll();
			}
		}
		selectExpertAction();
	}
	/**
	 * @Description: 点击添加临时专家按钮事件
	 * @author guoyr 
	 */
	private void addTempExpert(){
		if(isInEvaluationProgress()){
			return;
		}
		AddTempExpertNumDialog dialog = new AddTempExpertNumDialog(getShell(), new AddTempExperCallBack() {
			@Override
			public void addTempExper(int number, String password) {
				addTempExpert(number, password);
			}
		});
		dialog.open();
	}
	/**
	 * @Description: 新增临时专家
	 * @author guoyr 
	 */
	private void addTempExpert(int number, String password){
		String[] nowDates = DateUtils.getFormat(NowTimeUtils.getNowDate(), "MMddHHmm-ss").split("-");
		int millis = ObjectUtils.getIntValue(nowDates[1], 0);
		if (millis < 10) {
			millis *= 100;
		} else {
			millis *= 10;
		}
		for (int i = 0; i < number; i++) {
			int num = i + 1;
			AuthUser user = new AuthUser();
			user.setId(UuidUtils.getUUID());
			user.setGender(UserEnum.MALE);
			user.setUserType(UserEnum.EXPERT);
			user.setUserAccount(nowDates[0] + (millis + num));
			user.setUserName(Messages.Expert + num);
			user.setSource(UserEnum.USER_SOURCE_LOCAL);
			if(StringUtils.hasLength(password)) {
				user.setUserPassword(MD5Utils.getMD5String(password));
			}else {
				user.setUserPassword(MD5Utils.getMD5String(PropertiesUtils.getProperty(ConfigConstants.EXPERT_DEFAULT_PASSWORD, "123456")));
			}
			user.setUseStatus(CommonEnum.TEMP_STATUS);
			saveTemExper(user, getUserRoleList(user));
		}
		refreshAllExpert();
	}

	/**
	 * @Description: 获取用户权限列表
	 * @author chenxw
	 * @param user
	 * @return 
	 */
	private List<AuthUserRole> getUserRoleList(AuthUser user) {
		List<AuthUserRole> userRoleList = new ArrayList<AuthUserRole>();
		RoleService roleService = new RoleService();
		List<AuthRole> roleList = roleService.getRoleListByRoleCode(new String[] { UserEnum.ROLE_TYPE_EXPERT });
		if (null != roleList && roleList.size() > 0) {
			for (AuthRole role : roleList) {
				AuthUserRole userRole = new AuthUserRole();
				userRole.setId(UuidUtils.getUUID());
				userRole.setRoleId(role.getId());
				userRole.setUserId(user.getId());
				userRole.setCreateTime(NowTimeUtils.getNowDate());
				userRole.setCreateUserId(Constants.USER.getId());
				userRoleList.add(userRole);
			}
		}
		return userRoleList;
	}
	
	/**
	 * @Description: 保存临时专家
	 * @author chenxw
	 * @param user
	 * @param userRoleList 
	 */
	private void saveTemExper(AuthUser user, List<AuthUserRole> userRoleList) {
		Expert expert = new Expert();
		expert.setId(UuidUtils.getUUID());
		expert.setUser(user);
		expert.setTenderId(tenderProjectEntity.getId());
		if (null != tenderProjectEntity.getParentId() && !"".equals(tenderProjectEntity.getParentId())) {
			expert.setProjectId(tenderProjectEntity.getParentId());
		} else {
			expert.setProjectId(tenderProjectEntity.getId());
		}
		expert.setExpertType(ExpertEnum.EXPERT);
		expert.setUserId(user.getId());
		expert.setCreateTime(NowTimeUtils.getNowDate());
		expert.setCreateUserId(Constants.USER.getId());
		expert.setIsLeader(ExpertEnum.LEADER_NO);
		expertService.saveTemExpert(expert, userRoleList, user);
	}

	/**
	 * @Description: 验证是否已经进入评标环节
	 * @author guoyr
	 * @return 
	 */
	private boolean isInEvaluationProgress(){
		boolean isInEvaluationProgress = tenderProjectService.isInProgress(tenderProjectEntity.getId(), null);
		if(isInEvaluationProgress){
			MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_enteredEvaluation);
		}
		return isInEvaluationProgress;
	}
	
	
	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
