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; /** * *

Title:

*

卷管理panle:

*

Copyright: Copyright (c) 2012

*

Company: VCI

* @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 selfCustomButtons = new LinkedList(); { 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 { @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 getNewRowNode(PvolumeObject dataObj) { VCIJTableNode node = new VCIJTableNode(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 tablePanel = new VCIJTablePanel(dataProvider); private VCIJPanel tablePanel() { int startIndex = dataProvider.getDataColumnStartIndex(); LinkedHashMap widthMaps = new LinkedHashMap(); 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(); } }); } /** * 添加卷操�? *

Description:

* * @author llb * @time 2013-1-2 */ private void addButton_conform() { new PvolumeDialog(this, "add"); tablePanel.refreshTableData(); } /** * 修改卷操�? *

Description:

* * @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(); } /** * 删除卷操�? *

Description:

* * @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(); } } /** * 验证删除的卷是否被引�? *

Description:

* * @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; // } /** * 验证删除的卷是否为首选路�? *

Description:

* * @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); } } }