package com.gx.obe.management.composite;

import java.text.SimpleDateFormat;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.ImageResolver;
import org.eclipse.swt.core.listener.ChangeTextListener;
import org.eclipse.swt.core.listener.LoadingAdatper;
import org.eclipse.swt.core.listener.RoundBorderLineListener;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.ELink;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.core.widgets.ImageButton;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
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.Display;
import org.eclipse.swt.widgets.Label;

import com.gx.obe.ColorConstants;
import com.gx.obe.action.bean.Action;
import com.gx.obe.action.listener.ActionListener;
import com.gx.obe.action.utils.ActionUtil;
import com.gx.obe.business.entity.MenuFunction;
import com.gx.obe.business.enumeration.MenuEnum;
import com.gx.obe.business.enumeration.MenuFunctionEnum;
import com.gx.obe.business.enumeration.UserEnum;
import com.gx.obe.common.dialog.LimitBidRecommendDialog;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.common.widget.dialog.MessageViewDialog;
import com.gx.obe.common.widget.shell.ProgressMessageDialog;
import com.gx.obe.common.widget.thread.SyncThread;
import com.gx.obe.common.widget.utils.MenuFunctionUtils;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.enumeration.VideoMeetingEmum;
import com.gx.obe.config.ConfigConstants;
import com.gx.obe.config.utils.PropertiesUtils;
import com.gx.obe.listener.ProgressMessageAdapter;
import com.gx.obe.management.Activator;
import com.gx.obe.management.action.EnterTenderProjectAction;
import com.gx.obe.management.action.SubPackageLoadAction;
import com.gx.obe.management.dialog.HSTMeetingInfoDialog;
import com.gx.obe.management.thread.AutomaticDownloader;
import com.gx.obe.meeting.utils.VideoMeetingUtils;
import com.gx.obe.message.Messages;
import com.gx.obe.message.menu.MenuMessages;
import com.gx.obe.thread.AutoVerifyUserRemotePasswordThread;
import com.gx.obe.thread.RefreshProjectSupplierTenderInfoThread;
import com.gx.obe.thread.SyncThreadSet;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.web.entity.auth.Menu;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.MenuService;
import com.gx.obe.web.service.TenderProjectService;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

/**
 * @Description: 进入项目界面
 * @author guoyr
 */
public class SubPackageMenuEnterComposite extends Composite implements ActionListener{
	
	private ImageResolver imageResolver = new ImageResolver();
	private Label tenderNoLabel;
	private Label tenderNameLabel;
	private Composite rightContentComposite;
	private Composite leftMenuComposite;
	private ImageButton curMenu;
	private ImageButton curTopMenuBtn;
	private Image defaultTopIco;
	private ScrolledComposite scrolledComposite;
	private Label packageNoLabel;
	private Label packageNameLabel;
	private Composite topComposite;
	private ActionListener topActionListener;
	private Label bidOpeningTime;
	private Label evalTime;
//  	private TenderProjectRuleEntity tenderProjectRule;
	private Menu menu;
	public static String curMenuId;
	private TenderProjectRuleEntity tenderProjectRule;
	private TenderProjectEntity tenderProject;
// 	private TenderProjectVo tenderProjectVo;
	private TenderProjectService tenderProjectService;
	private MenuService menuService;
	private Action projectAction;
	private Label evalTimeLabel;
	private List<Menu> menuEntityList;
	private ImageButton startMeetingBtn;
	private MessageViewDialog dialog;
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();
	{
		LogUtils.logClass(SubPackageMenuEnterComposite.class);
	}
	static{
		/**
		 * 第二层验证
		 * **/
		try {
			com.gx.security.CertValidator.getInstance().validateAuthorization();
		} catch (com.gx.security.CertificateException e) {
			throw new com.gx.security.SecurityRuntimeException(e);
		}
	}
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public SubPackageMenuEnterComposite(Composite parent, TenderProjectEntity tenderProjectEntity, ActionListener topActionListener, Action projectAction, int style) {
		super(parent, style);
		this.projectAction = projectAction;
		this.topActionListener = topActionListener;
		this.menu = projectAction.getMenu();
		
		this.setData("topComposite",parent);
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				imageResolver.disposite();
			}
		});
		GridLayout gridLayout = new GridLayout(2, false);
		gridLayout.horizontalSpacing = 0;
		gridLayout.verticalSpacing = 0;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		
		Composite topComposite = new Composite(this, SWT.NONE);
		topComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
		GridLayout gl_topComposite = new GridLayout(5, false);
		gl_topComposite.verticalSpacing = 0;
		gl_topComposite.marginHeight = 0;
		topComposite.setLayout(gl_topComposite);
		
		CLabel label_2 = new CLabel(topComposite, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 1));
		label_2.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/pid_plan.png"));
		label_2.setText("");
		
		tenderNoLabel = new Label(topComposite, SWT.NONE);
		tenderNoLabel.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		tenderNoLabel.setForeground(ColorConstants.NOTE_TIPS_COLOR);
//		tenderNoLabel.setText("[ZFCG2014Z0021]");
		
		tenderNameLabel = new Label(topComposite, SWT.WRAP);
		tenderNameLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		tenderNameLabel.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		tenderNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
//		tenderNameLabel.setText("2014年国家航空航天遥感影像获取项目(三期)");
		
//		ELink changePack = new ELink(topComposite, SWT.NONE);
//		changePack.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
//		changePack.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/change.png"));
//		changePack.setText(MessageFormat.format(Messages.Button_selectFormat, Messages.SubPackage));
//		changePack.addMouseListener(new MouseAdapter() {
//			public void mouseUp(MouseEvent e) {
//				changeTenderPackAction();
//			}
//		});
		
		ELink bactProject = new ELink(topComposite, SWT.NONE);
		bactProject.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		bactProject.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/back.png"));
		bactProject.setText(Messages.ReturnProject);
		bactProject.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				enterProjectAction();
			}
		});
		
		startMeetingBtn = new ImageButton(topComposite, SWT.NONE);
		startMeetingBtn.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
		startMeetingBtn.setForeground(ColorConstants.SKIN_BG);
		startMeetingBtn.setActiveForeground(ColorConstants.SKIN_ACTIVE_BG);
		startMeetingBtn.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 1));
		startMeetingBtn.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		startMeetingBtn.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				

				String meetingType = PropertiesUtils.getProperty(ConfigConstants.VIDEO_MEETING_TYPE, "");
				if (e.button == 1) {//点击鼠标左键
					startMeeting();
				}else if(e.button==3){
					String roomIdAndPwd = tenderProject.getEvaluationMeeting();
					if(null == roomIdAndPwd || roomIdAndPwd.length() == 0) {
						return;
					}
					String roomId = "";
					String rpwd = "";
					if(roomIdAndPwd.contains("_")) {
						roomId = roomIdAndPwd.substring(0,roomIdAndPwd.indexOf("_"));
						rpwd = roomIdAndPwd.substring(roomIdAndPwd.indexOf("_")+1);
					}else {
						roomId = roomIdAndPwd;
						rpwd = "123456";
					}
					if(meetingType.equals(VideoMeetingEmum.MEETING_BK)){
						rpwd = "";
					} else if(meetingType.equals(VideoMeetingEmum.MEETING_HST)){
					}
					HSTMeetingInfoDialog dialog = new HSTMeetingInfoDialog(getShell(),roomId,rpwd);
					dialog.open();
				}
			}
		});
		startMeetingBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/videoOpen.png"));
		startMeetingBtn.setText(Messages.Button_startVideoMeeting);
		
		Label label = new Label(this, SWT.NONE);
		label.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		GridData gd_label = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		gd_label.heightHint = 1;
		label.setLayoutData(gd_label);
		
		scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL);
		GridData gd_scrolledComposite = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 4);
//		gd_scrolledComposite.widthHint = 150;
		scrolledComposite.setLayoutData(gd_scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		leftMenuComposite = new Composite(scrolledComposite, SWT.NONE);
		leftMenuComposite.setBackgroundMode(SWT.INHERIT_FORCE);
		leftMenuComposite.setBackground(SWTResourceManager.getColor(36, 142, 230));
		leftMenuComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		leftMenuComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		leftMenuComposite.addPaintListener(new RoundBorderLineListener(ColorConstants.BORDER_LINE_COLOR, 0));
		GridLayout gl_leftComposite = new GridLayout(1, false);
		gl_leftComposite.verticalSpacing = 0;
		gl_leftComposite.horizontalSpacing = 0;
		gl_leftComposite.marginHeight = 0;
		gl_leftComposite.marginWidth = 1;
		leftMenuComposite.setLayout(gl_leftComposite);
		scrolledComposite.setContent(leftMenuComposite);
		scrolledComposite.setMinSize(leftMenuComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		Composite composite = new Composite(this, SWT.NONE);
		composite.setBackground(SWTResourceManager.getColor(240, 240, 240));
		composite.setBackgroundMode(SWT.INHERIT_FORCE);
		GridLayout gl_composite = new GridLayout(6, false);
		gl_composite.marginHeight = 8;
		composite.setLayout(gl_composite);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		packageNoLabel = new Label(composite, SWT.NONE);
		packageNoLabel.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		packageNoLabel.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		packageNoLabel.setText("");
		
		packageNameLabel = new Label(composite, SWT.WRAP);
		packageNameLabel.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		packageNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		packageNameLabel.setText("");
		
		Label label_1 = new Label(composite, SWT.NONE);
		label_1.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_1.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		label_1.setText(Messages.BidOpeningTime + "：");
		
		bidOpeningTime = new Label(composite, SWT.WRAP);
		GridData gd_bidOpeningTime = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
//		gd_bidOpeningTime.widthHint = 140;
		bidOpeningTime.setLayoutData(gd_bidOpeningTime);
		bidOpeningTime.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
//		bidOpeningTime.setText("2015-03-25 09:00");
		
		evalTimeLabel = new Label(composite, SWT.NONE);
		evalTimeLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		evalTimeLabel.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		evalTimeLabel.setText(Messages.EvaluationTime + ": ");
		
		evalTime = new Label(composite, SWT.WRAP);
		evalTime.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
//		evalTime.setText("2015-03-25 10:30");
		
		ESepator sepLabel = new ESepator(this, SWT.SEPARATOR | SWT.HORIZONTAL);
		sepLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		sepLabel.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		
		rightContentComposite = new Composite(this, SWT.NONE);
		GridData gd_rightContentComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_rightContentComposite.widthHint = 500;
		gd_rightContentComposite.heightHint = 300;
		rightContentComposite.setLayoutData(gd_rightContentComposite);
		FillLayout fl_rightContentComposite = new FillLayout(SWT.HORIZONTAL);
		fl_rightContentComposite.marginHeight = 10;
		fl_rightContentComposite.marginWidth = 10;
		rightContentComposite.setLayout(fl_rightContentComposite);
		
		init();
	}
 	
	protected void limitBidRecommendAction() {
		LimitBidRecommendDialog bidRecommendDialog = new LimitBidRecommendDialog(getShell(), tenderProject);
		bidRecommendDialog.open();
	}

 

	/**
	 * @Description: 初始化
	 * @author guoyr
	 */
	private void init(){
		
		tenderProject = projectAction.getTenderProject();
		if(tenderProjectService == null ){
			tenderProjectService = new TenderProjectService();
		}
		if(menuService == null ){
			menuService = new MenuService();
		}
		tenderNameLabel.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				enterProjectAction();
			}
		});
		tenderNameLabel.addMouseTrackListener(new MouseTrackAdapter(){
			public void mouseEnter(MouseEvent e) {
				tenderNameLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
				tenderNameLabel.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			}
			public void mouseExit(MouseEvent e) {
				tenderNameLabel.setForeground(SWTResourceManager.getColor(80, 80, 80));
				tenderNameLabel.setCursor(null);
			}
			
		});
		
		SyncThreadSet myThreadSet = new SyncThreadSet(new SyncThreadSet.Runnable() {
			public void run() {
//				tenderProjectEntity = projectAction.refreshTenderProject();
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(!leftMenuComposite.isDisposed()){
							if(!tenderNoLabel.isDisposed()){
								tenderNoLabel.setText("["+tenderProject.getParentProjectEntity().getTenderNo() + "]");
								tenderNameLabel.setText(tenderProject.getParentProjectEntity().getTenderName());
								packageNoLabel.setText("["+tenderProject.getTenderNo() + "]");
								packageNameLabel.setText(tenderProject.getTenderName());
								tenderNameLabel.getParent().layout();
							}
							loadTenderProjectSubPackLeftMenu(menuEntityList);
						}
					}
				});
			}
		});
		
		myThreadSet.addSyncExec(new SyncThread(new SyncThread.Runnable() {
			public void run() {
				tenderProject = projectAction.refreshTenderProject();
			}
		}));
		
		myThreadSet.addSyncExec(new SyncThread(new SyncThread.Runnable() {
			public void run() {
				tenderProjectRule = projectAction.refreshTenderProjectRule();
				// 这里必须用异步
				Display.getDefault().asyncExec(new Runnable(){
					public void run(){
						if(!bidOpeningTime.isDisposed()){
							final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
							if(null != tenderProjectRule.getBidOpeningStartTime()){
								bidOpeningTime.setText(format.format(tenderProjectRule.getBidOpeningStartTime()));
							}
							if(null != tenderProjectRule.getBidEvaluationStartTime()){
								evalTime.setText(format.format(tenderProjectRule.getBidEvaluationStartTime()));
							}else {
								WidgetUtils.setControlVisible(evalTimeLabel, false);
								WidgetUtils.setControlVisible(evalTime, false);
							}
							bidOpeningTime.getParent().layout();
						}
					}
				});
			}
		}));
		myThreadSet.addSyncExec(new SyncThread(new SyncThread.Runnable() {
			public void run() {
				menuEntityList = menuService.getUserRoleMenuList(Constants.USER.getId(),Constants.USER.getAuthRole().getId(), MenuEnum.MANAGEMENT_PROJECT);
			}
		}));
		myThreadSet.start();
		
		if(UserEnum.ROLE_TYPE_EVALUATION_MANAGER.equals(Constants.USER.getUserType())){
			new AutoVerifyUserRemotePasswordThread(tenderProject,Constants.USER.getEncodePassWord()).start();
			
			new SyncThread(new SyncThread.Runnable() {
				public void run() {
					// 如果未获取最新投标信息，则自动获取
					if(!tenderProjectService.isGetLatestBidinfo(tenderProject.getId())){
						new RefreshProjectSupplierTenderInfoThread(tenderProject, new ProgressMessageAdapter(){}).start();
					}else if(!CommonEnum.YES.equals(tenderProject.getIsPack())) {
						//京能不要自动下载专家
						if(!MenuFunction.HIDE.equals(menuFunctionUtils.getAuthority(MenuFunctionEnum.AUTO_DOWN_EXPERT))){
							if (!tenderProjectService.isInProgress(tenderProject.getId(), null)) {
								AutomaticDownloader.start(tenderProject.getId());
							}
						}
					}
				}
			}).start();
		}
		
		menuFunctionUtils.initFunctionAuthority(menu);
		if(MenuFunction.HIDE.equals(menuFunctionUtils.getAuthority(MenuFunctionEnum.SHOW_MEETING_VIDEO))){
			WidgetUtils.setControlVisible(startMeetingBtn, false);
		}else if(CommonEnum.YES.equals(tenderProject.getIsPack())){
			WidgetUtils.setControlVisible(startMeetingBtn, false);
		}
		
		if(UserEnum.ROLE_SUPER_MANAGER.equals(Constants.USER.getUserType())){
			WidgetUtils.setControlVisible(startMeetingBtn, true);
		}else if(!UserEnum.ROLE_TYPE_EVALUATION_MANAGER.equals(Constants.USER.getUserType())) {
			WidgetUtils.setControlVisible(startMeetingBtn, false);
		}
		tenderNoLabel.addMouseListener(new ChangeTextListener());
		packageNoLabel.addMouseListener(new ChangeTextListener());
		packageNameLabel.addMouseListener(new ChangeTextListener());
	}

	/**
	 * @Description: 加载分包的菜单
	 * @author guoyr
	 */
	private void loadTenderProjectSubPackLeftMenu(List<Menu> menuList){
		for(Control control : leftMenuComposite.getChildren()){
			control.dispose();
		}
		boolean  isParentProject = false;
		int topMenuIndex = 0;
		if(null != menuList){
			boolean findFirstTopMenu = false;
			boolean isMonitor = UserEnum.ROLE_TYPE_EVALUATION_MONITOR.equals(Constants.USER.getUserType());
			for(Menu menu : menuList){
				if(isMonitor){
					menu.setParam("isDetail", "01");
				}
				boolean showTopMenu = true;
				if(isParentProject){
					if("00".equals(menu.getParam("parentVisible"))){
						showTopMenu = false;;
					}
				}else {
					if("00".equals(menu.getParam("packVisible"))){
						showTopMenu = false;;
					}
				}
				if(!showTopMenu){
					continue;
				}
				ImageButton topMenu =  null;
				List<Menu> subMenuList = menu.getChildList();
				if(null != subMenuList && subMenuList.size() > 0){
					int index = 0;
					boolean findFirstMenu = false;
					for(Menu subMenu : subMenuList){
						if(isMonitor){
							menu.setParam("isDetail", "01");
						}
						boolean showThisMenu = true;
						if(isParentProject){
							if("00".equals(subMenu.getParam("parentVisible"))){
								showThisMenu = false;;
							}
						}else {
							if("00".equals(subMenu.getParam("packVisible"))){
								showThisMenu = false;;
							}
						}
						if(!showThisMenu){
							continue;
						}
						if(index == 0){
							topMenu =  createTopMenu(menu);
						}
						ImageButton subMenuBtn = addSubMenu(topMenu, subMenu, index);
						if(index == 0){
							topMenu.setData("firstMenuBtn", subMenuBtn);
						}
						if(null != curMenuId && curMenuId.equals(subMenu.getId())){
							topMenu.setData("firstMenuBtn", subMenuBtn);
							curTopMenuBtn = topMenu;
							findFirstMenu = true;
							findFirstTopMenu = true;
						}
						if(!findFirstMenu && "01".equals(subMenu.getParam("firstMenu"))){
							topMenu.setData("firstMenuBtn", subMenuBtn);
							findFirstMenu = true;
						}
						index ++;
					}
					
					if(null != topMenu){
						Composite subMenuComposite = (Composite)topMenu.getData("subMenuComposite"); 
						GridData gridData = (GridData)subMenuComposite.getLayoutData();
						if(subMenuComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y < 150){
							gridData.heightHint = 150;
						}
					}
					
				}else {
					topMenu = addSignMenu(leftMenuComposite, menu);
					if(null != curMenuId && curMenuId.equals(menu.getId())){
						curTopMenuBtn = topMenu;
						findFirstTopMenu = true;
					}
				}
				
				if(null == curTopMenuBtn || topMenuIndex == 0){
					curTopMenuBtn = topMenu;
				}
				topMenuIndex ++;
				if(!findFirstTopMenu && "01".equals(menu.getParam("firstMenu"))){
					
					// 避免一直进入选择包件界面
					if(null != curTopMenuBtn && null != menu.getParam("ignore")) {
						continue;
					}
					curTopMenuBtn = topMenu;
					findFirstTopMenu = true;
				}
			}
		}
		
		if(null != curTopMenuBtn){
			curTopMenuBtn.notifyListeners(SWT.MouseUp, null);
		}
		leftMenuComposite.layout();
		scrolledComposite.setMinSize(leftMenuComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		scrolledComposite.getParent().layout();
	}
	

	private ImageButton createTopMenu(Menu menu){
		final ImageButton menuTitle = new ImageButton(leftMenuComposite, SWT.LEFT);
		menuTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		menuTitle.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		menuTitle.setActiveForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		menuTitle.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		menuTitle.setGAP(10);
		menuTitle.setLeftMargin(8);
		menuTitle.setBackground(SWTResourceManager.getColor(34, 145, 226));
		menuTitle.setBackgroundImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/bg.png"));
		
		menuTitle.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/default.png"));
		menuTitle.setActiveBgImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/active_bg.png"));
		
		menuTitle.setSubImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/down.png"));
		menuTitle.setSubImageHorAlign(SWT.RIGHT);
		menuTitle.setSubImageVerAlign(SWT.CENTER);
		menuTitle.setSubImageRightMargin(10);
		menuTitle.setMinWidth(150);
		
		Image menuImage = imageResolver.loadImage(IconsActivator.PLUGIN_ID, menu.getMenuIcon());
		if(null != menuImage){
			menuTitle.setImage(menuImage, 16, 16);
		}else {
			if(null == defaultTopIco){
				defaultTopIco = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/menu/blue/default.png");
			} 
			menuTitle.setImage(defaultTopIco);
		}
		menuTitle.setText(MenuMessages.getValue(menu.getLanguageCode(), menu.getMenuShortName()));
		
		final Composite subMenuComposite = new Composite(leftMenuComposite, SWT.NONE);
		GridData menuGridData = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
		subMenuComposite.setLayoutData(menuGridData);
		subMenuComposite.setBackground(SWTResourceManager.getColor(14, 115, 197));
		subMenuComposite.setBackgroundMode(SWT.INHERIT_FORCE);
		
		GridLayout gl_subMenuComposite = new GridLayout(1, false);
		gl_subMenuComposite.verticalSpacing = 0;
		gl_subMenuComposite.horizontalSpacing = 0;
		gl_subMenuComposite.marginHeight = 0;
		gl_subMenuComposite.marginWidth = 0;
		subMenuComposite.setLayout(gl_subMenuComposite);
		((GridData)subMenuComposite.getLayoutData()).exclude = true;
		subMenuComposite.setVisible(false);
		
		menuTitle.setData("subMenuComposite", subMenuComposite);
		menuTitle.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				if(null != curTopMenuBtn && !curTopMenuBtn.isDisposed() && !curTopMenuBtn.equals(menuTitle)){
					curTopMenuBtn.setBackgroundImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/bg.png"));
					curTopMenuBtn.setSubImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/down.png"));
//					curTopMenuBtn.setSelection(false);
					Composite menuContent = (Composite)curTopMenuBtn.getData("subMenuComposite");
					if(null != menuContent && !menuContent.isDisposed() && menuContent.getVisible()){
						((GridData)menuContent.getLayoutData()).exclude = true;
						menuContent.setVisible(false);
					}
				}
				
				if(!subMenuComposite.getVisible()){
					((GridData)subMenuComposite.getLayoutData()).exclude = false;
					subMenuComposite.setVisible(true);
					menuTitle.setBackgroundImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/open_bg.png"));
					menuTitle.setSubImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/up.png"));
					ImageButton firstMenuBtn = (ImageButton)menuTitle.getData("firstMenuBtn");
					if(null != firstMenuBtn && !firstMenuBtn.isDisposed()){
						firstMenuBtn.notifyListeners(SWT.MouseUp, null);
					}
				}else {
					((GridData)subMenuComposite.getLayoutData()).exclude = true;
					subMenuComposite.setVisible(false);
					menuTitle.setBackgroundImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/bg.png"));
					menuTitle.setSubImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/down.png"));
				}
				curTopMenuBtn = menuTitle;
//				curTopMenuBtn.setSelection(true);
				
				leftMenuComposite.layout();
				scrolledComposite.setMinSize(leftMenuComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
			}
		});
		
		return menuTitle;
	}

		
	private ImageButton addSubMenu(final ImageButton topMenuBtn, final Menu menu, int index){
		final Composite subMenuComposite = null != topMenuBtn ? (Composite)topMenuBtn.getData("subMenuComposite") : leftMenuComposite;
		ImageButton actionLabel = new ImageButton(subMenuComposite, SWT.LEFT);
		actionLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		actionLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		actionLabel.setActiveForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		actionLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		actionLabel.setTopMargin(6);
		actionLabel.setBottomMargin(6);
		actionLabel.setLeftMargin(15);
		actionLabel.setActiveBackgroundColor(SWTResourceManager.getColor(245, 150, 50));
		actionLabel.setSelectionBgColor(SWTResourceManager.getColor(255, 153, 51));
//		actionLabel.setActiveBgImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/active_bg.png"));
		actionLabel.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/point.png"));
		actionLabel.setText(MenuMessages.getValue(menu.getLanguageCode(), menu.getMenuShortName()));
		
		final Action action = (Action)ActionUtil.getAction(menu.getMenuUrl());
		if(null != action){
			action.setMenu(menu);
			action.setData("menu", menu);
			action.setData("menuLabel", actionLabel);
			action.setParentProject(tenderProject.getParentProjectEntity());
			action.setTenderProject(tenderProject);
			action.setTenderProjectRule(tenderProjectRule);
			action.setData("topActionListener", topActionListener);
			action.addActionListener(this);
			actionLabel.addMouseListener(new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					if(null != topMenuBtn){
						curTopMenuBtn = topMenuBtn;
					}
					if(null == menu.getParam("ignore")){
						curMenuId = menu.getId();
					}
					action.run();
				}
			});
		}
		return actionLabel;
	}
	private ImageButton addSignMenu(Composite subMenuComposite, final Menu menu){
		
		ImageButton actionLabel = new ImageButton(subMenuComposite, SWT.LEFT);
		actionLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		actionLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		actionLabel.setActiveForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		actionLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		actionLabel.setLeftMargin(8);
		actionLabel.setGAP(10);
		actionLabel.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/default.png"));
		actionLabel.setBackgroundImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/bg.png"));
		actionLabel.setActiveBgImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/active_bg.png"));
		actionLabel.setSubImageHorAlign(SWT.RIGHT);
		actionLabel.setSubImageVerAlign(SWT.CENTER);
		actionLabel.setSubImageRightMargin(10);
		actionLabel.setSubImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/right.png"));
		actionLabel.setMinWidth(150);
		
		Image menuImage = imageResolver.loadImage(IconsActivator.PLUGIN_ID, menu.getMenuIcon());
		if(null != menuImage){
			actionLabel.setImage(menuImage, 16, 16);
		}else {
			if(null == defaultTopIco){
				defaultTopIco = ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/left_menu/project_manage.png");
			} 
			actionLabel.setImage(defaultTopIco, 16, 16);
		}
		actionLabel.setText(MenuMessages.getValue(menu.getLanguageCode(), menu.getMenuShortName()));
		
		final Action action = (Action)ActionUtil.getAction(menu.getMenuUrl());
		if(null != action){
			action.setData("menu", menu);
			action.setMenu(menu);
			action.setData("menuLabel", actionLabel);
			action.setParentProject(tenderProject.getParentProjectEntity());
			action.setTenderProject(tenderProject);
			action.setTenderProjectRule(tenderProjectRule);
			action.setData("topActionListener", topActionListener);
			action.addActionListener(this);
			actionLabel.addMouseListener(new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					if(null == menu.getParam("ignore")){
						curMenuId = menu.getId();
					}
					if(null != curTopMenuBtn){
						curTopMenuBtn.setSelection(false);
					}
					action.run();
				}
			});
		}
		return actionLabel;
	}
	
	private void enterProjectAction(){
		final Action action = ActionUtil.getAction(EnterTenderProjectAction.class.getName());
		action.addActionListener(topActionListener);
		action.setTenderProject(tenderProject.getParentProjectEntity());
		action.setTenderProjectRule(tenderProjectRule);
 		action.run();
	}
	
	private void changeTenderPackAction(){
		final Action action = ActionUtil.getAction(SubPackageLoadAction.class.getName());
		action.setMenu(menu);
		action.setParentProject(tenderProject.getParentProjectEntity());
		action.setTenderProject(tenderProject);
		action.setTenderProjectRule(tenderProjectRule);
		action.setData("topActionListener", topActionListener);
		action.addActionListener(this);
		action.run();
	}
	
	@Override
	protected void checkSubclass() {
	}
	
	public void onLoad(Action action) {
 		action.setParentProject(tenderProject.getParentProjectEntity());
		action.setTenderProject(tenderProject);
		action.setTenderProjectRule(tenderProjectRule);
		action.setMenu(action.getMenu());
		for(Control control : rightContentComposite.getChildren()){
			control.dispose();
		}
		if(null != curMenu){
			curMenu.setSelection(false);
		}
		if(null != action.getData("menuLabel")){
			curMenu = (ImageButton)action.getData("menuLabel");
		}
		if(null != curMenu){
			curMenu.setSelection(true);
		}
	}
	public void loadComposite(Action action, Composite content) {
		rightContentComposite.layout();
		
		if(null != action.getData("intoPackage")){
			
			SyncThread syncThread = new SyncThread(new SyncThread.Runnable() {
				public void run() {
					menuEntityList = menuService.getUserRoleMenuList(Constants.USER.getId(),Constants.USER.getAuthRole().getId(), MenuEnum.MANAGEMENT_PROJECT);
					Display.getDefault().syncExec(new Runnable(){
						public void run(){
							if(!leftMenuComposite.isDisposed()){
								loadTenderProjectSubPackLeftMenu(menuEntityList);
							}
						}
					});
				}
			});
			syncThread.start();
		}
	}
	
	
	
	
	public void addTopActionListener(ActionListener actionListener){
		this.topActionListener = actionListener;
	}
	public Composite getParentComposite() {
		return rightContentComposite;
	}
	/**
	 * @Description: 启动视频服务：默认房主为FX_00015
	 * @author huangz
	 */
	private void startMeeting(){
		if(!startMeetingBtn.getEnabled())return;
		startMeetingBtn.setEnabled(false);
		final ProgressMessageDialog messageProgress = new ProgressMessageDialog(getShell(), true, -1, new LoadingAdatper() {
			public void finish(boolean flag) {
				Display.getDefault().syncExec(new Runnable() {
					public void run() {
						if(!startMeetingBtn.isDisposed()) {
							startMeetingBtn.setEnabled(true);
						}
					}
				});
			}
		});
		
		new Thread(new Runnable(){
			public void run() {
				VideoMeetingUtils.createMeeting(tenderProject, Constants.USER, VideoMeetingUtils.ROLE_MANAGER, false, true, messageProgress);
			}
		}).start();
		messageProgress.setTitle("正在启动视频会议");
		messageProgress.open();
	}
}
