package com.vci.client.logon.client; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.WindowEvent; import java.net.UnknownHostException; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.WindowConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import com.vci.client.LogonApplication; import com.vci.client.common.ConfigUtils; import com.vci.client.common.VCIBasePanel; import com.vci.client.common.objects.RoleObject; import com.vci.client.common.objects.UserEntityObject; import com.vci.client.common.objects.UserObject; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.framework.rightConfig.modelConfig.ModuleConfigMainPanel; import com.vci.client.framework.rightConfig.object.FunctionObject; import com.vci.client.framework.util.RightControlUtil; import com.vci.client.logon.base.SysCofigMenuBar; import com.vci.client.logon.base.TabPanelManage; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.image.BundleImage; import com.vci.client.ui.locale.LocaleDisplay; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.WindowClosedDialog; import com.vci.client.ui.swing.components.JClosableTabbedPane; import com.vci.client.ui.swing.components.VCIJFrame; import com.vci.client.ui.swing.components.VCIJLabel; import com.vci.client.ui.swing.components.VCIJMenuBar; import com.vci.client.ui.swing.components.VCIJPanel; import com.vci.client.ui.swing.components.VCIJTabbedPane; import com.vci.mw.ClientContextVariable; public class VciFrame extends VCIJFrame { private static final long serialVersionUID = 6370474022505400783L; private VCIJMenuBar menuBar = null; private JClosableTabbedPane closableTabbedPane = null; private JTabbedPane tabbedPane = null; private UserEntityObject userEntityObject; private String userName = LogonApplication.getUserEntityObject().getUserName(); private VCIJTabbedPane secondTabbedPane = null; private Map funcMap = new LinkedHashMap(); private HashMap secondModuleListMap = new LinkedHashMap(); private HashMap secondeAlreadLoadedPanles = new LinkedHashMap(); private String[] taskMessage = {};//单点登录信息 private HashMap jPanelistMap = new LinkedHashMap(); public UserEntityObject getUserEntityObject() { return userEntityObject; } public void setUserEntityObject(UserEntityObject userEntityObject) { this.userEntityObject = userEntityObject; } public VciFrame(UserObject userObj) { try { this.userEntityObject = LogonApplication.getUserEntityObject(); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(WindowEvent e) { this_windowClosing(e); } }); } catch (Exception e) { e.printStackTrace(); } } public void init() throws Exception { initEmpty(); initTitle(); // initMenuBar(); // initTabbedPane(); initClosableTabbedPane(); } /** * 清除面板的所有元素 * * @throws Exception */ private void initEmpty() throws Exception { this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().removeAll(); } /** * init the title of frame * * @throws Exception */ private void initTitle() throws Exception { String systenName = getI18nString("rmip.framework.system.name", "RMIPFramework"); String currentUser = getI18nString("rmip.framework.current.user", "RMIPFramework"); this.setTitle( systenName + " " + currentUser + LogonApplication.getUserEntityObject().getUserName() + " 真实姓名:" + LogonApplication.getUserObject().getTrueName() + getUserHasRoleString(LogonFrame.userName)); this.setIconImage(getImageIcon("logo.png").getImage()); this.setTitleNew(); } private String getUserHasRoleString(String userName){ StringBuffer sb = new StringBuffer(); RoleObject[] roles = getUserRoleObjects(userName); if(roles != null && roles.length > 0){ for(int i = 0; i < roles.length; i++){ sb.append(roles[i].getName()); if(i != roles.length - 1){ sb.append(","); } } } if(sb.length() != 0){ sb.insert(0, " " + getI18nString("rmip.stafforg.menu.role", "RMIPFramework") + ":"); } return sb.toString(); } private RoleObject[] getUserRoleObjects(String userName){ RoleObject[] roles = {}; try { UserObject userObject = LogonApplication.getUserObject(); String userId = userObject.getId(); roles = new RightManagementClientDelegate(getUserEntityObject()).fetchRoleInfoByUserId(userId); } catch (VCIException e) { e.printStackTrace(); } return roles; } /** * init menu bar * * @throws Exception */ private void initMenuBar() throws Exception { menuBar = new VCIJMenuBar(); this.setJMenuBar(menuBar); } private void loadHomePageTabs(){ String homePageCfgVal = ConfigUtils.getConfigValue("HomePageClasses"); String[] groups = homePageCfgVal.split(";"); if(homePageCfgVal != null && !"".equals(homePageCfgVal)){ for(String group : groups){ String[] homePageClasses = group.split(","); int length = homePageClasses.length; String className = length >= 1 ? homePageClasses[0] : ""; String title = length >= 2 ? homePageClasses[1] : ""; String imagePath = length >= 3 ? homePageClasses[2] : ""; if(!"".equals(className)){ FunctionObject funcObj = new FunctionObject(); //System.out.println(funcObj.getId()); funcObj.setResourceC(className); VCIModuleMainPanel mmp = new VCIModuleMainPanel(funcObj); Object objPal = mmp.getNewPanel(funcObj); Icon icon = null; if(!"".equals(imagePath)){ icon = VCISwingUtil.createImageIcon(imagePath); } if(objPal != null && objPal instanceof Component){ closableTabbedPane.insertTab(title, icon, (Component)objPal, title, 0); } } } } } private void loadJMenuBar(){ if(ConfigUtils.getBooleanConfigValue("top.menuBar.show")){ this.setJMenuBar(new SysCofigMenuBar(this)); } } // private void loadSpecialRoleTabs() throws Exception{ // if(RightControlUtil.isDeveloper(userName) || RightControlUtil.isAdmin(userName)) return; // int index = closableTabbedPane.getTabCount(); // int rowTab = index; // SpecialRoleClientObject[] specialRoleList = new SpecialRoleClientDelegate().getSpecialRoleList(); // RoleObject[] userRoleObjects = getUserRoleObjects(userName); // for(SpecialRoleClientObject o : specialRoleList){ // boolean roleIdFlag = false; // String logonRoleId = o.getLogonRoleId(); // String panelName = o.getPanelName(); // String moduleName = o.getModuleName(); // String iconName = o.getIconName(); // String moduleShowInfo = o.getModuleShowInfo(); // for(RoleObject roleObj : userRoleObjects){ // if(logonRoleId.equals(roleObj.getName()) || logonRoleId.equals(roleObj.getId())){ // roleIdFlag = true; // break; // } // } // if (!roleIdFlag) { // continue; // } // // VCIModuleMainPanel tabModule = null; // FunctionObject funobj = new FunctionObject(); // if (panelName.startsWith("plm.uif.engine.client.UILayout")){ // panelName = o.getPanelName().replaceAll("#", "&"); // funobj.setName(moduleName); // funobj.setResourceC(panelName); // tabModule = new VCIModuleMainPanel(funobj); // } else { // funobj.setName(moduleName); // funobj.setResourceC(panelName); // tabModule = new VCIModuleMainPanel(funobj); // } // // closableTabbedPane.addTab(moduleName, tabModule, VCISwingUtil.createImageIcon(iconName), moduleShowInfo, false); // jPanelistMap.put(index, tabModule); // funcMap.put(index, funobj); // index ++; // } //// if(rowTab == 0){ //// loadTab1(0); //// } // closableTabbedPane.addMouseListener(new MouseAdapter() { // public void mouseClicked(MouseEvent arg0) { // /**点击选项卡空白处时,仍然触发选项卡事件的处理 Begin**/ // Point p = arg0.getPoint(); // int r = closableTabbedPane.indexAtLocation(p.x, p.y); // if(r < 0) { // return; // } // /******End*****************************/ // int n = closableTabbedPane.getSelectedIndex(); // try { // loadTab1(n); // } catch (Exception e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // } // }); // } public void loadTab1(int n )throws Exception{ if (this.jPanelistMap.containsKey(n)) { VCIModuleMainPanel modulePanel = this.jPanelistMap.get(n); if (modulePanel != null) { String panelName = modulePanel.getFunobj().getResourceC(); Object pan = null; if(panelName.contains("@")){ String[] split = panelName.split("@"); if(split!=null){ Class cls = Class.forName(split[0]); String param = split[1]; if(param.contains(",")){ String[] params = param.split(","); pan = (JPanel)cls.getConstructor(FunctionObject.class,String.class).newInstance(new FunctionObject(),params[1]); }else{ pan = (JPanel) cls.getConstructor(FunctionObject.class).newInstance(new FunctionObject()); } } }else{ pan = modulePanel.getNewPanel(modulePanel.getFunobj()); } closableTabbedPane.setComponentAt(n, (JPanel)pan); closableTabbedPane.setSelectedIndex(n); closableTabbedPane.updateUI(); } else { this.setJMenuBar(new VCIJMenuBar()); VCIJPanel pal = new VCIJPanel(); VCIJLabel lbl = new VCIJLabel("加载模块面板出错!"); lbl.setForeground(Color.red); pal.add(lbl); closableTabbedPane.setComponentAt(n, pal); } } } private void initClosableTabbedPane() throws Exception { closableTabbedPane = new JClosableTabbedPane(); TabPanelManage.getInstance().setTabPanel(closableTabbedPane); ClientContextVariable.setFrame(this); closableTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); if(RightControlUtil.isRoot(userName)||RightControlUtil.isDeveloper(userName)){ ModuleConfigMainPanel sysmodulePanel = new ModuleConfigMainPanel(); closableTabbedPane.addTab("系统功能模块配置", VCISwingUtil.createImageIcon("product.gif"), sysmodulePanel, "系统功能模块配置"); } //System.out.print("完成了标题的设置"); loadJMenuBar(); //System.out.print("完成了菜单顶部栏设置"); loadHomePageTabs(); //System.out.print("完成了主页设置"); //loadSpecialRoleTabs(); //System.out.print("完成了三员那堆的设置"); VCIJPanel pal = new VCIJPanel(new BorderLayout()); pal.add(closableTabbedPane, BorderLayout.CENTER); pal.add(StatusBar.getInstance(), BorderLayout.SOUTH); StatusBar.getInstance().setStatusMessage("Welcome."); StatusBar.getInstance().setProgressBarVisiable(false, 3); closableTabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { closableTabbedPane_stateChange(e); } }); this.getContentPane().add(pal, BorderLayout.CENTER); //System.out.print("完成了页面的设置"); } private void closableTabbedPane_stateChange(ChangeEvent e){ Component compt = closableTabbedPane.getSelectedComponent(); if(compt instanceof VCIBasePanel){ // 设置当前功能模块对象 VCIBasePanel modulePanel = (VCIBasePanel)compt; FunctionObject funcObj = modulePanel.getFuncObj(); setModuleToUserObject(funcObj); } } /** * 设置当前用户所在的功能模块 * @param funcObj 功能模块对象 * */ private void setModuleToUserObject(FunctionObject funcObj){ if(funcObj != null){ String modules = funcObj.getResourceC(); LogonApplication.getUserEntityObject().setModules(modules); } } /** * add new tab component into main tabbedPane * * @param name * @param imageIcon * @param panel * @param description */ public void addTabbedPane(String name, ImageIcon imageIcon, VCIJPanel panel, String description) { tabbedPane.addTab(name, imageIcon, panel, description); } private void loadSecondTab(int n) { if(secondModuleListMap.containsKey(n)) { VCIModuleMainPanel secondMainPanel = this.secondModuleListMap.get(n); LogonApplication.getUserEntityObject().setModules(secondMainPanel.getSelectModuleName());//重新记录模块信息 if(null != secondMainPanel) { secondMainPanel.removeAll(); secondMainPanel.init(); secondTabbedPane.setComponentAt(n, secondMainPanel); secondTabbedPane.setSelectedIndex(n); secondMainPanel.updateUI(); secondeAlreadLoadedPanles.put(n, secondMainPanel); } } } private void this_windowClosing(WindowEvent e) { WindowClosedDialog closeDialg = new WindowClosedDialog(this); closeDialg.setVisible(true); if (closeDialg.getStatus() == 1){ if (!RightControlUtil.isAdminOrDeveloperOrRoot(LogonApplication.getUserObject().getUserName())){ /** * 保存日志 */ String message = "登出"; LogonApplication.getUserEntityObject().setModules(LogonPanel.class.getName()); try { new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).savelog(message); } catch (VCIException ex) { VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", ex); } catch (Throwable t) { t.printStackTrace(); } } System.exit(0); } } private void setTitleNew() { } public String[] getTaskMessage() { return taskMessage; } public void setTaskMessage(String[] taskMessage) { this.taskMessage = taskMessage; } private BundleImage bundleImage = new BundleImage(); private ImageIcon getImageIcon(String icon) { return bundleImage.createImageIcon(icon); } private String getI18nString(String keyCode, String fileName) { return LocaleDisplay.getI18nString(keyCode, fileName, this.getLocale()); } class ModuleData { private String modelCode; private String propFileName; private String tabbedIcon; private String mainPanelClass; public ModuleData() { super(); } public ModuleData(String modelCode, String propFileName, String tabbedIcon, String mainPanelClass) { super(); this.modelCode = modelCode; this.propFileName = propFileName; this.tabbedIcon = tabbedIcon; this.mainPanelClass = mainPanelClass; } public String getModelCode() { return modelCode; } public void setModelCode(String modelCode) { this.modelCode = modelCode; } public String getPropFileName() { return propFileName; } public void setPropFileName(String propFileName) { this.propFileName = propFileName; } public String getTabbedIcon() { return tabbedIcon; } public void setTabbedIcon(String tabbedIcon) { this.tabbedIcon = tabbedIcon; } public String getMainPanelClass() { return mainPanelClass; } public void setMainPanelClass(String mainPanelClass) { this.mainPanelClass = mainPanelClass; } } public static void main(String[] args) { UserObject object = new UserObject(); UserEntityObject entity = new UserEntityObject(); if(args!=null&&args.length>1){ object.setId(args[0]); object.setUserName(args[1]); entity.setUserName(args[1]); entity.setIp(getLocalIP()); }else{ object.setId("11111111111"); object.setUserName("1"); entity.setUserName("1"); entity.setIp(getLocalIP()); } LogonApplication.userObject = object; LogonApplication.userEntityObject = entity; VciFrame frame = new VciFrame(object); try { frame.init(); } catch (Exception e) { e.printStackTrace(); } LogonApplication.frame = frame; frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setFocusableWindowState(true); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getPreferredSize(); frameSize.height = screenSize.height / 5 * 4; frameSize.width = screenSize.width / 5 * 4 + 20; frame.setSize(frameSize); frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); } /** * 获取用户IP * @return */ private static String getLocalIP() { String ip = "127.0.0.1"; try { ip = java.net.InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); } return ip; } }