package com.vci.client.portal.NewNewUI.buttonmng; import java.awt.BorderLayout; import java.awt.Component; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Toolkit; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; 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.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTree; import javax.swing.border.EmptyBorder; import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeExpansionListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import org.apache.commons.lang3.StringUtils; import com.vci.corba.portal.*; import com.vci.corba.portal.data.PLCommandParameter; import com.vci.corba.portal.data.PLPageDefination; import com.vci.corba.portal.data.PLUILayout; import com.vci.corba.portal.data.PLTabButton; import com.vci.client.LogonApplication; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.process.QANProcessBar; import com.vci.client.ui.process.QANProcessBarFrame; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJButton; import com.vci.client.ui.swing.components.VCIJOptionPane; import com.vci.client.ui.swing.components.VCIJDialog.DialogResult; import com.vci.common.portal.utils.PortalUtil; import com.vci.common.utility.ObjectUtility; import com.vci.corba.common.VCIError; /** * 页签按钮配合窗口 * * FIXME 程序问题 * 1、保存按钮中数据库操作尽量复用了原有的代码,参数的创建和保存处理不合理 * 2、对于参数,没有做名称重复等校验 * * @author VCI-STGK006 * */ public class ButtonSettingDialog extends JDialog { /** * serialVersionUID */ private static final long serialVersionUID = -7532763453642444087L; /** * 父窗口 */ private JDialog owner; /** * 按钮面板 */ private JPanel buttonPanel; /** * 系统主面板 */ private JSplitPane mainSplitPane; /** * 按钮树面板 */ private JPanel buttonTreePanel; /** * 按钮树 */ private JTree buttonTree; /** * 添加按钮 */ private JButton createButtonBtn; /** * 修改按钮信息 */ private JButton editButtonBtn; /** * 删除按钮 */ private JButton deleteButtonBtn; /** * 保存按钮 */ private JButton saveBtn; /** * 取消按钮 */ private JButton cancelBtn; /** * 加入 */ private JButton joinBtn; /** * 撤销 */ private JButton exitBtn; private boolean showCopyButton = true; private boolean showPasteButton = true; private boolean showPasteToOther = true; private boolean showJoinBtn = true; private boolean showExitBtn = true; private VCIJButton btnCopy = VCISwingUtil.createVCIJButton("copy", "复制", "复制", "copy.gif", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copy(); } }); private VCIJButton btnPaste = VCISwingUtil.createVCIJButton("past", "粘贴", "粘贴", "paste.gif", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { paste(); } }); private VCIJButton btnCopyToOther = VCISwingUtil.createVCIJButton("copyToOther", "复制到其它组件", "复制到其它组件", "copy.gif", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copyToOther(); } }); // private VCIJButton viewI18nButton = VCISwingUtil.createVCIJButton("viewI18nButton", "查看国际化字典", "查看国际化字典", "image.png", new ActionListener() { // @Override // public void actionPerformed(ActionEvent e) { // i18nTable(); // } // }); private List otherCustomButtons = new ArrayList(); /** * 按钮配置信息面板 */ private JPanel settingsPanel; /** * 当前选中Button */ protected PLTabButton selectedTabButton; /** * 当前选中Button的兄节点 */ protected PLTabButton selectedBrotherTabButton; /** * 按钮配置信息 */ private PLPageDefination plPageDefination; /** * 上下文信息 */ @SuppressWarnings("unused") private PLUILayout plpagelayoutdefination; /** * 按钮区域 * XXX 怎么用? */ protected String buttonArea = ""; protected OptMode flag = OptMode.View; private Frame ownerFrame = null; public ButtonSettingDialog(){} public ButtonSettingDialog(Frame ownerFrame, PLPageDefination plPageDefination, PLUILayout plpagelayoutdefination, String buttonArea) { super(ownerFrame, "配置按钮", true); this.ownerFrame = ownerFrame; ButtonSettingDialog_(plPageDefination, plpagelayoutdefination, buttonArea); } /** * 构造器 * @param plPageDefination 不能为空 * @param plpagelayoutdefination * @param buttonArea */ public ButtonSettingDialog(JDialog owner, PLPageDefination plPageDefination, PLUILayout plpagelayoutdefination, String buttonArea) { super(owner, "配置按钮", true); this.owner = owner; ButtonSettingDialog_(plPageDefination, plpagelayoutdefination, buttonArea); } protected void ButtonSettingDialog_(PLPageDefination plPageDefination, PLUILayout plpagelayoutdefination, String buttonArea){ this.plPageDefination = plPageDefination; this.plpagelayoutdefination = plpagelayoutdefination; this.buttonArea = buttonArea; //绘制界面 init(null); //刷新树,设置树状态 refreshTreeNode(this.buttonTree.getPathForRow(0)); this.setLocationRelativeTo(owner); this.setResizable(true); this.setVisible(true); } /** * 绘制 */ protected void init(JPanel pal) { //add by caill this.setSize(900, 600); //工具条 getButtonPanel(); mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); mainSplitPane.setDividerSize(7); mainSplitPane.setContinuousLayout(true); mainSplitPane.setOneTouchExpandable(true); mainSplitPane.setDividerLocation(250); //Button树 getButtonTreePanel(); //Button配置详细信息 getSettingsPanel(); //添加 mainSplitPane.add(buttonTreePanel, JSplitPane.LEFT); mainSplitPane.add(settingsPanel, JSplitPane.RIGHT); JPanel panel = new JPanel(); panel.setBorder(new EmptyBorder(7, 7, 7, 7)); panel.setLayout(new BorderLayout(0, 0)); panel.add(buttonPanel, BorderLayout.NORTH); panel.add(mainSplitPane, BorderLayout.CENTER); this.getContentPane().add(panel); //this.getContentPane().add(buttonPanel, BorderLayout.NORTH); //this.getContentPane().add(mainSplitPane, BorderLayout.CENTER); //刷新树,设置树状态 refreshTreeNode(this.buttonTree.getPathForRow(0)); } /** * 得到工具条 */ private void getButtonPanel() { //按钮区域 FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT); flowLayout.setHgap(10); JPanel palBtns = new JPanel(); palBtns = new JPanel(flowLayout); createButtonBtn = new JButton("添加"); createButtonBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addButtonBtnListener(); } }); editButtonBtn = new JButton("修改"); editButtonBtn.setEnabled(false); editButtonBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { editButtonBtnListener(); } }); deleteButtonBtn = new JButton("删除"); deleteButtonBtn.setEnabled(false); deleteButtonBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { deleteButtonBtnListener(); } }); saveBtn = new JButton("保存"); saveBtn.setEnabled(false); saveBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { saveBtnListener(); } }); cancelBtn = new JButton("取消"); cancelBtn.setEnabled(false); cancelBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelBtnListener(); } }); joinBtn = new JButton("调整为下级按钮"); joinBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { joinBtnListener(); } }); exitBtn = new JButton("调整为上级按钮"); exitBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { exitBtnListener(); } }); palBtns.add(createButtonBtn); palBtns.add(editButtonBtn); palBtns.add(deleteButtonBtn); palBtns.add(saveBtn); palBtns.add(cancelBtn); if(isShowJoinBtn()){ palBtns.add(joinBtn); } if(isShowExitBtn()){ palBtns.add(exitBtn); } if(isShowCopyButton()){ palBtns.add(btnCopy); } if(isShowPasteButton()){ palBtns.add(btnPaste); } if(isShowPasteToOther()){ palBtns.add(btnCopyToOther); } //palBtns.add(viewI18nButton); List othBtns = getOtherCustomButtons(); if( othBtns != null){ for (JButton btn : othBtns){ palBtns.add(btn); } } buttonPanel = new JPanel(new BorderLayout()); buttonPanel.add(new JScrollPane(palBtns), BorderLayout.CENTER); } /** * 撤销 */ private void exitBtnListener() { PLTabButton plTabButton = this.selectedTabButton; plTabButton.plParentOid = ""; try { boolean success = UITools.getService().updatePLTabButton(plTabButton); if(success == false) { JOptionPane.showMessageDialog(this, "撤销失败!", "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } TreePath selectedPath = this.buttonTree.getPathForRow(0); this.refreshTreeNode(selectedPath); buttonPanel.add(joinBtn); buttonPanel.add(exitBtn); } /** * 加入上级 */ private void joinBtnListener() { PLTabButton plTabButton = this.selectedTabButton; //当选择的按钮为树的第一个节点的时候,他的兄节点是他自己,导致调整为下级按钮时出错,故作此判断。 if(this.selectedBrotherTabButton !=null && !plTabButton.plOId.equalsIgnoreCase(this.selectedBrotherTabButton.plOId) ){ plTabButton.plParentOid = this.selectedBrotherTabButton.plOId; try { boolean success = UITools.getService().updatePLTabButton(plTabButton); if(success == false) { JOptionPane.showMessageDialog(this, "修改失败!", "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } TreePath selectedPath = this.buttonTree.getSelectionPath(); TreePath parentPath = selectedPath.getParentPath(); this.refreshTreeNode(parentPath); } } protected String getRootNodeShowLable(){ return this.plPageDefination != null ? this.plPageDefination.name : "按钮定义"; } /** * 创建Button树面板 * @return */ private void getButtonTreePanel() { buttonTreePanel = new JPanel(new BorderLayout()); //初始化按钮树 DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(getRootNodeShowLable()); DefaultTreeModel dtml = new DefaultTreeModel(dmtn); buttonTree = new JTree(dtml); buttonTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); buttonTree.setCellRenderer(new TabButtonTreeRenderer()); buttonTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { buttonTreeSelectionListener(e.getPath()); } }); buttonTree.addTreeExpansionListener(new TreeExpansionListener() { @Override public void treeExpanded(TreeExpansionEvent event) { buttonTree.setSelectionPath(event.getPath()); } @Override public void treeCollapsed(TreeExpansionEvent event) { buttonTree.setSelectionPath(event.getPath()); } }); buttonTree.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if(buttonTree.isEnabled()){ int x = e.getX(); int y = e.getY(); TreePath pathForLocation = buttonTree.getPathForLocation(x, y); if(pathForLocation == null) { return; } buttonTree.setSelectionPath(pathForLocation); if(e.getButton() == MouseEvent.BUTTON3) { //TODO 树节点右键事件 } }else { // return; } } }); JScrollPane buttonTreeScrollPane = new JScrollPane(buttonTree); buttonTreeScrollPane.setBorder(new EmptyBorder(0,0, 0,0)); buttonTreePanel.add(buttonTreeScrollPane, BorderLayout.CENTER); } /** * *

国际化字典Dialog:

* @author yangyang * @time 2017-10-31 */ // private void i18nTable(){ // VciI18nTableDialog vi18n = new VciI18nTableDialog(); // vi18n.setModal(true); // vi18n.init(); // vi18n.setSize(900,600); // vi18n.setLocationRelativeTo(ClientContextVariable.getFrame()); // vi18n.setVisible(true); // } // /** * 刷新按钮树节点 * @param selectedPath 待刷新节点的树路径 */ protected void refreshTreeNode(TreePath selectedPath) { if(selectedPath == null) { return; } //加载页签区域按钮配置 PLTabButton[] buttons = this.downloadTabButton(); if(buttons == null) { return; } DefaultMutableTreeNode node = (DefaultMutableTreeNode)selectedPath.getLastPathComponent(); DefaultTreeModel dtml = (DefaultTreeModel) this.buttonTree.getModel(); this.refreshTreeNode(node, dtml, buttons); } /** * 刷新树节点,创建节点对象并加载 * @param parent 父节点 * @param dtml 树模型 * @param buttons PLTabButton数组 */ private void refreshTreeNode(DefaultMutableTreeNode parent, DefaultTreeModel dtml, PLTabButton[] buttons) { parent.removeAllChildren(); String poid = ""; Object userObject = parent.getUserObject(); if(userObject instanceof ClientPLTabButton) { ClientPLTabButton cptb = (ClientPLTabButton) userObject; poid = cptb.getPtb().plOId; } for(PLTabButton ptb : buttons) { if(ptb.plParentOid.equals(poid)) { ClientPLTabButton cptb = new ClientPLTabButton(ptb); DefaultMutableTreeNode child = new DefaultMutableTreeNode(cptb); dtml.insertNodeInto(child, parent, parent.getChildCount()); refreshTreeNode(child, dtml, buttons); } } dtml.reload(parent); this.buttonTree.updateUI(); } /** * 加载页签区域按钮配置信息 * @return */ protected PLTabButton[] downloadTabButton() { PLTabButton[] buttons; try { // buttons = Tool.getService().getPLTabButtonsByTableOId( // plPageDefination.plOId); buttons = UITools.getService().getPLTabButtonsByTableOId(plPageDefination.plOId); return buttons; } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "加载页签区域按钮配置信息异常:" + e.getMessage(), "系统提示", JOptionPane.ERROR_MESSAGE); return null; } } /** * 树节点点击事件 */ protected void buttonTreeSelectionListener(TreePath selectedPath) { if(selectedPath == null) { this.selectedTabButton = null; } else { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedPath.getLastPathComponent(); DefaultMutableTreeNode nodeBrother = node.getPreviousSibling(); Object userObject = node.getUserObject(); if(nodeBrother != null){ Object userObjectBrother = nodeBrother.getUserObject(); this.selectedBrotherTabButton = ((ClientPLTabButton) userObjectBrother).getPtb(); } if(userObject instanceof String) { this.selectedTabButton = null; } else { this.selectedTabButton = ((ClientPLTabButton) userObject).getPtb(); } } if(this.flag == OptMode.View) { if(this.selectedTabButton == null) { this.createButtonBtn.setEnabled(true); this.editButtonBtn.setEnabled(false); this.deleteButtonBtn.setEnabled(false); } else { this.createButtonBtn.setEnabled(true); this.editButtonBtn.setEnabled(true); this.deleteButtonBtn.setEnabled(true); } refreshSettingsPanel(); } else if(this.flag == OptMode.Add) { this.addButtonBtnListener(); } else if(this.flag == OptMode.Update) { if(this.selectedTabButton == null) { JOptionPane.showMessageDialog(this, "不能修改根节点信息", "系统提示", JOptionPane.INFORMATION_MESSAGE); this.cancelBtnListener(); } else { this.editButtonBtnListener(); } } } protected ButtonInfoPanel btnInfoPanel = null; public ButtonInfoPanel getBtnInfoPanel() { return btnInfoPanel; } /** * 得到TabButton属性信息面板 */ private void getSettingsPanel() { btnInfoPanel = new ButtonInfoPanel(this, null); btnInfoPanel.buildPanel(); this.settingsPanel = btnInfoPanel; } // /** // * 初始化按钮参数面板 // * @param params // * @return // */ // private void getTabButtonParamterPanel(PLCommandParameter[] params) { // if(params == null || params.length < 1) { // tabButtonParamsPanel.removeAll(); // tabButtonParamsPanel.updateUI(); // tabButtonParamsPanel.setPreferredSize(new Dimension(0, 0)); // tabButtonParamsPanel.setBounds(new Rectangle(3, 285, // tabButtonParamsPanel.getPreferredSize().width, // tabButtonParamsPanel.getPreferredSize().height)); // settingsPanel.setPreferredSize(new Dimension( // 460, 285 + tabButtonParamsPanel.getPreferredSize().height)); // return; // } // Color backgroudColor = Color.WHITE; // tabButtonParamsPanel.removeAll(); // tabButtonParamsPanel.updateUI(); // tabButtonParamsPanel.setLayout(null); // tabButtonParamsPanel.setBackground(backgroudColor); // //tabButtonParamsPanel.setBorder(BorderFactory.createTitledBorder("按钮参数")); // // //面板宽度、高度 // int width = 460, height = 250; // //自定义控件ButtonParamTableCompt接受参数类型为PLActionParam,把params转一下使用 // PLActionParam[] params2 = new PLActionParam[params.length]; // for(int i = 0; i < params.length; i++){ // params2[i] = new PLActionParam(); // params2[i].name = params[i].plKey; // params2[i].defaultValue = params[i].plValue; // } // ArrayList datas = new ArrayList(Arrays.asList(params2)); // ButtonParamTableCompt tableCompt = new ButtonParamTableCompt(datas); // tabButtonParamsPanel.add(tableCompt.getTablePanel()); // // tabButtonParamsPanel.setPreferredSize(new Dimension(width, height)); // tabButtonParamsPanel.setBounds(new Rectangle(3, 285, // tabButtonParamsPanel.getPreferredSize().width, // tabButtonParamsPanel.getPreferredSize().height)); // settingsPanel.setPreferredSize(new Dimension( // 460, 285 + tabButtonParamsPanel.getPreferredSize().height)); // } /** * 刷新按钮设置面板 */ //String show2="0"; private void refreshSettingsPanel() { btnInfoPanel.setTabButton(selectedTabButton); btnInfoPanel.setControlEnable(flag != OptMode.View); int location = mainSplitPane.getDividerLocation(); mainSplitPane.setDividerLocation(location); } /** * 添加按钮事件 */ protected void addButtonBtnListener() { btnInfoPanel.setOptMode(OptMode.Add); this.flag = OptMode.Add; this.refreshSettingsPanel(); this.setAddEditButtonEnable(); this.btnInfoPanel.getParamTablePanel().setEditable(true); this.btnInfoPanel.getParamTablePanel().setShowButton(true); } /** * 修改按钮事件 */ protected void editButtonBtnListener() { btnInfoPanel.setOptMode(OptMode.Update); this.flag = OptMode.Update; this.refreshSettingsPanel(); this.setAddEditButtonEnable(); this.btnInfoPanel.getParamTablePanel().setEditable(true); this.btnInfoPanel.getParamTablePanel().setShowButton(true); } private void setAddEditButtonEnable(){ //重置按钮的状态 this.createButtonBtn.setEnabled(false); this.editButtonBtn.setEnabled(false); this.deleteButtonBtn.setEnabled(false); this.saveBtn.setEnabled(true); this.cancelBtn.setEnabled(true); this.buttonTree.setEnabled(false); } /** * 按钮删除事件 */ protected void deleteButtonBtnListener() { try { //得到当前选择节点父节点,用于刷新使用 TreePath selectedPath = this.buttonTree.getSelectionPath(); TreePath parentPath = null; if(selectedPath != null) { parentPath = selectedPath.getParentPath(); } if(this.selectedTabButton == null) { JOptionPane.showMessageDialog(this, "根节点不能删除!", "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } /*int confirm = JOptionPane.showConfirmDialog(this, "是否删除当前按钮?", "系统提示", JOptionPane.OK_CANCEL_OPTION);*/ Object[] options = { "Yes", "No" }; int option = JOptionPane .showOptionDialog(this, "确认是否删除按钮\"" + this.selectedTabButton.plLabel + "\"", "按钮定义删除", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if(option != JOptionPane.YES_OPTION){ return; } if(option == JOptionPane.OK_OPTION) { boolean success = UITools.getService().deletePLTabButton(this.selectedTabButton); if(success == false){ JOptionPane.showMessageDialog(this, "该有子级按钮,不能删除!", "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } JOptionPane.showMessageDialog(this, "删除成功!", "系统提示", JOptionPane.INFORMATION_MESSAGE); //刷新树 if(parentPath != null) { this.refreshTreeNode(parentPath); this.buttonTree.setSelectionPath(parentPath); } } } catch (VCIError e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "执行删除操作时发生异常:" + e.getMessage(), "系统提示", JOptionPane.ERROR_MESSAGE); } } /** * 保存事件 */ public void saveBtnListener() { String btnParamValidate = getBtnInfoPanel().getParamTablePanel().geCheckRes(); if(btnParamValidate != null && btnParamValidate.trim().length() != 0){ JOptionPane.showMessageDialog(this, btnParamValidate , "系统提示", JOptionPane.ERROR_MESSAGE); return; } //创建PLTabButton对象 PLTabButton plTabButton = null; if(this.flag == OptMode.Add) { //如果是增加操作,直接创建PLTabButton对象 plTabButton = new PLTabButton(); plTabButton.plOId = ObjectUtility.getNewObjectID36(); } else { //修改操作 plTabButton = this.selectedTabButton; plTabButton.plModifyUser = LogonApplication.getUserEntityObject().getUserName(); } plTabButton = getBtnInfoPanel().getFillVaueButton(plTabButton); if(plPageDefination != null){ plTabButton.plTableOId = plPageDefination.plOId; } if (plTabButton.plSeq < 1 || plTabButton.plSeq > 63) { JOptionPane.showMessageDialog(this, "按序号超出范围,请修改,按钮【编号】只能在【1-63】范围内。", "系统提示", JOptionPane.ERROR_MESSAGE); return; } plTabButton.plCreateUser = LogonApplication.getUserEntityObject().getUserName(); plTabButton.plModifyUser = LogonApplication.getUserEntityObject().getUserName(); plTabButton.plAreaType = buttonArea; try { if(flag == OptMode.Add){ boolean success = UITools.getService().savePLTabButton(plTabButton); if(success == false) { JOptionPane.showMessageDialog(this, "编号重复,编号已经在当前页签下存在!", "系统提示", JOptionPane.INFORMATION_MESSAGE); return; } } else if(flag == OptMode.Update){ UITools.getService().updatePLTabButton(plTabButton); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "保存按钮信息时发生异常:" + e.getMessage(), "系统提示", JOptionPane.ERROR_MESSAGE); return; } //复用以前的代码,对于参数一条一条删除,一条一条创建 //数据量及并发较少,暂时这么处理没有什么问题 if(this.flag == OptMode.Update) { try { UITools.getService().deletePLCommandParameterByTabButtonId(plTabButton.plOId); } catch (VCIError e) { e.printStackTrace(); } } LinkedHashMap buttonParams = getBtnInfoPanel().getParamTablePanel().getButtonParams(); if(!buttonParams.isEmpty()) { Iterator> iterator = buttonParams.entrySet().iterator(); while(iterator.hasNext()){ Entry next = iterator.next(); if(StringUtils.isEmpty(next.getKey()) || StringUtils.isEmpty(next.getValue())){ iterator.remove(); } } if(!buttonParams.isEmpty()){ Iterator> kvItor = buttonParams.entrySet().iterator(); while(kvItor.hasNext()){ Entry next = kvItor.next(); PLCommandParameter plCommandParameter = new PLCommandParameter(); plCommandParameter.plOId = ObjectUtility.getNewObjectID36(); plCommandParameter.plCommandOId = plTabButton.plOId; plCommandParameter.plKey = next.getKey(); plCommandParameter.plValue = next.getValue(); plCommandParameter.plCreateUser = LogonApplication.getUserEntityObject().getUserName(); plCommandParameter.plModifyUser = LogonApplication.getUserEntityObject().getUserName(); try { UITools.getService().savePLCommandParameter(plCommandParameter); } catch (VCIError e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "保存按钮信息时发生异常:" + e.getMessage(), "系统提示", JOptionPane.ERROR_MESSAGE); return; } } } } if(this.flag == OptMode.Add) { //添加的时候刷新树节点 TreePath selectedPath = this.buttonTree.getSelectionPath(); this.refreshTreeNode(selectedPath); //遍历子节点,设置新增节点为选中状态 selectChildPath(selectedPath, plTabButton.plOId); }else{ //修改的时候刷新树节点 TreePath selectedPath = this.buttonTree.getSelectionPath(); //add by caill 加非空判断为了避免空指针异常 if(selectedPath != null){ TreePath parentPath = selectedPath.getParentPath(); this.refreshTreeNode(parentPath); } } //保存完成后重置面板 cancelBtnListener(); buttonTree.setEnabled(true); } /** * 取消按钮事件 */ protected void cancelBtnListener() { this.flag = OptMode.View; btnInfoPanel.setOptMode(this.flag); // this.selectedTabButton = null; this.refreshSettingsPanel(); //重置按钮状态 this.createButtonBtn.setEnabled(true); if(this.selectedTabButton != null) { this.editButtonBtn.setEnabled(true); this.deleteButtonBtn.setEnabled(true); } this.saveBtn.setEnabled(false); this.cancelBtn.setEnabled(false); //重置参数 this.flag = OptMode.View; buttonTree.setEnabled(true); this.btnInfoPanel.getParamTablePanel().setEditable(false); this.btnInfoPanel.getParamTablePanel().setShowButton(false); } /** * 遍历子节点,设置ploid节点为选中状态 * @param parentPath 遍历节点路径 * @param ploid 子节点ploid */ protected void selectChildPath(TreePath parentPath, String ploid) { if(parentPath == null) { return; } //设置当前节点展开 this.buttonTree.expandPath(parentPath); //遍历子节点 DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) parentPath.getLastPathComponent(); int childCount = parentNode.getChildCount(); for(int i = 0; i < childCount; i++) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) parentNode.getChildAt(i); ClientPLTabButton cptb = (ClientPLTabButton) childNode.getUserObject(); PLTabButton ptb = cptb.getPtb(); if(ploid.equals(ptb.plOId)) { int row = this.buttonTree.getRowForPath(parentPath); this.buttonTree.setSelectionRow(row + i + 1); break; } } } /** * 去除""字符串 * @param str * @return */ public String getNotNullString(String str) { if(str == null) { return ""; } return str.trim(); } private boolean checkSelectedIsButtonNode(boolean allowRoot){ TreePath selectedPath = this.buttonTree.getSelectionPath(); if(selectedPath == null){ return false; } DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedPath.getLastPathComponent(); if(!allowRoot && node.isRoot()){ return false; } return true; } private boolean isCanContinue(boolean allowRoot){ if(!checkSelectedIsButtonNode(allowRoot)){ VCIJOptionPane.showMessage(this, "请先选择有效的按钮!"); return false; } return true; } private void copy(){ if(!isCanContinue(false)) return; TreePath selectedPath = this.buttonTree.getSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedPath.getLastPathComponent(); ClientPLTabButton btn = (ClientPLTabButton)node.getUserObject(); String tabBtnOid = btn.getPtb().plOId; Toolkit.getDefaultToolkit().getSystemClipboard().setContents( new StringSelection(tabBtnOid), null); } private void paste(){ if(!isCanContinue(true)) return; try{ Transferable trans = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); if(Toolkit.getDefaultToolkit().getSystemClipboard().isDataFlavorAvailable(DataFlavor.stringFlavor)){ Object obj = trans.getTransferData(DataFlavor.stringFlavor); if(obj instanceof String){ String tabBtnOid = (String)obj; pasteTabBtnToNewCompt(tabBtnOid); } } }catch(Exception e){ e.printStackTrace(); VCIJOptionPane.showError(this, "从剪切模板中提取数据时发生错误!\n" + e.getMessage()); } } private void pasteTabBtnToNewCompt(String tabBtnOid){ try { PLTabButton btn = UITools.getService().getPLTabButtonById(tabBtnOid); if("".equals(btn.plOId)){ VCIJOptionPane.showMessage(this, "按钮无效,无法执行粘贴!"); return; } addButtonToTree(btn); } catch (VCIError e) { e.printStackTrace(); VCIJOptionPane.showError(this, "根据oid查询按钮时发生错误!\n" + e.getMessage()); } } private void addButtonToTree(PLTabButton btnSrc){ String parentOid = ""; TreePath selectedPath = this.buttonTree.getSelectionPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedPath.getLastPathComponent(); if(node.getUserObject() instanceof String){ parentOid = ""; } else if(node.getUserObject() instanceof ClientPLTabButton){ ClientPLTabButton btnSelected = (ClientPLTabButton)node.getUserObject(); parentOid = btnSelected.getPtb().plOId; } doPasteDet(btnSrc, parentOid, new String[]{this.plPageDefination.plOId}, true); refreshTreeNode(this.buttonTree.getPathForRow(0)); } private void doPasteDet(PLTabButton btnSrc, String btnParentOid, String[] targetComptOids, boolean showSuccessMessage){ PLCommandParameter[] cmdParSrcs = new PLCommandParameter[0]; try{ cmdParSrcs = UITools.getService().getPLCommandParametersByCommandOId(btnSrc.plOId); } catch (VCIError e) { e.printStackTrace(); VCIJOptionPane.showError(this, "查询按钮参数时发生错误!\n" + e.getMessage()); return; } List newBtns = new LinkedList(); List newBtnParams = new LinkedList(); for(String comptOid : targetComptOids){ doPastDetToCompt(btnSrc, cmdParSrcs, btnParentOid, comptOid, newBtns, newBtnParams); } doSaveNewPLTabButtonAndParams(newBtns, newBtnParams, this, showSuccessMessage); } private void doSaveNewPLTabButtonAndParams( final List newBtns, final List newBtnParams, final Component messageOwnerCompt, final boolean showSuccessMessage){ final QANProcessBarFrame frame = new QANProcessBarFrame(); final QANProcessBar bar = new QANProcessBar(new Thread(new Runnable() { @Override public void run() { try{ frame.setContent("正在保存按钮,请稍候..."); UITools.getService().savePLTabButtonAndParams( newBtns.toArray(new PLTabButton[]{}), newBtnParams.toArray(new PLCommandParameter[]{})); frame.setProcessBarCancel(true); if(showSuccessMessage){ VCIJOptionPane.showMessage(messageOwnerCompt, "保存按钮成功!"); } }catch (VCIError e) { e.printStackTrace(); frame.setProcessBarCancel(true); VCIJOptionPane.showError(messageOwnerCompt, "保存按钮(包含按钮参数)时发生错误!\n" + e.getMessage()); }finally{ frame.setProcessBarCancel(true); } } }), (JDialog)this, frame, false); bar.setTitle("保存按钮"); frame.setTitle(bar.getTitle()); bar.setVisible(true); } private void doPastDetToCompt(PLTabButton btnSrc, PLCommandParameter[] cmdParamsSrc, String btnParentOid, String targetComptOid, List newBtns, List newBtnParams){ PLTabButton btn = PortalUtil.getInstance().clonePLTabButton(btnSrc); newBtns.add(btn); for (int i = 0; i < cmdParamsSrc.length; i++) { PLCommandParameter newParam = PortalUtil.getInstance().clonePLCommandParameter(cmdParamsSrc[i]); newParam.plCommandOId = btn.plOId; newBtnParams.add(newParam); } btn.plParentOid = btnParentOid; btn.plTableOId = targetComptOid; } private void copyToOther(){ if(!isCanContinue(false)){ return ; } ButtonCopyToOtherComptDialog dlg = new ButtonCopyToOtherComptDialog(this); dlg.buildDialog(); dlg.setVisible(true); DialogResult dlgRes = dlg.getDialogResult(); if(dlgRes == DialogResult.OK){ List targetComptOids = dlg.getTargetComptOidList(); PLTabButton btnSrc = getSelectedPLTabButton(); doPasteDet(btnSrc, "", targetComptOids.toArray(new String[]{}), true); } } private PLTabButton getSelectedPLTabButton(){ TreePath selectedPath = this.buttonTree.getSelectionPath(); if(selectedPath == null){ return null; } DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedPath.getLastPathComponent(); if(node.getUserObject() instanceof ClientPLTabButton){ ClientPLTabButton btnSelected = (ClientPLTabButton)node.getUserObject(); return btnSelected.getPtb(); } return null; } public boolean isShowCopyButton() { return showCopyButton; } public void setShowCopyButton(boolean showCopyButton) { this.showCopyButton = showCopyButton; } public boolean isShowPasteButton() { return showPasteButton; } public void setShowPasteButton(boolean showPasteButton) { this.showPasteButton = showPasteButton; } public boolean isShowPasteToOther() { return showPasteToOther; } public void setShowPasteToOther(boolean showPasteToOther) { this.showPasteToOther = showPasteToOther; } public boolean isShowJoinBtn() { return showJoinBtn; } public void setShowJoinBtn(boolean showJoinBtn) { this.showJoinBtn = showJoinBtn; } public boolean isShowExitBtn() { return showExitBtn; } public void setShowExitBtn(boolean showExitBtn) { this.showExitBtn = showExitBtn; } public List getOtherCustomButtons() { return otherCustomButtons; } public void setOtherCustomButtons(List otherCustomButtons) { this.otherCustomButtons = otherCustomButtons; } public JTree getButtonTree() { return buttonTree; } }