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.MessageDialog;
import org.eclipse.swt.core.listener.RoundBorderLineListener;
import org.eclipse.swt.core.utils.WidgetUtils;
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.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import com.gx.obe.ColorConstants;
import com.gx.obe.action.bean.Action;
import com.gx.obe.business.entity.MenuFunction;
import com.gx.obe.business.entity.Worker;
import com.gx.obe.business.enumeration.ExpertEnum;
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.config.ConfigConstants;
import com.gx.obe.config.utils.PropertiesUtils;
import com.gx.obe.management.dialog.ApplyToOtherTenderPackMonitorDialog;
import com.gx.obe.management.dialog.EditWorkerDialog;
import com.gx.obe.message.Messages;
import com.gx.obe.message.menu.MenuMessages;
import com.gx.obe.thread.DownloadMonitorsThread;
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.web.entity.auth.AuthLoginRecordEntity;
import com.gx.obe.web.entity.auth.AuthUser;
import com.gx.obe.web.entity.auth.Menu;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.service.UserLoginRecordService;
import com.gx.obe.web.service.UserService;
import com.gx.obe.web.service.WorkerService;
import com.gx.utils.NowTimeUtils;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

/**
 * @Description: 监督人员管理
 * @author wangxiang
 */
public class MonitorComposite extends Composite {
	private TenderProjectEntity tenderProjectEntity;
 	private WorkerService workerService ;
	private ELink addNewWorkerBtn;
	private ELink updateWorkerBtn;
	private ELink delWorkerBtn;
	private Grid monitorGrid;
	private List<Worker> workerList;
	private String workerType = ExpertEnum.MONITOR;
	private Map<String, AuthLoginRecordEntity> loginRecordMap = new HashMap<String, AuthLoginRecordEntity>();
	private UserLoginRecordService loginRecordService;
	private ELink synchronousWorkerBtn;
	private Menu menu;
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();
	private TitleComposite titleComposite;
	private UserService userService;
	private Grid buyMonitorGrid;
	private ArrayList<Worker> monitorList;
	private ArrayList<Worker> buyMonitorList;
	private ELink applyToOtherPackBtn;

	{
		LogUtils.logClass(MonitorComposite.class);
	}
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param projectAction 
	 * @param style
	 */
	public MonitorComposite(Composite parent, Action projectAction, int style) {
		super(parent, style);
		setBackground(SWTResourceManager.getColor(255, 255, 255));
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.verticalSpacing = 0;
		gridLayout.horizontalSpacing = 10;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {

			}
		});
		this.tenderProjectEntity = projectAction.getTenderProject();
		this.menu = projectAction.getMenu();
		
		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();
			}
		});
		
		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) {
				loadEvaluationUser();
			}
		});
		
		synchronousWorkerBtn = titleComposite.addELink("DOWNLOAD");
		synchronousWorkerBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				synchronousWorkerAction();
			}
		});
		synchronousWorkerBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/download.png"));
		synchronousWorkerBtn.setText(Messages.Button_download);
		
		addNewWorkerBtn = titleComposite.addELink("ADD");
		addNewWorkerBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				createMonitorAction();
			}
		});
		addNewWorkerBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/add.png"));
		addNewWorkerBtn.setText(Messages.Button_add);
		
		updateWorkerBtn = titleComposite.addELink("EDIT");
		updateWorkerBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/edit.png"));
		updateWorkerBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				updateWorkerAction();
			}
		});
		updateWorkerBtn.setText(Messages.Button_modify);
		
		delWorkerBtn = titleComposite.addELink("DELETE");
		delWorkerBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/delete.png"));
		delWorkerBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				delWorkerAction();
			}
		});
		delWorkerBtn.setText(Messages.Button_delete);

		Composite composite = new Composite(this, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		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.addPaintListener(new RoundBorderLineListener(ColorConstants.BORDER_LINE_COLOR));
		
		monitorGrid = new Grid(composite, SWT.H_SCROLL | SWT.V_SCROLL);
		monitorGrid.setHeaderVisible(true);
		monitorGrid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		GridColumn gridNumColumn = new GridColumn(monitorGrid, SWT.CENTER);
		gridNumColumn.setText(Messages.Num);
		gridNumColumn.setWidth(40);
		gridNumColumn.setMaxmumWidth(50);
		
		GridColumn gridColumn = new GridColumn(monitorGrid, SWT.CENTER);
		gridColumn.setText(Messages.FullName);
		gridColumn.setWidth(80);
		
		GridColumn _gridColumn = new GridColumn(monitorGrid, SWT.CENTER);
		_gridColumn.setText(Messages.Account);
		_gridColumn.setWidth(80);
		
		GridColumn gridColumn1 = new GridColumn(monitorGrid, SWT.CENTER);
		gridColumn1.setText(Messages.Login_ip);
		gridColumn1.setWidth(80);
		
		GridColumn gridColumn2 = new GridColumn(monitorGrid, SWT.CENTER);
		gridColumn2.setText(Messages.Login_status);
		gridColumn2.setWidth(80);
		
		
		TitleComposite purchaseSupervisorTitleComposite = new TitleComposite(this, SWT.NONE);
		purchaseSupervisorTitleComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		purchaseSupervisorTitleComposite.setTitle(Messages.PurchaseSupervisor);
		menuFunctionUtils.addFunction(purchaseSupervisorTitleComposite, "PURCHASE_SUPERVISOR");
		
		Composite composite_2 = new Composite(this, SWT.NONE);
		composite_2.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		GridData gd_composite_2 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_composite_2.heightHint = 100;
		composite_2.setLayoutData(gd_composite_2);
		GridLayout gl_composite_2 = new GridLayout(1, false);
		gl_composite_2.marginHeight = 1;
		gl_composite_2.marginWidth = 1;
		composite_2.setLayout(gl_composite_2);
		composite_2.addPaintListener(new RoundBorderLineListener(ColorConstants.BORDER_LINE_COLOR));
		menuFunctionUtils.addFunction(composite_2, "PURCHASE_SUPERVISOR");
		
		buyMonitorGrid = new Grid(composite_2, SWT.H_SCROLL | SWT.V_SCROLL);
		buyMonitorGrid.setHeaderVisible(true);
		buyMonitorGrid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		GridColumn gridNumColumn_1 = new GridColumn(buyMonitorGrid, SWT.CENTER);
		gridNumColumn_1.setText(Messages.Num);
		gridNumColumn_1.setWidth(40);
		gridNumColumn_1.setMaxmumWidth(50);
		
		GridColumn gridColumn_1 = new GridColumn(buyMonitorGrid, SWT.CENTER);
		gridColumn_1.setText(Messages.FullName);
		gridColumn_1.setWidth(80);
		
		GridColumn _gridColumn_1 = new GridColumn(buyMonitorGrid, SWT.CENTER);
		_gridColumn_1.setText(Messages.Account);
		_gridColumn_1.setWidth(80);
		
		GridColumn gridColumn1_1 = new GridColumn(buyMonitorGrid, SWT.CENTER);
		gridColumn1_1.setText(Messages.Login_ip);
		gridColumn1_1.setWidth(80);
		
		GridColumn gridColumn2_1 = new GridColumn(buyMonitorGrid, SWT.CENTER);
		gridColumn2_1.setText(Messages.Login_status);
		gridColumn2_1.setWidth(80);
		
		
		init();
	}
	
	/**
	 * @Description: 初始化
	 * @author wangxiang 
	 */
	private void init(){
		if(titleComposite.isDisposed()){
			return;
		}
		applyToOtherPackBtn.setText(MessageFormat.format(Messages.Button_applyToOthers, com.gx.obe.components.core.I18N.getString(I18NEnum.SUBPACKAGE, tenderProjectEntity.getTenderType())));
		WidgetUtils.setControlVisible(applyToOtherPackBtn, null != tenderProjectEntity.getParentId());
		
		titleComposite.setTitle(MenuMessages.getValue(menu.getLanguageCode(), menu.getMenuShortName()));
		workerService = new WorkerService();
		loginRecordService = new UserLoginRecordService();
		menuFunctionUtils.initFunctionAuthority(menu, titleComposite.getFunctionComposite());
		loadEvaluationUser();
		monitorGrid.setItemHeight(Constants.ROW_HIGHT);
		// 添选中事件和右键菜单事件
		monitorGrid.addListener(SWT.Selection, new GridSelectionListener(){
			@Override
			public void leftMouseButtonDown(GridItem item) {
				selectMonitorAction();
			}
			@Override
			public void rightMouseButtonDown(GridItem item) {
				mouseRightClickAction();
			}
		});
		
		buyMonitorGrid.addListener(SWT.Selection, new GridSelectionListener(){
			@Override
			public void rightMouseButtonDown(GridItem item) {
				downMouseRightClickAction();
			}
		});
		
	}
	
	
	/**
	 * @Description: 显示所有监督人员成员列表
	 * @author wangxiang 
	 */
	private void loadEvaluationUser(){
		workerList = workerService.getWorkerList(false,tenderProjectEntity.getId(), workerType);
		if(null != workerList && workerList.size() >0){
			monitorList = new ArrayList<Worker>();
			buyMonitorList = new ArrayList<Worker>();
			for(Worker member : workerList){
				if(ExpertEnum.REALMONITOR.equals(member.getMonitorType())){
					monitorList.add(member);
				}else if(ExpertEnum.BUYMONITOR.equals(member.getMonitorType())){
					buyMonitorList.add(member);
				}
			}
			initLoginRecord(workerList);
		}
		
		if (monitorGrid.isDisposed()) {
			return;
		}
		monitorGrid.removeAll();
		buyMonitorGrid.removeAll();
		if(null != monitorList && monitorList.size() >0){
			int index = 1;
			for(Worker member : monitorList){
				AuthUser user = member.getUser();
				if(null == user)continue;
				GridItem gridItem = new GridItem(monitorGrid, SWT.NONE);
				gridItem.setText(0, (index ++) + "");
				setMonitorItemInfo(gridItem, member);
			}
		}
		if(monitorGrid.getItemCount() > 0 && monitorGrid.getSelectionCount() == 0){
			monitorGrid.setSelection(0);
		}
		monitorGrid.resizeColumnWidth();
		selectMonitorAction();
		
		if(null != buyMonitorList && buyMonitorList.size() >0){
			int index = 1;
			for(Worker member : buyMonitorList){
				AuthUser user = member.getUser();
				if(null == user)continue;
				GridItem gridItem = new GridItem(buyMonitorGrid, SWT.NONE);
				gridItem.setText(0, (index ++) + "");
				setMonitorItemInfo(gridItem, member);
			}
		}
		buyMonitorGrid.resizeColumnWidth();
	}
	private void initLoginRecord(List<Worker> workerList){
		loginRecordMap.clear();
		List<AuthLoginRecordEntity> loginRecordList = loginRecordService.getLoginRecordByEvalBidRoomId(null);
		if(null == loginRecordList || loginRecordList.size() == 0){
			loginRecordList = loginRecordService.getLoginRecordAllList();
		}
		
		List<String> userIdList = new ArrayList<String>();
		for(Worker member : workerList){
			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);
					}
				}
			}
		}
	}
	
	private void selectMonitorAction(){
		updateWorkerBtn.setEnabled(monitorGrid.getSelectionCount() > 0);
		delWorkerBtn.setEnabled(monitorGrid.getSelectionCount() > 0);
	}
	/**
	 * @Description: 设置工作人员的信息
	 * @author wangxaing
	 * @param gridItem
	 * @param worker
	 */
	private void setMonitorItemInfo(GridItem gridItem, Worker worker){
		AuthUser user = worker.getUser();
		gridItem.setText(1,user.getUserName());
		gridItem.setText(2,user.getUserAccount());
		AuthLoginRecordEntity authLoginRecordEntity = loginRecordMap.get(worker.getUserId());
		if(null != authLoginRecordEntity){
			gridItem.setText(3, ObjectUtils.getObjString(authLoginRecordEntity.getIp()));
			gridItem.setText(4, Messages.Logged_in);
		}else {
			gridItem.setText(3, "");
			gridItem.setText(4, Messages.NotLogged_in);
		}
		gridItem.setData("worker", worker);
	}
	/**
	 * @Description: 新增工作人员
	 * @author wangxiang 
	 */
	private void createMonitorAction(){
//		if(isInEvaluationStepProgress()){return;}
		if(addNewWorkerBtn.getEnabled()){
			final EditWorkerDialog dialog = new EditWorkerDialog(getShell(), tenderProjectEntity, null ,workerType);
			dialog.setCallBack(new CallBack(){
				public void callBackObject(Object obj) {
					Worker selectEvalWorker = null != obj ? (Worker)obj : null;
					if(null != selectEvalWorker){
						GridItem gridItem = new GridItem(monitorGrid, SWT.NONE);
						gridItem.setText(0, ObjectUtils.getObjString(monitorGrid.getItemCount()));
						gridItem.setText(1,selectEvalWorker.getUser().getUserName());
						gridItem.setText(2,selectEvalWorker.getUser().getUserAccount());
						gridItem.setText(3, "");
						gridItem.setText(4, Messages.NotLogged_in);
						gridItem.setData("worker", selectEvalWorker);
						monitorGrid.setSelection(new GridItem[]{gridItem});
					}
//					selectWorkerAction();
				}
			});
			dialog.open();
		}
	}
	
	/**
	 * @Description: 修改工作人员
	 * @author wangxiang
	 */
	private void updateWorkerAction(){
//		if(isInEvaluationProgress()){return;}
		if(updateWorkerBtn.getEnabled()){
			final Worker selectExpert = getSelectionWorker();
			final EditWorkerDialog dialog = new EditWorkerDialog(getShell(), tenderProjectEntity, selectExpert,workerType);
			dialog.setCallBack(new CallBack(){
				public void callBackObject(Object obj) {
					Worker selectEvalWorker = null != obj ? (Worker) obj : null;
					if(null != selectEvalWorker){
						GridItem selectItem = monitorGrid.getSelection()[0];
						selectItem.setData("expert", selectEvalWorker);
						selectItem.setText(1, selectEvalWorker.getUser().getUserName());
					}
				}
			});
			dialog.open();
		}
	}
	
	/**
	 * @Description: 获得选中的工作人员
	 * @author wangxiang
	 * @return 
	 */
	private Worker getSelectionWorker(){
		Worker selectWorker = null;
		if(monitorGrid.getSelectionCount() >0){
			selectWorker = (Worker)monitorGrid.getSelection()[0].getData("worker");
		}
		return selectWorker;
	}
	
	/**
	 * @Description: 删除专家
	 * @author wangxiang
	 */
	private void delWorkerAction(){
//		if(isInEvaluationProgress(delExpertBtn.getText())){return;}
//		if(isInEvaluationStepProgress()){return;}
		if(delWorkerBtn.getEnabled()){
			Worker selectWorker = getSelectionWorker();
			if(null != selectWorker && MessageDialog.openConfirm(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_deleteObj, ObjectUtils.getObjString(selectWorker.getUser().getUserName())), new String[]{Messages.Button_confirm, Messages.Button_cancel})){
				if(workerService.deleteWorker(tenderProjectEntity.getId(), selectWorker.getUserId(),workerType)){
					
					int selectIndex = monitorGrid.getSelectionIndex();
					monitorGrid.getSelection()[0].dispose();
					if(monitorGrid.getItemCount() > 0){
						if(monitorGrid.getItemCount() > selectIndex){
							monitorGrid.setSelection(selectIndex);
							for(int i = selectIndex; i < monitorGrid.getItemCount(); i ++){
								GridItem gridItem = monitorGrid.getItem(i);
								gridItem.setText(0, (i + 1) + "");
							}
						}else {
							monitorGrid.setSelection(selectIndex - 1);
						}
					}
				}else {
					MessageDialog.openWarning(getShell(), Messages.Tips_deleteFail);
				}
			}
		}
	}
	
	/**
	 * @Description: 删除所有工作人员
	 * @author wangxiang
	 */
	private void delAllWorkerAction(){
		if(MessageDialog.openConfirm(getShell(), "确定要删除全部监督人员吗？")){
			if(workerService.delAllWorkers(tenderProjectEntity.getId(),workerType,ExpertEnum.REALMONITOR)){
				monitorGrid.removeAll();
			}
		}
	}
	
	/**
	 * @Description: 删除所有工作人员
	 * @author wangxiang
	 */
	private void delDownGridAllWorkerAction(){
		if(MessageDialog.openConfirm(getShell(), "确定要删除全部采购监督人吗？")){
			if(workerService.delAllWorkers(tenderProjectEntity.getId(),workerType,ExpertEnum.BUYMONITOR)){
				buyMonitorGrid.removeAll();
			}
		}
	}
	
	
	/**
	 * @Description: 下载监督人员
	 * @author wangxiang
	 */
	private void synchronousWorkerAction(){
		String type = (String)synchronousWorkerBtn.getData("type");
		MessageViewDialog dialog = new MessageViewDialog(getShell(), -1);
		new DownloadMonitorsThread(tenderProjectEntity, dialog.getCallBack()).start();
		dialog.setTitle(MessageFormat.format(Messages.Button_downloadFormat, Messages.Supervisor));
		dialog.open();
		loadEvaluationUser();
	}
	
	/**
	 * @Description: 导入监督人
	 * @author wangxiang
	 */
//	private void importMonitorFromProjectAction() {
//		if(importMonitorBtn.isEnabled()){
//			ImportSuperviseFromTenderProjectDialog importSuperviseFromTenderProjectDialog = new ImportSuperviseFromTenderProjectDialog(getShell(), tenderProjectEntity,workerType);
//			importSuperviseFromTenderProjectDialog.open();
//			loadEvaluationUser();
//		}
//	}
	
	/**
	 * @Description: 右键菜单
	 * @author wangxiang
	 */
	private void mouseRightClickAction(){
		final EMenu gmenu = new EMenu(getShell());
		// 新增
		gmenu.addMenuItem(addNewWorkerBtn);
		// 修改
		gmenu.addMenuItem(updateWorkerBtn);
		// 删除
		gmenu.addMenuItem(delWorkerBtn);
		
		// 全部删除
		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() { 
					delAllWorkerAction();
				}
			});
		}
//		//重置密码
		if(MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority("RESET_PASSWORD"))){
			gmenu.addMenuItem(Messages.PasswordModify, ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/reStart.png"), true, new EMenu.ClickListener() {
				public void click() { 
					reSetPassWordAction();
				}
			});
		}
		
		gmenu.open();
	}
	
	/**
	 * @Description: 重置密码
	 * @author wangx
	 */
	private void reSetPassWordAction(){
		Worker selectWorker = getSelectionWorker();
		if(null != selectWorker){
			if(!MessageDialog.openConfirm(getShell(), Messages.PasswordModify, "是否将["+selectWorker.getUser().getUserName()+"]重置密码！", new String[] { "确认重置密码", Messages.Button_cancel })){
				return;
			}
			AuthUser user = selectWorker.getUser();
			String defaultPwd = PropertiesUtils.getProperty(ConfigConstants.EXPERT_DEFAULT_PASSWORD, "123456");
			user.setUserPassword(MD5Utils.getMD5String(defaultPwd));
			user.setDefaultPassword(CommonEnum.YES);
			if(null == userService){
				userService = new UserService();
			}
			if(userService.updateAssignProperty(user,new String[]{"userPassword","defaultPassword"})){
				MessageDialog.openInformation(getShell(), "已重置为初始化密码["+defaultPwd+"]！");
			}else{
				MessageDialog.openShortMessage("重置密码失败！");
			}
		}
	}
	
	/**
	 * @Description: 采购监督右键菜单
	 * @author wangxiang
	 */
	private void downMouseRightClickAction(){
		final EMenu gmenu = new EMenu(getShell());
		// 全部删除
		gmenu.addMenuItem(Messages.Button_deleteAll, ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/delete.png"), true, new EMenu.ClickListener() {
			public void click() { 
				delDownGridAllWorkerAction();
			}
		});
		
		gmenu.open();
	}
	
	/**
	 * @Description: 应用到其他包件
	 * @author guoyr 
	 */
	private void applyToOtherPackAction(){
		if(null != monitorList && monitorList.size() > 0){
			ApplyToOtherTenderPackMonitorDialog applyToOtherTenderPackDialog = new ApplyToOtherTenderPackMonitorDialog(getShell(), tenderProjectEntity, workerType);
			applyToOtherTenderPackDialog.open();
		}else {
			MessageDialog.openShortMessage("当前没有可批量复制的数据！");
		}
	}
	
	/**
	 * @Description: 设置指标分类的按钮
	 * @author wangxiang
	 * @param answerBtn
	 */
	private void setanswerBtnCss(ImageButton answerBtn) {
		answerBtn.setRightMargin(10);
		answerBtn.setLeftMargin(10);
		answerBtn.setTopMargin(5);
		answerBtn.setBottomMargin(5);
		answerBtn.setRightMargin(20);
		answerBtn.setLeftMargin(20);
		answerBtn.setTopMargin(5);
		answerBtn.setBottomMargin(5);
		answerBtn.setRightMargin(10);
		answerBtn.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));

		answerBtn.setForeground(ColorConstants.SKIN_ACTIVE_FOREGROUND);
		answerBtn.setBackgroundColor(ColorConstants.SKIN_BG);

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