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

import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.util.ArrayList;
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.nebula.widgets.grid.listener.GridSelectionListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.core.widgets.ECombo;
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.custom.CLabel;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
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.Label;
import org.eclipse.swt.widgets.Shell;

import com.gx.obe.ColorConstants;
import com.gx.obe.common.file.entity.BidFile;
import com.gx.obe.common.file.enumeration.FileConstants;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.I18NEnum;
import com.gx.obe.components.core.enumeration.EngineerConstants;
import com.gx.obe.evaluation.step.composite.boq.DwgcDetailComposite;
import com.gx.obe.evaluation.step.composite.boq.DwgcDetailComposite.DwgcSelectListener;
import com.gx.obe.evaluation.step.composite.boq.DxgcSummaryComposite;
import com.gx.obe.evaluation.step.composite.boq.ProjectSummaryComposite;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.util.utils.RuntimeUtils;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.boq.ConstructProject;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.service.SupplierService;
import com.gx.obe.web.service.TenderProjectService;
import com.gx.obe.web.service.boq.ConstructProjectService;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

public class ViewBoqDialog extends EDialog {
	
	private final String BID_BILL = "bid_bill";
	
	private SupplierService supplierService = new SupplierService();
	private TenderProjectService tenderProjectService = new TenderProjectService();
	private ConstructProjectService constructProjectService = new ConstructProjectService();
	private TenderProjectEntity tenderProject;
	private EvaluationStep evaluationStep;
	private Supplier supplier;
	private List<Supplier> supplierList = new ArrayList<Supplier>();
	private String selectSupplierId;
	private int selectProjectIndex = 0;
	private Grid projectGrid;
	private ECombo supplierCombo;
	private ELink preSupplierBtn;
	private ELink nextSupplierBtn;
	private Composite load_composite;
	private String curItemCode;// 记录当前选中的单位工程的项目
	private DwgcSelectListener dwgcSelectListener;
	private Composite sashForm;
	private Label tenderNoLabel;
	private Label tenderNameLabel;
	private Label packageNameLabel;
	private CLabel hideOrShowSupplier_btn;
	private Composite left_composite;
	private Composite right_omposite;
	private Label title_label_1;
	private GridColumn gridColumn;
	private ELink viewPdfBtn;
	{
		LogUtils.logClass(ViewBoqDialog.class);
	}
	
	/**
	 * Create the dialog.
	 * 
	 * @param parentShell
	 */
	public ViewBoqDialog(Shell parentShell, TenderProjectEntity tenderProject, Supplier supplier, EvaluationStep evaluationStep) {
		super(parentShell);
		this.tenderProject = tenderProject;
		this.supplier = supplier;
		this.evaluationStep = evaluationStep;
		this.setTitle("工程量清单");
	}
	
	/**
	 * Create contents of the dialog.
	 * 
	 * @param parent
	 */
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		GridLayout gl_container = new GridLayout(1, false);
		gl_container.verticalSpacing = 0;
		gl_container.horizontalSpacing = 0;
		gl_container.marginHeight = 0;
		gl_container.marginWidth = 0;
		container.setLayout(gl_container);
		
		Composite project_composite = new Composite(container, SWT.NONE);
		project_composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		RowLayout rl_project_composite = new RowLayout(SWT.HORIZONTAL);
		rl_project_composite.marginHeight = 5;
		project_composite.setLayout(rl_project_composite);
		
		tenderNoLabel = new Label(project_composite, SWT.NONE);
		tenderNoLabel.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		tenderNoLabel.setForeground(SWTResourceManager.getColor(100, 100, 100));
		
		tenderNameLabel = new Label(project_composite, SWT.NONE);
		tenderNameLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		tenderNameLabel.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		tenderNameLabel.setText("2014年国家航空航天遥感影像获取项目(三期)");
		
		packageNameLabel = new Label(project_composite, SWT.NONE);
		packageNameLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		packageNameLabel.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.NORMAL));
		packageNameLabel.setText("分包一");
		
		ESepator projectSep = new ESepator(container, SWT.NONE);
		projectSep.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		projectSep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		sashForm = new Composite(container, SWT.NONE);
		sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_sashForm = new GridLayout(3, false);
		gl_sashForm.verticalSpacing = 0;
		gl_sashForm.horizontalSpacing = 0;
		sashForm.setLayout(gl_sashForm);
		
		left_composite = new Composite(sashForm, SWT.NONE);
		GridData gd_left_composite = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
		gd_left_composite.widthHint = 350;
		left_composite.setLayoutData(gd_left_composite);
		left_composite.setBackground(ColorConstants.BORDER_LINE_COLOR);
		GridLayout gl_supplierComposite = new GridLayout(1, false);
		gl_supplierComposite.marginHeight = 1;
		gl_supplierComposite.marginWidth = 1;
		left_composite.setLayout(gl_supplierComposite);
		
		Composite composite_3 = new Composite(left_composite, SWT.NONE);
		composite_3.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_3.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_composite_3 = new GridLayout(1, false);
		gl_composite_3.verticalSpacing = 0;
		gl_composite_3.horizontalSpacing = 0;
		gl_composite_3.marginHeight = 0;
		gl_composite_3.marginWidth = 0;
		composite_3.setLayout(gl_composite_3);
		
		projectGrid = new Grid(composite_3, SWT.H_SCROLL | SWT.V_SCROLL);
		projectGrid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		projectGrid.setHeaderVisible(true);
		
		gridColumn = new GridColumn(projectGrid, SWT.NONE);
		gridColumn.setShowTreeTogglePic(false);
		gridColumn.setTree(true);
		gridColumn.setText("名称");
		gridColumn.setWordWrap(true);
		gridColumn.setWidth(248);
		gridColumn.setTreeIndent(10);
		
		GridColumn moneyColumn = new GridColumn(projectGrid, SWT.RIGHT);
		moneyColumn.setText("总价（元）");
		moneyColumn.setWordWrap(true);
		moneyColumn.setWidth(98);
		moneyColumn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/sum.png"));
		
		GridItem gridItem = new GridItem(projectGrid, SWT.NONE);
		gridItem.setText("New Row");
		
		Composite center_composite = new Composite(sashForm, SWT.NONE);
		center_composite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, true, 1, 1));
		GridLayout gl_center_composite = new GridLayout(1, false);
		gl_center_composite.marginWidth = 0;
		gl_center_composite.marginHeight = 0;
		center_composite.setLayout(gl_center_composite);
		
		hideOrShowSupplier_btn = new CLabel(center_composite, SWT.NONE);
		hideOrShowSupplier_btn.setRightMargin(0);
		hideOrShowSupplier_btn.setLeftMargin(0);
		hideOrShowSupplier_btn.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, true, 1, 1));
		hideOrShowSupplier_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				hideOrShowSupplierAction();
			}
		});
		hideOrShowSupplier_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/left_arrow.png"));
		
		right_omposite = new Composite(sashForm, SWT.NONE);
		right_omposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
//		right_omposite.setBackground(ColorConstants.BORDER_LINE_COLOR);
		GridLayout gl_right_omposite = new GridLayout(1, false);
		gl_right_omposite.horizontalSpacing = 0;
		gl_right_omposite.marginHeight = 1;
		gl_right_omposite.marginWidth = 1;
		right_omposite.setLayout(gl_right_omposite);
		
		Composite top_right_composite = new Composite(right_omposite, SWT.NONE);
		top_right_composite.setLayout(new GridLayout(1, false));
		top_right_composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		top_right_composite.setBackground(SWTResourceManager.getColor(60, 138, 226));
//		top_right_composite.setBackground(SWTResourceManager.getColor(240, 240, 240));
		top_right_composite.setBackgroundMode(SWT.INHERIT_FORCE);
		
		title_label_1 = new Label(top_right_composite, SWT.NONE);
		title_label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		title_label_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
//		title_label_1.setForeground(SWTResourceManager.getColor(50, 50, 50));
		title_label_1.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/white/sing.png"));
		title_label_1.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.BOLD));
		title_label_1.setText(" ");
		Composite supplier_composite = new Composite(right_omposite, SWT.NONE);
		GridLayout gl_composite_2 = new GridLayout(4, false);
		gl_composite_2.marginWidth = 0;
		gl_composite_2.marginHeight = 2;
		supplier_composite.setLayout(gl_composite_2);
		
		supplierCombo = new ECombo(supplier_composite, SWT.NONE);
		supplierCombo.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		GridData gd_selectCaType_combo_combo = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
		gd_selectCaType_combo_combo.widthHint = 300;
		supplierCombo.setBorderColor(SWTResourceManager.getColor(60, 138, 226));
		supplierCombo.setLayoutData(gd_selectCaType_combo_combo);
		supplierCombo.setText("");
		supplierCombo.setHintText("--请选择供应商--");
		supplierCombo.setDownArrowImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/arrow_down_simp.png"));
		
		preSupplierBtn = new ELink(supplier_composite, SWT.NONE);
		preSupplierBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				viewPreviewSupplier();
			}
		});
		preSupplierBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		preSupplierBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/arrow_up.png"));
		preSupplierBtn.setText("上一家");
		
		nextSupplierBtn = new ELink(supplier_composite, SWT.NONE);
		nextSupplierBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				viewNextSupplier();
			}
		});
		nextSupplierBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		nextSupplierBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/arrow_down.png"));
		nextSupplierBtn.setText("下一家");
		
		viewPdfBtn = new ELink(supplier_composite, SWT.NONE);
		viewPdfBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				viewSupplierBillFile();
			}
		});
		
		viewPdfBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		viewPdfBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/pdf_16.png"));
		viewPdfBtn.setText("查看清单文件");
		
		Composite load_border_composite = new Composite(right_omposite, SWT.NONE);
		load_border_composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_load_border_1 = new GridLayout(1, false);
		gl_load_border_1.verticalSpacing = 1;
		gl_load_border_1.horizontalSpacing = 1;
		gl_load_border_1.marginHeight = 1;
		gl_load_border_1.marginWidth = 1;
		load_border_composite.setLayout(gl_load_border_1);
		load_border_composite.setBackground(ColorConstants.BORDER_LINE_COLOR);
		
		load_composite = new Composite(load_border_composite, SWT.NONE);
		load_composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		load_composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		load_composite.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		init();
		return container;
	}
	
	/**
	 * @Description: 初始化界面
	 * @author guoyr
	 */
	private void init() {
		projectGrid.setItemHeight(Constants.ROW_HIGHT);
		projectGrid.setLinesVisible(false);
		projectGrid.setAutoHeight(true);
		projectGrid.removeAll();
//		projectGrid.setShowEvenBackground(false);
		if (null != tenderProject.getParentId() && !"".equals(tenderProject.getParentId())) {
			TenderProjectEntity parentProject = tenderProjectService.getById(tenderProject.getParentId());
			tenderNoLabel.setText("[" + parentProject.getTenderNo() + "]");
			tenderNameLabel.setText(parentProject.getTenderName());
			packageNameLabel.setText(" － " + tenderProject.getTenderName());
		} else {
			tenderNoLabel.setText("[" + tenderProject.getTenderNo() + "]");
			tenderNameLabel.setText(tenderProject.getTenderName());
			packageNameLabel.setText("");
		}
		supplierList = supplierService.getEvaluationStepSupplierList(tenderProject.getId(), evaluationStep);
		if (null == tenderProject.getParentId()) {
			gridColumn.setText("（项目/单项工程/单位工程）名称");
		} else {
			gridColumn.setText("（" + com.gx.obe.components.core.I18N.getString(I18NEnum.SUBPACKAGE, tenderProject.getTenderType()) + "/单项工程/单位工程）名称");
		}
		initSupplierCombo();
		
		supplierCombo.addSelectionListener(new ECombo.ComboSelectoinListener() {
			@Override
			public void itemSelectoin(String name, Object value, int index) {
				selectSupplierCombo();
			}
		});
		
		projectGrid.addListener(SWT.Selection, new GridSelectionListener() {
			public void leftMouseButtonDown(GridItem item) {
				selectSupplierProject();
			}
		});
	}
	
	/**
	 * Description: 最大化右侧
	 * Create Date: Jun 26, 201410:45:44 AM<br/>
	 * Author : guoyr <br/>
	 * Modify Date: <br/>
	 * Modify By : <br/>
	 * 
	 * @param maxRight
	 */
	private void hideOrShowSupplierAction() {
		
		if (null != hideOrShowSupplier_btn.getData("hide")) {
			((GridData) left_composite.getLayoutData()).widthHint = 350;
			hideOrShowSupplier_btn.setData("hide", null);
			hideOrShowSupplier_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/left_arrow.png"));
		} else {
			hideOrShowSupplier_btn.setData("hide", true);
			((GridData) left_composite.getLayoutData()).widthHint = 0;
			hideOrShowSupplier_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/right_arrow.png"));
		}
		sashForm.layout();
	}
	
	/**
	 * @Description: 初始化供应商下拉列表
	 * @author guoyr
	 */
	private void initSupplierCombo() {
		supplierCombo.removeAll();
		
		supplierCombo.addItem("招标工程量清单", BID_BILL);
		
		if (null != supplierList && supplierList.size() > 0) {
			for (Supplier supplier : supplierList) {
				supplierCombo.addItem(supplier.getSupplierName(), supplier.getId());
			}
			if (null != supplier) {
				supplierCombo.setSelectionValue(supplier.getId());
			} else {
				if (supplierCombo.getItemCount() > 1) {
					supplierCombo.select(1);
				} else {
					supplierCombo.select(0);
				}
			}
			selectSupplierCombo();
		} else {
			viewPdfBtn.setEnabled(false);
		}
	}
	
	/**
	 * @Description: 选中供应商事件
	 * @author guoyr
	 */
	private void selectSupplierCombo() {
		if (supplierCombo.getSelectionIndex() > -1) {
			viewPdfBtn.setEnabled(true);
			selectSupplierId = (String) supplierCombo.getSelectionValue();
			refreshBtnStatus();
			refreshSupplierProjectGrid();
		} else {
			viewPdfBtn.setEnabled(false);
		}
	}
	
	/**
	 * @Description: 列出单位工程和单项工程
	 * @author guoyr
	 */
	private void refreshSupplierProjectGrid() {
		projectGrid.removeAll();
		projectGrid.setAutoHeight(true);
		
		String supplierId = null;
		if (!BID_BILL.equals(selectSupplierId)) {
			supplierId = selectSupplierId;
		}
		
		// 获得工程项目
		ConstructProject constructProject = constructProjectService.getAllConstructProject(tenderProject.getId(), supplierId);
		if (null == constructProject) {
			return;
		}
		GridItem projectItem = new GridItem(projectGrid, SWT.NONE);
		projectItem.setText(tenderProject.getTenderName());
		if (null != constructProject.getProjectName() && constructProject.getProjectName().length() > 0) {
			projectItem.setText(0, constructProject.getProjectName());
		} else {
			projectItem.setText(0, tenderProject.getTenderName());
		}
		projectItem.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/engineering_buildings.png"));
		if (null != constructProject) {
			projectItem.setData("constructProject", constructProject);// 单项工程
			projectItem.setExpanded(true);
			if (null == tenderProject.getParentId()) {
				projectItem.setData("title", "[项目]" + tenderProject.getTenderName());
			} else {
				projectItem.setData("title", "[" + com.gx.obe.components.core.I18N.getString(I18NEnum.SUBPACKAGE, tenderProject.getTenderType()) + "]" + tenderProject.getTenderName());
			}
			projectItem.setText(1, ObjectUtils.getObjString(constructProject.getTotal()));//工程总造价
			// 获得单项工程
			List<ConstructProject> singleConstructionList = constructProject.getChildProjectList();
			if (null != singleConstructionList) {
				for (ConstructProject singleConstruction : singleConstructionList) {
					GridItem dxgcItem = new GridItem(projectItem, SWT.NONE);
					dxgcItem.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/engineering_building.png"));
					dxgcItem.setData(EngineerConstants.DXGC);
					dxgcItem.setData("constructProject", singleConstruction);// 单项工程主键
					dxgcItem.setExpanded(true);
					dxgcItem.setText(0, ObjectUtils.getObjString(singleConstruction.getProjectName()));
					dxgcItem.setText(1, ObjectUtils.getObjString(singleConstruction.getTotal()));// 单项工程金额
//					dxgcItem.setBackground(SWTResourceManager.getColor(234, 233, 247));
					dxgcItem.setData("title", "[单项工程]" + singleConstruction.getProjectName());
					// 获得单位工程
					List<ConstructProject> unitConstructionList = singleConstruction.getChildProjectList();
					if (null != unitConstructionList) {
						for (ConstructProject unitConstruction : unitConstructionList) {
							GridItem dwgcItem = new GridItem(dxgcItem, SWT.NONE);
							dwgcItem.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/engineering_building_item.png"));
							dwgcItem.setData(EngineerConstants.DWGC);
							dwgcItem.setData("constructProject", unitConstruction);// 单位工程主键
							dwgcItem.setText(0, ObjectUtils.getObjString(unitConstruction.getProjectName()));
							dwgcItem.setText(1, ObjectUtils.getObjString(unitConstruction.getTotal()));// 单位工程金额
							dwgcItem.setData("title", "[单项工程]" + singleConstruction.getProjectName() + " > [单位工程]" + unitConstruction.getProjectName());
						}
					}
				}
			}
			
		}
		projectGrid.select(selectProjectIndex);
		selectSupplierProject();
	}
	
	/**
	 * @Description: 选中工程
	 * @author guoyr
	 */
	private void selectSupplierProject() {
		for (Control control : load_composite.getChildren()) {
			control.dispose();
		}
		
		if (projectGrid.getSelectionCount() > 0) {
			if (null != dwgcSelectListener) {
				curItemCode = dwgcSelectListener.getItemCode();
			}
			GridItem selectItem = projectGrid.getSelection()[0];
			String selectProjectType = (String) selectItem.getData();
			ConstructProject constructProject = (ConstructProject) selectItem.getData("constructProject");
			String title = (String) selectItem.getData("title");
			title_label_1.setText(null == title ? "" : title);
			// 选中的是项目
			if (null == selectProjectType) {
				ProjectSummaryComposite composite = new ProjectSummaryComposite(load_composite, SWT.NONE);
				composite.getListener().select(tenderProject, supplier, constructProject);
			} else if (selectProjectType.equals(EngineerConstants.DXGC)) {
				DxgcSummaryComposite composite = new DxgcSummaryComposite(load_composite, SWT.NONE);
				composite.getListener().select(tenderProject, supplier, constructProject);
				
			} else if (selectProjectType.equals(EngineerConstants.DWGC)) {
				DwgcDetailComposite composite = new DwgcDetailComposite(load_composite, SWT.NONE);
				dwgcSelectListener = composite.getListener();
				dwgcSelectListener.select(tenderProject, supplier, constructProject, curItemCode);
				constructProject.getParentProject();
				curItemCode = dwgcSelectListener.getItemCode();
				
			}
			
			load_composite.layout();
		}
		
		selectProjectIndex = 0;
		if (projectGrid.getSelectionCount() > 0) {
			selectProjectIndex = projectGrid.getSelectionIndex();
		}
	}
	
	/**
	 * @Description: 上一家供应商
	 * @author guoyr
	 */
	private void viewPreviewSupplier() {
		int index = supplierCombo.getSelectionIndex();
		if (index > 0) {
			supplierCombo.select(index - 1);
			selectSupplierCombo();
		}
	}
	
	/**
	 * @Description: 下一家供应商
	 * @author guoyr
	 */
	private void viewNextSupplier() {
		int index = supplierCombo.getSelectionIndex();
		if (index < supplierCombo.getItemCount() - 1) {
			supplierCombo.select(index + 1);
			selectSupplierCombo();
		}
	}
	
	/**
	 * @Description: 查看工程量清单文件
	 * @author guoyr
	 */
	private void viewSupplierBillFile() {
		if (viewPdfBtn.getEnabled() && null != selectSupplierId) {
			
			if (BID_BILL.equals(selectSupplierId)) {
//	            File billBiddingFile = new File(Constants.getBiddingFilePath(tenderProject.getId()).concat(Constants.BILL_XML));
//	            if(null != billBiddingFile && billBiddingFile.exists()){
//	                RuntimeUtils.openFIle(billBiddingFile);
//	            }
				return;
			}
			
			File billFile = BidFile.getSupplierBidBillFile(tenderProject.getId(), selectSupplierId, FileConstants.PDF);
			if (null != billFile && billFile.exists()) {
				RuntimeUtils.openFIle(billFile);
			}
		}
	}
	
	/**
	 * @Description: 刷新按钮状态
	 * @author guoyr
	 */
	private void refreshBtnStatus() {
		int selectIndex = supplierCombo.getSelectionIndex();
		if (selectIndex == 0) {
			preSupplierBtn.setEnabled(false);
			nextSupplierBtn.setEnabled(true);
		} else if (selectIndex == supplierCombo.getItemCount() - 1) {
			preSupplierBtn.setEnabled(true);
			nextSupplierBtn.setEnabled(false);
		} else {
			preSupplierBtn.setEnabled(true);
			nextSupplierBtn.setEnabled(true);
		}
	}
	
	/**
	 * Return the initial size of the dialog.
	 */
	protected Point getInitialSize() {
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); // 取得当前屏幕属性
		int w = d.width; // 获取屏幕宽度
		int h = d.height; // 获取屏幕高度
		return new Point(w, h);
	}
}