package com.vci.client.framework.rightConfig.operate;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.Rectangle;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.io.BufferedWriter;
|
import java.io.File;
|
import java.io.FileWriter;
|
import java.io.IOException;
|
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
|
import javax.swing.JButton;
|
import javax.swing.JCheckBox;
|
import javax.swing.JFileChooser;
|
import javax.swing.JLabel;
|
import javax.swing.JOptionPane;
|
import javax.swing.JPanel;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextArea;
|
import javax.swing.JTextField;
|
import javax.swing.tree.TreePath;
|
|
import com.vci.client.LogonApplication;
|
import com.vci.client.common.TransmitTreeObject;
|
import com.vci.client.framework.delegate.OperateClientDelegate;
|
import com.vci.client.framework.rightConfig.object.OperateObject;
|
import com.vci.client.ui.exception.VCIException;
|
import com.vci.client.ui.image.BundleImage;
|
import com.vci.client.ui.locale.LocaleDisplay;
|
import com.vci.client.ui.swing.KTextField;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.tree.VCIBaseTreeNode;
|
|
/**
|
* 操作类型的管理是初始化系统中每个功能模块所具有的操作的集合。
|
*
|
* @author
|
*/
|
public class OperateMangePanel extends JPanel {
|
|
private static final long serialVersionUID = -3826623955360533220L;
|
private final OperateClientDelegate modelDelegate = new OperateClientDelegate(LogonApplication.getUserEntityObject());
|
private JLabel operateLab = new JLabel();
|
private JLabel nameLab = new JLabel();
|
private KTextField nameText = new KTextField();
|
private JLabel identifyLab = new JLabel();
|
private KTextField identifyText = new KTextField();
|
private JLabel aliasLab = new JLabel();
|
private KTextField aliasText = new KTextField();
|
private JLabel seqLab = new JLabel("顺序");
|
private KTextField seqText = new KTextField();
|
private JLabel describeLab = new JLabel();
|
private JTextArea describeTxtArea = new JTextArea();
|
private JButton addButton = new JButton();
|
private JButton updateButton = new JButton();
|
private JButton delButton = new JButton();
|
private JButton exportSqlButton = new JButton("导出sql");
|
private JTextField top = new JTextField();// 横线
|
private JTextField bottom = new JTextField();// 横线
|
private TransmitTreeObject transmitTreeObject = new TransmitTreeObject();// 传递树的信息
|
|
// 控件的坐标位置变量
|
private int x = 10;
|
private int y = 20;
|
private int width = 50;
|
private int height = 25;
|
/**
|
* 两控件间水平间隔
|
*/
|
private int hspan = 5;
|
|
private OperateClientDelegate operateClient = new OperateClientDelegate(LogonApplication.getUserEntityObject());
|
|
public OperateMangePanel(Object obj,TransmitTreeObject transmitTreeObject) {
|
super();
|
this.transmitTreeObject = transmitTreeObject;
|
init();
|
if (obj instanceof OperateObject) {
|
initData((OperateObject)obj);
|
}
|
this.setOpaque(false);
|
}
|
|
public void init(){
|
JPanel palMain = new JPanel();
|
JPanel contentPanel = new JPanel();
|
JPanel buttonPanel = new JPanel();
|
palMain.setLayout(new BorderLayout());
|
|
operateLab.setIcon(new BundleImage().createImageIcon("codevalue.gif"));
|
operateLab.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.operateTypeLab.file","RMIPFramework", getLocale()));
|
operateLab.setBounds(new Rectangle(0, 0, 30, 25));
|
|
contentItem(contentPanel);
|
jButtonPanl(buttonPanel);
|
|
palMain.add(operateLab,BorderLayout.NORTH);
|
palMain.add(contentPanel, BorderLayout.CENTER);
|
palMain.add(buttonPanel, BorderLayout.SOUTH);
|
this.setLayout(new BorderLayout());
|
this.add(palMain, BorderLayout.CENTER);
|
}
|
|
private void initData(OperateObject obj){
|
nameText.setText(obj.getName());
|
identifyText.setText(obj.getIdentify());
|
aliasText.setText(obj.getAlias());
|
seqText.setText(String.valueOf(obj.getSequence()));
|
describeTxtArea.setText(obj.getDesc());
|
addButton.setEnabled(false); // 按钮失效
|
updateButton.setEnabled(true); // 显示按钮
|
delButton.setEnabled(true); // 显示按钮
|
}
|
|
|
/**
|
* 按钮
|
*
|
* @return
|
*/
|
public void jButtonPanl(JPanel p) {
|
|
addButton.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.addButton.file", "RMIPFramework",getLocale()));
|
addButton.setIcon(new BundleImage().createImageIcon("create.gif"));
|
addButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if (!"operateNode".equals(transmitTreeObject.getCurrentTreeNode().getObj())) {
|
message("请选择操作类型节点","RMIPFramework");
|
return;
|
}
|
if (checkItem()) {
|
return;
|
}
|
try {
|
OperateObject ot = getValue();
|
String s = operateClient.saveOperate(ot);
|
/**返回1表示名称有重复,返回2表示标识有重复,返回3表示顺序有重复**/
|
if(s.equals("1")){
|
message("rmip.framework.operateType.nameIsExist.message","RMIPFramework");
|
return;
|
}else if(s.equals("2")){
|
message("rmip.framework.operateType.identifyingIsExist.message","RMIPFramework");
|
return;
|
}else if (s.equals("3")){
|
VCIOptionPane.showMessage(LogonApplication.frame, "操作的顺序值已经存在,保存失败");
|
return;
|
}
|
ot.setId(s);
|
if (!s.equals("") && s != null) {
|
updateTreeData("add", ot);
|
} else {
|
message("rmip.framework.operateType.savefail.message","RMIPFramework");
|
}
|
} catch (VCIException e1) {
|
e1.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame,LocaleDisplay.getI18nString(e1, "RMIPFramework", getLocale()));
|
return;
|
}
|
}
|
|
});
|
updateButton.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.updateButton.file","RMIPFramework", getLocale()));
|
updateButton.setIcon(new BundleImage().createImageIcon("modify.gif"));
|
updateButton.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
if (checkItem()) {
|
return;
|
}
|
OperateObject ot = getValue();
|
Object obj = transmitTreeObject.getCurrentTreeNode().getObj();
|
if(obj instanceof OperateObject){
|
ot.setId(((OperateObject) obj).getId());
|
}
|
try {
|
String res = operateClient.updateOperate(ot);
|
/**返回1表示名称有重复,返回2表示标识有重复,返回3表示顺序有重复**/
|
if(res.equals("1")){
|
message("rmip.framework.operateType.nameIsExist.message","RMIPFramework");
|
return;
|
}else if(res.equals("2")){
|
message("rmip.framework.operateType.identifyingIsExist.message","RMIPFramework");
|
return;
|
}else if (res.equals("3")){
|
VCIOptionPane.showMessage(LogonApplication.frame, "操作的顺序值已经存在,保存失败");
|
return;
|
}
|
message("rmip.framework.operateType.updatesusses.message","RMIPFramework");
|
updateTreeData("modify", ot);
|
} catch (VCIException e1) {
|
e1.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame,LocaleDisplay.getI18nString(e1, "RMIPFramework", getLocale()));
|
return;
|
}
|
}
|
});
|
delButton.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.delButton.file", "RMIPFramework",getLocale()));
|
delButton.setIcon(new BundleImage().createImageIcon("delete.gif"));
|
delButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
OperateObject curObj = (OperateObject)transmitTreeObject.getCurrentTreeNode().getObj();
|
try {
|
/**检查当前操作是否被引用,0表示无引用,1表示被模块引用,2表示已有权限信息**/
|
int res = operateClient.checkOperateIsReferenced(curObj.getId());
|
int ok = -1;
|
if(res == 1){
|
ok = VCIOptionPane.showQuestion(LogonApplication.frame, "当前操作已被模块引用,删除该操作的同时会将其从模块下移除,确认执行删除吗?");
|
}else if(res == 2){
|
ok = VCIOptionPane.showQuestion(LogonApplication.frame, "当前操作已经在权限模块被分配过权限,删除该操作的同时会将其从用户的权限中移除,确认执行删除吗?");
|
}else{
|
ok = VCIOptionPane.showQuestion(LogonApplication.frame, "确认执行删除吗?");
|
}
|
if(ok != 0){
|
return;
|
}
|
boolean success = operateClient.deleteOperate(curObj.getId());
|
if(success){
|
VCIBaseTreeNode parentNode = (VCIBaseTreeNode)transmitTreeObject.getCurrentTreeNode().getParent();
|
transmitTreeObject.getTreeModel().removeNodeFromParent(transmitTreeObject.getCurrentTreeNode());
|
transmitTreeObject.getTree().setSelectionPath(new TreePath(parentNode.getPath()));
|
}
|
} catch (VCIException e1) {
|
e1.printStackTrace();
|
VCIOptionPane.showError(LogonApplication.frame,LocaleDisplay.getI18nString(e1, "RMIPFramework", getLocale()));
|
}
|
}
|
});
|
updateButton.setEnabled(false); // 按钮失效
|
delButton.setEnabled(false); // 按钮失效
|
exportSqlButton.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent arg0) {
|
// TODO Auto-generated method stub
|
exportTxt();
|
}
|
});
|
p.add(addButton);
|
p.add(updateButton);
|
p.add(delButton);
|
p.add(exportSqlButton);
|
}
|
//add by caill Start 2015.12.11 为操作类型添加导出sql功能
|
public void exportTxt(){
|
int size = 0;
|
try {
|
size = modelDelegate.getAllOperitionsNum();
|
} catch (VCIException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
System.out.println("size = "+size);
|
String[][] plDatas = new String[size][6];
|
try {
|
plDatas = modelDelegate.getAllOperitions(size);
|
} catch (VCIException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
//modelDelegate.checkLevel();
|
|
JFileChooser fileChooser = new JFileChooser();
|
fileChooser.setDialogTitle("导出sql");
|
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
fileChooser.setApproveButtonText("导出");
|
int result = fileChooser.showOpenDialog(this);
|
if(result == JFileChooser.APPROVE_OPTION){
|
String dir = fileChooser.getSelectedFile().getAbsolutePath();
|
if(expData(dir,plDatas)==true){
|
JOptionPane.showMessageDialog(this, "导出成功", "导出成功", JOptionPane.INFORMATION_MESSAGE);
|
}else{
|
JOptionPane.showMessageDialog(this, "导出失败", "导出失败", JOptionPane.INFORMATION_MESSAGE);
|
}
|
|
}
|
}
|
public boolean expData(String dir, String[][] plDatas){
|
new File(dir).mkdir();
|
File file = new File(dir + "/ploperation.sql");
|
try {
|
FileWriter w = new FileWriter(file);
|
BufferedWriter bw = new BufferedWriter(w);
|
for(int i=0;i<plDatas.length;i++){
|
bw.write("insert into ploperation values('"+plDatas[i][0]+"','"+plDatas[i][1]+"',"+"'"+plDatas[i][2]+"',"+"'"+plDatas[i][3]+"',"+"'"+plDatas[i][4]+"',"
|
+"'"+plDatas[i][5]+"');");
|
bw.write("\r\n");
|
}
|
bw.flush();
|
bw.close();
|
return true;
|
} catch (IOException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
return false;
|
}
|
|
//add by caill end
|
/**
|
* 获取页面的值
|
*
|
* @return
|
*/
|
private OperateObject getValue() {
|
OperateObject ot = new OperateObject();
|
ot.setName(nameText.getText());
|
ot.setIdentify(identifyText.getText());
|
ot.setAlias(aliasText.getText());
|
ot.setDesc(describeTxtArea.getText());
|
ot.setSequence(Integer.valueOf(seqText.getText()));
|
return ot;
|
}
|
|
/**
|
* 内容项
|
*
|
* @return
|
*/
|
public void contentItem(JPanel p) {
|
JPanel panel = new JPanel();
|
|
top.setPreferredSize(new Dimension(63,2));
|
bottom.setPreferredSize(new Dimension(63,2));
|
|
x = 30;y = 30;width = 80;height = 25;
|
nameLab.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.designationLab.file","RMIPFramework", getLocale()));
|
nameLab.setBounds(new Rectangle(x, y, width, height));
|
|
x += nameLab.getWidth() + hspan;y = 30;width = 200;height = 25;
|
nameText.setBounds(new Rectangle(x, y, width, height));
|
|
x = 30;y = 70;width = 80;height = 25;
|
identifyLab.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.identifyingLab.file","RMIPFramework", getLocale()));
|
identifyLab.setBounds(new Rectangle(x, y, width, height));;
|
|
x += identifyLab.getWidth() + hspan;y = 70;width = 200;height = 25;
|
identifyText.setBounds(new Rectangle(x, y, width, height));
|
|
x = 30;y = 110;width = 80;height = 25;
|
aliasLab.setText("别名");
|
aliasLab.setBounds(new Rectangle(x, y, width, height));
|
|
x += aliasLab.getWidth() + hspan;y = 110;width = 200;height = 25;
|
aliasText.setBounds(new Rectangle(x, y, width, height));
|
|
x = 30;y = 150;width = 80;height = 25;
|
seqLab.setBounds(new Rectangle(x, y, width, height));
|
x += seqLab.getWidth() + hspan;y = 150;width = 200;height = 25;
|
seqText.setBounds(new Rectangle(x, y, width, height));
|
|
x = 30;y = 190;width = 80;height = 25;
|
describeLab.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.describeLab.file", "RMIPFramework",getLocale()));
|
describeLab.setBounds(new Rectangle(x, y, width, height));
|
|
x += describeLab.getWidth() + hspan;y = 190;width = 200;height = 100;
|
JScrollPane scroll = new JScrollPane(describeTxtArea);
|
scroll.setBounds(new Rectangle(x, y, width, height));
|
describeTxtArea.setLineWrap(true);
|
|
panel.setLayout(null);
|
panel.add(nameLab);
|
panel.add(nameText);
|
panel.add(identifyLab);
|
panel.add(identifyText);
|
panel.add(aliasLab);
|
panel.add(aliasText);
|
panel.add(seqLab);
|
panel.add(seqText);
|
panel.add(describeLab);
|
panel.add(scroll);
|
|
p.setLayout(new BorderLayout());
|
p.add(top,BorderLayout.NORTH);
|
p.add(panel,BorderLayout.CENTER);
|
p.add(bottom,BorderLayout.SOUTH);
|
}
|
|
/**
|
* 校验
|
*
|
* @return
|
*/
|
public boolean checkItem() {
|
if (nameText.getText() == null|| "".equals(nameText.getText())) {
|
message("rmip.framework.operateType.designationTextNotNull.message","RMIPFramework");
|
nameText.requestFocus();
|
return true;
|
}
|
if (identifyText.getText() == null|| "".equals(identifyText.getText())) {
|
message("rmip.framework.operateType.identifyingIsChoice.message","RMIPFramework");
|
identifyText.requestFocus();
|
return true;
|
|
}
|
if (aliasText.getText() == null|| "".equals(aliasText.getText())) {
|
message("rmip.framework.operateType.aliasTextNotNull.message","RMIPFramework");
|
identifyText.requestFocus();
|
return true;
|
|
}
|
if (seqText.getText().equals("")){
|
VCIOptionPane.showMessage(this, "请输入操作的顺序值!");
|
seqText.requestFocus();
|
return true;
|
}
|
String seq = seqText.getText();
|
Pattern pattern = Pattern.compile("[0-9]*");
|
Matcher isNum = pattern.matcher(seq);
|
if( !isNum.matches() ){
|
VCIOptionPane.showMessageDialog(LogonApplication.frame ,"操作的顺序值只能是[0-9]之间的数字,并且必须是正整数.\n长度不允许输入小数或者负数!");
|
return true;
|
}
|
if (nameText.getText().length() > 128) {
|
message("rmip.framework.operateType.designationTextLength.message","RMIPFramework");
|
return true;
|
}
|
if (describeTxtArea.getText().length() > 255) {
|
message("rmip.framework.operateType.describeTextAreaLength.message","RMIPFramework");
|
return true;
|
}
|
if (aliasText.getText().length() > 128) {
|
message("rmip.framework.operateType.aliasTextLength.message","RMIPFramework");
|
return true;
|
}
|
return false;
|
}
|
|
private void message(String key,String file){
|
String msg = LocaleDisplay.getI18nString(key,file,getLocale());
|
VCIOptionPane.showMessage(LogonApplication.frame, msg);
|
}
|
|
// 更新树
|
private void updateTreeData(String identifer, OperateObject ot) {
|
if (identifer.equals("add")) {// 添加
|
VCIBaseTreeNode addTreeNode = new VCIBaseTreeNode(ot.getName(), ot);
|
addTreeNode.setLeaf(true);
|
transmitTreeObject.getCurrentTreeNode().setLeaf(false);
|
if(transmitTreeObject.getCurrentTreeNode().isExpand()){
|
transmitTreeObject.getTreeModel().insertNodeInto(addTreeNode,transmitTreeObject.getCurrentTreeNode(),transmitTreeObject.getCurrentTreeNode().getChildCount());
|
transmitTreeObject.getTree().setSelectionPath(new TreePath(addTreeNode.getPath()));// 设置路径
|
}else{
|
transmitTreeObject.getTree().expandPath(new TreePath(transmitTreeObject.getCurrentTreeNode().getPath()));
|
transmitTreeObject.getTree().setSelectionPath(new TreePath(transmitTreeObject.getCurrentTreeNode().getPath()));
|
}
|
}
|
if (identifer.equals("modify")) {// 修改
|
transmitTreeObject.getCurrentTreeNode().setObj(ot);
|
transmitTreeObject.getCurrentTreeNode().setUserObject(ot.getName());
|
transmitTreeObject.getTreeModel().nodeChanged(transmitTreeObject.getCurrentTreeNode());
|
}
|
}
|
|
}
|