田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
package com.vci.client.auth2.view;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.table.AbstractTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
 
import com.vci.client.omd.btm.wrapper.BtmItemWrapper;
import com.vci.client.omd.provider.BtmProvider;
import com.vci.client.omd.ui.OmdTreeCellRenderer;
import com.vci.client.omd.versionrule.util.VersionRuleWrapper;
import com.vci.client.portal.NewNewUI.actionmng.ActionSelectDialog;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.tree.VCIBaseTreeModel;
import com.vci.client.ui.tree.VCIBaseTreeNode;
import com.vci.client.ui.util.PostorderEnumeration;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.portal.data.PLAction;
import com.vci.corba.portal.data.PLTypeAction;
import com.vci.mw.ClientContextVariable;
 
public class TypeActionPanel extends JPanel implements ActionListener {
 
    /**
     * 
     */
    private static final long serialVersionUID = -3727722741228601983L;
    // instance
    private static TypeActionPanel instance = null;
    private static final String ADD_COMMAND = "add";
    private static final String DEL_COMMAND = "del";
 
    public static JPanel getInstance() {
        if (instance == null) {
            instance = new TypeActionPanel();
        }
        return instance;
    }
 
    private JTree btTree;
    private JPanel contentPanel;
    private JPanel textPanel;
    private JPanel left=new JPanel();
    private MyTableModel tableModel;
    private JTable table;
    private JTextField textField = new JTextField();
    private JButton sel=new JButton("定位");
    private JTextField textField2 = new JTextField(20);
    private JTextField textField3 = new JTextField(20);
    private JButton sel2=new JButton("查询");
    
    public TypeActionPanel(){
        this.initUI();
    }
 
    private void initUI() {
        this.setBackground(Color.WHITE);
        this.setLayout(new BorderLayout(0, 0));
        this.initLeftPanel();
        this.initContentPanel();
        //add by caill start
        //增加textPanel容器和left容器
        //搜索框的设置
        GridBagConstraints gb = new GridBagConstraints();
        gb.gridx = 0;
        gb.gridy = 0;
        gb.weightx = 0.7;
        gb.weighty = 0;
        gb.fill = GridBagConstraints.HORIZONTAL;
        textPanel=new JPanel();
        textPanel.setLayout(new GridBagLayout());
        textPanel.add(textField,gb);
        textPanel.add(sel);
        left.setLayout(new BorderLayout());
        left.add(textPanel,BorderLayout.NORTH);
        left.add(new JScrollPane(btTree),BorderLayout.CENTER);
        //add by caill start 2015.12.4
        JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, contentPanel);
        jSplitPane.setDividerLocation(Toolkit.getDefaultToolkit().getScreenSize().width/6);
        jSplitPane.setOneTouchExpandable(true);
        this.add(jSplitPane);
        //add by caill end
        //为定位按钮增加点击事件
        sel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //e.getSource();
                String test = textField.getText().trim();
                DefaultTreeModel model = (DefaultTreeModel)btTree.getModel();
                model.reload();
                TreeNode root = (TreeNode) model.getRoot();
                PostorderEnumeration enumeration = new PostorderEnumeration(
                        root);
                while (enumeration.hasMoreElements()) {
                    DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration
                            .nextElement();                
                    if (element.getUserObject() instanceof String) {
                        String wrapper = (String) element
                                .getUserObject();
                        if (wrapper != null 
                                && wrapper.equals(test)) {
                            TreeNode[] path = element.getPath();
                            TreePath treePath = new TreePath(path);
                            btTree.setSelectionPath(treePath);
                            return;
                        }
                        ;
                    }
                }
                if (test.equals("")) {
                    JOptionPane.showMessageDialog(
                            com.vci.client.LogonApplication.frame,
                            "请输入业务类型", "提示", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(
                            com.vci.client.LogonApplication.frame,
                            "{ " + test + " }业务类型不存在", "提示",
                            JOptionPane.INFORMATION_MESSAGE);
                }
 
            }
 
        });
        //为定位框添加事件
        textField.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent e) {
                
                JTextField text = (JTextField) e.getSource();
                String test = text.getText().trim();
                DefaultTreeModel model = (DefaultTreeModel)btTree.getModel();
                model.reload();    
                TreeNode root = (TreeNode) model.getRoot();
                PostorderEnumeration enumeration = new PostorderEnumeration(
                        root);
                
                while (enumeration.hasMoreElements()) {
                    DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration
                            .nextElement();                
                    if (element.getUserObject() instanceof String) {
                        String wrapper = (String) element
                                .getUserObject();
                        if (wrapper != null 
                                && wrapper.equals(test)) {
                            TreeNode[] path = element.getPath();
                            TreePath treePath = new TreePath(path);
                            btTree.setSelectionPath(treePath);
                            return;
                        }
                        ;
                    }
                }
                if (test.equals("")) {
                    JOptionPane.showMessageDialog(
                            com.vci.client.LogonApplication.frame,
                            "请输入业务类型", "提示", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(
                            com.vci.client.LogonApplication.frame,
                            "{ " + test + " }业务类型不存在", "提示",
                            JOptionPane.INFORMATION_MESSAGE);
                }
 
            }
 
        });        
        //给搜索按钮增添点击事件,是在initData()方法的基础上做了修改
        sel2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                sel();
            }
        });
        //为名称搜索框添加键盘事件
        textField2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                sel();
            }
        });
        //为编号查询框添加键盘事件
        textField3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                sel();
            }
        });
        // add by caill end        
    }
    
    private void initLeftPanel() {
        try {
            btTree = new JTree();
            btTree.setCellRenderer(new OmdTreeCellRenderer());
            btTree.setModel(createTreeModel());
            btTree.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    super.mouseClicked(e);
                    initData();
                }
            });
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
    
    private void initContentPanel() {
        JPanel btnPanel = this.getBtnPanel();
        JPanel selPanel = new JPanel();
        tableModel = new MyTableModel();
        table = new JTable(tableModel);
        GridBagLayout g = new GridBagLayout();
        g.rowHeights = new int[]{0, 0, 0};
        g.columnWidths = new int[]{0};
        g.rowWeights = new double[]{0.0, Double.MIN_VALUE, 0.0};
        g.columnWeights = new double[]{Double.MIN_VALUE};
        contentPanel = new JPanel(g);
        //add by caill start 设置查询框和 查询按钮的位置 
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(5, 5, 5, 5);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 0.4;
        gbc.weighty = 0;
        contentPanel.add(new JLabel("Action配置管理"),gbc);
        //add by caill start 2015.12.5  将搜索框和查询按钮放到新创建的selPanel中
        JLabel ts = new JLabel("Action配置管理");
        JLabel bh = new JLabel("编号");
        JLabel mc = new JLabel("名称");
        selPanel.add(bh);
        selPanel.add(textField3);
        selPanel.add(mc);
        selPanel.add(textField2);
        selPanel.add(sel2);
        contentPanel.add(selPanel,gbc);
        //add by caill end
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.insets = new Insets(5, 5, 5, 5);
        contentPanel.add(new JScrollPane(table), gbc);
        gbc.gridx = 0;
        gbc.gridy = 2;
        contentPanel.add(btnPanel, gbc);
        
    }
    
    private JPanel getBtnPanel() {
        JPanel panel = new JPanel();
        JButton addBtn = new JButton("添加");
        addBtn.setActionCommand(ADD_COMMAND);
        addBtn.addActionListener(this);
        JButton delBtn = new JButton("移除");
        delBtn.setActionCommand(DEL_COMMAND);
        delBtn.addActionListener(this);
        panel.add(addBtn);
        panel.add(delBtn);
        return panel;
    }
 
    @Override
    public void actionPerformed(ActionEvent e) {
        try {
            String command = e.getActionCommand();
            if(DEL_COMMAND.equals(command)){
                int[] selRows = table.getSelectedRows();
                if(selRows == null ||selRows.length <= 0){
                    VCIOptionPane.showMessage(ClientContextVariable.getFrame(), "请选择记录!");
                }else{
                    VCIBaseTreeNode selNode = (VCIBaseTreeNode) btTree.getLastSelectedPathComponent();
                    Object selObj = selNode.getObj();
                    if(selObj instanceof BtmItem){
                        String typeName = ((BtmItem)selObj).name;
                        /*Object[] options = { "Yes", "No" };
                        int n = JOptionPane
                                .showOptionDialog(getInstance(), "确认是否移除Action\""
                                        + typeName + "\"", "Action移除",
                                        JOptionPane.YES_NO_OPTION,
                                        JOptionPane.QUESTION_MESSAGE, null, options,
                                        options[1]);
            //            int n = JOptionPane.showConfirmDialog(null, "您确定要执行删除操作吗?");
                        if(n != JOptionPane.YES_OPTION){
                            return;
                        }*/
                        for(int i : selRows){
                            PLAction selAction = tableModel.getRowAt(i);
                            Object[] options = { "Yes", "No" };
                            int n = JOptionPane
                                    .showOptionDialog(getInstance(), "确认是否移除Action\""
                                            + selAction.plName + "\"", "Action移除",
                                            JOptionPane.YES_NO_OPTION,
                                            JOptionPane.QUESTION_MESSAGE, null, options,
                                            options[1]);
                //            int n = JOptionPane.showConfirmDialog(null, "您确定要执行删除操作吗?");
                            if(n != JOptionPane.YES_OPTION){
                                return;
                            }
                            boolean res = UITools.getService().deletePLTypeActionEntityByTypeAndAction(typeName, selAction.plOId);
                        }
                    }
                }
            }else if(ADD_COMMAND.equals(command)){
                String boType = "bpdatarule";
                String context = "activitySelAndAddindatarule";
                VCIBaseTreeNode selNode = (VCIBaseTreeNode) btTree.getLastSelectedPathComponent();
                if(selNode == null){
                    VCIOptionPane.showMessage(ClientContextVariable.getFrame(), "请选择类型!");
                }
                Object selObj = selNode.getObj();
                if(selObj instanceof BtmItem){
                    String typeName = ((BtmItem)selObj).name;
//                    PLActionSelectionDialog dialog = new PLActionSelectionDialog();
                     ActionSelectDialog dialog = new ActionSelectDialog(new JDialog());
                     // PLAction action = dialog.getSelectedAction();
                     //add by caill start
                     //定义一个list用来接收选中的索引行
                     List<PLAction> action = dialog.getSelectedActions();
 
//                    if(dialog.isOK()){
//                        List<PLAction> selActions = dialog.getResult();
//                        if(selActions != null && selActions.size() > 0){
                            PLAction[] actions = UITools.getService().getAllPLActionEntityByType(typeName);
                            List<String> ploids = new ArrayList<String>();
                            //add by caill
                            //遍历数组和list,比较新添加的索引行是否已经存在
                            for(PLAction ac: actions){
                                for(int i=0;i<action.size();i++){
                                    if(action.get(i).plOId.equals(ac.plOId)){
                                        VCIOptionPane.showMessage(ClientContextVariable.getFrame(),"已存在名称为 “ "+action.get(i).plName+" ” 的action");
                                        return;
                                    }
                                }
                            
                            }
                            /*for(PLAction ac: actions){
                                if(action.plOId.equals(ac.plOId)){
                                    VCIOptionPane.showMessage(ClientContextVariable.getFrame(), "您添加的action已存在");
                                    return;
                                }
                            }*/
//                            for(PLAction selAction: selActions){
//                                if(ploids.contains(selAction.plOId)){
//                                    continue;
//                                }
                            //add by caill 
                            for(int i=0;i<action.size();i++){
                                PLTypeAction plTypeAction = new PLTypeAction(ObjectUtility.getNewObjectID36(), typeName, action.get(i).plOId);
                                boolean res = UITools.getService().savePLTypeActionEntity(plTypeAction);
                            }
                            //add by caill end
//                            }
//                        }
//                    }
                }else{
                    VCIOptionPane.showMessage(ClientContextVariable.getFrame(), "该类型不能添加action!");
                }
            }
            this.initData();
        } catch (VCIError e1) {
            e1.printStackTrace();
        }
    }
    
    private void initData(){
        VCIBaseTreeNode selNode = (VCIBaseTreeNode) btTree.getLastSelectedPathComponent();
        try {
            List<PLAction> actions = new ArrayList<PLAction>();
            Object selObj = selNode.getObj();
            if(selObj instanceof BtmItem){
                String typeName = ((BtmItem)selObj).name;
                PLAction[] plActions = UITools.getService().getAllPLActionEntityByType(typeName);
                actions = Arrays.asList(plActions);
            }
            tableModel.setData(actions);
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
 
    private DefaultTreeModel createTreeModel() throws VCIError {
        BtmItem[] allBtItems = BtmProvider.getInstance().getAllBtmItems();
        VCIBaseTreeNode rootNode = new VCIBaseTreeNode("业务类型树","root");
        VCIBaseTreeModel treeModel = new VCIBaseTreeModel(rootNode);
        for(int i=0;i<allBtItems.length;i++){
            VCIBaseTreeNode node = new VCIBaseTreeNode(allBtItems[i].name,allBtItems[i]);
            node.setLeaf(true);
            treeModel.insertNodeInto(node, rootNode, rootNode.getChildCount());
        }
        return new DefaultTreeModel(rootNode);
    }
 
    
 
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame("测试");
                frame.setSize(400, 400);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(TypeActionPanel.getInstance());
                frame.setVisible(true);
            }
        });
    }
 
    private class MyTableModel extends AbstractTableModel{
 
        private static final long serialVersionUID = 1L;
 
        private String[] columns = new String[]{"序号", "编号", "名称", "类路径", "链接地址", "类型", "描述"};
        private List<PLAction> data;
 
        public List<PLAction> getData(){
            return data;
        }
        public MyTableModel() {
            this.data = new ArrayList<PLAction>();
        }
        public void setData(List<PLAction> data){
            this.data = data;
            fireTableDataChanged();
        }
        public void addRow(PLAction dataRule){
            this.data.add(dataRule);
            fireTableStructureChanged();
        }
        public PLAction getRowAt(int rowIndex){
            if(rowIndex >= 0 && rowIndex<data.size()){
                return data.get(rowIndex);
            }
            return null;
        }
        
        @Override
        public String getColumnName(int column) {
            return columns[column];
        }
        @Override
        public int getRowCount() {
            if(data == null){
                return 0;
            }
            return data.size();
        }
 
        @Override
        public int getColumnCount() {
            return this.columns.length;
        }
 
        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            if(this.data == null){
                return null;
            }
            PLAction plAction = this.data.get(rowIndex);
            if(plAction == null){
                return null;
            }
            switch(columnIndex){
                case 0: return rowIndex + 1;
                case 1: return plAction.plCode;
                case 2: return plAction.plName;
                case 3: return plAction.plCSClass;
                case 4: return plAction.plBSUrl;
                case 5: {
                    String plTypeType = plAction.plTypeType;
                    if (plTypeType.equals("business")) {
                        return "业务类型";
                    }else if (plTypeType.equals("link")) {
                        return "链接类型";
                    }
                }
                case 6: return plAction.plDesc;
            }
            return null;
        }
        
//        @Override
//        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
//            PLAction plAction = this.data.get(rowIndex);
//            String value = (String)aValue;
//            switch(columnIndex){
//                case 0: break;
//                case 1: plAction.setName(value);break;
//                case 2: plAction.setDesc(value);break;
//                case 3: plAction.setDataName(value);break;
//                case 4: plAction.setDataType(value);break;
//            }
//        }
    }
    //add by caill
    public void sel(){
        String textValue = textField2.getText().trim();    
        String textValue3 = textField3.getText().trim();
        VCIBaseTreeNode selNode = (VCIBaseTreeNode) btTree.getLastSelectedPathComponent();
        
        try {
            List<PLAction> actions = new ArrayList<PLAction>();
            Object selObj = selNode.getObj();
            if(selObj instanceof BtmItem){
                String typeName = ((BtmItem)selObj).name;
                PLAction[] plActions = UITools.getService().getAllPLActionEntityByType(typeName);
                if(textValue.equals("") && textValue3.equals("")){
                    actions = Arrays.asList(plActions);
                }else{
                    for(int i=0;i<plActions.length;i++){
            
                        if(plActions[i].plName.contains(textValue) && !textValue.equals("") && textValue3.equals("")){
                            //actions = Arrays.asList(plActions[i]);
                            actions.add(plActions[i]);
                        } else if(plActions[i].plCode.contains(textValue3) && !textValue3.equals("") && textValue.equals("")){
                            //actions = Arrays.asList(plActions[i]);
                            actions.add(plActions[i]);
                        } else if(plActions[i].plCode.contains(textValue3) && !textValue3.equals("") 
                                && plActions[i].plName.contains(textValue) && !textValue.equals("") ){
                            //actions = Arrays.asList(plActions[i]);
                            actions.add(plActions[i]);
                        }
                    
                    }
                }
            }
            tableModel.setData(actions);
        } catch (VCIError en) {
            en.printStackTrace();
        }
    }
    
}