ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
package com.vci.client.portal.UI;
 
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.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.PinyinCommon;
import com.vci.client.common.VCIBasePanel;
import com.vci.client.framework.rightConfig.object.FunctionObject;
import com.vci.client.portal.utility.UITools;
import com.vci.client.ui.swing.VCIOptionPane;
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;
 
/**
 * Action管理
 */
public class ActionConfPanel extends VCIBasePanel {
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private VCIJButton addBtn = VCISwingUtil.createVCIJButton("add", "增加", "增加", "add.png");
    private VCIJButton editBtn = VCISwingUtil.createVCIJButton("edit", "修改", "修改", "edit.png");
    private VCIJButton delBtn = VCISwingUtil.createVCIJButton("delete", "删除", "查询", "delete.png");
    
    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");
    public ActionConfPanel(FunctionObject funcObj) {
        super(funcObj);
        init();
    }
 
    private void init() {
        initUI();
        initActionListener();
    }
    
    private void initUI(){
        setLayout(new BorderLayout());
        add(getNorthPanel(), BorderLayout.NORTH);
        add(getWestPanel(), BorderLayout.WEST);
        add(getCenterPanel(), BorderLayout.CENTER);
        add(getEastPanel(), BorderLayout.EAST);
        add(getSouthPanel(), BorderLayout.SOUTH);
    }
 
    private VCIJPanel getNorthPanel(){
        VCIJPanel pal = new VCIJPanel(new GridBagLayout());
        int gridx = 0; int gridy = 0; int padxy = 2;
        int anchor = GridBagConstraints.NORTHWEST;
        int fill = GridBagConstraints.BOTH;
        pal.add(lblCode, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        pal.add(txtCode, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        pal.add(lblName, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        pal.add(txtName, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        
        gridx = 0; gridy += 1;
        pal.add(lblBSClass, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        pal.add(txtBSClass, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        pal.add(lblCSClass, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        pal.add(txtCSClass, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        
        gridx = 0; gridy += 1;
        pal.add(lblType, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        pal.add(cbxType, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        pal.add(lblDesc, getGBC(gridx++, gridy, 1, 1, 0, 0, anchor, fill, padxy));
        pal.add(txtDesc, getGBC(gridx++, gridy, 1, 1, 1.0, 0.0, anchor, fill, padxy));
        
        VCIJPanel pp = new VCIJPanel(new BorderLayout());
        pp.add(pal, BorderLayout.CENTER);
        
        VCIJPanel pb = new VCIJPanel();
        pb.add(btnSearch);pb.add(btnClear);
        pp.add(pb, BorderLayout.SOUTH);
        
        return pp;
    }
 
    private VCIJPanel getWestPanel(){
        VCIJPanel pal = new VCIJPanel(new BorderLayout());
        return pal;
    }
 
    private VCIJPanel getEastPanel(){
        VCIJPanel pal = new VCIJPanel(new BorderLayout());
        return pal;
    }
    
    private VCIJPanel getSouthPanel(){
        VCIJPanel pal = new VCIJPanel(new BorderLayout());
        return pal;
    }
    
    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;
        }
    }
    
    private PLAction[] getTablePanelData(){
        PLAction[] res = getAllActionsFromDB();
        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;
    }
 
    private PLAction[] getAllActionsFromDB(){
        PLAction[] res = new PLAction[0];
        try {
            res = UITools.getService().getPLActionsByConsArray(getFilterConstraints());
        } catch (VCIError e) {
            e.printStackTrace();
        }
        return res;
    }
    
    private Constraint[] getFilterConstraints(){
        Constraint[] 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());
        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 VCIJTablePanel<PLAction> tablePanel = null;
    private VCIJPanel getCenterPanel(){
        tablePanel = new VCIJTablePanel<PLAction>(new ActionDataProvider());
        List<VCIJButton> btns = new LinkedList<VCIJButton>();
        btns.add(addBtn);btns.add(editBtn);btns.add(delBtn);
        tablePanel.setCustomButtons(btns);
        tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER);
        tablePanel.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);
        tablePanel.setColumnWidthMaps(columnWidthMap);
        tablePanel.buildTablePanel();
        tablePanel.refreshTableData();
        return tablePanel;
    }
    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);
    }
    
    private void refreshActionData(){
        tablePanel.refreshTableData();
    }
    
    private PLAction getSelectedAction(){
        int[] rows = tablePanel.getSelectedRowIndexs();
        int selectedRowCount = rows.length;
        if(selectedRowCount == 0){
            VCIOptionPane.showMessage(LogonApplication.frame, "请选择一条数据!");
            return null;
        } else if(selectedRowCount > 1){
            VCIOptionPane.showMessage(LogonApplication.frame, "一次只能选择一条数据进行此操作!");
            return null;
        }
        return tablePanel.getSpecialObjectByRowIndex(rows[0]);
    }
    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) {
                refreshActionData();
            }
        });
        addBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                ActionConfDialog dialog = new ActionConfDialog(null);
                dialog.setVisible(true);
                refreshActionData();
            }
        });
        editBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                PLAction obj = getSelectedAction();
                if(obj == null) return;
                
                ActionConfDialog dialog = new ActionConfDialog(obj);
                dialog.setVisible(true);
                refreshActionData();
            }
        });
        delBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                PLAction obj = getSelectedAction();
                if(obj == null) return;
                try {
                    UITools.getService().deletePLAction(obj);
                    VCIOptionPane.showMessage(LogonApplication.frame, "删除成功!");
                } catch (VCIError e) {
                    VCIOptionPane.showMessage(LogonApplication.frame, "删除失败!");
                    e.printStackTrace();
                }
                refreshActionData();
            }
        });
    }
}