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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
package com.vci.client.framework.systemConfig.volumn;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedHashMap;
 
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
 
import com.vci.client.LogonApplication;
import com.vci.client.framework.delegate.PvolumeClientDelegate;
import com.vci.client.framework.systemConfig.volumn.object.PvolumeObject;
import com.vci.client.logon.base.BaseJDialog;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.KJButton;
import com.vci.client.ui.swing.KTextField;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.tree.VCIBaseTreeNode;
/**
 * 
 * <p>Title:PvolumeDialog </p>
 * <p>Description:卷服务弹出dialog </p>
 * <p>Copyright: Copyright (c) 2012</p>
 * <p>Company: VCI</p>
 * @author sunbo
 * @time 2012-5-23
 * @version 1.0
 */
public class PvolumeDialog extends BaseJDialog{
    
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private KTextField nameField = null;
    private KTextField ipField = null;
    private KTextField srvField = null;
    private KTextField paField = null;
    //private JLabel type = new JLabel(LocaleDisplay.getI18nString("rmip.rm.sysconfig.type", "RMIPFramework", getLocale()));
    private JRadioButton type1 = new JRadioButton("Unix",false);
    private JRadioButton type2 = new JRadioButton("Win NT",true);
    private JCheckBox isvalid = null;
    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");
    private PvolumeClientDelegate pvolumeSrv = new PvolumeClientDelegate(LogonApplication.getUserEntityObject());
    @SuppressWarnings("unused")
    private PvolumePanel panel;
    private JComboBox typeGroup = new JComboBox();
    private LinkedHashMap<Integer, JRadioButton> rbtns = new LinkedHashMap<Integer, JRadioButton>();
    private String noteType;
    private PvolumeObject pvolumeObject;
    
    
    
    public PvolumeDialog(PvolumePanel panel, String noteType){
        super(LogonApplication.frame);
        this.setModal(true);
        this.panel = panel;
        this.noteType = noteType;
        init();
    }
    public PvolumeDialog(PvolumePanel panel, String noteType, PvolumeObject pvolumeObject){
        super(LogonApplication.frame);
        this.setModal(true);
        this.panel = panel;
        this.noteType = noteType;
        this.pvolumeObject = pvolumeObject;
        init();
    }
   
    private void init(){
        this.setTitle("卷配置");
        //JLabel titleLabel = new JLabel();
        //titleLabel.setText("卷配置");
        JPanel bottomPanel = new JPanel();
        bottomPanel.add(conformButton);
        bottomPanel.add(cancelButton);
        JPanel contentPanel = initCenterContentPanel();         
        JPanel midPanel = new JPanel();
        midPanel.setLayout(new BorderLayout());
        JTextField jTextField1 = new JTextField();//instead of up line
        JTextField jTextField2 = new JTextField();//instead of down line
        jTextField1.setPreferredSize(new Dimension(63,2));
        jTextField2.setPreferredSize(new Dimension(63,2));
        midPanel.add(jTextField1, BorderLayout.NORTH);
        midPanel.add(jTextField2, BorderLayout.SOUTH);
        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()) +500;
//        int y = (int)(this.getParent().getLocationOnScreen().getY()) +200;
//        this.setLocation(x , y);
//        this.setSize(350, 350);
        initDialogSize(350, 280);
        this.setVisible(true);
    }
    private JPanel initCenterContentPanel() {
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(null);
        JLabel nameLabel = new JLabel("卷名称:");
        nameField = new KTextField();
        nameLabel.setBounds(new Rectangle(50,20,100,20));
        nameField.setBounds(new Rectangle(95,20,200,25));
        if(noteType.equals("edit")){
            nameField.setEditable(false);    //卷名称不能修改,by zhonggy 2015-03-16
        }
 
        JLabel ipLabel = new JLabel("服务器:");
        ipField= new KTextField();
        ipLabel.setBounds(new Rectangle(25,50,100,20));
        ipField.setBounds(new Rectangle(95,50,200,25));
        
        JLabel srvLabel = new JLabel("卷服务:");
        srvField= new KTextField();
        srvLabel.setBounds(new Rectangle(25,80,100,20));
        srvField.setBounds(new Rectangle(95,80,200,25));
        
        JLabel type = new JLabel("机器类型:");
        type.setBounds(new Rectangle(35,110,100,20));//new Rectangle(35,80,100,20)
        type1.setBounds(new Rectangle(120,110,100,20));//new Rectangle(120,80,100,20)
        type2.setBounds(new Rectangle(220,110,100,20));//new Rectangle(220,80,100,20)
        
        JLabel paLabel = new JLabel("路径:");
        paField= new KTextField();
        paLabel.setBounds(new Rectangle(60,140,100,20));
        paField.setBounds(new Rectangle(95,140,200,25));
        
        JLabel isField = new JLabel("首选路径:");
        isvalid= new JCheckBox();
        isField.setBounds(new Rectangle(35,170,200,25));
        isvalid.setBounds(new Rectangle(95,170,200,25));
 
        typeGroup.add(type1);
        typeGroup.add(type2);
        rbtns.put(0, type1);
        rbtns.put(1, type2);
        contentPanel.add(nameLabel);
        contentPanel.add(nameField);
        contentPanel.add(ipField);
        contentPanel.add(ipLabel);
        
        contentPanel.add(srvField);
        contentPanel.add(srvLabel);
        
        contentPanel.add(paLabel);
        contentPanel.add(type);
        contentPanel.add(type1);
        contentPanel.add(type2);
        contentPanel.add(paField);
        contentPanel.add(isField);
        contentPanel.add(isvalid);
        conformButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(noteType.equals("add")){
                    savePvolume_actionPerfermed(e);
                }else{
                    updatePvolume_actionPerfermed(e);
                }
                
            }
        });
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                cancelButton_ActionPerformed(e);
            }
        });
        initAction();
        initContent();
        return contentPanel;
    }
    /**
     * 
     * <p>Description:按钮单项选择 </p>
     * 
     * @author sunbo
     * @time 2012-5-24
     */
    public void initAction(){
        type1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                if (type1.isSelected()){
                    type2.setSelected(false);
                }else{
                    type2.setSelected(true);
                }
            }
        });
        type2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                if (type2.isSelected()){
                    type1.setSelected(false);
                }else{
                    type2.setSelected(true);
                }
            }
        });
    }
    /**
     * 
     * <p>Description: 增加卷</p>
     * 
     * @author sunbo
     * @time 2012-5-24
     * @param e
     */
    private void savePvolume_actionPerfermed(ActionEvent e){ //卷的创建
        boolean rs = check("save");
        if (! rs){
            return;
        }
        PvolumeObject pvolume =  getPvolumeInfo("save");        
        boolean res = checkSysHavedVolumn();
        if (res && pvolume.getIsvalid()){
            try{
                pvolumeSrv.updatePvolumeInvalid();
            }catch(VCIException ex){
                VCIOptionPane.showError(LogonApplication.frame,"RMIPRm",ex);
                return;
            }
        }
        try{
            String id= this.pvolumeSrv.savePvolume(pvolume);
            pvolume.setId(id);
        }catch(VCIException ex){
            VCIOptionPane.showError(LogonApplication.frame,"RMIPRm",ex);
            return;
        }
        VCIOptionPane.showMessage(LogonApplication.frame, "保存成功!");
        this.dispose();
        try {
             PvolumeObject[] pvolumnObject = new PvolumeClientDelegate(LogonApplication.getUserEntityObject()).getAllPvolumes();
             
             int len = pvolumnObject.length;
             for (int i = 0; i < len; i++) {
                 @SuppressWarnings("unused")
                VCIBaseTreeNode node = new VCIBaseTreeNode(pvolumnObject[i].getName(),pvolumnObject[i]);
//                 this.getTransmitTreeObject().getTreeModel().insertNodeInto(node, this.getTransmitTreeObject().getCurrentTreeNode(), this.getTransmitTreeObject().getCurrentTreeNode().getChildCount());
             }
             
         } catch (VCIException ex) {
                VCIOptionPane.showError(LogonApplication.frame,"RMIPRm",ex);
         }
    }
    /**
     * 
     * <p>Description:修改卷 </p>
     * 
     * @author sunbo
     * @time 2012-5-24
     * @param e
     */
    private void updatePvolume_actionPerfermed(ActionEvent e){ //卷修改
        boolean rs = check("edit");
        if (! rs){
            return;
        }
        PvolumeObject pvoObject = getPvolumeInfo("edit");
//        String id = pvoObject.getId();
//        int count = this.checkVolumnIsUsed(id);
        int ok = 0;
//        if (count != 0){
//            ok=VCIOptionPane.showQuestion(LogonApplication.frame,
//                    pvoObject.getName()+LocaleDisplay.getI18nString("rmip.stafforg.operate.conformchange", "RMIPRm", getLocale()));
//        }
        if (ok == 0){
            PvolumeObject[] volumnInfo = null;
            try {
                volumnInfo = new PvolumeClientDelegate(LogonApplication.getUserEntityObject()).getAllPvolumes();
            } catch (VCIException ex) {
                VCIOptionPane.showError(LogonApplication.frame,"RMIPRm",ex);
                return;
            }
            
            if (volumnInfo.length <=1 && !isvalid.isSelected()){
                VCIOptionPane.showMessageDialog(LogonApplication.frame, 
                        LocaleDisplay.getI18nString("rmip.stafforg.operate.mustisvalid", "RMIPRm", getLocale()));
                return;
            } else if (volumnInfo.length >1 && isvalid.isSelected()){
                try{
                    pvolumeSrv.updatePvolumeInvalid();
                }catch(VCIException ex){
                    VCIOptionPane.showError(LogonApplication.frame,"RMIPRm",ex);
                    return;
                }
            } 
            try {
                pvolumeSrv.updatePvolume(pvoObject);
            }catch(VCIException ex) {
                VCIOptionPane.showError(LogonApplication.frame,"RMIPRm",ex);
                return;
            }
        }
        VCIOptionPane.showMessage(LogonApplication.frame, "修改成功!");
        this.dispose();
//        
//        
    }
    /**
     * 
     * <p>Description:得到卷的信息 </p>
     * 
     * @author sunbo
     * @time 2012-5-24
     * @param type
     * @return
     */
    public PvolumeObject getPvolumeInfo(String type){
        PvolumeObject pvoObject = new PvolumeObject();
        pvoObject.setHost(ipField.getText());
        pvoObject.setService(srvField.getText());
        pvoObject.setName(nameField.getText());
        if (type1.isSelected()){
            pvoObject.setType((short)0);
            pvoObject.setPath(paField.getText());
        }else{
            pvoObject.setType((short)1);
            pvoObject.setPath(paField.getText());
        }
        if(isvalid.isSelected()){
            pvoObject.setIsvalid(true);
        }else {
            pvoObject.setIsvalid(false);
        }    
        if("edit".equalsIgnoreCase(type)){
            PvolumeObject editeUserInfo = pvolumeObject;
            pvoObject.setId(editeUserInfo.getId());
            if(editeUserInfo.getIsvalid()!= pvoObject.getIsvalid()){
                @SuppressWarnings("unused")
                int ok=VCIOptionPane.showQuestion(LogonApplication.frame,
                        LocaleDisplay.getI18nString("rmip.stafforg.operate.modified", "RMIPRm", getLocale()));
            }
        }
        return pvoObject;
    }
    private void initContent(){
        if (pvolumeObject != null){
            PvolumeObject editeUserInfo = pvolumeObject;
            ipField.setText(editeUserInfo.getHost());
            srvField.setText(editeUserInfo.getService());
            nameField.setText(editeUserInfo.getName());
            paField.setText(editeUserInfo.getPath());
            if(editeUserInfo.getType()==0){
                type1.setSelected(true);
                type2.setSelected(false);
            }else{
                type1.setSelected(false);
                type2.setSelected(true);
            }
            if(editeUserInfo.getIsvalid()){
                isvalid.setSelected(true);
            }else {
                isvalid.setSelected(false);
            }    
        }
    }
    /**
     * 
     * <p>Description:检验卷名称是否重复 </p>
     * 
     * @author sunbo
     * @time 2012-5-24
     * @param name
     * @param type
     * @return
     */
    public boolean checkName(String name,String type){
        PvolumeObject[] volumnInfo = null;
        try {
            volumnInfo = new PvolumeClientDelegate(LogonApplication.getUserEntityObject()).getAllPvolumes();
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame,"RMIPRm",e);
            return false;
        }
        int size = volumnInfo.length;
        for(int i = 0; i < size; i++){
            if (name.equals(volumnInfo[i].getName())) {
                if("edit".equalsIgnoreCase(type)){ //如果是要进行修改,名称不变的情况下可以成功修改,这种情况下不是名称重复。
                    PvolumeObject currentVolumnInfo = pvolumeObject;
                    if (currentVolumnInfo.getId().equals(volumnInfo[i].getId())) {
                        continue;
                    }
                }
                VCIOptionPane.showMessageDialog(this,
                        LocaleDisplay.getI18nString("rmip.stafforg.operate.error", "RMIPRm", getLocale()));
                return false;
            }
        }
        return true;
    }
 
    private boolean check(String type){
        String pName = nameField.getText();
        String service = srvField.getText();
        String path = paField.getText();
        if ("".equals(pName)){
            VCIOptionPane.showMessageDialog(this,
                    LocaleDisplay.getI18nString("rmip.stafforg.operate.pnameerror", "RMIPRm", getLocale()));
            return false;
        }
        if ("".equals(service)){
            VCIOptionPane.showMessageDialog(this,
                    LocaleDisplay.getI18nString("rmip.stafforg.operate.piperror", "RMIPRm", getLocale()));
            return false;
        }
        if ("".equals(path)){
            VCIOptionPane.showMessageDialog(this,
                    LocaleDisplay.getI18nString("rmip.stafforg.operate.patherror", "RMIPRm", getLocale()));
            return false;
        }
        boolean rs = checkName(pName,type);
        if (! rs){
            return false;
        }
        
        boolean res = checkSysHavedVolumn();
        if (!res && !isvalid.isSelected()){
            VCIOptionPane.showMessageDialog(this,
                    LocaleDisplay.getI18nString("rmip.stafforg.operate.mustisvalid", "RMIPRm", getLocale()));
            return false;
        }
        return true;
    }
    
    /**
     * 
     * <p>Description:查看卷是否被使用 </p>
     * 
     * @author sunbo
     * @time 2012-5-24
     * @param id
     * @return
     */
//    public int checkVolumnIsUsed(String id){
//        int count = 0;
//        try {
//            count = new PvolumeClientDelegate(LogonApplication.getUserEntityObject()).fetchVolumnInfoByIds(id);
//        } catch (VCIException e) {
//            VCIOptionPane.showError(LogonApplication.frame,"RMIPRm",e);
//            return 0;
//        }
//        return count;
//    }
    /**
     * 
     * <p>Description:验证系统中是否已经存在卷 </p>
     * 
     * @author sunbo
     * @time 2012-5-24
     * @return
     */
    public boolean checkSysHavedVolumn(){
        boolean res = false;
        PvolumeObject[] volumnInfo = null;
        try {
            volumnInfo = new PvolumeClientDelegate(LogonApplication.getUserEntityObject()).getAllPvolumes();
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame,"RMIPRm",e);
            return false;
        }
        if (volumnInfo.length != 0){
            res = true;
        }else {
            res = false;
        }
        return res;
    }
    /**
     * 取消按钮事件
     * @param e
     */
    private void cancelButton_ActionPerformed(ActionEvent e) {
        this.dispose();
    }
}