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; /** * *
Title:PvolumeDialog
*Description:卷服务弹出dialog
*Copyright: Copyright (c) 2012
*Company: VCI
* @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 LinkedHashMapDescription:按钮单项选择
* * @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); } } }); } /** * *Description: 增加卷
* * @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); } } /** * *Description:修改卷
* * @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(); // // } /** * *Description:得到卷的信息
* * @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); } } } /** * *Description:检验卷名称是否重复
* * @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; } /** * *Description:查看卷是否被使用
* * @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; // } /** * *Description:验证系统中是否已经存在卷
* * @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(); } }