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
package com.vci.client.framework.systemConfig.stafforgmanage;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
 
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
 
import org.apache.commons.lang3.StringUtils;
 
import com.vci.client.ClientSession;
import com.vci.client.LogonApplication;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.framework.delegate.UserEntityClientDelegate;
import com.vci.client.framework.systemConfig.object.TransmitMethod;
import com.vci.client.logon.base.BaseJDialog;
import com.vci.client.ui.swing.KJButton;
import com.vci.client.ui.swing.KTextField;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.common.locale.LocaleDisplay;
import com.vci.corba.common.VCIError;
import com.vci.corba.framework.data.MachSecurityInfo;
import com.vci.corba.omd.etm.EnumChild;
import com.vci.corba.omd.etm.EnumItem;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.mw.ClientContextVariable;
 
 
public class MachSecurityDialog extends BaseJDialog {
    private static final long serialVersionUID = 1L;
 
    private static final String ENUM_USERSECURITYENUM = "usersecurityenum";
    private static final String ENUM_SECURITYGRADE = "Enumsecretgrade";
    private EnumChild[] securityEnum;
    
    private UserEntityInfo userInfo = null;
 
    private OptionType opType = OptionType.Unknow;
    private MachSecurityPanel tablePanel;
    private MachSecurityInfo msObj = null;
 
    private JLabel nameLabel = new JLabel(
            LocaleDisplay.getI18nString("rmip.stafforg.logal.name", "RMIPFramework", getLocale()));
    private JLabel descLabel = new JLabel(
            LocaleDisplay.getI18nString("rmip.stafforg.logal.desc", "RMIPFramework", getLocale()));
    KTextField nameText = new KTextField();
    KTextField ipText = new KTextField();
    JTextArea descArea = new JTextArea();
 
    private JLabel securityLabel = new JLabel(
            LocaleDisplay.getI18nString("rmip.stafforg.logal.security", "RMIPFramework", getLocale()));
    private JComboBox securityCombo = new JComboBox();
 
    private KJButton conformButton = new KJButton(
            LocaleDisplay.getI18nString("rmip.framework.button.confirm", "RMIPFramework", getLocale()),
            "bullet_blue.png");
    private KJButton cancelButton = new KJButton(
            LocaleDisplay.getI18nString("rmip.framework.button.cancel", "RMIPFramework", getLocale()),
            "bullet_delete.png");
 
    public enum OptionType {
        Unknow, Add, Edit
    }
 
    public MachSecurityDialog(MachSecurityPanel tablePanel, MachSecurityInfo obj, OptionType opType) {
        super(LogonApplication.frame);
        this.opType = opType;
        this.msObj = obj;
        this.tablePanel = tablePanel;
        
        userInfo = UserEntityClientDelegate.changeUserEntityToInfo(LogonApplication.getUserEntityObject());
 
        this.setModal(true);
 
        initDialog();
    }
 
    /**
     * 初始化界面
     */
    public void initDialog() {
        this.setTitle("机器密级");
 
        JPanel bottomPanel = new JPanel();
        conformButton.setPreferredSize(new Dimension(90, 30));
        cancelButton.setPreferredSize(new Dimension(90, 30));
        bottomPanel.add(conformButton);
        bottomPanel.add(cancelButton);
 
        conformButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                add_actionPerformed(e);
            }
        });
        
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                cancelButton_ActionPerformed(e);
            }
        });
 
        JPanel contentPanel = initCenterContentPanel();
 
        this.setLayout(new BorderLayout());
        // this.add(titleLabel, BorderLayout.NORTH);
        this.add(contentPanel, BorderLayout.CENTER);
        this.add(bottomPanel, BorderLayout.SOUTH);
        initDialogSize(420, 320);
        this.setVisible(true);
    }
 
    private JPanel initCenterContentPanel() {
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(null);
 
        JLabel ipLabel = new JLabel();
        ipLabel.setText("IP地址");
        ipLabel.setBounds(new Rectangle(30, 20, 60, 25));
        ipText.setBounds(new Rectangle(90, 20, 300, 25));
        if (opType != OptionType.Add)
            ipText.setEditable(false);
        
        contentPanel.add(ipLabel);
        contentPanel.add(ipText);
 
        nameLabel.setBounds(new Rectangle(30, 55, 60, 25));
        nameLabel.setText("机器名");
        nameText.setBounds(new Rectangle(90, 55, 300, 25));
        contentPanel.add(nameLabel);
        contentPanel.add(nameText);
 
        securityLabel.setBounds(new Rectangle(30, 90, 60, 25));
        securityLabel.setText("密级");
        securityCombo.setBounds(new Rectangle(90, 90, 300, 25));
        contentPanel.add(securityLabel);
        contentPanel.add(securityCombo);
 
        JScrollPane jsDescription = new JScrollPane();
        descLabel.setBounds(new Rectangle(30, 125, 60, 25));
        descLabel.setText("描述");
        descArea.setLineWrap(true);
        jsDescription.getViewport().add(descArea);
        jsDescription.setBounds(new Rectangle(90, 125, 300, 100));
        contentPanel.add(descLabel);
        contentPanel.add(jsDescription);
 
        initContent();
        return contentPanel;
    }
 
    private void initContent() {
        if (msObj != null) {
            nameText.setText(msObj.name);
            ipText.setText(msObj.ipAddress);
            descArea.setText(msObj.desc);
        }
 
        initSecurityCombo();
    }
 
    @SuppressWarnings("unchecked")
    private void initSecurityCombo() {
        try {
            securityCombo.setEditable(false);
            EnumItem item = ServiceProvider.getOMDService().getEnumService().getEmItemByName(ENUM_SECURITYGRADE);
            securityEnum = item.children;
            if (!ClientContextVariable.getIpSecretSwitch().equals("on")) {
                securityCombo.addItem("");
            }
 
            String secretGrade = "";
            if (msObj != null) {
                secretGrade = String.valueOf(msObj.secretGrade);
            }
            for (EnumChild child : securityEnum) {
                securityCombo.addItem(child.name);
                if (msObj != null && child.value.equals(secretGrade)) {
                    securityCombo.setSelectedItem(child.name);
                }
            }
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
    
 
    private void add_actionPerformed(ActionEvent e) {
    
        if (!checkValue()) {
            return;
        }
 
        try {
            if(opType == OptionType.Add) {
                ClientSession.getFrameworkService().saveMachSecurity(msObj, userInfo);
            } else if (opType == OptionType.Edit) {
                ClientSession.getFrameworkService().updateMachSecurity(msObj, userInfo);
            }
        } catch (VCIError er) {
            VCIOptionPane.showError(LogonApplication.frame, er);
            return;
        }
        this.dispose();
        tablePanel.refreshTableData();
    }
 
    /**
     * 取消按钮事件
     * 
     * @param e
     */
    private void cancelButton_ActionPerformed(ActionEvent e) {
        this.dispose();
    }
 
    private boolean checkValue() {
        
        String name = nameText.getText();
        String ipAddress = ipText.getText();
        short secretGrade = getSecurity();
        String desc = descArea.getText();
        
        if("".equals(name)){
            VCIOptionPane.showMessageDialog(this, "机器名不能空");
            return false;
        }
        
        if(opType == OptionType.Add) {
            ipAddress = ipAddress.trim();
            if ("".equals(ipAddress)){
                VCIOptionPane.showMessageDialog(this, "机器IP地址不能空");
                return false;
            }
            
            String regEx = "^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$";
            if (!TransmitMethod.checkCharacter(ipAddress, regEx)) {
                VCIOptionPane.showMessageDialog(this, "机器IP地址不符合IP地址格式要求");
                return false;
            }
            
            MachSecurityInfo ms;
            try {
                ms = ClientSession.getFrameworkService().getMachSecurityInfo(ipAddress, (short)0, userInfo);
            } catch (VCIError e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return false;
            }
            if (!StringUtils.isEmpty(ms.id)) {
                VCIOptionPane.showMessageDialog(this, "机器IP地址已经存在,请重新输入IP地址!");
                return false;
            }
        }
        
        msObj.name = name;
        msObj.ipAddress = ipAddress;
        msObj.secretGrade = secretGrade;
        msObj.desc = desc;
        
        return true;
    }
 
    public short getSecurity(){
        String selItem = (String) securityCombo.getSelectedItem();
        if(selItem != ""){
            for(EnumChild child: securityEnum){
                if(child.name.equals(selItem)){
                    return Short.valueOf(child.value);
                }
            }
        }
        return 0;
    }
}