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

import java.text.MessageFormat;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.widgets.EButton;
import org.eclipse.swt.core.widgets.EDialog;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
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.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.gx.obe.ColorConstants;
import com.gx.obe.business.entity.BidPriceRound;
import com.gx.obe.business.entity.ExpertEvaluationStep;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.service.TenderProjectService;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

/** 
 * @Description: 提前结束多轮报价
 * @author wangx 
 */
public class EndRoundPriceConfirmDialog extends EDialog {
	private EButton confirm_btn;
	private Label tipsLabel;
	private Composite endReasonComposite;
	private Text endReasonText;
	private Label textCount;
	private boolean confirm = false;
	private String endReason;
	{
		LogUtils.logClass(EndRoundPriceConfirmDialog.class);
	}
	
	public EndRoundPriceConfirmDialog(Shell parentShell, BidPriceRound curbidPriceRound) {
		super(parentShell);
		setTitle(Messages.Button_endCurRound);
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		
		Composite top = (Composite) super.createDialogArea(parent);
		GridLayout gl_top = new GridLayout(1, false);
		gl_top.verticalSpacing = 0;
		gl_top.horizontalSpacing = 0;
		gl_top.marginHeight = 0;
		gl_top.marginWidth = 0;
		top.setLayout(gl_top);
		
		Composite container = new Composite(top, SWT.NONE);
		container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_container = new GridLayout(1, false);
		gl_container.marginHeight = 10;
		gl_container.marginWidth = 10;
		container.setLayout(gl_container);
		
		tipsLabel = new Label(container, SWT.WRAP);
		tipsLabel.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		tipsLabel.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.BOLD));
		tipsLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		tipsLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
		tipsLabel.setText(Messages.Tips_endCurRound);
		
		endReasonComposite = new Composite(top, SWT.NONE);
		endReasonComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		endReasonComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		GridLayout gl_apply_composite = new GridLayout(1, false);
		gl_apply_composite.verticalSpacing = 0;
		gl_apply_composite.marginHeight = 0;
		gl_apply_composite.marginWidth = 0;
		endReasonComposite.setLayout(gl_apply_composite);
		
		CLabel message_label = new CLabel(endReasonComposite, SWT.WRAP);
		message_label.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/edit.png"));
		message_label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		message_label.setForeground(ColorConstants.FONT_BLACK_COLOR);
		message_label.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		message_label.setText(Messages.Button_endCurRoundReason);
		
		{
			ESepator label = new ESepator(endReasonComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
			label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
			label.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		}
		
		endReasonText = new Text(endReasonComposite, SWT.WRAP | SWT.V_SCROLL);
		endReasonText.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		endReasonText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		ESepator label = new ESepator(top, SWT.SEPARATOR | SWT.HORIZONTAL);
		label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		label.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		Composite composite_1 = new Composite(top, SWT.NONE);
		composite_1.setBackgroundMode(SWT.INHERIT_FORCE);
		composite_1.setBackgroundImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/fill_bg.png"));
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		GridLayout gl_composite_1 = new GridLayout(3, false);
		composite_1.setLayout(gl_composite_1);
		
		textCount = new Label(composite_1, SWT.NONE);
		textCount.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		textCount.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textCount.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		textCount.setText("");
		
		confirm_btn = new EButton(composite_1, SWT.NONE);
		confirm_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				saveAction();
			}
		});
		confirm_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		confirm_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/ok.png"));
		confirm_btn.setText(Messages.Button_agree);
		
		EButton cancel_btn = new EButton(composite_1, SWT.NONE);
		cancel_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		cancel_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/close.png"));
		cancel_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				getShell().close();
			}
		});
		cancel_btn.setText(Messages.Button_close);
		init();
		return container;
	}
	
	/**
	 * @Description:初始化 
	 * @author guoyr 
	 */
	private void init(){
		endReasonText.forceFocus();
		endReasonText.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent arg0) {
				textCount.setText(MessageFormat.format(Messages.Tips_inputWordsCountWidthMax, endReasonText.getText().trim().length(), 200));
			}
		});
	}

	/**
	 * @Description: 保存
	 * @author guoyr 
	 */
	private void saveAction(){
		if(!confirm_btn.getEnabled()){
			return;
		}
		if(endReasonText.getText().trim().length() == 0){
			MessageDialog.openShortMessage(MessageFormat.format(Messages.Tips_pleaseEnter, Messages.Button_endCurRoundReason));
			return ;
		}
		
		confirm = true;
		endReason = endReasonText.getText().trim();
		getShell().close();
	
	}
	
	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(650, 400);
	}

	public boolean isConfirm() {
		return confirm;
	}

	public String getOpinion() {
		return endReason;
	}
}
