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();
|
}
|
}
|