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

import java.text.MessageFormat;
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.swt.SWT;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.utils.GridUtils;
import org.eclipse.swt.core.widgets.EButton;
import org.eclipse.swt.core.widgets.EDialog;
import org.eclipse.swt.core.widgets.ELink;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.core.widgets.ImageButton;
import org.eclipse.swt.core.widgets.RectangleRadioButton;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

import com.gx.obe.ColorConstants;
import com.gx.obe.business.entity.Worker;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.common.widget.button.ImageRaido;
import com.gx.obe.common.widget.utils.ImageRaidoUtils;
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.evaluation.step.inter.IEvaluationGroup;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.CollectionUtils;
import com.gx.obe.util.utils.ScreenUtils;
import com.gx.obe.web.entity.auth.AuthUser;
import com.gx.obe.web.entity.expert.Expert;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.service.UserService;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

public class EvaluationGroupDialog extends EDialog {
	
	private final String TYPE_EXPERT = "01";
	private final String TYPE_WORKER = "02";
	private TenderProjectEntity tenderProject;
	private String evalBidType;
	private Composite evalBidTypeComposite;
	private Grid supplierGrid;
	private final IEvaluationGroup evaluationGroup;
	private StackLayout stackLayout = new StackLayout();
	private Composite expertComposite;
	private Grid expertGrid;
	private Composite workerComposite;
	private Grid workerGrid;
	private Composite buttonComposite;
	private Composite userComposite;
	private ImageButton curButton;
	private CLabel thirdTip;
	private CLabel secondTip;
	private CLabel firstTip;
	private StyledText tipsSupplierLabel;
	private StyleRange tipsStyleRange;
	private String SUPPLIER_NAME;
	private UserService userService = new UserService();
	/** 
	 * @author chenxw
	 * @param parentShell
	 * @param tenderProject
	 * @param evalBidType
	 * @param evaluationGroup 
	 */
	public EvaluationGroupDialog(Shell parentShell, TenderProjectEntity tenderProject, String evalBidType, IEvaluationGroup evaluationGroup) {
		super(parentShell);
		this.tenderProject = tenderProject;
		this.evaluationGroup = evaluationGroup;
		this.evalBidType = evalBidType;
	}
	
	/**
	 * Create contents of the dialog.
	 * 
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		container.setLayout(new GridLayout(1, false));
		container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		Composite composite_5 = new Composite(container, SWT.NONE);
		composite_5.setLayout(new GridLayout(3, false));
		composite_5.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
		
//		
//		ESepator topSep = new ESepator(container, SWT.NONE);
//		topSep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
//		topSep.setBackground(ColorConstants.SKIN_BG);
//		topSep.setLineStyle(SWT.LINE_DOT);
//		topSep.setLineWidth(3);
		
		Composite composite_2 = new Composite(container, SWT.NONE);
		composite_2.setBackground(ColorConstants.BORDER_LINE_COLOR);
		GridLayout gl_composite_2 = new GridLayout(1, false);
		gl_composite_2.verticalSpacing = 0;
		gl_composite_2.horizontalSpacing = 0;
		gl_composite_2.marginHeight = 1;
		gl_composite_2.marginWidth = 1;
		composite_2.setLayout(gl_composite_2);
		GridData gd_composite_2 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_composite_2.heightHint = 200;
		composite_2.setLayoutData(gd_composite_2);
		
		Composite composite_8 = new Composite(composite_2, SWT.NONE);
		composite_8.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_8.setBackgroundMode(SWT.INHERIT_FORCE);
		GridLayout gl_composite_8 = new GridLayout(1, false);
		gl_composite_8.marginHeight = 0;
		gl_composite_8.marginWidth = 0;
		gl_composite_8.verticalSpacing = 0;
		composite_8.setLayout(gl_composite_8);
		composite_8.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		Composite composite_7 = new Composite(composite_8, SWT.NONE);
		GridLayout gl_composite_7 = new GridLayout(5, false);
		gl_composite_7.marginHeight = 0;
		gl_composite_7.verticalSpacing = 0;
		gl_composite_7.horizontalSpacing = 0;
		composite_7.setLayout(gl_composite_7);
		composite_7.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		secondTip = new CLabel(composite_7, SWT.NONE);
		secondTip.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		secondTip.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		secondTip.setText("选择待评议的供应商");
		secondTip.setForeground(ColorConstants.FONT_BLUE_COLOR);
		secondTip.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/number_1.png"));
		
		ELink link = new ELink(composite_7, SWT.NONE);
		link.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				selectSupplierAction(true);
			}
		});
		link.setText(Messages.Button_selectAll);
		link.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/select_all.png"));
		
		ELink link_1 = new ELink(composite_7, SWT.NONE);
		link_1.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				selectSupplierAction(false);
			}
		});
		link_1.setText(Messages.Button_selectInvert);
		link_1.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/disselect_all.png"));
		
		ELink link_2 = new ELink(composite_7, SWT.NONE);
		link_2.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				GridUtils.checkAll(supplierGrid, 1, false);
			}
		});
		link_2.setText(Messages.Button_deselected);
		link_2.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/clear.png"));
		
		ESepator supplierSep = new ESepator(composite_8, SWT.NONE);
		supplierSep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		supplierSep.setBackground(ColorConstants.BORDER_LINE_COLOR);
		
		supplierGrid = new Grid(composite_8, SWT.V_SCROLL);
		supplierGrid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		supplierGrid.setHeaderVisible(true);
		supplierGrid.setAutoHeight(true);
		supplierGrid.setAutoWidth(true);
		supplierGrid.setItemHeight(Constants.ROW_HIGHT);
		
		GridColumn indexColumn = new GridColumn(supplierGrid, SWT.CENTER);
		indexColumn.setText(Messages.Num);
		indexColumn.setWidth(50);
		indexColumn.setMaxmumWidth(50);
		
		GridColumn gridColumn = new GridColumn(supplierGrid, SWT.CHECK);
		gridColumn.setText(MessageFormat.format(Messages.NameFormat, evaluationGroup.getSupplierName()));
		gridColumn.setWidth(300);
		gridColumn.setWordWrap(true);
		
		GridColumn gridColumn_1 = new GridColumn(supplierGrid, SWT.CENTER);
		gridColumn_1.setText(Messages.Business);
		gridColumn_1.setWidth(50);
		
		GridColumn gridColumn_2 = new GridColumn(supplierGrid, SWT.CENTER);
		gridColumn_2.setText(Messages.Technology);
		gridColumn_2.setWidth(50);
		
		GridColumn gridColumn_3 = new GridColumn(supplierGrid, SWT.CENTER);
		gridColumn_3.setText(Messages.Economic);
		gridColumn_3.setWidth(50);
		
		Composite evalBidTypeParentComposite = new Composite(container, SWT.NONE);
		GridLayout gl_evalBidTypeParentComposite = new GridLayout(2, false);
		gl_evalBidTypeParentComposite.marginHeight = 0;
		evalBidTypeParentComposite.setLayout(gl_evalBidTypeParentComposite);
		evalBidTypeParentComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		firstTip = new CLabel(evalBidTypeParentComposite, SWT.NONE);
		firstTip.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		firstTip.setText("选择评议分类 ");
		firstTip.setForeground(ColorConstants.FONT_BLUE_COLOR);
		firstTip.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/number_2.png"));
		firstTip.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		
		evalBidTypeComposite = new Composite(evalBidTypeParentComposite, SWT.NONE);
		GridLayout gl_evalBidTypeComposite = new GridLayout(4, false);
		gl_evalBidTypeComposite.marginHeight = 0;
		evalBidTypeComposite.setLayout(gl_evalBidTypeComposite);
		evalBidTypeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		CLabel firstTitle = new CLabel(evalBidTypeComposite, SWT.NONE);
		firstTitle.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		firstTitle.setForeground(ColorConstants.FONT_BLUE_COLOR);
		firstTitle.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/number_3.png"));
		
		Button button = new Button(evalBidTypeComposite, SWT.RADIO);
		button.setText(Messages.Business);
		button.setData("evalBidType", EvaluationFactorEnum.EVAL_BID_BUS);
		button.setForeground(ColorConstants.FONT_BLUE_COLOR);
		button.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		
		Button button_1 = new Button(evalBidTypeComposite, SWT.RADIO);
		button_1.setText(Messages.Technology);
		button_1.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		button_1.setForeground(ColorConstants.FONT_BLUE_COLOR);
		button_1.setData("evalBidType", EvaluationFactorEnum.EVAL_BID_TEC);
		
		Button priceButton = new Button(evalBidTypeComposite, SWT.RADIO);
		priceButton.setForeground(ColorConstants.FONT_BLUE_COLOR);
		priceButton.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		priceButton.setText(Messages.Economic);
		priceButton.setData("evalBidType", EvaluationFactorEnum.EVAL_BID_PRICE);
		
		Composite composite_3 = new Composite(container, SWT.NONE);
		composite_3.setBackground(ColorConstants.BORDER_LINE_COLOR);
		GridLayout gl_composite_3 = new GridLayout(1, false);
		gl_composite_3.verticalSpacing = 0;
		gl_composite_3.marginHeight = 1;
		gl_composite_3.marginWidth = 1;
		composite_3.setLayout(gl_composite_3);
		GridData gd_composite_3 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_composite_3.heightHint = 150;
		composite_3.setLayoutData(gd_composite_3);
		
		buttonComposite = new Composite(composite_3, SWT.NONE);
		buttonComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		GridLayout gl_buttonComposite = new GridLayout(3, false);
		gl_buttonComposite.marginHeight = 0;
		buttonComposite.setLayout(gl_buttonComposite);
		buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		thirdTip = new CLabel(buttonComposite, SWT.NONE);
		thirdTip.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		thirdTip.setText(Messages.Button_assignWorker);
		thirdTip.setForeground(ColorConstants.FONT_BLUE_COLOR);
		thirdTip.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/number_3.png"));
		thirdTip.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		
		ESepator workerSep = new ESepator(composite_3, SWT.NONE);
		workerSep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		workerSep.setBackground(ColorConstants.BORDER_LINE_COLOR);
		
		userComposite = new Composite(composite_3, SWT.NONE);
		userComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		userComposite.setLayout(stackLayout);
		userComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		expertComposite = new Composite(userComposite, SWT.NONE);
		GridLayout gl_expertComposite = new GridLayout(1, false);
		gl_expertComposite.marginWidth = 0;
		gl_expertComposite.marginHeight = 0;
		expertComposite.setLayout(gl_expertComposite);
		
		expertGrid = new Grid(expertComposite, SWT.V_SCROLL);
		expertGrid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		expertGrid.setHeaderVisible(true);
		expertGrid.setAutoHeight(true);
		expertGrid.setAutoWidth(true);
		expertGrid.setItemHeight(Constants.ROW_HIGHT);
		
		GridColumn expertIndexColumn = new GridColumn(expertGrid, SWT.CENTER);
		expertIndexColumn.setText(Messages.Num);
		expertIndexColumn.setWidth(50);
		
		GridColumn gridColumn_4 = new GridColumn(expertGrid, SWT.CENTER);
		gridColumn_4.setText(Messages.FullName);
		gridColumn_4.setWidth(150);
		
		GridColumn gridColumn_5 = new GridColumn(expertGrid, SWT.CENTER);
		gridColumn_5.setText(Messages.ExpertType);
		gridColumn_5.setWidth(200);
		
		GridColumn gridColumn_7 = new GridColumn(expertGrid, SWT.NONE);
		gridColumn_7.setWidth(500);
		
		workerComposite = new Composite(userComposite, SWT.NONE);
		GridLayout gl_workerComposite = new GridLayout(1, false);
		gl_workerComposite.marginHeight = 0;
		gl_workerComposite.marginWidth = 0;
		workerComposite.setLayout(gl_workerComposite);
		
		workerGrid = new Grid(workerComposite, SWT.V_SCROLL);
		workerGrid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		workerGrid.setHeaderVisible(true);
		workerGrid.setAutoHeight(true);
		workerGrid.setAutoWidth(true);
		workerGrid.setItemHeight(Constants.ROW_HIGHT);
		
		GridColumn workerIndexColumn = new GridColumn(workerGrid, SWT.CENTER);
		workerIndexColumn.setText(Messages.Num);
		workerIndexColumn.setWidth(50);
		
		GridColumn gridColumn_6 = new GridColumn(workerGrid, SWT.CENTER);
		gridColumn_6.setText(Messages.FullName);
		gridColumn_6.setWidth(150);
		
		GridColumn gridColumn_8 = new GridColumn(workerGrid, SWT.NONE);
		gridColumn_8.setWidth(500);
		
		Composite composite_4 = new Composite(container, SWT.NONE);
		composite_4.setLayout(new GridLayout(5, false));
		composite_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		tipsSupplierLabel = new StyledText(composite_4, SWT.READ_ONLY);
		tipsSupplierLabel.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.NORMAL));
		tipsSupplierLabel.setForeground(ColorConstants.FONT_BLACK_COLOR);
		tipsSupplierLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		tipsSupplierLabel.setText("");
		
		ELink button_3 = new ELink(composite_4, SWT.NONE);
		button_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		button_3.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				confirmAction();
			}
		});
		button_3.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		button_3.setForeground(ColorConstants.FONT_BLUE_COLOR);
		button_3.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/ok.png"));
		button_3.setText(Messages.Button_confirmAssign);
		
		EButton button_close = new EButton(composite_4, SWT.NONE);
		button_close.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				getShell().close();
			}
		});
		button_close.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		button_close.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		button_close.setText(Messages.Button_close);
		
		init();
		return container;
	}
	
	/**
	 * @Description: 初始化
	 * @author chenxw
	 */
	private void init() {
//		expertGrid.setAutoWidth(false);
//		workerGrid.setAutoWidth(false);
		SUPPLIER_NAME = com.gx.obe.components.core.I18N.getString(I18NEnum.SUPPLIERNAME, tenderProject.getTenderType());
		secondTip.setText(MessageFormat.format(Messages.Button_selectFormat, SUPPLIER_NAME));
		firstTip.setText(MessageFormat.format(Messages.Button_selectFormat, Messages.EvalType));
		thirdTip.setText(Messages.Button_assignWorker);
		
		for (Control control : evalBidTypeComposite.getChildren()) {
			control.dispose();
		}
		ImageButton busBtn = createBidTypeBtn(EvaluationFactorEnum.EVAL_BID_BUS, Messages.Business);
		ImageButton tecBtn = createBidTypeBtn(EvaluationFactorEnum.EVAL_BID_TEC, Messages.Technology);
		ImageButton pricBtn = createBidTypeBtn(EvaluationFactorEnum.EVAL_BID_PRICE, Messages.Economic);
		
		busBtn.setEnabled(false);
		tecBtn.setEnabled(false);
		pricBtn.setEnabled(false);
		ImageButton curRadioBtn = null;
		if (EvaluationFactorEnum.EVAL_BID_DETAIL.equals(evalBidType)) {
			curRadioBtn = busBtn;
			busBtn.setEnabled(true);
			tecBtn.setEnabled(true);
		} else if (EvaluationFactorEnum.EVAL_BID_BUS.equals(evalBidType)) {
			curRadioBtn = busBtn;
			busBtn.setEnabled(true);
		} else if (EvaluationFactorEnum.EVAL_BID_TEC.equals(evalBidType)) {
			curRadioBtn = tecBtn;
			tecBtn.setEnabled(true);
		} else if (EvaluationFactorEnum.EVAL_BID_PRICE.equals(evalBidType)) {
			curRadioBtn = pricBtn;
			pricBtn.setEnabled(true);
		}
		
		evaluationGroup.initEvaluationGroupGrid(supplierGrid);
		evaluationGroup.refreshEvaluationGroupGrid(supplierGrid);
		
		curButton = createImageButton(Messages.Expert, TYPE_EXPERT, expertComposite);
		createImageButton(Messages.Worker, TYPE_WORKER, workerComposite);
		
//		supplierGrid.addListener(SWT.Selection, new GridCheckedListener(1,true));
		supplierGrid.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				// 选中了复选框事件
				if (event.detail == SWT.CHECK) {} else {
					GridItem item = (GridItem) event.item;
					item.setChecked(1, !item.getChecked(1));
				}
				showTips();
			}
			
		});
		expertGrid.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				showTips();
			}
			
		});
		workerGrid.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				showTips();
			}
			
		});
		
		refreshExpertGrid();
		refreshWorkerGrid();
		
		if (null != curRadioBtn) {
			curRadioBtn.notifyListeners(SWT.MouseUp, null);
		}
		curButton.notifyListeners(SWT.MouseUp, null);
	}
	
	private ImageButton createBidTypeBtn(final String evalBidType, String evlBidTypeName) {
		final ImageRaido imageButton = new ImageRaido(evalBidTypeComposite, SWT.NONE);
		imageButton.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		imageButton.setImageSize(24);
		imageButton.setData("evalBidType", evalBidType);
		imageButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
		imageButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				if (!imageButton.getEnabled()) return;
				imageButton.setSelection(true);
				boolean isPrice = evalBidType.equals(EvaluationFactorEnum.EVAL_BID_PRICE);
				for (GridItem gridItem : supplierGrid.getItems()) {
					if (isPrice) {
						gridItem.setChecked(1, true);
						gridItem.setCheckable(1, false);
					} else {
						gridItem.setCheckable(1, true);
					}
				}
				showTips();
			}
		});
		imageButton.setText(evlBidTypeName);
		return imageButton;
	}
	
	/**
	 * @Description: 刷新专家列表
	 * @author chenxw
	 */
	private void refreshExpertGrid() {
		List<Expert> expertList = evaluationGroup.getExpertList();
		if (CollectionUtils.isNull(expertList)) {
			return;
		}
		int index = 1;
		for (Expert expert : expertList) {
			GridItem gridItem = new GridItem(expertGrid, SWT.NONE);
			gridItem.setText(0, (index++) + "");
			gridItem.setText(1, expert.getUser().getUserName());
			gridItem.setText(2, expert.getExpertTypeCN());
			gridItem.setData("userId", expert.getUser().getId());
		}
	}
	
	/**
	 * @Description: 刷新工作人员列表
	 * @author chenxw
	 */
	private void refreshWorkerGrid() {
		List<Worker> workerList = evaluationGroup.getWorkerList();
		if (CollectionUtils.isNull(workerList)) {
			return;
		}
		int index = 1;
		for (Worker worker : workerList) {
			GridItem gridItem = new GridItem(workerGrid, SWT.NONE);
			gridItem.setText(0, (index++) + "");
			gridItem.setText(1, worker.getUser().getUserName());
			gridItem.setData("userId", worker.getUser().getId());
		}
	}
	
	/**
	 * @Description: 确认事件
	 * @author chenxw
	 */
	private void confirmAction() {
		List<String> supplierIdList = GridUtils.getCheckedValues(supplierGrid, 1, "supplierId");
		if (null == supplierIdList || supplierIdList.size() == 0) {
			MessageDialog.openShortMessage(MessageFormat.format(Messages.Tips_pleaseSelect, SUPPLIER_NAME));
			return;
		}
		ImageRaido radioImage = ImageRaidoUtils.getSelectionRadio(evalBidTypeComposite);
		String evalBidType = (String) radioImage.getData("evalBidType");
		
		Grid grid = null;
		boolean isExpert = false;
		if (TYPE_EXPERT.equals(curButton.getData())) {
			grid = expertGrid;
			isExpert = true;
		} else if (TYPE_WORKER.equals(curButton.getData())) {
			grid = workerGrid;
		}
		
		String userId = null;
		if (null != grid && grid.getSelectionCount() > 0) {
			userId = (String) grid.getSelection()[0].getData("userId");
		}
		if (null == userId) {
			firstTip.setText(MessageFormat.format(Messages.Button_selectFormat, Messages.Worker));
			return;
		}else if(isExpert) {
			AuthUser user = userService.findById(userId);
			if(null != user && CommonEnum.TEMP_STATUS.equals(user.getUseStatus())) {
				MessageDialog.openInformation(getShell(), "当前用户为临时用户，请完善用户信息或重新选择！");
				return;	
			}
		}
		evaluationGroup.putAllGroupTypeMapSupplierMap(supplierIdList, evalBidType, userId);
		evaluationGroup.refreshEvaluationGroupGrid(supplierGrid);
		MessageDialog.openShortMessage(Messages.Tips_operateSuccess);
	}
	
	/**
	 * @Description: 获得按钮
	 * @author chenxw
	 * @param string
	 * @param composite
	 * @return
	 */
	private ImageButton createImageButton(String name, String data, final Composite composite) {
		final RectangleRadioButton button = new RectangleRadioButton(buttonComposite, SWT.NONE);
		button.setText(name);
		button.setData(data);
		button.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				curButton.setSelection(false);
				curButton = button;
				curButton.setSelection(true);
				stackLayout.topControl = composite;
				userComposite.layout();
				showTips();
			}
		});
		return button;
	}
	
	/**
	 * @Description: 全选、反选
	 * @author chenxw
	 * @param isSelect
	 */
	private void selectSupplierAction(boolean isSelect) {
		if (isSelect) {
			GridUtils.checkAll(supplierGrid, 1, true);
		} else {
			GridUtils.checkAllBack(supplierGrid, 1);
		}
		showTips();
	}
	
	private void showTips() {
		
		List<String> supplierIdList = GridUtils.getCheckedValues(supplierGrid, 1, "supplierId");
		
		ImageRaido radioImage = ImageRaidoUtils.getSelectionRadio(evalBidTypeComposite);
		String selectSize = "    ";
		if(null != supplierIdList && supplierIdList.size() > 0){
			selectSize = supplierIdList.size() +"";
		}
		String task = radioImage.getText();
		
		Grid grid = null;
		if (TYPE_EXPERT.equals(curButton.getData())) {
			grid = expertGrid;
			
		} else if (TYPE_WORKER.equals(curButton.getData())) {
			grid = workerGrid;
		}
		
		String userName = "         ";
		if (null != grid && grid.getSelectionCount() > 0) {
			userName = grid.getSelection()[0].getText(1);
		}
		
		String tips = MessageFormat.format(Messages.Tips_assignBidCommentTask, selectSize, SUPPLIER_NAME, task, userName);
		tipsSupplierLabel.setText(tips +"-->");
		tipsSupplierLabel.getParent().layout();
		if (null == tipsStyleRange) {
			tipsStyleRange = new StyleRange();
			tipsStyleRange.foreground = ColorConstants.FONT_BLUE_COLOR;
			tipsStyleRange.fontStyle = SWT.BOLD;
			tipsStyleRange.font = SWTResourceManager.getFont("微软雅黑", 12, SWT.BOLD);
		}
		int searchIndex = 0;
		while(true){
			int startIndex = tips.indexOf("[", searchIndex);
			int endIndex = startIndex + 1;
			if(startIndex > 0){
				endIndex = tips.indexOf("]", searchIndex);
				searchIndex = endIndex + 1;
			}else {
				break;
			}
			tipsStyleRange.start = startIndex;
			tipsStyleRange.length = endIndex - startIndex + 1;
			tipsSupplierLabel.setStyleRange(tipsStyleRange);
		}
	}
	
	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		ScreenUtils util = new ScreenUtils();
		return new Point((int) (util.getScreenWight() * 0.6), (int) (util.getScreenHight() * 0.8));
	}
}
