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

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import com.gx.obe.ColorConstants;
import com.gx.obe.components.core.vo.Qualification;
import com.gx.obe.evaluation.step.inter.IStruct;
import com.gx.obe.util.utils.DateUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.web.entity.Struct;

/** 
 * @Description: 资信等级
 * @author chenxw 
 */
public class QualificationZXDJComposite extends Composite implements IStruct {
	private Label certificateNamelabel;
	private Combo awardLevelCombo;
	private Label companyNameLabel;
	private Label issueAuthorityLabel;
	private Label issueDateLabel;
	private Label periodValidityLabel;
	private Qualification qualification;
	private Struct struct;
	
	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public QualificationZXDJComposite(Composite parent, int style) {
		super(parent, style);
		setLayout(new GridLayout(2, false));
		
		Label label = new Label(this, SWT.NONE);
		label.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label.setText("证书名称：");
		
		certificateNamelabel = new Label(this, SWT.NONE);
		certificateNamelabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_6 = new Label(this, SWT.NONE);
		label_6.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_6.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_6.setText("证书等级：");
		
		awardLevelCombo = new Combo(this, SWT.READ_ONLY);
		GridData gd_combo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_combo.widthHint = 100;
		awardLevelCombo.setLayoutData(gd_combo);
		
		Label label_5 = new Label(this, SWT.NONE);
		label_5.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_5.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_5.setText("企业名称：");
		
		companyNameLabel = new Label(this, SWT.NONE);
		companyNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_2 = new Label(this, SWT.NONE);
		label_2.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_2.setText("颁发机构：");
		
		issueAuthorityLabel = new Label(this, SWT.NONE);
		issueAuthorityLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_3 = new Label(this, SWT.NONE);
		label_3.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_3.setText("发证日期：");
		
		issueDateLabel = new Label(this, SWT.NONE);
		issueDateLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_7 = new Label(this, SWT.NONE);
		label_7.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_7.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_7.setText("有效期至：");
		
		periodValidityLabel = new Label(this, SWT.NONE);
		periodValidityLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
	}
	
	/** 
	 * @Description: 刷新
	 * @author chenxw
	 * @param struct 
	 */
	public void refresh(Struct struct) {
		this.struct = struct;
		qualification = struct.getQualification();
		certificateNamelabel.setText(ObjectUtils.getObjString(qualification.getCertificateName()));
		
		String[] awardLevels = new String[] { "AAA", "AA", "A" };
		for (int i = 0; i < awardLevels.length; i++) {
			awardLevelCombo.add(awardLevels[i], i);
			awardLevelCombo.setData(i + "", awardLevels[i]);
		}
		WidgetUtils.setComboSelection(awardLevelCombo, ObjectUtils.getObjString(qualification.getAwardLevel()));
		
		companyNameLabel.setText(ObjectUtils.getObjString(qualification.getCompanyName()));
		issueAuthorityLabel.setText(ObjectUtils.getObjString(qualification.getIssueAuthority()));
		issueDateLabel.setText(ObjectUtils.getObjString(qualification.getIssueDate()));
		periodValidityLabel.setText(ObjectUtils.getObjString(DateUtils.getFormat(qualification.getPeriodValidity(), "yyyy年MM月dd日")));
	}
	
	/** 
	 * @Description: 设置是否编辑
	 * @author chenxw
	 * @param isEdit 
	 */
	public void setEdit(boolean isEdit) {
		awardLevelCombo.setEnabled(isEdit);
	}
	
	/** 
	 * @Description: 刷新编辑数据
	 * @author chenxw 
	 */
	public void refreshEditData() {
		qualification.setAwardLevel(awardLevelCombo.getText());
		struct.setQualification(qualification);
	}
	
	/** 
	 * @Description: 获取标题名称
	 * @author chenxw
	 * @return 
	 */
	public String getTopName() {
		return ObjectUtils.getObjString(qualification.getCertificateName());
	}
	
	protected void checkSubclass() {}
	
}
