wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
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();
}