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
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
package com.vci.client.auth2.view;
 
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
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.ArrayList;
import java.util.List;
 
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
 
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.HighlighterFactory;
 
import com.vci.client.LogonApplication;
import com.vci.client.auth2.action.QueryAction;
import com.vci.client.auth2.component.RefTextField;
import com.vci.client.auth2.model.BooleanTableModel;
import com.vci.client.auth2.utils.IRightConstant;
import com.vci.client.auth2.utils.RightManagerHelper;
import com.vci.client.auth2.vo.OpItem;
import com.vci.client.common.objects.DeptObject;
import com.vci.client.common.objects.RoleObject;
import com.vci.client.common.objects.UserObject;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.logon.base.BaseJDialog;
import com.vci.client.ui.exception.VCIException;
import com.vci.corba.framework.data.CheckValue;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.omd.data.BusinessObject;
 
public class CheckRightResultView extends BaseJDialog {
    /**
     * 
     */
    private static final long serialVersionUID = 2310057621717549497L;
    private static CheckRightResultView instance;
    private final int TABLE_HEADER_HEIGHT = 25;
    private final int ROW_HEIGHT = 30;
    private JXTable OPTable = new JXTable();
    private BusinessObject businessObject;
    private int length = 0;;
    // 主体
    private JPanel userPanel = new JPanel();
 
    private JPanel objectPanel = new JPanel();
    // 用户
    private JComboBox userCombbox = new JComboBox();
    // 角色
    private JComboBox roleCombbox = new JComboBox();
    // 用户组
    private JComboBox userGroupCombbox = new JComboBox();
 
    private RefTextField objectTextField = new RefTextField(15);
 
    private JScrollPane opPanel = new JScrollPane();
    private QueryAction query = new QueryAction("查询业务对象");
    @SuppressWarnings("unused")
    private BtmItem resourceType;
    private RightManagementClientDelegate dao = new RightManagementClientDelegate();
    private AbstractUIFunclet funclet;
 
    public static CheckRightResultView getInstance() {
        if (instance == null) {
            instance = new CheckRightResultView();
        }
        return instance;
    }
 
    private CheckRightResultView() {
        super(LogonApplication.frame);
        setTitle("查看授权结果");
        setModal(true);
        initUI();
    }
 
    public void refresh() {
        initData();
    }
 
    public BusinessObject getBusinessObject() {
        return businessObject;
    }
 
    public void setBusinessObject(BusinessObject businessObject) {
        this.businessObject = businessObject;
    }
 
    private void initObjectListener() {
        objectTextField.getText().getDocument().addDocumentListener(
                new DocumentListener() {
                    @Override
                    public void removeUpdate(DocumentEvent e) {
                        // textValueChange();
                    }
 
                    @Override
                    public void insertUpdate(DocumentEvent e) {
                        textValueChange();
                    }
 
                    @Override
                    public void changedUpdate(DocumentEvent e) {
                        textValueChange();
                    }
                });
        objectTextField.getText().addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                textValueChange();
            }
        });
    }
 
    private void textValueChange() {
        CheckValue params = new CheckValue();
        params.users = getString(userCombbox);
        params.roles = getString(roleCombbox);
        params.userGroups = getString(userGroupCombbox);
        params.businesstype = getResourceType(objectTextField.getText().getText().trim()
                .equals("") ? "22385E82-485C-549D-E2F4-91278E9E0A76"
                : objectTextField.getText().getText().trim());
        params.opname = IRightConstant.OPS;
        params.objectmoid = "";
        params.objectroid = "";
        params.objectoid = objectTextField.getText().getText().trim().equals("") ? "22385E82-485C-549D-E2F4-91278E9E0A76"
                : objectTextField.getText().getText().trim();
        initData(params);
    }
 
    private void initSubjectDatas() {
        // 主体
        UserObject uo = com.vci.client.LogonApplication.userObject;
        switch (uo.getUserType()) {
        case 0:
 
        case 1:
            // 管理员用户(系统)
            // 查询所有的普通用户信息
            UserObject[] userInfos = null;
            try {
                userInfos = new RightManagementClientDelegate(
                        LogonApplication.getUserEntityObject())
                        .fetchUserInfoByType(1);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(
                        com.vci.client.LogonApplication.frame,
                        "查询用户信息出错\n" + e.getMessage(), "提示",
                        JOptionPane.ERROR_MESSAGE);
            }
            initCombobox(userCombbox, userInfos);
            break;
        case 2:
            // 普通用户
            addSubjectData(uo, dao);
            break;
        default:
            // 普通用户
            addSubjectData(uo, dao);
        }
    }
 
    private void addUserComboboxListener() {
        // 增加选择监听
        userCombbox.addActionListener(new ActionListener() {
 
            @Override
            public void actionPerformed(ActionEvent e) {
                UserObject uo = (UserObject) userCombbox.getSelectedItem();
                if (uo != null) {
                    // 查询角色
                    initRoleAndUserGroupCombobox(uo, dao);
                }
 
            }
        });
    }
 
    private void initRoleAndUserGroupCombobox(UserObject uo,
            RightManagementClientDelegate dao) {
        if (uo == null)
            return;
        // 角色
        RoleObject[] roleObjects = null;
        DeptObject depObject = null;
        try {
            roleObjects = dao.fetchRoleInfoByUserId(uo.getId());
            depObject = dao.fetchDeptByUserId(uo.getId());
        } catch (VCIException e) {
            JOptionPane.showMessageDialog(
                    com.vci.client.LogonApplication.frame,
                    "查询信息出错\n" + e.getMessage(), "提示",
                    JOptionPane.ERROR_MESSAGE);
        }
        initCombobox(roleCombbox, roleObjects);
        initCombobox(userGroupCombbox, new Object[] { depObject });
    }
 
    private void initCombobox(JComboBox combobox, Object[] datas) {
        DefaultComboBoxModel model = (DefaultComboBoxModel) combobox.getModel();
        model.removeAllElements();
        if (datas != null && datas.length != 0) {
            for (Object o : datas) {
                combobox.addItem(o);
            }
        }
    }
 
    private void addSubjectData(UserObject uo, RightManagementClientDelegate dao) {
        initCombobox(userCombbox, new Object[] { uo });
        initRoleAndUserGroupCombobox(uo, dao);
    }
 
    private String getString(JComboBox combobox) {
        StringBuffer sb = new StringBuffer();
        if (combobox.getItemCount() == 0) {
            return "";
        }
        Object eachItem = combobox.getSelectedItem();
        if (eachItem instanceof UserObject) {
            sb.append(((UserObject) eachItem).getUserName());
            return sb.toString();
        }
 
        for (int i = 0; i < combobox.getItemCount(); i++) {
            Object item = combobox.getItemAt(i);
            sb.append(item);
            sb.append(",");
        }
 
        return sb.substring(0, sb.lastIndexOf(","));
 
    }
 
    private void initData(CheckValue params) {
        // 操作
        List<OpItem> opitems = new ArrayList<OpItem>();
        try {
            String where = ServiceProvider.getFrameService().checkRight(params);
            String[] ops = where.split(":");
 
            for (String s : ops) {
                if (s != null && !s.equals("")) {
                    OpItem item = new OpItem();
                    String[] op = s.split(",");
                    item.setName(op[0]);
                    item.setValue(op[1]);
                    opitems.add(item);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(
                    com.vci.client.LogonApplication.frame, "鉴权出错\n"
                            + e.getLocalizedMessage(), "提示",
                    JOptionPane.ERROR_MESSAGE);
        }
        // 设置列头
        // 操作信息
        // 设置Table列头信息
        List<String> tableHeader = new ArrayList<String>();
 
        for (int m = 0; m < opitems.size(); m++) {
            tableHeader.add(opitems.get(m).getName());
 
        }
        BooleanTableModel booleanModel = new BooleanTableModel();
        booleanModel.setColumnCount(tableHeader.size());
        booleanModel.setColumnIdentifiers(tableHeader.toArray(new String[tableHeader.size()]));
        getOPTable().setModel(booleanModel);
        booleanModel.setColumnCount(tableHeader.size());
        booleanModel.setColumnIdentifiers(tableHeader.toArray(new String[tableHeader.size()]));
        // 设置列宽
        JTable table = getOPTable();
        TableColumnModel columnModel = table.getColumnModel();
        double maxWidth = 0;
        for (int i = 0; i < columnModel.getColumnCount(); i++) {
            TableColumn column = columnModel.getColumn(i);
            TableCellRenderer cellRenderer = column.getHeaderRenderer();
            if (cellRenderer == null)
                cellRenderer = table.getDefaultRenderer(columnModel.getColumn(i).getClass());
            Object headerValue = column.getHeaderValue();
            Component columnComp = cellRenderer.getTableCellRendererComponent(
                    (JTable) table, headerValue, false, false, 0, i);
 
            maxWidth = Math.max(maxWidth, columnComp.getPreferredSize().getWidth());
        }
 
        JTableHeader jtableHeader = table.getTableHeader();
        Dimension size = jtableHeader.getPreferredSize();
        size.width = (int) maxWidth;
        jtableHeader.setPreferredSize(size);
        // 设置数据
        booleanModel.setRowCount(1);
        for (int n = 0; n < opitems.size(); n++) {
            booleanModel.setValueAt(
                    opitems.get(n).getValue().equals("1") ? true : false, 0, n);
 
        }
        // Action
        query.setFunclet(getFunclet());
        query.setUiContainer(this);
        refreshUI();
    }
 
    private void initData() {
        initSubjectDatas();
        // 操作
        CheckValue params = new CheckValue();
        params.users = getString(userCombbox);
        params.roles = getString(roleCombbox);
        params.userGroups = getString(userGroupCombbox);
        params.paramValues="";
        params.businesstype = getResourceType(objectTextField.getText().getText().trim()
                .equals("") ? "22385E82-485C-549D-E2F4-91278E9E0A76"
                : objectTextField.getText().getText().trim());
        params.opname = IRightConstant.OPS;
        params.objectmoid = "";
        params.objectroid = "";
        params.objectoid = objectTextField.getText().getText().trim().equals("") ? "22385E82-485C-549D-E2F4-91278E9E0A76"
                : objectTextField.getText().getText().trim();
        initData(params);
    }
 
    private void refreshUI() {
        //
        initDialogSize(opPanel.getPreferredSize().width + 20, 450);
        userPanel.setPreferredSize(new Dimension(
                opPanel.getPreferredSize().width, 60));
        opPanel.setPreferredSize(new Dimension(
                opPanel.getPreferredSize().width, 120));
    }
 
    private void initUI() {
        JPanel mainPanel = new JPanel();
        // 主体信息
        GridBagConstraints g_mpnl = new GridBagConstraints();
        g_mpnl.insets = new Insets(5, 5, 5, 5);
        g_mpnl.anchor = GridBagConstraints.EAST;
        g_mpnl.gridx = 0;
        g_mpnl.gridy = 0;
        JLabel userLable = new JLabel("  用户:");
        userPanel.add(userLable, g_mpnl);
        g_mpnl.gridx = 1;
        userPanel.add(userCombbox, g_mpnl);
        g_mpnl.anchor = GridBagConstraints.CENTER;
        g_mpnl.gridx = 2;
        JLabel roleLable = new JLabel("  角色:");
        userPanel.add(roleLable, g_mpnl);
        g_mpnl.gridx = 3;
        userPanel.add(roleCombbox, g_mpnl);
        JLabel usergLable = new JLabel("  用户组:");
        g_mpnl.anchor = GridBagConstraints.WEST;
        g_mpnl.gridx = 4;
        userPanel.add(usergLable, g_mpnl);
        g_mpnl.gridx = 5;
        userPanel.add(userGroupCombbox, g_mpnl);
        userPanel.setBorder(BorderFactory.createTitledBorder("用户信息"));
 
        userPanel.setLayout(new GridBagLayout());
 
        userPanel.setPreferredSize(new Dimension(this.length == 0 ? 450
                : this.length, 300));
 
        // 客体
 
        objectTextField.setLable("  业务对象:");
        objectPanel.add(objectTextField);
        ((RefTextField) objectTextField).setParent(objectPanel);
        ((RefTextField) objectTextField).setRefButton((JButton) query);
        ((RefTextField) objectTextField).updateUI();
        initObjectListener();
        // 操作
        JPanel OpMainPanel = new JPanel();
        OpMainPanel.setLayout(new BorderLayout());
        // UIAction ok = new UIAction("确定");
        JPanel actionPanel = new JPanel();
        actionPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
        // actionPanel.add(ok);
        // table
        OpMainPanel.add(opPanel, BorderLayout.NORTH);
        OpMainPanel.add(actionPanel, BorderLayout.CENTER);
        opPanel.setBorder(BorderFactory.createTitledBorder("  授权结果:"));
        getOPTable().setRowHeight(ROW_HEIGHT);
        getOPTable().setHorizontalScrollEnabled(true);
        getOPTable().setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        getOPTable().setHighlighters(
                HighlighterFactory.createAlternateStriping());
        // ruleTable.setSortable(true);
        getOPTable().setDragEnabled(false);
        JTableHeader tableHeader = getOPTable().getTableHeader();
        Dimension size = tableHeader.getPreferredSize();
        size.height = TABLE_HEADER_HEIGHT;
        size.width = TABLE_HEADER_HEIGHT;
        tableHeader.setPreferredSize(size);
        opPanel.setViewportView(getOPTable());
        initDialogSize(600, 450);
        mainPanel.add(objectPanel, BorderLayout.NORTH);
        mainPanel.add(userPanel, BorderLayout.CENTER);
        mainPanel.add(OpMainPanel, BorderLayout.SOUTH);
        add(mainPanel);
        addUserComboboxListener();
    }
 
    public JXTable getOPTable() {
        return OPTable;
    }
 
    public void setOPTable(JXTable oPTable) {
        OPTable = oPTable;
    }
 
    private String getResourceType(String objectId) {
        if (getResourceType() == null) {
            JOptionPane.showMessageDialog(
                    com.vci.client.LogonApplication.frame,
                    "请选择类型树信息", "提示", JOptionPane.INFORMATION_MESSAGE);
        }
        return getResourceType().name;
    }
 
    public BtmItem getResourceType() {
        return RightManagerHelper.getResourceType(funclet);
    }
 
    public void setResourceType(BtmItem resourceType) {
        this.resourceType = resourceType;
    }
 
    public JTextField getObjectTextField() {
        return objectTextField.getText();
    }
 
 
    public AbstractUIFunclet getFunclet() {
        return funclet;
    }
 
    public void setFunclet(AbstractUIFunclet funclet) {
        this.funclet = funclet;
    }
}