wangting
2025-01-16 18c43123b51a1688ab4ae01fe3d171c7d92e619b
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
package com.vci.client.portal.NewNewUI.actionmng;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
 
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
 
import com.vci.client.common.PinyinCommon;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJComboBox;
import com.vci.client.ui.swing.components.VCIJLabel;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.VCIJTextField;
import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
import com.vci.corba.common.VCIError;
import com.vci.corba.portal.data.Constraint;
import com.vci.corba.portal.data.PLAction;
import com.vci.corba.portal.data.PLActionCls;
import com.vci.mw.ClientContextVariable;
 
/**
 * Action选择窗口
 * @author VCI-STGK006
 *
 */
public class ActionSelectDialog extends JDialog {
 
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 5783143146712146457L;
    private VCIJTablePanel<PLAction> actionTablePanel = null;
    private JTree clsTree;
    String[] headerName = new String[] {
        "编号", "名称","类路径", "链接地址", "类型", "描述"
    };
    private VCIJLabel lblCode = new VCIJLabel("编号:");
    private VCIJTextField txtCode = new VCIJTextField("");
    private VCIJLabel lblName = new VCIJLabel("名称:");
    private VCIJTextField txtName = new VCIJTextField("");
    
    private VCIJLabel lblBSClass = new VCIJLabel("B/S类路径:");
    private VCIJTextField txtBSClass = new VCIJTextField("");
    private VCIJLabel lblCSClass = new VCIJLabel("C/S类路径:");
    private VCIJTextField txtCSClass = new VCIJTextField("");
    
    private VCIJLabel lblType = new VCIJLabel("业务类型:");
    private VCIJComboBox cbxType = new VCIJComboBox(new String[]{"","业务类型","链接类型"});
    private VCIJLabel lblDesc = new VCIJLabel("描述:");
    private VCIJTextField txtDesc = new VCIJTextField("");
    
    private VCIJButton btnSearch = VCISwingUtil.createVCIJButton("search", "查询", "查询", "search.png");
    private VCIJButton btnClear = VCISwingUtil.createVCIJButton("clear", "清空", "清空", "clear.gif");
    
    private JSplitPane mainSplitPanel;
    
    /**
     * 用户选择的Action
     */
    private PLAction selectedAction = null;
    //PLAction[] selectedActions =new PLAction[2];
    //add by caill 定义一个list
    List<PLAction> list=new ArrayList();
    /**
     * 当前选择的分类节点
     * 当选择根节点时为null
     */
    private PLActionCls currentCls = null;
 
    /**
     * 构造器
     * @param owner
     */
    public ActionSelectDialog(JDialog owner) {
        super(owner, "选择Action", true);
        init();
        this.validate();
        this.setSize(800, 600);
        this.setLocationRelativeTo(owner);
        this.setVisible(true);
    }
 
    private void init() {
        initUI();
        initActionListener();
        
        //设置第一个分类选中状态
        clsTree.expandRow(0);
        clsTree.setSelectionRow(0);
    }
    
    private void initUI(){
        //
        this.setLayout(new BorderLayout());
        
        //得到分类树面板
        JPanel treePanel = getTreePanel();
        
        //刷新分类树
        refreshClsTree(clsTree.getPathForRow(0));
        
        //得到Action列表
        JPanel actionPanel = getActionPanel();
        actionPanel.setBorder(BorderFactory.createTitledBorder("Action列表"));
        
        mainSplitPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        mainSplitPanel.setDividerSize(2);
        mainSplitPanel.setDividerLocation(0.2);
        mainSplitPanel.add(treePanel, JSplitPane.LEFT);
        mainSplitPanel.add(actionPanel, JSplitPane.RIGHT);
        
        //创建按钮面板
        FlowLayout fl = new FlowLayout(FlowLayout.CENTER);
        fl.setHgap(10);
        JPanel btnPanel = new JPanel(fl);
        JButton okBtn = new JButton("确定");
        okBtn.setSize(50, 25);
        okBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                okBtnListener();
            }
        });
        JButton cancelBtn = new JButton("取消");
        cancelBtn.setSize(50, 25);
        cancelBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                cancelBtnListener();
            }
        });
        btnPanel.add(okBtn);
        btnPanel.add(cancelBtn);
        
        this.getContentPane().setLayout(new BorderLayout());
        this.getContentPane().add(mainSplitPanel, BorderLayout.CENTER);
        this.getContentPane().add(btnPanel, BorderLayout.SOUTH);
        
        this.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
                mainSplitPanel.setDividerLocation(0.2);
            }
        });
    }
    
    /**
     * 确定按钮
     */
    private void okBtnListener() {
        int[] selectedCount = this.actionTablePanel.getSelectedRowIndexs();
        
        if(selectedCount == null || selectedCount.length < 1) {
            JOptionPane.showMessageDialog(this, "请选择Action!", 
                    "系统提示", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        /*if(selectedCount.length > 1) {
            JOptionPane.showMessageDialog(this, "只能选择一个Action!", 
                    "系统提示", JOptionPane.INFORMATION_MESSAGE);
            return;
        }*/
        //add by caill start
        //将所有选中的索引行加入到list中
        for(int i=0;i<selectedCount.length;i++){
            list.add(this.actionTablePanel.getSpecialObjectByRowIndex(selectedCount[i]));            
        }
        //add by caill end
        this.selectedAction = this.actionTablePanel.getSpecialObjectByRowIndex(selectedCount[0]);
    
        this.dispose();
    }
    
    /**
     * 取消按钮
     */
    private void cancelBtnListener() {
        this.dispose();
    }
    
    private void refreshClsTree(TreePath tp) {
        try {
            //分类较少,直接查询所有分类
            PLActionCls[] clses = UITools.getService().getPLActionClsArray();
            
            DefaultTreeModel dtml = (DefaultTreeModel) clsTree.getModel();
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) 
                    tp.getLastPathComponent();
            addClsTreeNode(dtml, node, clses);
        } catch (VCIError e1) {
            e1.printStackTrace();
            JOptionPane.showMessageDialog(ClientContextVariable.getFrame(), 
                    "刷新分类树异常:" + e1.getMessage(), "系统异常", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    /**
     * 得到Action分类树面板
     * @return
     */
    private JPanel getTreePanel() {
        JPanel panel = new JPanel(new BorderLayout());
        
        //初始化树
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Action分类");
        DefaultTreeModel dtml = new DefaultTreeModel(root);
        clsTree = new JTree(dtml);
        clsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        clsTree.addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
                clsTreeSelectionListener(e);
            }
        });
        
        //添加树
        JScrollPane scrollPane = new JScrollPane(clsTree);
        panel.add(scrollPane, BorderLayout.CENTER);
        return panel;
    }
    
    /**
     * 添加分类树节点
     * @param dtml 树模型
     * @param node 节点
     * @param clses 分类 
     */
    private void addClsTreeNode(DefaultTreeModel dtml, 
            DefaultMutableTreeNode node, PLActionCls[] clses) {
        node.removeAllChildren();
        String pid = "";
        Object userObject = node.getUserObject();
        if(!(userObject instanceof String)) {
            PLActionCls pac = ((ClientPLActionCls) userObject).getPac();
            pid = pac.id;
        }
        //添加子节点
        for(PLActionCls plac : clses) {
            if(plac.pid.equals(pid)) {
                DefaultMutableTreeNode child = new DefaultMutableTreeNode(
                        new ClientPLActionCls(plac));
                dtml.insertNodeInto(child, node, node.getChildCount());
                addClsTreeNode(dtml, child, clses);
            }
        }
        if(pid.equals("")) {
            PLActionCls plac = new PLActionCls("", "未分类", "", "", "", 0, (short)0);
            DefaultMutableTreeNode child = new DefaultMutableTreeNode(
                    new ClientPLActionCls(plac));
            dtml.insertNodeInto(child, node, node.getChildCount());
        }
        dtml.reload(node);
    }
    
    /**
     * 树节点选择事件
     * @param e
     */
    private void clsTreeSelectionListener(TreeSelectionEvent e) {
        TreePath tp = e.getPath();
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tp.getLastPathComponent();
        Object userObject = node.getUserObject();
        if(userObject instanceof String) {
            this.currentCls = null;
        } else {
            ClientPLActionCls pac = (ClientPLActionCls) userObject;
            this.currentCls = pac.getPac();
        }
        actionTablePanel.refreshTableData();
    }
 
    /**
     * Action管理
     * @return
     */
    private JPanel getActionPanel(){
        JPanel topPanel = new JPanel();
        topPanel.setLayout(new BorderLayout());
        //查询区域
        VCIJPanel queryPanel = new VCIJPanel(new GridBagLayout());
        int gridx = 0; int gridy = 0; int padxy = 2;
        int anchor = GridBagConstraints.NORTHWEST;
        int fill = GridBagConstraints.BOTH;
        queryPanel.add(lblCode, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        queryPanel.add(txtCode, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        queryPanel.add(lblName, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        queryPanel.add(txtName, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        
        gridx = 0; gridy += 1;
        queryPanel.add(lblBSClass, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        queryPanel.add(txtBSClass, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        queryPanel.add(lblCSClass, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        queryPanel.add(txtCSClass, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        
        gridx = 0; gridy += 1;
        queryPanel.add(lblType, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        queryPanel.add(cbxType, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        queryPanel.add(lblDesc, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        queryPanel.add(txtDesc, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        
        VCIJPanel pb = new VCIJPanel();
        pb.add(btnSearch);
        pb.add(btnClear);
        
        JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        
        VCIJPanel pp = new VCIJPanel(new BorderLayout());
        pp.add(queryPanel, BorderLayout.NORTH);
        pp.add(pb, BorderLayout.CENTER);
        pp.add(btnPanel, BorderLayout.SOUTH);
        
        //按钮列表
        actionTablePanel = new VCIJTablePanel<PLAction>(new ActionDataProvider());
        actionTablePanel.setPageSizeList(new int[]{100,150,200,250,300,350,400});
        HashMap<Integer, Integer> columnWidthMap = new HashMap<Integer, Integer>();
        columnWidthMap.put(1, 150);
        columnWidthMap.put(2, 250);
        columnWidthMap.put(3, 400);
        columnWidthMap.put(4, 500);
        columnWidthMap.put(5, 300);
        columnWidthMap.put(6, 200);
        columnWidthMap.put(7, 500);
        actionTablePanel.setColumnWidthMaps(columnWidthMap);
        actionTablePanel.setLastClickRowToChecked(true);
        actionTablePanel.setShowCheckbox(false);
        actionTablePanel.buildTablePanel();
        actionTablePanel.refreshTableData();
        
        topPanel.add(pp, BorderLayout.NORTH);
        topPanel.add(actionTablePanel, BorderLayout.CENTER);
        
        return topPanel;
    }
    
    class ActionDataProvider extends AbstractVCIJTableDataProvider<PLAction>{
        @Override
        public PLAction[] getDatas(int pageIndex, int pageSize) {
            PLAction[] res = getTablePanelData();
            super.total = res.length;
            return res;
        }
        @Override
        public VCIJTableNode<PLAction> getNewRowNode(PLAction obj) {
            return getTablePanelNode(obj);
        }
        @Override
        public String[] getSpecialColumns() {
            return headerName;
        }
        @Override
        public int getTotal() {
            return total;
        }
    }
    
    /**
     * 查询Action表格数据
     * @return
     */
    private PLAction[] getTablePanelData(){
        PLAction[] res = null;
        try {
            res = UITools.getService().getPLActionsByConsArray(getFilterConstraints());
        } catch (VCIError e) {
            e.printStackTrace();
        }
        
        Arrays.sort(res, new Comparator<PLAction>(){
            @Override
            public int compare(PLAction o1, PLAction o2) {
                String py1 = PinyinCommon.getPingYin(o1.plName);
                String py2 = PinyinCommon.getPingYin(o2.plName);
                return py1.compareTo(py2);
            }});
        return res;
    }
    
    /**
     * 设置table查询条件
     * @return
     */
    private Constraint[] getFilterConstraints(){
        Constraint[] consArray = new Constraint[7];
        if(this.currentCls == null) {
            consArray = new Constraint[6];
        }
        consArray[0] = new Constraint("plcode", txtCode.getText().trim());
        consArray[1] = new Constraint("plname", txtName.getText().trim());
        consArray[2] = new Constraint("plbsurl", txtBSClass.getText().trim());
        consArray[3] = new Constraint("plcsclass", txtCSClass.getText().trim());
        String type = cbxType.getSelectedItem().toString();
        if(type.equals("业务类型")){
            type = "business";
        } else if(type.equals("链接类型")){
            type = "link";
        }
        consArray[4] = new Constraint("pltypetype", type);
        consArray[5] = new Constraint("pldesc", txtDesc.getText().trim());
        if(this.currentCls != null) {
            if(this.currentCls.name.equals("未分类")) {
                consArray[6] = new Constraint("plactioncls", "");
            } else {
                consArray[6] = new Constraint("plactioncls", this.currentCls.id);
            }
        }
        return consArray;
    }
    
    private VCIJTableNode<PLAction> getTablePanelNode(PLAction obj){
        VCIJTableNode<PLAction> res = new VCIJTableNode<PLAction>(obj);
        res.setPropertyValue(headerName[0], obj.plCode);
        res.setPropertyValue(headerName[1], obj.plName);
        res.setPropertyValue(headerName[2], obj.plCSClass);
        res.setPropertyValue(headerName[3], obj.plBSUrl);
        String plTypeType = obj.plTypeType;
        String disType = "";
        if(plTypeType.equals("business")){
            disType = "业务类型";
        }
        else if(plTypeType.equals("link")){
            disType = "链接类型";
        }
        res.setPropertyValue(headerName[4], disType);
        res.setPropertyValue(headerName[5], obj.plDesc);
        return res;
    }
    
    private void clear(){
        txtCode.setText("");txtName.setText("");
        txtBSClass.setText("");txtCSClass.setText("");
        cbxType.setSelectedIndex(0);
        cbxType.setSelectedItem("");
        txtDesc.setText("");
    }
    
    private void initActionListener(){
        btnClear.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                clear();
            }
        });
        btnSearch.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                actionTablePanel.refreshTableData();
            }
        });
    }
    
    private GridBagConstraints getGBC(int gridx, int gridy, int gridwidth,
            int gridheight, double weightx, double weighty, int anchor,
            int fill, int padxy) {
        return new GridBagConstraints(gridx, gridy, gridwidth, gridheight,
                weightx, weighty, anchor, fill, new Insets(padxy, padxy, padxy,
                        padxy), padxy, padxy);
    }
 
    /**
     * 得到用户选择的Action
     * @return
     */
    public PLAction getSelectedAction() {
    
        return selectedAction;
    }
    //add by caill start
    //添加list返回方法
    public  List<PLAction> getSelectedActions() {    
        
        return list;
        
    }
    //add by caill end
}