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<linkTypes.length; i++){
|
VCIBaseTreeNode node = new VCIBaseTreeNode(linkTypes[i].name, linkTypes[i]);
|
treeModel.insertNodeInto(node, rootNode, rootNode.getChildCount());
|
QTInfo[] qtsByLinkTypeName = QTClientForLink2.getService().getQTS(linkTypes[i].name);
|
for(QTInfo qt: qtsByLinkTypeName){
|
VCIBaseTreeNode qtdNode = new VCIBaseTreeNode(qt.qtName,qt);
|
treeModel.insertNodeInto(qtdNode, node, node.getChildCount());
|
}
|
}*/
|
|
//初始化树
|
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Action分类");
|
DefaultTreeModel dtml = new DefaultTreeModel(root);
|
clsTree = new JTree(dtml);
|
clsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
//刷新分类树
|
refreshClsTree(clsTree.getPathForRow(0));
|
|
treeManager = new CheckBoxTreeManager(clsTree);
|
contentPanel.getViewport().removeAll();
|
contentPanel.setViewportView(clsTree);
|
contentPanel.repaint();
|
return contentPanel;
|
}
|
|
private void refreshClsTree(TreePath tp) {
|
try {
|
//分类较少,直接查询所有分类
|
PLActionCls[] clses = UITools.getService().getPLActionClsArray();
|
|
DefaultTreeModel dtml = (DefaultTreeModel) clsTree.getModel();
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
|
tp.getLastPathComponent();
|
addClsTreeNode(dtml, node, clses);
|
} catch (VCIError e1) {
|
e1.printStackTrace();
|
JOptionPane.showMessageDialog(ClientContextVariable.getFrame(),
|
"刷新分类树异常:" + e1.getMessage(), "系统异常", JOptionPane.ERROR_MESSAGE);
|
}
|
}
|
/**
|
* 添加分类树节点
|
* @param dtml 树模型
|
* @param node 节点
|
* @param clses 分类
|
*/
|
private void addClsTreeNode(DefaultTreeModel dtml,
|
DefaultMutableTreeNode node, PLActionCls[] clses) {
|
node.removeAllChildren();
|
String pid = "";
|
Object userObject = node.getUserObject();
|
if(!(userObject instanceof String)) {
|
PLActionCls pac = ((ClientPLActionCls) userObject).getPac();
|
pid = pac.id;
|
}
|
//添加子节点
|
for(PLActionCls plac : clses) {
|
if(plac.pid.equals(pid)) {
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
|
new ClientPLActionCls(plac));
|
dtml.insertNodeInto(child, node, node.getChildCount());
|
addClsTreeNode(dtml, child, clses);
|
}
|
}
|
if(pid.equals("")) {
|
PLActionCls plac = new PLActionCls("", "未分类", "", "", "", 0, (short)0);
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
|
new ClientPLActionCls(plac));
|
dtml.insertNodeInto(child, node, node.getChildCount());
|
}
|
dtml.reload(node);
|
}
|
|
private JPanel getBtnPanel() {
|
JPanel btnPanel = new JPanel();
|
btnPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
JButton okButton = new JButton("确定");
|
JButton closeButton = new JButton("关闭");
|
btnPanel.add(okButton);
|
btnPanel.add(closeButton);
|
closeButton.addActionListener(new ActionListener() {
|
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
setVisible(false);
|
}
|
});
|
|
okButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent arg0) {
|
TreePath[] treePath = treeManager.getSelectionModel().getSelectionPaths();
|
//openFileChoser();
|
if (treePath != null) {
|
try {
|
List<PLActionCls> selActionCls = new ArrayList<PLActionCls>();
|
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<PLActionCls> 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<PLActionCls> selActionCls) {
|
PLActionCls pac = ((ClientPLActionCls)node.getUserObject()).getPac();
|
selActionCls.add(pac);
|
for(int i=0; i<node.getChildCount(); i++){
|
DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
|
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(List<PLActionCls> selActionCls) {
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
HSSFSheet actionSheet = workbook.createSheet("action_sheet");
|
HSSFSheet paramSheet = workbook.createSheet("param_sheet");
|
HSSFSheet clsSheet = workbook.createSheet("cls_sheet");
|
List<PLAction> selActions = new ArrayList<PLAction>();
|
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<PLAction> 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<PLActionCls> 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<PLActionCls> selActionCls, List<PLAction> 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<PLAction>(){
|
@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("#");
|
}
|
|
|
}
|