package com.vci.client.portal.NewNewUI.actionExport;
|
|
import java.io.File;
|
import java.io.PrintWriter;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
|
import javax.swing.JOptionPane;
|
import javax.swing.JTable;
|
import javax.swing.table.DefaultTableModel;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreeSelectionModel;
|
|
import com.vci.client.portal.NewNewUI.Export.ExportTreeCellRenderer;
|
import com.vci.client.portal.NewNewUI.Export.VCIExportTree;
|
import com.vci.client.portal.utility.UITools;
|
import com.vci.client.ui.tree.CheckBoxTreeManager;
|
import com.vci.corba.common.VCIError;
|
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.mw.ClientContextVariable;
|
|
public class VCIActionExportTree extends VCIExportTree{
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
private CheckBoxTreeManager treeManager = null;
|
private ExportBeans exportBeans = null;
|
private PrintWriter fileLog = null ;
|
private DefaultTableModel tableLog = null;
|
private SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
private HashMap<String,PLActionCls> actionCls = new HashMap<String,PLActionCls>();
|
public VCIActionExportTree(DefaultTreeModel treeModel) {
|
super(treeModel);
|
this.setCellRenderer(new ExportTreeCellRenderer());
|
}
|
public VCIActionExportTree() {
|
super(new DefaultTreeModel(new DefaultMutableTreeNode("Action分类")));
|
this.setCellRenderer(new ExportTreeCellRenderer());
|
}
|
|
@Override
|
public void init() {
|
this.getSelectionModel().setSelectionMode(
|
TreeSelectionModel.SINGLE_TREE_SELECTION);
|
DefaultTreeModel dtml = new DefaultTreeModel(new DefaultMutableTreeNode("Action分类"));
|
this.setModel(dtml);
|
// 刷新分类树
|
refreshExportTree(this.getPathForRow(0));
|
if (treeManager == null) {
|
treeManager = new CheckBoxTreeManager(this);
|
}else{
|
TreePath[] paths = treeManager.getSelectionModel().getSelectionPaths();
|
if(paths != null)
|
treeManager.getSelectionModel().removeSelectionPaths(paths);
|
}
|
|
}
|
private void refreshExportTree(TreePath pathForRow) {
|
try {
|
// 分类较少,直接查询所有分类
|
PLActionCls[] pLActionClses = UITools.getService().getPLActionClsArray();
|
PLAction[] plActions = UITools.getService().getAllPLAction();
|
//清楚分类id
|
actionCls.clear();
|
//保存所有分类id
|
for (int i = 0; i < pLActionClses.length; i++) {
|
actionCls.put(pLActionClses[i].id,pLActionClses[i]);
|
}
|
//保存所有存在action的分类(子分类存在action也保存)
|
HashSet<PLActionCls> pLActionClsList =new HashSet<PLActionCls> ();
|
for (int i = 0; i < plActions.length; i++) {
|
//缓存该分类的所有父分类
|
saveParentCls(plActions[i].plActionCls,pLActionClsList);
|
}
|
PLActionCls[] actionClses = new PLActionCls[pLActionClsList.size()];
|
pLActionClsList.toArray(actionClses);
|
|
DefaultTreeModel dtml = (DefaultTreeModel) this.getModel();
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathForRow
|
.getLastPathComponent();
|
addExportTreeNode(dtml, node,actionClses,plActions);
|
//展开所有树节点
|
// TreeNode rootNode = (TreeNode)this.getModel().getRoot();
|
// this.expandAllTreeNode(new TreePath(rootNode), true);
|
} catch (VCIError e1) {
|
e1.printStackTrace();
|
JOptionPane.showMessageDialog(ClientContextVariable.getFrame(),
|
"刷新分类树异常:" + e1.getMessage(), "系统异常",
|
JOptionPane.ERROR_MESSAGE);
|
}
|
}
|
|
/**
|
* 保存所有父分类
|
* @param plActionCls
|
* @param pLActionClsList
|
*/
|
private void saveParentCls(String plActionCls,
|
HashSet<PLActionCls> pLActionClsList) {
|
if(actionCls.containsKey(plActionCls)){
|
PLActionCls pCls = actionCls.get(plActionCls);
|
pLActionClsList.add(pCls);
|
saveParentCls(pCls.pid,pLActionClsList);
|
}
|
|
}
|
private void addExportTreeNode(DefaultTreeModel dtml,
|
DefaultMutableTreeNode node, PLActionCls[] pLActionClses,PLAction[] plActions) {
|
// node.removeAllChildren();
|
String pid = "";
|
Object userObject = node.getUserObject();
|
if (!(userObject instanceof String)) {
|
|
if (userObject instanceof ExportPLActionClsBean) {
|
PLActionCls pac = ((ExportPLActionClsBean) userObject).getBean();
|
pid = pac.id;
|
}
|
}
|
|
// 添加子节点(源table节点)
|
for (PLAction plAction : plActions) {
|
|
if ((!pid.equals("")) && plAction.plActionCls.equals(pid)) {
|
DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(
|
new ExportPLActionBean(plAction));
|
// TreePath newChildTreePath = new TreePath(newChild);
|
//
|
dtml.insertNodeInto(newChild, node,
|
node.getChildCount());
|
|
}
|
}
|
// 添加子节点(源树节点)
|
for (PLActionCls plac : pLActionClses) {
|
|
if(plac.pid.equals(pid)){
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
|
new ExportPLActionClsBean(plac));
|
dtml.insertNodeInto(child, node, node.getChildCount());
|
addExportTreeNode(dtml, child, pLActionClses,plActions);
|
}
|
|
}
|
if (pid.equals("")) {
|
PLActionCls plac = new PLActionCls("", "未分类", "", "", "", 0, (short)0);
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
|
new ExportPLActionClsBean(plac), true);
|
dtml.insertNodeInto(child, node, node.getChildCount());
|
for (PLAction plAction : plActions) {
|
if (plAction.plActionCls.equals("")) {
|
DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(
|
new ExportPLActionBean(plAction), false);
|
dtml.insertNodeInto(newChild, child, child.getChildCount());
|
}
|
}
|
|
}
|
dtml.reload(node);
|
|
}
|
@Override
|
public String getExportDataFileName(String filePath,Long currentTimes) {
|
|
return filePath + File.separator + "VCIACTIONMODELFILE"
|
+ format.format(new Date(currentTimes)) + ".vciamf";
|
|
}
|
@Override
|
public String getExportLogFileName(String filePath ,Long currentTimes) {
|
return filePath + File.separator + "VCIACTIONMODELFILE"
|
+ format.format(new Date(currentTimes)) + ".log";
|
}
|
|
public boolean hasSelectExportContent() {
|
TreePath[] treePath = treeManager.getSelectionModel()
|
.getSelectionPaths();
|
if (treePath == null) {
|
return false;
|
}
|
return true;
|
}
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
public HashMap getExportBeans(HashMap exportBeansMap,PrintWriter log,
|
JTable tblExportLog) {
|
|
|
this.fileLog = log;
|
this.addTblExportLogHeader(tblExportLog);
|
this.tableLog= (DefaultTableModel)tblExportLog.getModel();
|
this.exportBeans = new ExportBeans();
|
while(this.tableLog.getRowCount() > 0 ){
|
this.tableLog.removeRow(0);
|
}
|
|
TreePath[] treePath = treeManager.getSelectionModel()
|
.getSelectionPaths();
|
|
if (treePath != null) {
|
try {
|
// List<PLActionCls> selActionCls = new ArrayList<PLActionCls>();
|
// List<PLAction> selAction = new ArrayList<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)) {
|
addAllData();
|
exportBeansMap.put("exportBeans", exportBeans);
|
return exportBeansMap ;
|
}
|
}
|
|
if (obj instanceof ExportPLActionBean) {
|
//递归所有父节点添加到exportBeans中
|
allPLActionClsParent((DefaultMutableTreeNode) node.getParent());
|
this.exportBeans.addPLActionBean(((ExportPLActionBean) obj).getBean());
|
ExportActionLogBean bean = exportBeans.getLogBean();
|
this.fileLog.println(bean.getLogRowContent());
|
this.tableLog.addRow(bean.getLogRowObjcets());
|
}else if (obj instanceof ExportPLActionClsBean) {
|
//递归所有父节点添加到exportBeans中
|
allPLActionClsParent(node);
|
//递归所有子节点添加到exportBeans中
|
allPLActionClsChildren(node);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
exportBeansMap.put("exportBeans", exportBeans);
|
return exportBeansMap ;
|
|
}
|
|
/**
|
* 将数据库中所有action数据导出
|
*/
|
private void addAllData() {
|
try {
|
PLActionCls[] plActionCls = UITools.getService().getPLActionClsArray();
|
|
|
|
for (PLActionCls plActionCls2 : plActionCls) {
|
exportBeans.addPLActionClsBean(plActionCls2);
|
PLAction[] plActions = getTablePanelData(plActionCls2);
|
for (int i = 0; i < plActions.length; i++) {
|
exportBeans.addPLActionBean(plActions[i],plActionCls2.name);
|
ExportActionLogBean bean = exportBeans.getLogBean();
|
this.fileLog.println(bean.getLogRowContent());
|
this.tableLog.addRow(bean.getLogRowObjcets());
|
// tableLog.insertRow(0, bean.getLogRowObjcets());
|
|
}
|
|
}
|
|
PLActionCls plac = new PLActionCls("", "未分类", "", "", "", 0, (short)0);
|
exportBeans.addPLActionClsBean(plac);
|
PLAction[] plas = getTablePanelData(plac);
|
for (int i = 0; i < plas.length; i++) {
|
exportBeans.addPLActionBean(plas[i],plac.name);
|
ExportActionLogBean bean = exportBeans.getLogBean();
|
this.fileLog.println(bean.getLogRowContent());
|
this.tableLog.addRow(bean.getLogRowObjcets());
|
// tableLog.insertRow(0, bean.getLogRowObjcets());
|
|
}
|
|
} catch (VCIError e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
/**
|
* 查询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();
|
}
|
return res;
|
}
|
|
|
private void allPLActionClsParent(DefaultMutableTreeNode node) {
|
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
|
PLActionCls pac = ((ExportPLActionClsBean)node.getUserObject()).getBean();
|
if(pac.pid != ""){
|
allPLActionClsParent(parent);
|
}
|
exportBeans.addPLActionClsBean(pac);
|
// this.addPLActionByPLActionCls(pac);
|
|
}
|
/**
|
* 通过action类别 添加类别下所有action
|
* @param pac
|
*/
|
private void addPLActionByPLActionCls(PLActionCls pac) {
|
PLAction[] action = this.getTablePanelData(pac);
|
for (PLAction plAction : action) {
|
exportBeans.addPLActionBean(plAction,pac.name);
|
ExportActionLogBean bean = exportBeans.getLogBean();
|
this.fileLog.println(bean.getLogRowContent());
|
this.tableLog.addRow(bean.getLogRowObjcets());
|
}
|
}
|
private void allPLActionClsChildren(DefaultMutableTreeNode node) {
|
if(node.getUserObject() instanceof ExportPLActionClsBean){
|
PLActionCls pac = ((ExportPLActionClsBean)node.getUserObject()).getBean();
|
exportBeans.addPLActionClsBean(pac);
|
this.addPLActionByPLActionCls(pac);
|
for(int i=0; i<node.getChildCount(); i++){
|
DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
|
allPLActionClsChildren(child);
|
}
|
}
|
}
|
|
/**
|
* 为log记录Table添加数据
|
* @param tblExportLog
|
*/
|
private void addTblExportLogHeader(JTable tblExportLog) {
|
tblExportLog.setModel(new DefaultTableModel(new Object[][] { { null,
|
null, null, null, null, null, null, null, null }, },
|
new String[] { "\u5E8F\u53F7", "\u5BFC\u51FA\u72B6\u6001",
|
"\u7F16\u53F7", "\u540D\u79F0", "CS\u6CE8\u518C",
|
"BS\u6CE8\u518C", "\u7C7B\u578B", "\u63CF\u8FF0",
|
"\u6240\u5C5E\u5206\u7C7B" }) {
|
/**
|
* serialVersionUID
|
*/
|
private static final long serialVersionUID = 1L;
|
boolean[] columnEditables = new boolean[] { false, false, false,
|
false, false, false, false, false, false };
|
|
public boolean isCellEditable(int row, int column) {
|
return columnEditables[column];
|
}
|
});
|
tblExportLog.getColumnModel().getColumn(0).setResizable(false);
|
tblExportLog.getColumnModel().getColumn(0).setPreferredWidth(35);
|
tblExportLog.getColumnModel().getColumn(0).setMinWidth(35);
|
tblExportLog.getColumnModel().getColumn(0).setMaxWidth(35);
|
tblExportLog.getColumnModel().getColumn(1).setMinWidth(60);
|
tblExportLog.getColumnModel().getColumn(1).setMaxWidth(150);
|
tblExportLog.getColumnModel().getColumn(2).setMinWidth(60);
|
tblExportLog.getColumnModel().getColumn(2).setMaxWidth(150);
|
tblExportLog.getColumnModel().getColumn(3).setMinWidth(60);
|
tblExportLog.getColumnModel().getColumn(3).setMaxWidth(150);
|
tblExportLog.getColumnModel().getColumn(4).setPreferredWidth(120);
|
tblExportLog.getColumnModel().getColumn(4).setMinWidth(60);
|
tblExportLog.getColumnModel().getColumn(4).setMaxWidth(150);
|
tblExportLog.getColumnModel().getColumn(5).setPreferredWidth(120);
|
tblExportLog.getColumnModel().getColumn(5).setMinWidth(60);
|
tblExportLog.getColumnModel().getColumn(5).setMaxWidth(150);
|
tblExportLog.getColumnModel().getColumn(6).setMinWidth(50);
|
tblExportLog.getColumnModel().getColumn(6).setMaxWidth(100);
|
tblExportLog.getColumnModel().getColumn(7).setMaxWidth(150);
|
tblExportLog.getColumnModel().getColumn(8).setMinWidth(60);
|
tblExportLog.getColumnModel().getColumn(8).setMaxWidth(150);
|
|
}
|
|
}
|