package com.vci.client.portal.NewNewUI.actionmng; import javax.swing.JDialog; public class ExpActionDialog4 extends JDialog { private static final long serialVersionUID = 1L;/* private static final long serialVersionUID = 1L; private JTree clsTree; private CheckBoxTreeManager treeManager; private File selectedFile; private String exportFileName; private PLAction[] plActions = null;// 接收plaction public ExpActionDialog4() { super(LogonApplication.frame,"action导出向导", true); this.initUI(); this.setSize(500, 500); this.setLocationRelativeTo(null); } private void initUI() { try { getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); JLabel label = new JLabel("第一步:action分类"); this.getContentPane().add(label); JScrollPane contentPanel = this.getContentPanel(); this.getContentPane().add(contentPanel); JPanel btnPanel = this.getBtnPanel(); this.getContentPane().add(btnPanel); } catch (VCIError e) { e.printStackTrace(); } } @SuppressWarnings("serial") 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 HashSet(); HashSet selAction = new HashSet(); 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 = Tool.getService() .getPLActionClsArray(); PLActionCls plac = new PLActionCls("", "未分类", "", "", "", "", 0); Collections.addAll(selActionCls, clses); selActionCls.add(plac); } } else if (obj instanceof ClientPLActionCls) { allPLActionClsParent(node, selActionCls); selActionCls.remove(selActionCls.size() - 1); // allPLActionClsChildren(node, selActionCls); }else if (obj instanceof ClientPLAction){ DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); allPLActionClsParent(parentNode, selActionCls); selActionCls.remove(selActionCls.size() - 1); // allPLActionClsChildren(parentNode, selActionCls); ClientPLAction action= (ClientPLAction)obj; selAction.add(action.getPa()); } } System.out.println(selActionCls.size()); System.out.println(selAction.size()); openFileChoser(); System.out.println(ExpActionDialog4.this.exportFileName); 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 class FilePanel{ // JPanel filePanel = new JPanel(); // // // public FilePanel() { // // filePanel.setLayout(new FlowLayout(FlowLayout.CENTER)); // fileChooser.setDialogTitle("选择文件"); // int result = fileChooser.showOpenDialog(filePanel); // if (result == 0) { // File file = fileChooser.getSelectedFile(); // String newfilePath = file.getAbsolutePath(); // } // filePanel.add(fileChooser); // } // // } private void allPLActionClsParent(DefaultMutableTreeNode node, HashSet 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, HashSet selActionCls) { PLActionCls pac = ((ClientPLActionCls) node.getUserObject()).getPac(); selActionCls.add(pac); for (int i = 0; i < node.getChildCount(); i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node .getChildAt(i); if(child.getUserObject() instanceof ClientPLActionCls) allPLActionClsChildren(child, selActionCls); } } private void openFileChoser() { JFileChooser jf = new JFileChooser(); jf.removeChoosableFileFilter(jf.getFileFilter()); jf.setFileFilter(new FileFilter() { public String getDescription() { return "xls"; } public boolean accept(File f) { return ((f.isDirectory()) || (f.getName().endsWith(".xls"))); } }); jf.setDialogTitle("打开"); int showOpenDialog = jf.showOpenDialog(LogonApplication.frame); if (showOpenDialog == JFileChooser.APPROVE_OPTION) { selectedFile = jf.getSelectedFile(); exportFileName = selectedFile.getAbsolutePath(); if (!exportFileName.endsWith(".xls")) { exportFileName = exportFileName + ".xls"; } } } private boolean writeFile(HashSet 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 = Tool.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, HashSet 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, HashSet 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 = valueRow.createCell(5); valueCell.setCellValue(action.plDesc); valueCell = valueRow.createCell(6); valueCell.setCellValue(action.plCreateTime); 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 = Tool.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 = Tool.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("#"); } */}