|
|
package com.connor.kwc.createTemplate;
|
|
|
|
|
|
import java.awt.Dimension;
|
|
|
import java.awt.Toolkit;
|
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
|
import java.time.Year;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.ResourceBundle;
|
|
|
import java.util.Map.Entry;
|
|
|
import javax.swing.GroupLayout;
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import javax.swing.JTextField;
|
|
|
import javax.swing.JTree;
|
|
|
import javax.swing.WindowConstants;
|
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
|
|
|
import com.connor.kwc.jtreeUtilClass.CheckBoxTreeCellRenderer;
|
|
|
import com.connor.kwc.jtreeUtilClass.CheckBoxTreeNode;
|
|
|
import com.connor.kwc.jtreeUtilClass.CheckBoxTreeNodeSelectionListener;
|
|
|
import com.connor.kwc.util.Util;
|
|
|
import com.connor.kwc.util.UtilBean;
|
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
|
import com.teamcenter.rac.kernel.TCComponentDataset;
|
|
|
import com.teamcenter.rac.kernel.TCComponentFolder;
|
|
|
import com.teamcenter.rac.kernel.TCComponentForm;
|
|
|
import com.teamcenter.rac.kernel.TCComponentItem;
|
|
|
import com.teamcenter.rac.kernel.TCException;
|
|
|
import com.teamcenter.rac.kernel.TCSession;
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @ClassName: CreateTemplateDialg
|
|
|
* @Description: 创建文档窗口实现
|
|
|
* @author hcj
|
|
|
* @date 2023年12月22日
|
|
|
*
|
|
|
*/
|
|
|
public class CreateTemplateDialg extends JFrame {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
//依据模板创建
|
|
|
private final static String YJMBCJ = "yjmbcj";
|
|
|
//产品代号
|
|
|
private final static String CPDH = "cpdh";
|
|
|
//确定
|
|
|
private final static String QD = "qd";
|
|
|
//产品代号不能为空!
|
|
|
private final static String CPDHBNWK = "cpdhbnwk";
|
|
|
//提示
|
|
|
private final static String TS = "ts";
|
|
|
//创建失败
|
|
|
private final static String CJSB = "cjsb";
|
|
|
//创建成功
|
|
|
private final static String CJCG = "cjcg";
|
|
|
//已存在于TC
|
|
|
private final static String YCZYTC = "yczytc";
|
|
|
//模板
|
|
|
private final static String MB = "mb";
|
|
|
|
|
|
private TCSession session;
|
|
|
private TCComponent target;
|
|
|
private ResourceBundle resource;
|
|
|
private JButton jButton3;
|
|
|
private JLabel jLabel3;
|
|
|
private JPanel jPanel1;
|
|
|
private JPanel jPanel2;
|
|
|
private JPanel jPanel4;
|
|
|
private JScrollPane jScrollPane1;
|
|
|
private JTextField jTextField3;
|
|
|
private JTree jTree1;
|
|
|
private String[] createDOCtemplate;
|
|
|
private String[] createDOCAttribute;
|
|
|
private Map<String, Map<String, List<Map<TCComponent, CheckBoxTreeNode>>>> folderByNodeMap = new HashMap<String, Map<String, List<Map<TCComponent, CheckBoxTreeNode>>>>();
|
|
|
private Map<CheckBoxTreeNode, List<Map<TCComponent, CheckBoxTreeNode>>> isSavaAsMap = new HashMap<CheckBoxTreeNode, List<Map<TCComponent, CheckBoxTreeNode>>>();
|
|
|
private Map<String, CheckBoxTreeNode> nodeIsSelectMap = new HashMap<String, CheckBoxTreeNode>();
|
|
|
private Map<String, Map<TCComponent, CheckBoxTreeNode>> isSelectByNodeMap = new HashMap<String, Map<TCComponent, CheckBoxTreeNode>>();
|
|
|
|
|
|
/**
|
|
|
* Creates new form CreateTemplateDialg
|
|
|
*/
|
|
|
public CreateTemplateDialg(TCSession session, TCComponent folder) {
|
|
|
this.session = session;
|
|
|
this.target = folder;
|
|
|
getData();
|
|
|
try {
|
|
|
initComponents();
|
|
|
} catch (TCException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @Title: getData
|
|
|
* @Description: 清空数据,读取配置文件,获取首选项的值
|
|
|
* @param 参数
|
|
|
* @return void 返回类型
|
|
|
* @throws
|
|
|
*/
|
|
|
private void getData() {
|
|
|
// 清理数据
|
|
|
System.out.println("清理数据.......");
|
|
|
folderByNodeMap.clear();
|
|
|
isSavaAsMap.clear();
|
|
|
nodeIsSelectMap.clear();
|
|
|
isSelectByNodeMap.clear();
|
|
|
System.out.println("数据清理完毕.......");
|
|
|
//读取配置文件
|
|
|
resource = ResourceBundle.getBundle("com.connor.kwc.message.Message", Locale.getDefault());
|
|
|
//读取首选项
|
|
|
createDOCtemplate = Util.getSXX(session, UtilBean.CREATRDOCTEMPLATE);
|
|
|
createDOCAttribute = Util.getSXX(session, UtilBean.CRWATEDOCATTRIBUTE);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @Title: initComponents
|
|
|
* @Description: 创建窗口对象
|
|
|
* @param @throws TCException 参数
|
|
|
* @return void 返回类型
|
|
|
* @throws
|
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private void initComponents() throws TCException {
|
|
|
//依据模板创建
|
|
|
this.setTitle(resource.getString(YJMBCJ));
|
|
|
jPanel1 = new JPanel();
|
|
|
jPanel2 = new JPanel();
|
|
|
jLabel3 = new JLabel();
|
|
|
jScrollPane1 = new JScrollPane();
|
|
|
jTree1 = new JTree();
|
|
|
// 初始化Jtree
|
|
|
initTree(jTree1);
|
|
|
jTree1.setCellRenderer(new CheckBoxTreeCellRenderer());
|
|
|
jButton3 = new JButton();
|
|
|
jTextField3 = new JTextField();
|
|
|
jTextField3.setText(target.getStringProperty(UtilBean.ITEMID));
|
|
|
jPanel4 = new JPanel();
|
|
|
|
|
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
|
|
setBackground(new java.awt.Color(240, 240, 240));
|
|
|
|
|
|
jPanel1.setBackground(new java.awt.Color(240, 240, 240));
|
|
|
|
|
|
jPanel2.setBackground(new java.awt.Color(240, 240, 240));
|
|
|
//产品代号
|
|
|
jLabel3.setText(resource.getString(CPDH));
|
|
|
|
|
|
jScrollPane1.setViewportView(jTree1);
|
|
|
//确定
|
|
|
jButton3.setText(resource.getString(QD));
|
|
|
|
|
|
GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
|
|
|
jPanel2.setLayout(jPanel2Layout);
|
|
|
jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
|
|
.addGroup(jPanel2Layout.createSequentialGroup().addGap(53, 53, 53).addComponent(jLabel3)
|
|
|
.addGap(18, 18, 18)
|
|
|
.addComponent(jTextField3, GroupLayout.PREFERRED_SIZE, 213, GroupLayout.PREFERRED_SIZE)
|
|
|
.addGap(18, 18, 18).addComponent(jButton3)
|
|
|
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
|
.addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
|
|
|
.addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE).addContainerGap()));
|
|
|
jPanel2Layout
|
|
|
.setVerticalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
|
|
.addGroup(jPanel2Layout.createSequentialGroup().addGap(13, 13, 13)
|
|
|
.addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
|
|
.addComponent(jButton3)
|
|
|
.addComponent(jTextField3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
|
|
|
GroupLayout.PREFERRED_SIZE)
|
|
|
.addComponent(jLabel3))
|
|
|
.addGap(18, 18, 18)
|
|
|
.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 544, GroupLayout.PREFERRED_SIZE)
|
|
|
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
|
|
|
|
|
|
jPanel4.setBackground(new java.awt.Color(255, 255, 255));
|
|
|
|
|
|
GroupLayout jPanel4Layout = new GroupLayout(jPanel4);
|
|
|
jPanel4.setLayout(jPanel4Layout);
|
|
|
jPanel4Layout.setHorizontalGroup(
|
|
|
jPanel4Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 538, Short.MAX_VALUE));
|
|
|
jPanel4Layout.setVerticalGroup(
|
|
|
jPanel4Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
|
|
|
|
|
|
GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
|
|
|
jPanel1.setLayout(jPanel1Layout);
|
|
|
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
|
|
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
|
|
|
.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
|
|
.addComponent(jPanel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
|
|
|
Short.MAX_VALUE)
|
|
|
.addComponent(jPanel4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
|
|
|
Short.MAX_VALUE))
|
|
|
.addContainerGap()));
|
|
|
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
|
|
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
|
|
|
.addComponent(jPanel2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
|
|
|
GroupLayout.PREFERRED_SIZE)
|
|
|
.addGap(73, 73, 73)
|
|
|
.addComponent(jPanel4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
|
.addContainerGap()));
|
|
|
|
|
|
GroupLayout layout = new GroupLayout(getContentPane());
|
|
|
getContentPane().setLayout(layout);
|
|
|
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
|
|
.addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap()
|
|
|
.addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
|
.addContainerGap()));
|
|
|
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
|
|
.addGroup(layout.createSequentialGroup().addContainerGap()
|
|
|
.addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, 619, GroupLayout.PREFERRED_SIZE)
|
|
|
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
|
|
|
|
|
|
pack();
|
|
|
|
|
|
//设置窗口居中
|
|
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
|
int screenWidth = screenSize.width;
|
|
|
int screenHeight = screenSize.height;
|
|
|
int x = (screenWidth - this.getWidth()) / 2;
|
|
|
int y = (screenHeight - this.getHeight()) / 2;
|
|
|
this.setLocation(x, y); //
|
|
|
this.setDefaultCloseOperation(2);
|
|
|
|
|
|
// 确定按钮监听
|
|
|
this.jButton3.addActionListener(new ActionListener() {
|
|
|
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
String name = jTextField3.getText();
|
|
|
if (name.isEmpty()) {
|
|
|
//产品代号不能为空! 提示
|
|
|
MessageBox.post(resource.getString(CPDHBNWK), resource.getString(TS), MessageBox.INFORMATION);
|
|
|
} else {
|
|
|
try {
|
|
|
// 开旁路
|
|
|
Util.setByPass(true);
|
|
|
|
|
|
// 根据当前文件夹下的关系匹配树节点的选中状态创建对象
|
|
|
for (Entry<String, CheckBoxTreeNode> nodeIsSelect : nodeIsSelectMap.entrySet()) {
|
|
|
if (nodeIsSelect.getValue().isSelected()) {
|
|
|
List<Map<TCComponent, CheckBoxTreeNode>> list = isSavaAsMap
|
|
|
.get(nodeIsSelect.getValue());
|
|
|
for (Map<TCComponent, CheckBoxTreeNode> childMap : list) {
|
|
|
// 判断是否选中
|
|
|
for (Map.Entry<TCComponent, CheckBoxTreeNode> entry1 : childMap.entrySet()) {
|
|
|
if (entry1.getValue().isSelected()) {
|
|
|
// 创建对象
|
|
|
TCComponent oldObj = entry1.getKey();
|
|
|
if (oldObj instanceof TCComponentFolder) {
|
|
|
TCComponentFolder oldFolder = (TCComponentFolder) oldObj;
|
|
|
TCComponentFolder saveAs = oldFolder.saveAs(jTextField3.getText()
|
|
|
+ oldFolder.getStringProperty(UtilBean.OBJECTSTRING)
|
|
|
.replaceFirst("\\[.*?\\]", ""));
|
|
|
|
|
|
TCComponent[] referenceListProperty = saveAs
|
|
|
.getReferenceListProperty(UtilBean.CONTENTS);
|
|
|
saveAs.remove("contents", referenceListProperty);
|
|
|
target.add(nodeIsSelect.getKey(), saveAs);
|
|
|
// 挂载新的对象
|
|
|
isLoadNewCompint(oldObj, saveAs);
|
|
|
} else if (oldObj instanceof TCComponentItem) {
|
|
|
TCComponentItem oldItem = (TCComponentItem) oldObj;
|
|
|
TCComponentItem saveAsItem;
|
|
|
String replaceName = jTextField3.getText()
|
|
|
+ oldItem.getStringProperty(UtilBean.OBJECTSTRING)
|
|
|
.replaceFirst("\\[.*?\\]", "");
|
|
|
String replace = replaceName.replace("[Y]",
|
|
|
String.valueOf(Year.now().getValue()));
|
|
|
try {
|
|
|
|
|
|
saveAsItem = oldItem.getLatestItemRevision().saveAsItem(replace,
|
|
|
null);
|
|
|
} catch (Exception e1) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e1.printStackTrace();
|
|
|
MessageBox.post(
|
|
|
//创建失败 已存在于TC
|
|
|
resource.getString(CJSB) + ",ID【" + replaceName + "】"
|
|
|
+ resource.getString(YCZYTC),
|
|
|
resource.getString(TS), MessageBox.INFORMATION);
|
|
|
return;
|
|
|
}
|
|
|
target.add(nodeIsSelect.getKey(), saveAsItem);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
dispose();
|
|
|
//创建成功
|
|
|
MessageBox.post(resource.getString(CJCG), resource.getString(TS), MessageBox.INFORMATION);
|
|
|
return;
|
|
|
} catch (Exception e1) {
|
|
|
e1.printStackTrace();
|
|
|
dispose();
|
|
|
//创建失败
|
|
|
MessageBox.post(resource.getString(CJSB), resource.getString(TS), MessageBox.INFORMATION);
|
|
|
return;
|
|
|
} finally {
|
|
|
// 关闭旁路
|
|
|
Util.setByPass(false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @Title: isLoadNewCompint
|
|
|
* @Description: 根据旧节点的选中状态,创建新对象挂载
|
|
|
* @param @param oldObj
|
|
|
* @param @param newObj
|
|
|
* @param @throws TCException 参数
|
|
|
* @return void 返回类型
|
|
|
* @throws
|
|
|
*/
|
|
|
private void isLoadNewCompint(TCComponent oldObj, TCComponent newObj) throws TCException {
|
|
|
if (isSelectByNodeMap.containsKey(oldObj.getStringProperty(UtilBean.OBJECTSTRING))) {
|
|
|
// 创建文件夹挂载新创建的对象
|
|
|
|
|
|
Map<TCComponent, CheckBoxTreeNode> map = isSelectByNodeMap.get(oldObj.getStringProperty(UtilBean.OBJECTSTRING));
|
|
|
System.out.println("saveAs length:" + map.size());
|
|
|
for (Map.Entry<TCComponent, CheckBoxTreeNode> entry : map.entrySet()) {
|
|
|
if (entry.getValue().isSelected()) {
|
|
|
// 另存文件,复制属性规则
|
|
|
TCComponentItem item = (TCComponentItem) entry.getKey();
|
|
|
System.out.println("start saveAs:" + item.getStringProperty(UtilBean.OBJECTSTRING));
|
|
|
String itemId = item.getStringProperty(UtilBean.ITEMID);
|
|
|
String newId = itemId.replace(UtilBean.ITEMIDHEAD, jTextField3.getText());
|
|
|
String replace = newId.replace(UtilBean.YEAR, String.valueOf(Year.now().getValue()));
|
|
|
System.out.println("replace:" + replace);
|
|
|
TCComponentItem saveAsItem;
|
|
|
try {
|
|
|
saveAsItem = item.getLatestItemRevision().saveAsItem(replace, null);
|
|
|
} catch (TCException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
//创建失败 已存在于TC
|
|
|
MessageBox.post(resource.getString(CJSB) + ",ID【" + replace + "】" + resource.getString(YCZYTC),
|
|
|
resource.getString(TS), MessageBox.INFORMATION);
|
|
|
return;
|
|
|
}
|
|
|
// 判断版本下面是否有数据集,有的话需要改变数据集的名字
|
|
|
TCComponent[] spectficationObj = saveAsItem.getLatestItemRevision()
|
|
|
.getReferenceListProperty(UtilBean.IMANSPECIFICATION);
|
|
|
if (spectficationObj != null && spectficationObj.length > 0) {
|
|
|
for (TCComponent tcComponent : spectficationObj) {
|
|
|
if (tcComponent instanceof TCComponentDataset) {
|
|
|
TCComponentDataset dataset = (TCComponentDataset) tcComponent;
|
|
|
String datasettName = dataset.getStringProperty(UtilBean.OBJECTNAMR);
|
|
|
String[] splitName = datasettName.split("-");
|
|
|
TCComponentDataset newDataset = dataset
|
|
|
.saveAs(replace + splitName[splitName.length - 1]);
|
|
|
|
|
|
saveAsItem.getLatestItemRevision().remove(UtilBean.IMANSPECIFICATION, spectficationObj);
|
|
|
saveAsItem.getLatestItemRevision().add(UtilBean.IMANSPECIFICATION, newDataset);
|
|
|
|
|
|
// 改变内置文件名
|
|
|
String oldFileName = dataset.getRelatedComponent(UtilBean.REFLIST)
|
|
|
.getProperty(UtilBean.ORIGINALFILENAME);
|
|
|
// 分离文件名和扩展名
|
|
|
int dotIndex = oldFileName.lastIndexOf('.');
|
|
|
String extension = "";
|
|
|
if (dotIndex != -1) {
|
|
|
extension = oldFileName.substring(dotIndex);
|
|
|
oldFileName = oldFileName.substring(0, dotIndex);
|
|
|
// 替换文件名前缀并添加原来的扩展名
|
|
|
String newFileName = replace + splitName[splitName.length - 1] + extension;
|
|
|
newDataset.getRelatedComponent(UtilBean.REFLIST).setProperty(UtilBean.ORIGINALFILENAME,
|
|
|
newFileName);
|
|
|
} else {
|
|
|
newDataset.getRelatedComponent(UtilBean.REFLIST).setProperty(UtilBean.ORIGINALFILENAME,
|
|
|
replace + splitName[splitName.length - 1]);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 替换属性
|
|
|
for (String attrStr : createDOCAttribute) {
|
|
|
if (attrStr.startsWith(saveAsItem.getStringProperty(UtilBean.OBJECTTYPE))) {
|
|
|
try {
|
|
|
String[] replaces = attrStr.split("=")[1].split(";");
|
|
|
for (String replace1 : replaces) {
|
|
|
String[] getValues = replace1.split("\\.");
|
|
|
Object val = "";
|
|
|
if (getValues[0].equals(UtilBean.ITEM)) {
|
|
|
//替换item属性
|
|
|
val = Util.getTCPropertyValue(item, getValues[1]);
|
|
|
Util.setTCPropertyValue(saveAsItem, getValues[1], val);
|
|
|
} else if (getValues[0].equals(UtilBean.REV)) {
|
|
|
//替换版本属性
|
|
|
val = Util.getTCPropertyValue(item.getLatestItemRevision(), getValues[1]);
|
|
|
Util.setTCPropertyValue(saveAsItem.getLatestItemRevision(), getValues[1], val);
|
|
|
} else if (getValues[0].equals(UtilBean.RM)) {
|
|
|
//替换版本表单属性
|
|
|
TCComponent[] oldreferenceListProperty = item.getLatestItemRevision()
|
|
|
.getReferenceListProperty(UtilBean.IMANMASTERFORMREV);
|
|
|
TCComponentForm oldform = (TCComponentForm) oldreferenceListProperty[0];
|
|
|
val = Util.getTCPropertyValue(oldform, getValues[1]);
|
|
|
TCComponent[] newreferenceListProperty = saveAsItem.getLatestItemRevision()
|
|
|
.getReferenceListProperty(UtilBean.IMANMASTERFORMREV);
|
|
|
TCComponentForm newform = (TCComponentForm) newreferenceListProperty[0];
|
|
|
Util.setTCPropertyValue(newform, getValues[1], val);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e1) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
newObj.add("contents", saveAsItem);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @Title: initTree
|
|
|
* @Description: 初始化树结构
|
|
|
* @param @param tree 参数
|
|
|
* @return void 返回类型
|
|
|
* @throws
|
|
|
*/
|
|
|
private void initTree(JTree tree) {
|
|
|
String puids = createDOCtemplate[0].split("=")[1];
|
|
|
System.out.println(puids);
|
|
|
String releaseNames = createDOCtemplate[1].split("=")[1];
|
|
|
System.out.println(releaseNames);
|
|
|
try {
|
|
|
//模板
|
|
|
CheckBoxTreeNode rootNode = new CheckBoxTreeNode(resource.getString(MB));
|
|
|
TCComponent tcComponent = session.stringToComponent(puids);
|
|
|
|
|
|
String[] releaseName = releaseNames.split(";");
|
|
|
System.out.println(tcComponent.getStringProperty(UtilBean.OBJECTSTRING));
|
|
|
|
|
|
//根据分号分割,获取关系名称,循环创建关系下的对象
|
|
|
for (String release : releaseName) {
|
|
|
System.out.println("release:" + release);
|
|
|
String[] attr = release.split("-");
|
|
|
CheckBoxTreeNode childNode = new CheckBoxTreeNode(attr[1]);
|
|
|
rootNode.add(childNode);
|
|
|
nodeIsSelectMap.put(attr[0], childNode);
|
|
|
TCComponent[] pseudoFolders = tcComponent.getReferenceListProperty(attr[0]);
|
|
|
if (pseudoFolders != null) {
|
|
|
List<Map<TCComponent, CheckBoxTreeNode>> components = new ArrayList<Map<TCComponent, CheckBoxTreeNode>>();
|
|
|
for (TCComponent reCompont : pseudoFolders) {
|
|
|
Map<TCComponent, CheckBoxTreeNode> map = new HashMap<TCComponent, CheckBoxTreeNode>();
|
|
|
CheckBoxTreeNode topNode = new CheckBoxTreeNode(reCompont.getStringProperty(UtilBean.OBJECTSTRING));
|
|
|
childNode.add(topNode);
|
|
|
map.put(reCompont, topNode);
|
|
|
components.add(map);
|
|
|
//循环创建子节点
|
|
|
buildTree(reCompont, topNode);
|
|
|
}
|
|
|
// 将List集合放入Map中,与伪文件夹关系对象
|
|
|
isSavaAsMap.put(childNode, components);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//渲染Jtree复选框
|
|
|
DefaultTreeModel model = new DefaultTreeModel(rootNode);
|
|
|
tree.addMouseListener(new CheckBoxTreeNodeSelectionListener());
|
|
|
tree.setModel(model);
|
|
|
tree.setCellRenderer(new CheckBoxTreeCellRenderer());
|
|
|
tree.setRowHeight(0);
|
|
|
|
|
|
// 展开所有节点并选中
|
|
|
for (int i = 0; i < tree.getRowCount(); i++) {
|
|
|
tree.expandRow(i);
|
|
|
}
|
|
|
rootNode.setSelected(true);
|
|
|
} catch (TCException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 循环创建树的子节点
|
|
|
*
|
|
|
* @param component
|
|
|
* @param rootNode
|
|
|
* @throws TCException
|
|
|
*/
|
|
|
private void buildTree(TCComponent component, CheckBoxTreeNode topNode) throws TCException {
|
|
|
TCComponent[] relatedComponent = component.getReferenceListProperty(UtilBean.CONTENTS);
|
|
|
if (relatedComponent != null && relatedComponent.length > 0) {
|
|
|
System.out.println("length:" + relatedComponent.length);
|
|
|
Map<TCComponent, CheckBoxTreeNode> isSelectMap = new HashMap<TCComponent, CheckBoxTreeNode>();
|
|
|
for (TCComponent child : relatedComponent) {
|
|
|
CheckBoxTreeNode childNode = new CheckBoxTreeNode(child.getStringProperty(UtilBean.OBJECTSTRING));
|
|
|
isSelectMap.put(child, childNode);
|
|
|
topNode.add(childNode);
|
|
|
}
|
|
|
isSelectByNodeMap.put(component.getStringProperty(UtilBean.OBJECTSTRING), isSelectMap);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|