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

import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.EDialog;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

import com.gx.obe.business.entity.BidPriceRound;
import com.gx.obe.common.widget.listener.SelectSupplierListener;
import com.gx.obe.evaluation.step.composite.BidPriceResutlTableComposite;
import com.gx.obe.evaluation.step.composite.MultiBidPriceResultDetailComposite;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.tender.TenderProjectEntity;

public class ViewMultiRoundPriceDialog extends EDialog {

	private BidPriceResutlTableComposite bidPriceResutlTableComposite;
	private MultiBidPriceResultDetailComposite showDetailComposite;
	private TenderProjectEntity tenderProjectEntity;
	private List<Supplier> supplierList;
	private int round;
	private BidPriceRound curbidPriceRound;

	/**
	 * Create the dialog.
	 * @param parentShell
	 */
	public ViewMultiRoundPriceDialog(Shell parentShell, TenderProjectEntity tenderProjectEntity, List<Supplier> supplierList, int round,BidPriceRound curbidPriceRound) {
		super(parentShell);
		this.tenderProjectEntity = tenderProjectEntity;
		this.supplierList = supplierList;
		this.round = round;
		this.curbidPriceRound = curbidPriceRound;
		this.setOperator(SWT.MAX);
	}

	/**
	 * 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));

		bidPriceResutlTableComposite  = new BidPriceResutlTableComposite(container, SWT.NONE);
		GridData gd_bidPriceResutlTableComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_bidPriceResutlTableComposite.heightHint = 50;
		bidPriceResutlTableComposite.setLayoutData(gd_bidPriceResutlTableComposite);
		
		showDetailComposite = new MultiBidPriceResultDetailComposite(container, SWT.NONE);
		GridData gd_showDetailComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_showDetailComposite.heightHint = 50;
		showDetailComposite.setLayoutData(gd_showDetailComposite);
		init();
		return container;
	}
	
	private void init(){
		bidPriceResutlTableComposite.addSelectSupplierListener(new SelectSupplierListener(){
			public void selectSupplier(Supplier supplier) {
				if(null != supplier){
					WidgetUtils.setControlVisible(showDetailComposite, true);
					showDetailComposite.refresh(tenderProjectEntity, supplier, round, curbidPriceRound, false);
				}
			}
		});
		bidPriceResutlTableComposite.refreshBidPriceResultTable(tenderProjectEntity, supplierList, round,curbidPriceRound);	
	}


	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(800, 400);
	}

}
