package com.gx.obe.management.composite;

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.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.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.icons.IconsActivator;
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.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.util.utils.StringUtils;
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.ProjectRuleService;
import com.gx.obe.web.service.TenderProjectService;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

/**
 * @Description: 进入项目界面
 * @author guoyr
 */
public class TenderProjectEnterMenuComposite extends Composite implements ActionListener{
	
	private ImageResolver imageResolver = new ImageResolver();
	private Label tenderNoLabel;
	private Label tenderNameLabel;
 	private TenderProjectEntity tenderProject;
 	private TenderProjectRuleEntity tenderProjectRule;
	private Composite rightContentComposite;
	private Composite leftMenuComposite;
	private ImageButton curMenu;
	private ImageButton curTopMenuBtn;
	private Image defaultTopIco;
	private ActionListener topActionListener;
	private MenuService menuService;
 	private TenderProjectService tenderProjectService;
 	List<Menu> menuList;
	private ScrolledComposite scrolledComposite;
	private ProjectRuleService projectRuleService;
	private Menu menu;
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();
	private ImageButton startMeetingBtn;
	{
		LogUtils.logClass(TenderProjectEnterMenuComposite.class);
	}
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public TenderProjectEnterMenuComposite(Composite parent, Action action, int style) {
		super(parent, style);
		this.tenderProject = action.getTenderProject();
		this.topActionListener = action.getListener();
		this.menu = action.getMenu();
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				imageResolver.disposite();
			}
		});
		GridLayout gridLayout = new GridLayout(2, false);
		gridLayout.horizontalSpacing = 5;
		gridLayout.marginWidth = 0;
		gridLayout.marginHeight = 0;
		gridLayout.verticalSpacing = 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(3, false);
		gl_topComposite.marginHeight = 0;
		gl_topComposite.verticalSpacing = 0;
		topComposite.setLayout(gl_topComposite);
		
		CLabel label_2 = new CLabel(topComposite, SWT.NONE);
		label_2.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/pid_plan.png"));
		label_2.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 1));
		label_2.setText("");
		
		Composite projectComposite = new Composite(topComposite, SWT.NONE);
		projectComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_projectComposite = new GridLayout(2, false);
		gl_projectComposite.marginHeight = 0;
		gl_projectComposite.marginWidth = 0;
		projectComposite.setLayout(gl_projectComposite);
		
		tenderNoLabel = new Label(projectComposite, SWT.NONE);
		tenderNoLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		tenderNoLabel.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		tenderNoLabel.setForeground(SWTResourceManager.getColor(100, 100, 100));
//		tenderNoLabel.setText("[ZFCG2014Z0021]");
		
		tenderNameLabel = new Label(projectComposite, 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, true, 1, 1));
//		tenderNameLabel.setText("2014年国家航空航天遥感影像获取项目(三期)");
		
		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);
		
		ESepator label = new ESepator(this, SWT.NONE);
		label.setBackground(SWTResourceManager.getColor(240, 240, 240));
		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, 1);
//		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.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));
		
		rightContentComposite = new Composite(this, SWT.NONE);
		rightContentComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		FillLayout fl_rightContentComposite = new FillLayout(SWT.HORIZONTAL);
		fl_rightContentComposite.marginHeight = 10;
		fl_rightContentComposite.marginWidth = 10;
		rightContentComposite.setLayout(fl_rightContentComposite);
		
		init();
 	}
	
	/**
	 * @Description: 初始化
	 * @author guoyr
	 */
	private void init(){
		/**
		 * 第二层验证
		 * **/
		try {
			com.gx.security.CertValidator.getInstance().validateAuthorization();
		} catch (com.gx.security.CertificateException e) {
			throw new com.gx.security.SecurityRuntimeException(e);
		}
		
		tenderProjectService = new TenderProjectService();
		projectRuleService = new ProjectRuleService();
		menuService = new MenuService();
		SyncThreadSet myThreadSet = new SyncThreadSet(new SyncThreadSet.Runnable() {
			public void run() {
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(!rightContentComposite.isDisposed()){
							rightContentComposite.setData("tenderProject", tenderProject);
							rightContentComposite.setData("parentProject", tenderProject);
							tenderNoLabel.setText("["+tenderProject.getTenderNo() + "]");
							tenderNameLabel.setText(tenderProject.getTenderName());
							loadParentProjectLeftMenu(menuList);
							tenderNoLabel.getParent().layout();
						}
					}
				});
			}
		});
		
		myThreadSet.addSyncExec(new SyncThread(new SyncThread.Runnable() {
			public void run() {
				tenderProject = tenderProjectService.getTenderProjectInfo(tenderProject.getId());
				if(StringUtils.isNotEmpty(tenderProject.getParentId())){
					TenderProjectEntity parentProject = tenderProjectService.getTenderProjectInfo(tenderProject.getParentId());
					tenderProject.setParentProjectEntity(parentProject);
				}
			}
		}));
		myThreadSet.addSyncExec(new SyncThread(new SyncThread.Runnable() {
			public void run() {
				tenderProjectRule = projectRuleService.getProjectRule(tenderProject.getId());
			}
		}));
		
		myThreadSet.addSyncExec(new SyncThread(new SyncThread.Runnable() {
			public void run() {
				menuList = 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);
		}
		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());
		tenderNameLabel.addMouseListener(new ChangeTextListener());
	}
	
	
	private ImageButton createTopMenu(Menu menu){
		final ImageButton menuTitle = new ImageButton(leftMenuComposite, SWT.LEFT | SWT.WRAP);
		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, 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.setMinWidth(150);
		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);
			action.setTenderProject(tenderProject);
			action.setData("topActionListener", topActionListener);
			action.addActionListener(this);
			actionLabel.addMouseListener(new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					if(null != topMenuBtn){
						curTopMenuBtn = topMenuBtn;
					}
					action.run();
				}
			});
		}
		return actionLabel;
	}
	private ImageButton addSignMenu(Composite subMenuComposite, Menu menu){
		
		ImageButton actionLabel = new ImageButton(subMenuComposite, SWT.LEFT | SWT.WRAP);
		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.setMinWidth(150);
		actionLabel.setSubImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/menu/blue/right.png"));
		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.setParentProject(tenderProject);
			action.setTenderProject(tenderProject);
			action.setTenderProjectRule(tenderProjectRule);
			action.setData("menuLabel", actionLabel);
			action.setData("topActionListener", topActionListener);
			action.addActionListener(this);
			actionLabel.addMouseListener(new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					if(null != curTopMenuBtn){
						curTopMenuBtn.setSelection(false);
					}
					action.run();
				}
			});
		}
		return actionLabel;
	}

	/**
	 * @Description: 加载带分包的项目的菜单
	 * @author guoyr
	 */
	private void loadParentProjectLeftMenu(List<Menu> menuList){
		
		for(Control control : leftMenuComposite.getChildren()){
			control.dispose();
		}
		// 是否父级项目
		boolean isParentProject = tenderProject.hasSubPacks();
		if(isParentProject) {
			SubPackageListComposite.CUR_PAGE_NO = 1;
		}
		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(null != 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){
							subMenu.setParam("isDetail", "01");
						}
						boolean showThisMenu = true;
						if(isParentProject){
							if("00".equals(subMenu.getParam("parentVisible"))){
								showThisMenu = false;;
							}
						}else {
							if(null != 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(!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 {
						continue;
					}
					
				}else {
					topMenu = addSignMenu(leftMenuComposite, menu);
					
				}
				if(topMenuIndex == 0){
					curTopMenuBtn = topMenu;
				}
				if(!findFirstTopMenu && "01".equals(menu.getParam("firstMenu"))){
					curTopMenuBtn = topMenu;
					findFirstTopMenu = true;
				}
				topMenuIndex ++;
			}
		}
		
		if(null != curTopMenuBtn){
			curTopMenuBtn.notifyListeners(SWT.MouseUp, null);
		}
		leftMenuComposite.layout();
 		scrolledComposite.setMinSize(leftMenuComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		scrolledComposite.getParent().layout();
	}
	
	
	@Override
	protected void checkSubclass() {
	}
	
	public void onLoad(Action action) {
		action.setParentProject(tenderProject);
		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();
	}
	
	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();
	}
	
}
