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