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<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.setCellRenderer(new ActionManagerTreeCellRenderer());
|
|
clsTree.getSelectionModel().setSelectionMode(
|
TreeSelectionModel.SINGLE_TREE_SELECTION);
|
// 刷新分类树
|
refreshClsTree(clsTree.getPathForRow(0));
|
|
treeManager = new CheckBoxTreeManager(clsTree);
|
contentPanel.getViewport().removeAll();
|
contentPanel.setViewportView(clsTree);
|
contentPanel.repaint();
|
JLabel label = new JLabel("第一步:action分类");
|
return contentPanel;
|
}
|
|
private void refreshClsTree(TreePath tp) {
|
try {
|
// 分类较少,直接查询所有分类
|
PLActionCls[] clses = Tool.getService().getPLActionClsArray();
|
plActions = Tool.getService().getAllPLAction();
|
|
DefaultTreeModel dtml = (DefaultTreeModel) clsTree.getModel();
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tp
|
.getLastPathComponent();
|
addClsTreeNode(dtml, node, clses);
|
try {
|
new JTreeDecorater(this.clsTree).expandAllNode();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
} 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)) {
|
|
if (userObject instanceof ClientPLActionCls) {
|
PLActionCls pac = ((ClientPLActionCls) userObject).getPac();
|
pid = pac.id;
|
}
|
}
|
|
// 添加子节点(源table节点)
|
for (PLAction plAction : this.plActions) {
|
|
if ((!pid.equals("")) && plAction.plActionCls.equals(pid)) {
|
DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(
|
new ClientPLAction(plAction));
|
TreePath newChildTreePath = new TreePath(newChild);
|
|
dtml.insertNodeInto(newChild, node,
|
node.getChildCount());
|
|
}
|
}
|
// 添加子节点(源树节点)
|
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);
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
|
new ClientPLActionCls(plac), true);
|
dtml.insertNodeInto(child, node, node.getChildCount());
|
for (PLAction plAction : this.plActions) {
|
if (plAction.plActionCls.equals("")) {
|
DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(
|
new ClientPLAction(plAction), false);
|
dtml.insertNodeInto(newChild, child, child.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 {
|
HashSet<PLActionCls> selActionCls = new HashSet<PLActionCls>();
|
HashSet<PLAction> selAction = new HashSet<PLAction>();
|
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<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,
|
HashSet<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);
|
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<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 = 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<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,
|
HashSet<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 = 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<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 = 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("#");
|
}
|
|
*/}
|