package com.vci.client.logon.base; import java.awt.Dimension; import java.awt.Frame; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; import com.vci.client.ClientSession; import com.vci.client.LogonApplication; import com.vci.client.common.ConfigUtils; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.framework.util.RightControlUtil; import com.vci.client.logon.client.LogonPanel; 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.WindowClosedDialog; import com.vci.client.ui.swing.components.VCIJMenu; import com.vci.client.ui.swing.components.VCIJMenuBar; import com.vci.client.ui.swing.components.VCIJMenuItem; import com.vci.common.resource.CommonProperties; import com.vci.corba.common.VCIError; public abstract class BaseMenuBar extends VCIJMenuBar{ private Frame frame; public BaseMenuBar(Frame frame) { this.frame = frame; this.initBaseMenubar(); } private static final long serialVersionUID = 1L; public VCIJMenu sysMenu = new VCIJMenu("系统"); public VCIJMenu helpMenu = new VCIJMenu("帮助"); public VCIJMenuItem prepLogging=new VCIJMenuItem("重新登录"); public VCIJMenuItem changePassword=new VCIJMenuItem("更改密码"); public VCIJMenuItem exitMenuItem = new VCIJMenuItem("退出"); public VCIJMenuItem helpItem=new VCIJMenuItem("使用帮助"); public VCIJMenuItem aboutItem=new VCIJMenuItem("关于"); public void initBaseMenubar(){ prepLogging.setIcon(new BundleImage().createImageIcon("login.png")); changePassword.setIcon(new BundleImage().createImageIcon ("password.gif")); exitMenuItem.setIcon(new BundleImage().createImageIcon ("exit.gif")); helpItem.setIcon(new BundleImage().createImageIcon ("help.gif")); sysMenu.setText(LocaleDisplay.getI18nString("rmip.framework.menu.file", "RMIPFramework", getLocale())); helpMenu.setText(LocaleDisplay.getI18nString("rmip.framework.menu.help", "RMIPFramework", getLocale())); prepLogging.setText(LocaleDisplay.getI18nString("rmip.framework.menu.file.relogon", "RMIPFramework", getLocale())); changePassword.setText(LocaleDisplay.getI18nString("rmip.framework.menu.file.update.password", "RMIPFramework", getLocale())); exitMenuItem.setText(LocaleDisplay.getI18nString("rmip.framework.menu.file.exit", "RMIPFramework", getLocale())); helpItem.setText(LocaleDisplay.getI18nString("rmip.framework.menu.help.use", "RMIPFramework", getLocale())); helpMenu.setText(LocaleDisplay.getI18nString("rmip.framework.menu.about", "RMIPFramework", getLocale())); if(ConfigUtils.getBooleanConfigValue("top.menuBar.menuItem.relogin")){ sysMenu.add(prepLogging); } if(ConfigUtils.getBooleanConfigValue("top.menuBar.menuItem.changePassword")){ sysMenu.add(changePassword); } sysMenu.add(exitMenuItem); helpMenu.add(aboutItem); // helpMenu.add(helpItem); changePassword.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { manageMenu_actionEvent(e); } }); aboutItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { aboutMenu_actionEvent(e); } }); helpItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { helpMenu_actionEvent(e); } }); exitMenuItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { manageMenu_actionEvent(e); } }); prepLogging.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { prepLoggingMenu_actionEvent(e); } }); } private void manageMenu_actionEvent(ActionEvent ae) { String action = ae.getActionCommand(); String str = LocaleDisplay.getI18nString("rmip.framework.menu.file.update.password", "RMIPFramework", getLocale()); if(action.equals(str)){ ChangePasswordDialog changePasswordDialog=new ChangePasswordDialog(frame, false,LogonApplication.getUserEntityObject()); Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize (); Dimension dialogSize = changePasswordDialog.getPreferredSize (); dialogSize.height = 300; dialogSize.width = 300; changePasswordDialog.setSize (dialogSize); changePasswordDialog.setModal(true); changePasswordDialog.setResizable(false); changePasswordDialog.setLocation ( (screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); changePasswordDialog.setVisible (true); } String exitMsg = LocaleDisplay.getI18nString("rmip.framework.menu.file.exit", "RMIPFramework", getLocale()); if (action.equals(exitMsg)) { WindowClosedDialog closeDialg = new WindowClosedDialog(frame); closeDialg.setVisible(true); int status = closeDialg.getStatus(); if (status == 1){ /** * 记录登录日志 简单记录登出日志 */ if (!RightControlUtil.isAdminOrDeveloperOrRoot(LogonApplication.getUserObject().getUserName())){ String message = "登出"; LogonApplication.getUserEntityObject().setModules(LogonPanel.class.getName()); try { new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).savelog(message); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e); } } System.exit(0); } } } public void prepLoggingMenu_actionEvent(ActionEvent ae) { String title = LocaleDisplay.getI18nString("rmip.framework.reload.title", "RMIPFramework", getLocale()); String msg = LocaleDisplay.getI18nString("rmip.framework.reload.message", "RMIPFramework", getLocale()); int i = VCIOptionPane.showConfirmDialog(frame, msg, title, VCIOptionPane.YES_NO_OPTION); if(i == 0){ if (frame != null){ // update by xchao 2012.09.07 // 用frame.setVisible(false)替换frame.dispose() /** * 修改此处的原因是, * 新程序使用的是JAVA自带的 com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel * 其在编辑、修改流程模板时,会出现拖动任务对象时,会导致空指针问题, * 因此该问题的修改方案是时,在进入流程设计模板时切换到 com.incors.plaf.alloy.AlloyLookAndFeel * 使用该LAF,可以正常操作流程,但会导致使用该LAF进行编辑、修改流程模板后,有需要进行重新登录时, * 调用frame.dispose时会引发 java.awt.Component.firePropertyChange * 进而引发 com.incors.plaf.alloy.AlloyRootPaneUI.propertyChange事件处理, * 但此时在该内部处理中会出现NullPointerException, * 为了解决此异常,决定采用 frame.setVisiable(false)代替frame.dispose() * 这样的方案下,可正常重新登录、其它操作均正常 */ // frame.dispose(); frame.setVisible(false); frame = null; } cleanMessage(); new LogonApplication(); } } /** * */ private void cleanMessage(){ try { String timeCountstr = ""; try { timeCountstr = ClientSession.getFrameworkService().getConfigValue("extendservicecount"); } catch (VCIError e1) { e1.printStackTrace(); } if(timeCountstr == null || timeCountstr.length() == 0) { return; } int timeCount = Integer.parseInt(timeCountstr); if ( timeCount < 1) { return; } String service = null; for (int i = 0; i < timeCount; i++) { try { service = CommonProperties.getStringProperty("extendservice" + i); Class cl = Class.forName(service); Object obj = cl.newInstance(); Object util = cl.getDeclaredField("util").get(obj); Object dialog = util.getClass().getDeclaredField("dialog").get(util); if(dialog != null) { dialog.getClass().getDeclaredMethod("close").invoke(dialog); } List list = (List)cl.getDeclaredField("oldMessageList").get(obj); list.clear(); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } public void aboutMenu_actionEvent(ActionEvent ae) { new AboutDialog(frame, true); } /** * "使用帮助" 打开网页 * @see com.vci.rmip.logon.corba.method.LogonFactoryOperations#helpMenu_actionEvent() */ public void helpMenu_actionEvent(ActionEvent ae) { } public void loadMenuAndMenuItem(){ this.add(sysMenu); this.initSpecialMenuBar(); this.add(helpMenu); } public abstract void initSpecialMenuBar(); }