dangsn
2024-12-26 4e9ff2ce6a830bb2340d7c8612c72eea0c5a553e
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
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<Integer, FunctionObject> funcMap = new LinkedHashMap<Integer, FunctionObject>();
    private HashMap<Integer, VCIModuleMainPanel> secondModuleListMap = new LinkedHashMap<Integer, VCIModuleMainPanel>();
    private HashMap<Integer, VCIModuleMainPanel> secondeAlreadLoadedPanles = new LinkedHashMap<Integer, VCIModuleMainPanel>();
    private String[] taskMessage = {};//单点登录信息
    private HashMap<Integer, VCIModuleMainPanel> jPanelistMap = new LinkedHashMap<Integer, VCIModuleMainPanel>();
    
    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;
    }
}