wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
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
package com.vci.client.framework.specialrole;
 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
 
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.objects.UserObject;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.framework.systemConfig.object.PasswordStrategyObject;
import com.vci.client.logon.base.BaseJDialog;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.image.BundleImage;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
 
/**
 * <p>Title: 为人员设置密级</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2012</p>
 * <p>Company: VCI</p>
 * @author wangxl
 * @time 2012-5-23
 * @version 1.0
 */
public class PasswordStrategySetingDialog extends BaseJDialog{
 
    private static final long serialVersionUID = 1L;
    private JLabel secretLevelLabel = new JLabel();
    private JComboBox secretPsdComBox = new JComboBox(); 
    private JButton conformBut = new JButton(LocaleDisplay.getI18nString("rmip.stafforg.operate.conform", "RMIPFramework", getLocale()));
    private JButton cancelBut = new JButton(LocaleDisplay.getI18nString("rmip.stafforg.operate.cancel", "RMIPFramework", getLocale()));
    private UserTablePanel userPanel;
    private List<UserObject> userList;
    
    public PasswordStrategySetingDialog(UserTablePanel userPanel ,List<UserObject> userList){
        super(LogonApplication.frame);
        this.userList = userList;
        this.userPanel = userPanel;
        this.setModal(true);
        init();
    }
     
    
    /**
     * 初始化界面
     */
    private void init() {
         JLabel titleLabel = new JLabel();
         titleLabel.setText("设置密码策略");
         titleLabel.setIcon(new BundleImage().createImageIcon ("folder_images.gif"));
         JPanel bottomPanel = new JPanel();
         bottomPanel.add(conformBut);
         bottomPanel.add(cancelBut);
         
         JPanel contentPanel = initCenterContentPanel();
         JPanel midPanel = new JPanel();
         midPanel.setLayout(new BorderLayout());
 
         midPanel.add(contentPanel, BorderLayout.CENTER);
         
         this.setLayout(new BorderLayout());
         this.add(titleLabel, BorderLayout.NORTH);
         this.add(midPanel, BorderLayout.CENTER);
         this.add(bottomPanel, BorderLayout.SOUTH); 
//         int x = (int)(this.getParent().getLocationOnScreen().getX()) + 200;
//         int y = (int)(this.getParent().getLocationOnScreen().getY()) + 80;
//         this.setLocation(x , y);
//         this.setSize(400, 200);
         initDialogSize(400, 200);
         this.setVisible(true);
    }
    
    private JPanel initCenterContentPanel() {
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(null);
        
        secretLevelLabel.setText("密码策略:");
        secretLevelLabel.setBounds(60, 30, 60, 25);
        
        secretPsdComBox.setBounds(130, 30, 150, 25);
        initPasswordStrategy();
        
        conformBut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                addButton_actionPerformed();
            }
        });
        
        cancelBut.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                cancelCreate();
            }
        });
        contentPanel.add(secretLevelLabel);
        contentPanel.add(secretPsdComBox);
        return contentPanel;
        
    }
    
    private void addButton_actionPerformed() {
       String passwordStrategyId = "";
       if (secretPsdComBox.getSelectedItem() instanceof PasswordStrategyObject){
           passwordStrategyId = ((PasswordStrategyObject)secretPsdComBox.getSelectedItem()).getId() == null ? "" : ((PasswordStrategyObject)secretPsdComBox.getSelectedItem()).getId() ;
       }
       String[] userIds = new String[userList.size()];
       for (int i = 0 ; i < userList.size() ; i ++){
           userIds[i] = userList.get(i).getId();
       }
       try{
           new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
                   .saveUserPasswordStrateg(userIds,passwordStrategyId);
           
       }catch(VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
            return ;
        }
       userPanel.tablePanel.refreshTableData();
       this.dispose();
    }
    
    public void cancelCreate(){
        this.dispose();
    }
    
    /**
     * <p>Description: 初始化</p>
     * 
     * @author wangxl
     * @time 2012-5-23
     */
    private void initPasswordStrategy() {
         try {
             secretPsdComBox.addItem(new PasswordStrategyObject());
            PasswordStrategyObject[] objs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchAllPasswordStrategy();
            int size = objs.length;
            for (int i = 0; i < size; i++) {
                secretPsdComBox.addItem(objs[i]);
            }
            if (userList.size() == 1){
                PasswordStrategyObject userPasswordStrategyObj = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
                   .fetchPasswordStrategyByUserId(userList.get(0).getId());
                if (userPasswordStrategyObj != null){
                    int count = secretPsdComBox.getItemCount();  
                    for (int i = 0 ; i < count ; i++){
                        PasswordStrategyObject secObj  =  (PasswordStrategyObject)secretPsdComBox.getItemAt(i);
                        if (userPasswordStrategyObj.getId().equals(secObj.getId())){
                            secretPsdComBox.setSelectedIndex(i);
                            break;
                        }
                    }
                }
            }
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework", e);
            return ;
        }
    }
}