package com.vci.client.auth2.view; import java.awt.BorderLayout; import java.awt.Color; import java.awt.EventQueue; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.table.AbstractTableModel; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import com.vci.client.omd.btm.wrapper.BtmItemWrapper; import com.vci.client.omd.provider.BtmProvider; import com.vci.client.omd.ui.OmdTreeCellRenderer; import com.vci.client.omd.versionrule.util.VersionRuleWrapper; import com.vci.client.portal.NewNewUI.actionmng.ActionSelectDialog; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.ui.tree.VCIBaseTreeModel; import com.vci.client.ui.tree.VCIBaseTreeNode; import com.vci.client.ui.util.PostorderEnumeration; import com.vci.common.utility.ObjectUtility; import com.vci.corba.common.VCIError; import com.vci.corba.omd.btm.BtmItem; import com.vci.corba.portal.data.PLAction; import com.vci.corba.portal.data.PLTypeAction; import com.vci.mw.ClientContextVariable; public class TypeActionPanel extends JPanel implements ActionListener { /** * */ private static final long serialVersionUID = -3727722741228601983L; // instance private static TypeActionPanel instance = null; private static final String ADD_COMMAND = "add"; private static final String DEL_COMMAND = "del"; public static JPanel getInstance() { if (instance == null) { instance = new TypeActionPanel(); } return instance; } private JTree btTree; private JPanel contentPanel; private JPanel textPanel; private JPanel left=new JPanel(); private MyTableModel tableModel; private JTable table; private JTextField textField = new JTextField(); private JButton sel=new JButton("定位"); private JTextField textField2 = new JTextField(20); private JTextField textField3 = new JTextField(20); private JButton sel2=new JButton("查询"); public TypeActionPanel(){ this.initUI(); } private void initUI() { this.setBackground(Color.WHITE); this.setLayout(new BorderLayout(0, 0)); this.initLeftPanel(); this.initContentPanel(); //add by caill start //增加textPanel容器和left容器 //搜索框的设置 GridBagConstraints gb = new GridBagConstraints(); gb.gridx = 0; gb.gridy = 0; gb.weightx = 0.7; gb.weighty = 0; gb.fill = GridBagConstraints.HORIZONTAL; textPanel=new JPanel(); textPanel.setLayout(new GridBagLayout()); textPanel.add(textField,gb); textPanel.add(sel); left.setLayout(new BorderLayout()); left.add(textPanel,BorderLayout.NORTH); left.add(new JScrollPane(btTree),BorderLayout.CENTER); //add by caill start 2015.12.4 JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, contentPanel); jSplitPane.setDividerLocation(Toolkit.getDefaultToolkit().getScreenSize().width/6); jSplitPane.setOneTouchExpandable(true); this.add(jSplitPane); //add by caill end //为定位按钮增加点击事件 sel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //e.getSource(); String test = textField.getText().trim(); DefaultTreeModel model = (DefaultTreeModel)btTree.getModel(); model.reload(); TreeNode root = (TreeNode) model.getRoot(); PostorderEnumeration enumeration = new PostorderEnumeration( root); while (enumeration.hasMoreElements()) { DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration .nextElement(); if (element.getUserObject() instanceof String) { String wrapper = (String) element .getUserObject(); if (wrapper != null && wrapper.equals(test)) { TreeNode[] path = element.getPath(); TreePath treePath = new TreePath(path); btTree.setSelectionPath(treePath); return; } ; } } if (test.equals("")) { JOptionPane.showMessageDialog( com.vci.client.LogonApplication.frame, "请输入业务类型", "提示", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog( com.vci.client.LogonApplication.frame, "{ " + test + " }业务类型不存在", "提示", JOptionPane.INFORMATION_MESSAGE); } } }); //为定位框添加事件 textField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JTextField text = (JTextField) e.getSource(); String test = text.getText().trim(); DefaultTreeModel model = (DefaultTreeModel)btTree.getModel(); model.reload(); TreeNode root = (TreeNode) model.getRoot(); PostorderEnumeration enumeration = new PostorderEnumeration( root); while (enumeration.hasMoreElements()) { DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumeration .nextElement(); if (element.getUserObject() instanceof String) { String wrapper = (String) element .getUserObject(); if (wrapper != null && wrapper.equals(test)) { TreeNode[] path = element.getPath(); TreePath treePath = new TreePath(path); btTree.setSelectionPath(treePath); return; } ; } } if (test.equals("")) { JOptionPane.showMessageDialog( com.vci.client.LogonApplication.frame, "请输入业务类型", "提示", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog( com.vci.client.LogonApplication.frame, "{ " + test + " }业务类型不存在", "提示", JOptionPane.INFORMATION_MESSAGE); } } }); //给搜索按钮增添点击事件,是在initData()方法的基础上做了修改 sel2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sel(); } }); //为名称搜索框添加键盘事件 textField2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sel(); } }); //为编号查询框添加键盘事件 textField3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sel(); } }); // add by caill end } private void initLeftPanel() { try { btTree = new JTree(); btTree.setCellRenderer(new OmdTreeCellRenderer()); btTree.setModel(createTreeModel()); btTree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); initData(); } }); } catch (VCIError e) { e.printStackTrace(); } } private void initContentPanel() { JPanel btnPanel = this.getBtnPanel(); JPanel selPanel = new JPanel(); tableModel = new MyTableModel(); table = new JTable(tableModel); GridBagLayout g = new GridBagLayout(); g.rowHeights = new int[]{0, 0, 0}; g.columnWidths = new int[]{0}; g.rowWeights = new double[]{0.0, Double.MIN_VALUE, 0.0}; g.columnWeights = new double[]{Double.MIN_VALUE}; contentPanel = new JPanel(g); //add by caill start 设置查询框和 查询按钮的位置 GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(5, 5, 5, 5); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 0.4; gbc.weighty = 0; contentPanel.add(new JLabel("Action配置管理"),gbc); //add by caill start 2015.12.5 将搜索框和查询按钮放到新创建的selPanel中 JLabel ts = new JLabel("Action配置管理"); JLabel bh = new JLabel("编号"); JLabel mc = new JLabel("名称"); selPanel.add(bh); selPanel.add(textField3); selPanel.add(mc); selPanel.add(textField2); selPanel.add(sel2); contentPanel.add(selPanel,gbc); //add by caill end gbc.gridx = 0; gbc.gridy = 1; gbc.insets = new Insets(5, 5, 5, 5); contentPanel.add(new JScrollPane(table), gbc); gbc.gridx = 0; gbc.gridy = 2; contentPanel.add(btnPanel, gbc); } private JPanel getBtnPanel() { JPanel panel = new JPanel(); JButton addBtn = new JButton("添加"); addBtn.setActionCommand(ADD_COMMAND); addBtn.addActionListener(this); JButton delBtn = new JButton("移除"); delBtn.setActionCommand(DEL_COMMAND); delBtn.addActionListener(this); panel.add(addBtn); panel.add(delBtn); return panel; } @Override public void actionPerformed(ActionEvent e) { try { String command = e.getActionCommand(); if(DEL_COMMAND.equals(command)){ int[] selRows = table.getSelectedRows(); if(selRows == null ||selRows.length <= 0){ VCIOptionPane.showMessage(ClientContextVariable.getFrame(), "请选择记录!"); }else{ VCIBaseTreeNode selNode = (VCIBaseTreeNode) btTree.getLastSelectedPathComponent(); Object selObj = selNode.getObj(); if(selObj instanceof BtmItem){ String typeName = ((BtmItem)selObj).name; /*Object[] options = { "Yes", "No" }; int n = JOptionPane .showOptionDialog(getInstance(), "确认是否移除Action\"" + typeName + "\"", "Action移除", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); // int n = JOptionPane.showConfirmDialog(null, "您确定要执行删除操作吗?"); if(n != JOptionPane.YES_OPTION){ return; }*/ for(int i : selRows){ PLAction selAction = tableModel.getRowAt(i); Object[] options = { "Yes", "No" }; int n = JOptionPane .showOptionDialog(getInstance(), "确认是否移除Action\"" + selAction.plName + "\"", "Action移除", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); // int n = JOptionPane.showConfirmDialog(null, "您确定要执行删除操作吗?"); if(n != JOptionPane.YES_OPTION){ return; } boolean res = UITools.getService().deletePLTypeActionEntityByTypeAndAction(typeName, selAction.plOId); } } } }else if(ADD_COMMAND.equals(command)){ String boType = "bpdatarule"; String context = "activitySelAndAddindatarule"; VCIBaseTreeNode selNode = (VCIBaseTreeNode) btTree.getLastSelectedPathComponent(); if(selNode == null){ VCIOptionPane.showMessage(ClientContextVariable.getFrame(), "请选择类型!"); } Object selObj = selNode.getObj(); if(selObj instanceof BtmItem){ String typeName = ((BtmItem)selObj).name; // PLActionSelectionDialog dialog = new PLActionSelectionDialog(); ActionSelectDialog dialog = new ActionSelectDialog(new JDialog()); // PLAction action = dialog.getSelectedAction(); //add by caill start //定义一个list用来接收选中的索引行 List action = dialog.getSelectedActions(); // if(dialog.isOK()){ // List selActions = dialog.getResult(); // if(selActions != null && selActions.size() > 0){ PLAction[] actions = UITools.getService().getAllPLActionEntityByType(typeName); List ploids = new ArrayList(); //add by caill //遍历数组和list,比较新添加的索引行是否已经存在 for(PLAction ac: actions){ for(int i=0;i actions = new ArrayList(); Object selObj = selNode.getObj(); if(selObj instanceof BtmItem){ String typeName = ((BtmItem)selObj).name; PLAction[] plActions = UITools.getService().getAllPLActionEntityByType(typeName); actions = Arrays.asList(plActions); } tableModel.setData(actions); } catch (VCIError e) { e.printStackTrace(); } } private DefaultTreeModel createTreeModel() throws VCIError { BtmItem[] allBtItems = BtmProvider.getInstance().getAllBtmItems(); VCIBaseTreeNode rootNode = new VCIBaseTreeNode("业务类型树","root"); VCIBaseTreeModel treeModel = new VCIBaseTreeModel(rootNode); for(int i=0;i data; public List getData(){ return data; } public MyTableModel() { this.data = new ArrayList(); } public void setData(List data){ this.data = data; fireTableDataChanged(); } public void addRow(PLAction dataRule){ this.data.add(dataRule); fireTableStructureChanged(); } public PLAction getRowAt(int rowIndex){ if(rowIndex >= 0 && rowIndex actions = new ArrayList(); Object selObj = selNode.getObj(); if(selObj instanceof BtmItem){ String typeName = ((BtmItem)selObj).name; PLAction[] plActions = UITools.getService().getAllPLActionEntityByType(typeName); if(textValue.equals("") && textValue3.equals("")){ actions = Arrays.asList(plActions); }else{ for(int i=0;i