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
package com.vci.client.portal.NewUI;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
 
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
 
import com.vci.client.LogonApplication;
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.table.VCIBaseTableModel;
import com.vci.client.ui.table.VCIBaseTableNode;
import com.vci.corba.common.VCIError;
import com.vci.corba.portal.data.PLAction;
 
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import java.awt.FlowLayout;
import javax.swing.JTextField;
 
/**
 * Action管理
 */
public class ActionConfPanel extends VCIBasePanel {
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private JButton addBtn ;
    private JButton editBtn ;
    private JButton delBtn ;
    private JPanel tablePanel;
    private JScrollPane scrollPane;
    private JTable actionTable;
    private VCIBaseTableModel actionTableModel;
    
    String[] headerName = new String[] {
            "编号", "名称","类路径", "链接地址", "类型", "描述"
        };
    Class[] columnTypes = new Class[] {
            String.class, String.class, String.class, String.class, String.class
    };
    private JPanel searchPanel;
    private JLabel label;
    private JTextField searchText;
    private String searchValue ;    
    public ActionConfPanel(FunctionObject funcObj) {
        super(funcObj);
        init();
        initActionListener();
        initData();
    }
 
    private void init() {
        setLayout(new BorderLayout(0, 0));
        
        JPanel panel = new JPanel();
        add(panel, BorderLayout.SOUTH);
        
        addBtn = new JButton("新建");
        panel.add(addBtn);
        
        editBtn = new JButton("修改");
        panel.add(editBtn);
        
        delBtn = new JButton("删除");
        panel.add(delBtn);
        
        tablePanel = new JPanel();
        add(tablePanel, BorderLayout.CENTER);
        tablePanel.setLayout(new BorderLayout(0, 0));
        
        scrollPane = new JScrollPane();
        tablePanel.add(scrollPane);
        
        actionTable = new JTable();
        actionTableModel = new VCIBaseTableModel(headerName,columnTypes);
        actionTable.setModel(actionTableModel);
        scrollPane.setViewportView(actionTable);
        
        searchPanel = new JPanel();
        FlowLayout flowLayout = (FlowLayout) searchPanel.getLayout();
        flowLayout.setAlignment(FlowLayout.LEFT);
        add(searchPanel, BorderLayout.NORTH);
        
        label = new JLabel("编号:");
        searchPanel.add(label);
        
        searchText = new JTextField();
        searchPanel.add(searchText);
        searchText.setColumns(10);
    }
 
    private void initData(){
        actionTableModel.list.clear();
        VCIBaseTableNode vciBaseTableNode = null;
        try {
            PLAction[] obj = UITools.getService().getAllPLAction();
            for(int i =0;i<obj.length;i++){
                vciBaseTableNode = new VCIBaseTableNode(obj[i]);
                vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(0), obj[i].plCode);
                vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(1), obj[i].plName);
                vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(2), obj[i].plCSClass);
                vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(3), obj[i].plBSUrl);
                String plTypeType = obj[i].plTypeType;
                String disType = "";
                if(plTypeType.equals("business")){
                    disType = "业务类型";
                }
                else if(plTypeType.equals("link")){
                    disType = "链接类型";
                }
                vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(4), disType);
                vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(5), obj[i].plDesc);
                actionTableModel.addRow(i, vciBaseTableNode);
            }
            actionTable.setModel(actionTableModel);
            setBanMaXian(actionTable); 
            actionTable.updateUI();
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
    private void initSearchData(){
        actionTableModel.list.clear();
        VCIBaseTableNode vciBaseTableNode = null;
        try {
            PLAction[] obj = UITools.getService().getAllPLAction();
            for(int i =0;i<obj.length;i++){
                vciBaseTableNode = new VCIBaseTableNode(obj[i]);
                if(obj[i].plCode.toLowerCase().contains(searchValue)){
                    vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(0), obj[i].plCode);
                    vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(1), obj[i].plName);
                    vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(2), obj[i].plCSClass);
                    vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(3), obj[i].plBSUrl);
                    String plTypeType = obj[i].plTypeType;
                    String disType = "";
                    if(plTypeType.equals("business")){
                        disType = "业务类型";
                    }
                    else if(plTypeType.equals("link")){
                        disType = "链接类型";
                    }
                    vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(4), disType);
                    vciBaseTableNode.setPropertyValueByName(actionTable.getColumnName(5), obj[i].plDesc);
                    actionTableModel.addRow(i, vciBaseTableNode);
                }
            }
            actionTable.setModel(actionTableModel);
            setBanMaXian(actionTable); 
            actionTable.updateUI();
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
    
    //设置JTable斑马线效果  
    public void setBanMaXian(JTable table)  
    {  
        //斑马线设置  
        DefaultTableCellRenderer d = new DefaultTableCellRenderer()  
        {//需要重写类中的getTableCellRendererComponent的方法  
            @Override  
            public Component getTableCellRendererComponent(JTable table,  
                    Object value, boolean isSelected, boolean hasFocus,  
                    int row, int column)  
            {  
                if(row % 2 == 0)//JTable中的奇数行  
                {  
                    setBackground(Color.WHITE);  
                }  
                else//JTable中的偶数行  
                {  
                    setBackground(Color.LIGHT_GRAY);  
                }  
                return super.getTableCellRendererComponent(table, value, isSelected, hasFocus,  
                        row, column);  
            }  
        };  
            for(int i = 0; i< table.getColumnCount();i++)  
            {  
                TableColumn col = table.getColumn(table.getColumnName(i));  
                col.setCellRenderer(d);//将斑马线对象放置到表格中  
            }  
    } 
    
    private void initActionListener(){
        searchText.getDocument().addDocumentListener(new DocumentListener() {
            
            @Override
            public void removeUpdate(DocumentEvent arg0) {
                searchValue = searchText.getText();
                if(searchValue==null||"".equals(searchValue)){
                    initData();
                }else{
                    initSearchData();
                }
            }
            
            @Override
            public void insertUpdate(DocumentEvent arg0) {
                searchValue = searchText.getText();
                if(searchValue==null||"".equals(searchValue)){
                    return;
                }else{
                    initSearchData();
                }
            }
            
            @Override
            public void changedUpdate(DocumentEvent arg0) {
            }
        });
        addBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                ActionConfDialog dialog = new ActionConfDialog(null);
                dialog.setVisible(true);
                initData();
            }
        });
        editBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int selectedRowCount = actionTable.getSelectedRowCount();
                if(selectedRowCount==0){
                    VCIOptionPane.showMessage(LogonApplication.frame, "请选择一条数据!");
                    return;
                }
                int selectedRow = actionTable.getSelectedRow();
                PLAction obj = (PLAction) actionTableModel.getValueAt(selectedRow).getObj();
                
                ActionConfDialog dialog = new ActionConfDialog(obj);
                dialog.setVisible(true);
                initData();
            }
        });
        delBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int selectedRowCount = actionTable.getSelectedRowCount();
                if(selectedRowCount==0){
                    VCIOptionPane.showMessage(LogonApplication.frame, "请选择一条数据!");
                    return;
                }
                if (VCIOptionPane.showQuestion(LogonApplication.frame,
                        "确定要删除记录吗?") != 0) {
                    return;
                }
                int selectedRow = actionTable.getSelectedRow();
                PLAction obj = (PLAction) actionTableModel.getValueAt(selectedRow).getObj();
                try {
                    UITools.getService().deletePLAction(obj);
                    VCIOptionPane.showMessage(LogonApplication.frame, "删除成功!");
                } catch (VCIError e) {
                    VCIOptionPane.showMessage(LogonApplication.frame, "删除失败!");
                    e.printStackTrace();
                }
                initData();
            }
        });
    }
}