package com.gx.obe.management.dialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.CallBack;
import org.eclipse.swt.core.CloseShellThread;
import org.eclipse.swt.core.widgets.EButton;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Shell;

import com.gx.obe.common.icons.IconsActivator;
import com.swtdesigner.ResourceManager;

/**
 * @Description: 
 * @author guoyr
 */
public class ImportSingleBidFileShell extends Shell {
	private Rectangle rectangle;
	private CallBack callBack;

	/**
	 * Create the shell.
	 * @param display
	 */
	public ImportSingleBidFileShell(Shell shell, Rectangle rectangle, final CallBack callBack) {
		super(shell, SWT.NO_TRIM |SWT.TOP);
		this.callBack = callBack;
		this.rectangle = rectangle;
		setLayout(new FillLayout(SWT.HORIZONTAL));
		
		EButton button = new EButton(this, SWT.NONE);
		button.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				if(null != callBack){
					getShell().close();
					callBack.callBack();
				}
			}
		});
		button.setText("单独导入其他文件");
		button.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/upload.png"));
		createContents();
	}
	@Override
	public void open() {
		this.pack();
//		Point point = SWTUtil.getMouseLoaction();
//		this.setLocation(SWTUtil.getFittingPoint(new Point(point.x - 1,point.y - 1), this.getSize()));
		CloseShellThread closeShellThread = new CloseShellThread(this,rectangle.height-20);
		closeShellThread.addContainsRectangle(rectangle);
		closeShellThread.start();
		super.open();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("SWT Application");
		setSize(172, 39);

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
