package com.vci.client.portal.NewNewUI.actionmng; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.filechooser.FileFilter; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import com.vci.corba.portal.*; import com.vci.corba.portal.data.Constraint; import com.vci.corba.portal.data.PLAction; import com.vci.corba.portal.data.PLActionCls; import com.vci.corba.portal.data.PLActionParam; import com.vci.mw.ClientContextVariable; import com.vci.client.LogonApplication; import com.vci.client.common.PinyinCommon; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.ui.tree.CheckBoxTreeManager; import com.vci.corba.common.VCIError; import com.vci.corba.omd.qtm.QTInfo; public class ExpActionDialog extends JDialog{ private static final long serialVersionUID = 1L; private JTree clsTree; private CheckBoxTreeManager treeManager; private File selectedFile; private String exportFileName; public ExpActionDialog() { super(LogonApplication.frame,true); this.initUI(); this.setSize(500, 500); this.setLocationRelativeTo(null); } private void initUI() { try { JScrollPane contentPanel = this.getContentPanel(); this.getContentPane().add(contentPanel, BorderLayout.CENTER); JPanel btnPanel = this.getBtnPanel(); this.getContentPane().add(btnPanel, BorderLayout.SOUTH); } catch (VCIError e) { e.printStackTrace(); } } private JScrollPane getContentPanel() throws VCIError { JScrollPane contentPanel = new JScrollPane(); /*VCIBaseTreeNode rootNode = new VCIBaseTreeNode("Action分类","root"); VCIBaseTreeModel treeModel = new VCIBaseTreeModel(rootNode); //链接类型 LinkType[] linkTypes = LinkTypeProvider.getInstance().getLinkTypes(); for(int i=0; i selActionCls = new ArrayList(); for(int i = 0;i < treePath.length;i++){ DefaultMutableTreeNode node = (DefaultMutableTreeNode)treePath[i].getLastPathComponent(); Object obj = node.getUserObject(); if(obj instanceof String){//如果是root节点,则保存所有模块 String nodeName = (String)obj; if("Action分类".equals(nodeName)){ PLActionCls[] clses = UITools.getService().getPLActionClsArray(); PLActionCls plac = new PLActionCls("", "未分类", "", "", "", 0, (short)0); Collections.addAll(selActionCls, clses); selActionCls.add(plac); } }else if(obj instanceof ClientPLActionCls){ allPLActionClsParent(node, selActionCls); selActionCls.remove(selActionCls.size()-1); allPLActionClsChildren(node, selActionCls); } } System.out.println(selActionCls.size()); openFileChoser(); if(writeFile(selActionCls)){ VCIOptionPane.showMessage(LogonApplication.frame, "导出成功"); setVisible(false); }else{ VCIOptionPane.showMessage(LogonApplication.frame, "导出失败!"); } } catch (VCIError e) { e.printStackTrace(); VCIOptionPane.showMessage(LogonApplication.frame, "导出异常!"); } }else{ VCIOptionPane.showMessage(LogonApplication.frame, "请选择要导出的模板定义!"); return; } } }); return btnPanel; } private void allPLActionClsParent(DefaultMutableTreeNode node, List selActionCls) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); PLActionCls pac = ((ClientPLActionCls)node.getUserObject()).getPac(); if(pac.pid != ""){ allPLActionClsParent(parent, selActionCls); } selActionCls.add(pac); } private void allPLActionClsChildren(DefaultMutableTreeNode node, List selActionCls) { PLActionCls pac = ((ClientPLActionCls)node.getUserObject()).getPac(); selActionCls.add(pac); for(int i=0; i selActionCls) { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet actionSheet = workbook.createSheet("action_sheet"); HSSFSheet paramSheet = workbook.createSheet("param_sheet"); HSSFSheet clsSheet = workbook.createSheet("cls_sheet"); List selActions = new ArrayList(); this.initClsSheet(clsSheet, selActionCls); this.initActionSheet(actionSheet, selActionCls, selActions); this.initParamSheet(paramSheet, selActions); try { FileOutputStream fos = new FileOutputStream(exportFileName); workbook.write(fos); fos.flush(); fos.close(); System.out.println("文件"+exportFileName + "生成成功!"); } catch (Exception e) { e.printStackTrace(); return false; } return true; } private void initParamSheet(HSSFSheet paramSheet, List selActions) { HSSFRow titleRow = paramSheet.createRow(0); HSSFCell cell = titleRow.createCell(0); cell.setCellValue(new HSSFRichTextString("参数名称")); cell = titleRow.createCell(1); cell.setCellValue("默认值"); cell = titleRow.createCell(2); cell.setCellValue("提示信息"); cell = titleRow.createCell(3); cell.setCellValue("所属action"); int i = 1; try { for(PLAction action: selActions){ PLActionParam[] params = UITools.getService().getPLActionParamArrayByActionId(action.plOId); for(PLActionParam param: params){ HSSFRow valueRow = paramSheet.createRow(i++); HSSFCell valueCell = valueRow.createCell(0); valueCell.setCellValue(param.name); valueCell = valueRow.createCell(1); valueCell.setCellValue(param.defaultValue); valueCell = valueRow.createCell(2); valueCell.setCellValue(param.description); valueCell = valueRow.createCell(3); valueCell.setCellValue(action.plCode); } } } catch (VCIError e) { e.printStackTrace(); } } private void initClsSheet(HSSFSheet clsSheet, List selActionCls) { HSSFRow titleRow = clsSheet.createRow(0); HSSFCell cell = titleRow.createCell(0); cell.setCellValue(new HSSFRichTextString("类全路径")); cell = titleRow.createCell(1); cell.setCellValue("描述"); cell = titleRow.createCell(2); cell.setCellValue("创建人"); cell = titleRow.createCell(3); cell.setCellValue("创建时间"); cell = titleRow.createCell(4); cell.setCellValue("分类序号"); int i = 1; for(PLActionCls cls: selActionCls){ String clsPath = this.getClsPath(cls); if(clsPath.equals("未分类")){ continue; } HSSFRow valueRow = clsSheet.createRow(i++); HSSFCell valueCell = valueRow.createCell(0); valueCell.setCellValue(clsPath); valueCell = valueRow.createCell(1); valueCell.setCellValue(cls.description); valueCell = valueRow.createCell(2); valueCell.setCellValue(cls.creator); valueCell = valueRow.createCell(3); valueCell.setCellValue(cls.createTime); valueCell = valueRow.createCell(4); valueCell.setCellValue(cls.serialno); } } private void initActionSheet(HSSFSheet actionSheet, List selActionCls, List selActions) { HSSFRow titleRow = actionSheet.createRow(0); HSSFCell cell = titleRow.createCell(0); cell.setCellValue(new HSSFRichTextString("编号")); cell = titleRow.createCell(1); cell.setCellValue("名称"); cell = titleRow.createCell(2); cell.setCellValue("类路径"); cell = titleRow.createCell(3); cell.setCellValue("链接地址"); cell = titleRow.createCell(4); cell.setCellValue("类型"); cell = titleRow.createCell(5); cell.setCellValue("描述"); cell = titleRow.createCell(6); cell.setCellValue("创建时间"); cell = titleRow.createCell(7); cell.setCellValue("创建人"); cell = titleRow.createCell(8); cell.setCellValue("修改时间"); cell = titleRow.createCell(9); cell.setCellValue("修改人"); cell = titleRow.createCell(10); cell.setCellValue("所属分类"); cell = titleRow.createCell(11); cell.setCellValue("plLicensOrs"); int i = 1; for(PLActionCls cls: selActionCls){ String clsPath = this.getClsPath(cls); PLAction[] actions = this.getTablePanelData(cls); for(PLAction action: actions){ selActions.add(action); HSSFRow valueRow = actionSheet.createRow(i++); HSSFCell valueCell = valueRow.createCell(0); valueCell.setCellValue(action.plCode); valueCell = valueRow.createCell(1); valueCell.setCellValue(action.plName); valueCell = valueRow.createCell(2); valueCell.setCellValue(action.plCSClass); valueCell = valueRow.createCell(3); valueCell.setCellValue(action.plBSUrl); valueCell = valueRow.createCell(4); valueCell.setCellValue(action.plTypeType); valueCell.setCellValue(action.plDesc); valueCell = valueRow.createCell(5); valueCell.setCellValue(action.plCreateTime); valueCell = valueRow.createCell(6); valueCell = valueRow.createCell(7); valueCell.setCellValue(action.plCreateUser); valueCell = valueRow.createCell(8); valueCell.setCellValue(action.plModifyTime); valueCell = valueRow.createCell(9); valueCell.setCellValue(action.plModifyUser); valueCell = valueRow.createCell(10); valueCell.setCellValue(clsPath); valueCell = valueRow.createCell(11); valueCell.setCellValue(action.plLicensOrs); } } } /** * 查询Action数据 * @param currentCls * @return */ private PLAction[] getTablePanelData(PLActionCls currentCls){ Constraint[] consArray = new Constraint[1]; if(currentCls.name.equals("未分类")) { consArray[0] = new Constraint("plactioncls", ""); } else { consArray[0] = new Constraint("plactioncls", currentCls.id); } PLAction[] res = null; try { res = UITools.getService().getPLActionsByConsArray(consArray); } catch (VCIError e) { e.printStackTrace(); } Arrays.sort(res, new Comparator(){ @Override public int compare(PLAction o1, PLAction o2) { String py1 = PinyinCommon.getPingYin(o1.plName); String py2 = PinyinCommon.getPingYin(o2.plName); return py1.compareTo(py2); }}); return res; } private String getClsPath(PLActionCls cls) { try { PLActionCls[] clses = UITools.getService().getPLActionClsArray(); StringBuilder sbuf = new StringBuilder(); this.parseClsPath(cls, clses, sbuf); return sbuf.substring(0, sbuf.length()-1).toString(); } catch (VCIError e) { e.printStackTrace(); } return ""; } private void parseClsPath(PLActionCls cls, PLActionCls[] clses, StringBuilder sbuf) { if(cls.pid != null && cls.pid.trim().length() > 0){ for(PLActionCls actionCls: clses){ if(cls.pid.equals(actionCls.id)){ this.parseClsPath(actionCls, clses, sbuf); } } } sbuf.append(cls.name).append("#"); } }