package com.gx.obe.evaluation.step.composite.clear;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.EButton;
import org.eclipse.swt.core.widgets.ELabel;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.custom.CLabel;
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.Color;
import org.eclipse.swt.layout.FillLayout;
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.Label;

import com.gx.obe.ColorConstants;
import com.gx.obe.DictValueEnum;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.components.core.I18NEnum;
import com.gx.obe.evaluation.step.checker.ArithmeticErrorChecker;
import com.gx.obe.evaluation.step.inter.IChecker;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.web.entity.CheckResult;
import com.gx.obe.web.entity.DictionaryValue;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

import de.kupzog.ktable.KTable;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.editors.KTableCellEditorButton;
import de.kupzog.ktable.model.CommonKtableCModel;
import de.kupzog.ktable.renderers.ButtonCellRenderer;
import de.kupzog.ktable.renderers.CellAlignmentRender;
import de.kupzog.ktable.renderers.CellContentRender;
import de.kupzog.ktable.renderers.CellEditorRender;
import de.kupzog.ktable.renderers.CellEventActionRender;
import de.kupzog.ktable.renderers.CellForegroundRender;
import de.kupzog.ktable.renderers.CellRender;
import de.kupzog.ktable.renderers.FixedWrapCellRenderer;
import de.kupzog.ktable.renderers.TextWrapCellRenderer;

/**
 * @Description:
 * @author guoyr
 */
public class BusinessClearTenderItemResultComposite extends Composite {
	private EvaluationStep evaluationStep;
	private TenderProjectEntity tenderProject;
	private DictionaryValue dictionaryValue;
	private Object[][] contentArray;
	private KTable resultKTable;
	private CommonKtableCModel commKTableModel;
	private Composite contentComposite;
	public ClickButtonListener listener;
	private List<IChecker> checkerList;
	private List<IChecker> tableCheckerList;
	private Color lightRedColor = SWTResourceManager.getColor(SWT.COLOR_RED);
	private Color lightGreenColor = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
	private CLabel cleanTenderStepName;
	private Composite composite;
	private Button showAllBtn;
	private Button showPassYesOnlyBtn;
	private Button showPassNoOnlyBtn;
	private Label messageLabel;
	private EButton button;
	private Composite checkContentComposite;
	private int errorNumIndex = 2;
	private int checkResultIndex = 3;
	private int checkOpinionIndex = 4;
	private int operateIndex = 5;
	{
		LogUtils.logClass(BusinessClearTenderItemResultComposite.class);
	}
	
	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public BusinessClearTenderItemResultComposite(Composite parent, int style) {
		super(parent, style);
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.horizontalSpacing = 0;
		gridLayout.verticalSpacing = 0;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		
		Composite composite_2 = new Composite(this, SWT.NONE);
		GridLayout gl_composite_2 = new GridLayout(4, false);
		gl_composite_2.horizontalSpacing = 0;
		composite_2.setLayout(gl_composite_2);
		composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));
		
		cleanTenderStepName = new CLabel(composite_2, SWT.NONE);
		cleanTenderStepName.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1));
		cleanTenderStepName.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		cleanTenderStepName.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/tips_blue.png"));
//		cleanTenderStepName.setText("商务标清标结果");
		
		messageLabel = new Label(composite_2, SWT.WRAP);
		messageLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		messageLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		messageLabel.setText("");
		
		composite = new Composite(composite_2, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		GridLayout gl_composite = new GridLayout(3, false);
		gl_composite.marginHeight = 0;
		composite.setLayout(gl_composite);
		
		showAllBtn = new Button(composite, SWT.RADIO);
		showAllBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				changeResultShowTypeAction();
			}
		});
		showAllBtn.setText("显示全部");
		showAllBtn.setData("all");
		showAllBtn.setSelection(true);
		
		showPassYesOnlyBtn = new Button(composite, SWT.RADIO);
		showPassYesOnlyBtn.setText("只显示正确项");
		showPassYesOnlyBtn.setData("yes");
		showPassYesOnlyBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				changeResultShowTypeAction();
			}
		});
		
		showPassNoOnlyBtn = new Button(composite, SWT.RADIO);
		showPassNoOnlyBtn.setText("只显示错误项");
		showPassNoOnlyBtn.setData("no");
		showPassNoOnlyBtn.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				changeResultShowTypeAction();
			}
		});
		button = new EButton(composite_2, SWT.NONE);
		button.setText("重新检查");
		button.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/refresh.png"));
		button.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				if (null != listener) {
					listener.refresh(true);
				}
			}
		});
		
		ESepator top_sep = new ESepator(this, SWT.SEPARATOR | SWT.HORIZONTAL);
		top_sep.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		top_sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		contentComposite = new Composite(this, SWT.NONE);
		FillLayout fl_contentComposite = new FillLayout(SWT.HORIZONTAL);
		fl_contentComposite.marginWidth = 0;
		contentComposite.setLayout(fl_contentComposite);
		contentComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		ESepator sep = new ESepator(this, SWT.SEPARATOR | SWT.HORIZONTAL);
		sep.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		checkContentComposite = new Composite(this, SWT.NONE);
		checkContentComposite.setBackground(SWTResourceManager.getColor(252, 252, 238));
		checkContentComposite.setBackgroundMode(SWT.INHERIT_FORCE);
		checkContentComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		checkContentComposite.setLayout(new GridLayout(1, false));
		
		CLabel label = new CLabel(checkContentComposite, SWT.NONE);
		label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		label.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/open.png"));
		label.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		label.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		label.setText("检查内容");
	}
	
	public void showCheckResult(TenderProjectEntity tenderProject, EvaluationStep evaluationStep, DictionaryValue dictionaryValue, List<IChecker> checkerList) {
		this.checkerList = checkerList;
		this.tenderProject = tenderProject;
		this.dictionaryValue = dictionaryValue;
		this.evaluationStep = evaluationStep;
		if (null != checkerList && checkerList.size() > 0) {
			int noPassCount = 0;
			for (int i = 0; i < checkerList.size(); i++) {
				IChecker checker = checkerList.get(i);
				if (null != checker) {
					CheckResult result = checker.getCheckResult();
					if (null != result && ObjectUtils.equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED, result.getAccessment())) {
						noPassCount++;
					}
				}
			}
			StringBuilder msg = new StringBuilder();
			msg.append("共对[");
			msg.append(checkerList.size());
			msg.append("]家");
			msg.append(com.gx.obe.components.core.I18N.getString(I18NEnum.SUPPLIERNAME, tenderProject.getTenderType()));
			msg.append("进行");
			msg.append(dictionaryValue.getDictValueName());
			if (noPassCount == 0) {
				msg.append("，全部通过检查。");
			} else {
				msg.append("，其中[");
				msg.append(checkerList.size() - noPassCount);
				msg.append("]家无错误，[");
				msg.append(noPassCount);
				msg.append("]家有错误。");
			}
			messageLabel.setText(msg.toString());
			// 如果全部不通过或全部通过，则只显示全部
			if (noPassCount == 0 || noPassCount == checkerList.size()) {
				showPassNoOnlyBtn.setEnabled(false);
				showPassYesOnlyBtn.setEnabled(false);
			}
		}
		if (null != dictionaryValue) {
//			cleanTenderStepName.setText(dictionaryValue.getDictValueName());
			initKtableContent();
			showCheckContent();
		}
		this.layout();
	}
	
	/**
	 * @Description: 切换显示清标结果方式
	 * @author guoyr
	 */
	private void changeResultShowTypeAction() {
		initKtableContent();
		contentComposite.layout();
	}
	
	/**
	 * @Description: 显示检查内容
	 * @author guoyr
	 */
	private void showCheckContent() {
		
		boolean showCalculationMsg = false;
		if (null != dictionaryValue) {
			//算术性错误
			if (dictionaryValue.getDictValueCode().equals(DictValueEnum.CleanTender.ARITHMETIC_ERROR)) {
				if (ArithmeticErrorChecker.tempCheckTotalPrice) addCheckItem("工程总报价=单项工程报价之和");
				if (ArithmeticErrorChecker.tempCheckTotalPrice) addCheckItem("单项工程报价=单位工程报价之和");
//				addCheckItem("单位工程报价=分部分项报价+措施项目报价+其他项目报价+规费+税金");
				addCheckItem("清单合价=清单单价*清单工程量");
//				msg.append("1、工程总报价=单项工程报价之和；\r\n");
//				msg.append("2、单项工程报价=单位工程报价之和；\r\n");
//				msg.append("3、单位工程报价=分部分项报价+措施项目报价+其他项目报价+规费+税金；\r\n");
//				msg.append("4、清单合价=清单单价*清单工程量。");
				showCalculationMsg = true;
			} else if (dictionaryValue.getDictValueCode().equals(DictValueEnum.CleanTender.ERROR_LEAK)) {// 错漏项检查
				addCheckItem("分部分项、单价措施清单、其他项目(除计时工)：名称、计量单位和工程量是否与招标文件规定一致");
				addCheckItem("分部分项、其他项目(除计日工)：与招标文件清单相比是否存在增项或漏项");
				addCheckItem("单价措施清单：与招标文件清单相比是否存在漏项");
				
			} else if (dictionaryValue.getDictValueCode().equals(DictValueEnum.CleanTender.GUIFEI_RATE_CHECK)) {// 规费
				addCheckItem("每个单位工程下的规费是否按照规定的费率计取");
				showCalculationMsg = true;
			} else if (dictionaryValue.getDictValueCode().equals(DictValueEnum.CleanTender.AQWMSGF_RATE_CHECK)) {// 安全文明施工费
				addCheckItem("每个单位工程下的安全文明施工费是否按照规定的费率计取");
				showCalculationMsg = true;
			} else if (dictionaryValue.getDictValueCode().equals(DictValueEnum.CleanTender.TAX_RATE_CHECK)) {// 税金
				if (null != dictionaryValue.getDictValueDesc() && dictionaryValue.getDictValueDesc().equals("unit")) {
					addCheckItem("每个单位工程下的销项税额是否按照9%费率计取");
					addCheckItem("每个单位工程下的附加税费是否按照规定的费率计取");
				} else {
					addCheckItem("每个单项工程下的销项税额是否按照9%费率计取");
					addCheckItem("每个单项工程下的附加税费是否按照规定的费率计取");
				}
				showCalculationMsg = true;
			} else if (dictionaryValue.getDictValueCode().equals(DictValueEnum.CleanTender.INVENTORY_PRICE)) {//清单报价检查
				addCheckItem("与定额单价相比，清单报价是否过高或过低");
				if (null != evaluationStep) {
					StringBuilder msg = new StringBuilder();
					msg.append("其中");
					BigDecimal priceRateMaxRate = evaluationStep.getEvaluationParamByKey(EvaluationStep.MAX_DIFFERENCE_RATE, BigDecimal.class);
					if (null == priceRateMaxRate || priceRateMaxRate.compareTo(BigDecimal.ZERO) <= 0) {
						priceRateMaxRate = BigDecimal.valueOf(25);
					}
					BigDecimal priceRateMinRate = evaluationStep.getEvaluationParamByKey(EvaluationStep.MIN_DIFFERENCE_RATE, BigDecimal.class);
					if (null == priceRateMinRate || priceRateMinRate.compareTo(BigDecimal.ZERO) >= 0) {
						priceRateMinRate = BigDecimal.valueOf(-25);
					}
					msg.append("差额率大于[");
					msg.append(priceRateMaxRate);
					msg.append("%]为过高，小于[");
					msg.append(priceRateMinRate);
					msg.append("%]为过低！");
					addCheckItem(msg.toString());
				}
				
			} else if (dictionaryValue.getDictValueCode().equals(DictValueEnum.CleanTender.MATERIAL_PRICE)) {//材料报价检查
				addCheckItem("与组成材料报价相比，材料报价是否过高或过低");
				if (null != evaluationStep) {
					StringBuilder msg = new StringBuilder();
					msg.append("其中");
					BigDecimal priceRateMaxRate = evaluationStep.getEvaluationParamByKey(EvaluationStep.MAX_DIFFERENCE_RATE, BigDecimal.class);
					if (null == priceRateMaxRate || priceRateMaxRate.compareTo(BigDecimal.ZERO) <= 0) {
						priceRateMaxRate = BigDecimal.valueOf(25);
					}
					BigDecimal priceRateMinRate = evaluationStep.getEvaluationParamByKey(EvaluationStep.MIN_DIFFERENCE_RATE, BigDecimal.class);
					if (null == priceRateMinRate || priceRateMinRate.compareTo(BigDecimal.ZERO) >= 0) {
						priceRateMinRate = BigDecimal.valueOf(-25);
					}
					msg.append("差额率大于±");
					msg.append(priceRateMaxRate);
					msg.append("%为过高，小于");
					msg.append(priceRateMinRate);
					msg.append("%为过低！");
					addCheckItem(msg.toString());
				}
			} else if (dictionaryValue.getDictValueCode().equals(DictValueEnum.CleanTender.UNCOMPETE_CHECK)) {//不可竞争费检查
				addCheckItem("规费和税金费率是否与招标文件规定费率相同");
			}
			
			if (showCalculationMsg && null != evaluationStep) {
				StringBuilder msg = new StringBuilder();
				msg.append("其中");
				String calculationError = evaluationStep.getEvaluationParamByKey(EvaluationStep.CALCULATION_ERROR);
				// 如果是根据差额率来计算
				if (ObjectUtils.equals(calculationError, EvaluationStep.CALCULATION_ERROR_RATE)) {
					BigDecimal rate = evaluationStep.getEvaluationParamByKey(EvaluationStep.CALCULATION_ERROR_RATE, BigDecimal.class);
					if (null == rate || rate.compareTo(BigDecimal.ZERO) == 0) {
						rate = BigDecimal.valueOf(5);
					}
					msg.append("差额率超过[±");
					msg.append("差额率超过[±");
					msg.append(rate);
					msg.append("%]为算术错误！");
				} else {
					BigDecimal value = evaluationStep.getEvaluationParamByKey(EvaluationStep.CALCULATION_ERROR_VALUE, BigDecimal.class);
					if (null == value || value.compareTo(BigDecimal.ZERO) == 0) {
						value = BigDecimal.valueOf(20);
					}
					msg.append("费率差超过[±0.5");
					msg.append("]%、");
					msg.append("金额差额超过[±");
					msg.append(value);
					msg.append("]元");
					msg.append("为算术错误！");
				}
				addCheckItem(msg.toString());
			}
			
		}
	}
	
	/**
	 * @Description: 设置检查内容
	 * @author guoyr
	 * @param checkContent
	 */
	private void addCheckItem(String checkContent) {
		ELabel label = new ELabel(checkContentComposite, SWT.WRAP);
		label.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		label.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label.setLeftMargin(30);
		label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		label.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/point.png"));
		label.setText(checkContent);
	}
	
	/**
	 * @Description: 初始化Ktable内容
	 * @author guoyr
	 */
	private void initKtableContent() {
		if (null == tableCheckerList) {
			tableCheckerList = new ArrayList<IChecker>();
		} else {
			tableCheckerList.clear();
		}
		
		Object showType = WidgetUtils.getRadioVal(composite);
		if (null != showType && (showType.equals("yes") || showType.equals("no"))) {
			for (IChecker checker : checkerList) {
				CheckResult result = checker.getCheckResult();
				if (showType.equals("yes") && ObjectUtils.equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED, result.getAccessment())) {
					tableCheckerList.add(checker);
				} else if (showType.equals("no") && ObjectUtils.equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED, result.getAccessment())) {
					tableCheckerList.add(checker);
				}
			}
		} else {
			tableCheckerList.addAll(checkerList);
		}
		checkOpinionIndex = -1;
		int rowCount = tableCheckerList.size() + 1;
		int colCount = 4 + (checkResultIndex > 0 ? 1 : 0) + (checkOpinionIndex > 0 ? 1 : 0);
		contentArray = new Object[rowCount][colCount];
		// 设置标题
		contentArray[0][0] = "序号";
		contentArray[0][1] = com.gx.obe.components.core.I18N.getString(I18NEnum.SUPPLIERNAME, tenderProject.getTenderType()) + "名称";
		contentArray[0][errorNumIndex] = "错误数";
		
		int contentCol = errorNumIndex;
		if (checkResultIndex > 0) {
			contentCol++;
			checkResultIndex = contentCol;
			contentArray[0][checkResultIndex] = "提示信息";
		}
		if (checkOpinionIndex > 0) {
			contentCol++;
			checkOpinionIndex = contentCol;
			contentArray[0][checkOpinionIndex] = dictionaryValue.getDictValueName() + "结果";
		}
		contentCol++;
		operateIndex = contentCol;
		contentArray[0][operateIndex] = "操作";
		int row = 1;
		for (IChecker checker : tableCheckerList) {
			Supplier supplier = checker.getSupplier();
			CheckResult result = checker.getCheckResult();
			contentArray[row][0] = row;
			contentArray[row][1] = supplier.getSupplierName();
			contentArray[row][errorNumIndex] = result.getErrorNum();
			if (checkResultIndex > 0) {
				contentArray[row][checkResultIndex] = ObjectUtils.equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED, result.getAccessment()) ? false : true;
			}
			if (checkOpinionIndex > 0) {
				contentArray[row][checkOpinionIndex] = ObjectUtils.getObjString(result.getCheckResult());
			}
			contentArray[row][operateIndex] = "查看详情";
			row++;
		}
		drawKtable();
	}
	
	/**
	 * @Description: 渲染Ktable
	 * @author guoyr
	 */
	private void drawKtable() {
		if (null != resultKTable && !resultKTable.isDisposed()) {
			resultKTable.dispose();
		}
		resultKTable = new KTable(contentComposite, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.EDIT_ON_KEY);
		commKTableModel = new CommonKtableCModel(resultKTable, 1, 2, tableCheckerList.size(), contentArray[0].length - 2);
		// 设置行高
		commKTableModel.setContentRowHeight(30);
		commKTableModel.setColumnWidth(0, 60);
		commKTableModel.setColumnMaxWidth(0, 60);
		
		commKTableModel.setColumnMinWidth(1, 150);
		commKTableModel.setColumnMaxWidth(errorNumIndex, 50);
		
		if (checkResultIndex > 0) {
			commKTableModel.setColumnMaxWidth(checkResultIndex, 60);
		}
		if (checkOpinionIndex > 0) {
			commKTableModel.setColumnMinWidth(checkOpinionIndex, 250);
			commKTableModel.setColumnMaxWidth(checkOpinionIndex, 300);
		}
		commKTableModel.setColumnMaxWidth(operateIndex, 60);
		
		// 设置单元格内容
		CellContentRender contentRender = new CellContentRender() {
			public Object receiveContent(int row, int col) {
				Object value = contentArray[row][col];
				if (row == 0) {
					return ObjectUtils.getObjString(value);
				} else {
					if (col == 0) {
						return row + "";
					} else if (col == checkResultIndex) {
						return (Boolean) contentArray[row][col] ? "清单检查合理" : "清单检查不合理";
//						return (Boolean)contentArray[row][col] ? "通过" : "不通过";
					} else {
						return ObjectUtils.getObjString(value);
					}
				}
			}
		};
		commKTableModel.setCellContentRender(contentRender);
		
		final ButtonCellRenderer buttonCellRenderer = new ButtonCellRenderer();
		// 设置单元格渲染器
		CellRender cellRender = new CellRender() {
			public Object receiveCellRender(int row, int col) {
				if (commKTableModel.isFixedCell(col, row)) {
					return new FixedWrapCellRenderer();
				} else {
					if (col == operateIndex) {
						buttonCellRenderer.setEnable(true);
						return buttonCellRenderer;
					}
					return new TextWrapCellRenderer();
				}
			}
		};
		commKTableModel.setCellRender(cellRender);
		
		// 设置单元格编辑器
		CellEditorRender cellEditorRender = new CellEditorRender() {
			public Object receiveCellEditor(int row, int col) {
				if (col == operateIndex) {
					return new KTableCellEditorButton(resultKTable, new CellEventActionRender() {
						public void receiveAction(int row, int col) {
							IChecker checker = tableCheckerList.get(row - commKTableModel.getFixedRowCount());
							if (null != listener) {
								listener.loadDetail(checker);
							}
						}
					});
				}
				return null;
			}
		};
		commKTableModel.setCellEditorRender(cellEditorRender);
		
		// 编辑单元格对齐方式
		CellAlignmentRender cellAlignmentRender = new CellAlignmentRender() {
			public int receiveCellAlignment(int row, int col) {
				if (row < commKTableModel.getFixedRowCount()) {
					return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
				} else if (col == 1 || col == checkOpinionIndex) {
					return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_LEFT;
				} else {
					return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
				}
			}
		};
		commKTableModel.setCellAlignmentRender(cellAlignmentRender);
		// 设置单元格前景色
		CellForegroundRender cellForegroundRender = new CellForegroundRender() {
			
			public Color receiveCellForeground(int row, int col) {
				if (!commKTableModel.isFixedCell(col, row)) {
					if (col == errorNumIndex || col == checkResultIndex) {
						if (col == errorNumIndex) {
							Object content = contentArray[row][col];
							if (null != content && Integer.parseInt(content.toString()) > 0) {
								return lightRedColor;
							}
						} else if (col == checkResultIndex) {
							Object content = contentArray[row][col];
							if (null != content && !(Boolean) contentArray[row][col]) {
								return lightRedColor;
							} else {
								return lightGreenColor;
							}
						}
						
					}
				}
				return null;
			}
		};
		commKTableModel.setCellForegroundRender(cellForegroundRender);
		resultKTable.setModel(commKTableModel);
	}
	
	interface ClickButtonListener {
		public void loadDetail(IChecker checker);
		
		public void refresh(boolean is);
	}
	
	public ClickButtonListener getListener() {
		return listener;
	}
	
	public void addListener(ClickButtonListener listener) {
		this.listener = listener;
	}
	
	/**
	 * @Description: 刷新表格的大小
	 * @author guoyr
	 */
	public void refreshTableSize() {
		if (null != resultKTable && !resultKTable.isDisposed()) {
			resultKTable.resizeColumnOptimal();
		}
	}
	
	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
