田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
package com.vci.client.framework.systemConfig.volumn;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.util.LinkedHashMap;
import java.util.LinkedList;
 
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.VCIBasePanel;
import com.vci.client.common.objects.UserObject;
import com.vci.client.framework.delegate.PvolumeClientDelegate;
import com.vci.client.framework.rightConfig.object.FunctionObject;
import com.vci.client.framework.systemConfig.volumn.object.PvolumeObject;
import com.vci.client.framework.util.RightControlUtil;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJPanel;
import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider;
import com.vci.client.ui.swing.components.table.VCIJTableNode;
import com.vci.client.ui.swing.components.table.VCIJTablePanel;
 
/**
 * 
 * <p>Title: </p>
 * <p>卷管理panle: </p>
 * <p>Copyright: Copyright (c) 2012</p>
 * <p>Company: VCI</p>
 * @author lilb
 * @time 2013-1-2
 * @version 1.0
 */
public class PvolumePanel extends VCIBasePanel {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private UserObject logonUserInfo = LogonApplication.getUserObject();
    private JComboBox typeCombo = new JComboBox();
    DefaultComboBoxModel tempModel = new DefaultComboBoxModel();
    private VCIJButton addButton = VCISwingUtil.createVCIJButton("",
            LocaleDisplay.getI18nString("rmip.stafforg.operate.add",
                    "RMIPFramework", getLocale()), LocaleDisplay.getI18nString(
                    "rmip.stafforg.operate.add", "RMIPFramework", getLocale()),
            "create.gif", null);
    private VCIJButton editButton = VCISwingUtil.createVCIJButton("",
            LocaleDisplay.getI18nString("rmip.stafforg.operate.modify",
                    "RMIPFramework", getLocale()), LocaleDisplay.getI18nString(
                    "rmip.stafforg.operate.modify", "RMIPFramework",
                    getLocale()), "modify.gif", null);
    private VCIJButton deleteButton = VCISwingUtil.createVCIJButton("",
            LocaleDisplay.getI18nString("rmip.stafforg.operate.delete",
                    "RMIPFramework", getLocale()), LocaleDisplay.getI18nString(
                    "rmip.stafforg.operate.delete", "RMIPFramework",
                    getLocale()), "delete.gif", null);
    
    private VCIJButton rightButton = VCISwingUtil.createVCIJButton("", "分配成员","分配成员", "user.gif" ,null);
 
    private LinkedList<VCIJButton> selfCustomButtons = new LinkedList<VCIJButton>();
    {
        selfCustomButtons.add(addButton);
        selfCustomButtons.add(editButton);
        selfCustomButtons.add(deleteButton);
        selfCustomButtons.add(rightButton);
    }
 
    public PvolumePanel(FunctionObject funcObj) {
        super(funcObj);
        init();
        checkPermission();
    }
 
    private void checkPermission() {
        checkRight(RightControlUtil.CREATE, addButton);
        checkRight(RightControlUtil.UPDATE, editButton);
        checkRight(RightControlUtil.DELETE, deleteButton);
        if (logonUserInfo.getUserType() == 2) {
            checkRight(RightControlUtil.FREEZE, rightButton);
        } else {
            checkRight(RightControlUtil.CREATE, rightButton);
        }
    }
 
    public void init() {
        this.setLayout(new BorderLayout());
        LogonApplication.getUserEntityObject().setModules(this.getClass().getName());
        tempModel.addElement("Unix");
        tempModel.addElement("Win NT");
        typeCombo.setModel(tempModel);
        JPanel pal = initTablePanel();
        this.add(pal, BorderLayout.CENTER);
        initAction();
    }
 
    /**
     * 初始化table的Panle
     * 
     * @return
     */
    private JPanel initTablePanel() {
        JPanel pal = new JPanel();
        pal.setLayout(new BorderLayout());
        pal.setBorder(new TitledBorder("文件柜管理"));
        pal.add(tablePanel(), BorderLayout.CENTER);
        pal.setVisible(true);
        return pal;
    }
 
    class MyDataProvider extends AbstractVCIJTableDataProvider<PvolumeObject> {
 
        @Override
        public PvolumeObject[] getDatas(int pageSize, int pageIndex) {
            PvolumeObject[] pvObjects = null;
            try {
                pvObjects = new PvolumeClientDelegate(
                        LogonApplication.getUserEntityObject()).getPvolumesPage((short)pageSize, (short)pageIndex);
            } catch (VCIException e) {
                VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
                return null;
            }
            return pvObjects;
        }
 
        @Override
        public VCIJTableNode<PvolumeObject> getNewRowNode(PvolumeObject dataObj) {
            VCIJTableNode<PvolumeObject> node = new VCIJTableNode<PvolumeObject>(dataObj);
            node.setPropertyValue(getSpecialColumns()[0], dataObj.getName());
            
            if (dataObj.getType() == 0) {
                node.setPropertyValue(getSpecialColumns()[1], "Unix");
            } else {
                node.setPropertyValue(getSpecialColumns()[1], "Win NT");
            }
            
            node.setPropertyValue(getSpecialColumns()[2], dataObj.getPath());
            if (dataObj.getIsvalid()) {
                node.setPropertyValue(getSpecialColumns()[3], true);
            } else {
                node.setPropertyValue(getSpecialColumns()[3], false);
            }
            node.setPropertyValue(getSpecialColumns()[4], dataObj.getHost());
            node.setPropertyValue(getSpecialColumns()[5], dataObj.getService());
            return node;
        }
 
        @Override
        public String[] getSpecialColumns() {
            return "卷名,机器类型,路径名称,首选路径,服务器,卷服务".split(",");
        }
 
        @Override
        public int getTotal() {
            PvolumeObject[] pvObjects = null;
            try {
                pvObjects = new PvolumeClientDelegate(LogonApplication.getUserEntityObject()).getAllPvolumes();
            } catch (VCIException e) {
                VCIOptionPane.showError(LogonApplication.frame,
                        "RMIPFramework", e);
                total = 0;
            }
            if(pvObjects !=null){
                total = pvObjects.length;
            }
            return this.total;
        }
    }
 
    MyDataProvider dataProvider = new MyDataProvider();
    VCIJTablePanel<PvolumeObject> tablePanel = new VCIJTablePanel<PvolumeObject>(dataProvider);
 
    private VCIJPanel tablePanel() {
        int startIndex = dataProvider.getDataColumnStartIndex();
        LinkedHashMap<Integer, Integer> widthMaps = new LinkedHashMap<Integer, Integer>();
        widthMaps.put(startIndex++, 200);
//        widthMaps.put(startIndex++, 200);
        widthMaps.put(startIndex++, 80);
        widthMaps.put(startIndex++, 300);
        widthMaps.put(startIndex++, 80);
        widthMaps.put(startIndex++, 200); // 
        widthMaps.put(startIndex++, 200); // 
        
        tablePanel.setColumnWidthMaps(widthMaps);
        tablePanel.setShowPaging(false);
        tablePanel.setCustomButtons(selfCustomButtons);
        tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER);
        tablePanel.setPageButtonFlowAlign(FlowLayout.CENTER);
        tablePanel.buildTablePanel();
        tablePanel.refreshTableData();
        return tablePanel;
 
    }
    
    public void initAction() {
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                addButton_conform();
            }
        });
        editButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                editButton_conform();
            }
        });
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                delPvolume_actionPerfermed();
            }
        });
        rightButton.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(ActionEvent arg0) {
                 rightButton_conform();
             }
         });
    }
 
    /**
     * 添加卷操�?
     * <p>Description: </p>
     * 
     * @author llb
     * @time 2013-1-2
     */
    private void addButton_conform() {
        new PvolumeDialog(this, "add");
        tablePanel.refreshTableData();
    }
 
    /**
     * 修改卷操�?
     * <p>Description: </p>
     * 
     * @author llb
     * @time 2013-1-2
     */
    private void editButton_conform() {
        int len = tablePanel.getSelectedRowIndexs().length;
        if (len == 0) {
            VCIOptionPane.showMessage(this, LocaleDisplay.getI18nString(
                    "rmip.stafforg.operate.deptedit1", "RMIPFramework",
                    getLocale()));
            return;
        }
        if (len > 1) {
            VCIOptionPane.showMessage(this, LocaleDisplay.getI18nString(
                    "rmip.stafforg.operate.deptedit2", "RMIPFramework",
                    getLocale()));
            return;
        }
        PvolumeObject obj = tablePanel.getSelectedRowObjects().get(0);
        new PvolumeDialog(this, "edit", obj);
        tablePanel.refreshTableData();
    }
 
    /**
     * 删除卷操�?
     * <p>Description: </p>
     * 
     * @author llb
     * @time 2013-1-2
     */
    private void delPvolume_actionPerfermed() { 
        int len = tablePanel.getSelectedRowIndexs().length;
        if (len == 0) {
            VCIOptionPane.showMessage(this, LocaleDisplay.getI18nString(
                    "rmip.stafforg.operate.deptedit1", "RMIPFramework",
                    getLocale()));
            return;
        }
 
        String[] puids = new String[len];
        for (int i = 0; i < len; i++) {
            PvolumeObject obj = tablePanel.getSelectedRowObjects().get(i);
            puids[i] = obj.getId();
            boolean isvalid = this.checkDelIsvalid(puids[i]);
            if (isvalid) {
                VCIOptionPane.showMessageDialog(
                        LogonApplication.frame,
                        obj.getName()
                                + LocaleDisplay.getI18nString(
                                        "rmip.stafforg.operate.cannotdel1",
                                        "RMIPRm", getLocale()));
                return;
            }
//            int count = this.checkVolumnIsUsed(puids[i]);
//            if (count != 0) {
//                VCIOptionPane.showMessageDialog(
//                        LogonApplication.frame,
//                        obj.getName()
//                                + LocaleDisplay.getI18nString(
//                                        "rmip.stafforg.operate.cannotdel",
//                                        "RMIPRm", getLocale()));
//                return;
//            }
        }
 
        int ok = VCIOptionPane.showQuestion(LogonApplication.frame,
                LocaleDisplay.getI18nString("rmip.stafforg.operate.conformdel",
                        "RMIPRm", getLocale()));
        if (ok == 0) {
            boolean rs = true;
            try {
                PvolumeClientDelegate pvolumeSrv = new PvolumeClientDelegate(LogonApplication.getUserEntityObject());
                rs = pvolumeSrv.deletePvolume(puids);
            } catch (VCIException ex) {
                VCIOptionPane.showError(LogonApplication.frame, "RMIPRm", ex);
                return;
            }
            if (!rs) {
                return;
            }
            tablePanel.refreshTableData();
        }
    }
 
/**
 * 验证删除的卷是否被引�?
 * <p>Description: </p>
 * 
 * @author llb
 * @time 2013-1-2
 * @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 llb
     * @time 2013-1-2
     * @param id
     * @return
     */
    public boolean checkDelIsvalid(String id) {
        boolean res = false;
        try {
            res = new PvolumeClientDelegate(
                    LogonApplication.getUserEntityObject()).checkDelIsvalid(id);
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPRm", e);
            return false;
        }
        return res;
    }
    
    /**
     * 分配成员事件
     */
    private void rightButton_conform(){
        int len = tablePanel.getSelectedRowIndexs().length;
        if (len == 0){
            VCIOptionPane.showMessage(this, "请选择文件柜进行成员分�?");
            return;
        }else if (len > 1){
            VCIOptionPane.showMessage(this, "一次只能对一个文件柜进行分配人员操作!");
            return;
        }else {
            PvolumeObject  pvolumeObject = tablePanel.getSelectedRowObjects().get(0);
            PvolumeUserDialog dialog = new PvolumeUserDialog(pvolumeObject);
//            RightRoleDialog dialog = new RightRoleDialog(pvolumeObject);
            dialog.setVisible(true);
        }
    }
 
    
    
    
}