- 添加多个新功能模块,包括计算材料定额、批量修改任务名称、更新属性到对象等 - 集成 SQL Server 数据库连接和操作 - 增加 Word 和 Excel 模板处理功能 - 优化插件配置,移除不必要的依赖 - 更新插件菜单和弹出菜单结构main
parent
1fbdd06a88
commit
eae81092c1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
LD6_NewProdForm.FORMJAVARENDERING=com.langtech.plm.form.LD6_NewProdForm
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,215 @@
|
||||
package com.langtech.plm.batchRename;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentForm;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
|
||||
import com.teamcenter.rac.kernel.TCException;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
import com.teamcenter.rac.util.PropertyLayout;
|
||||
|
||||
public class BatchRenameDialog extends JFrame implements ActionListener {
|
||||
|
||||
private TCSession session;
|
||||
protected DefaultTableModel tm_part;
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private TCComponentScheduleTask task;
|
||||
private JTextField find = new JTextField();
|
||||
private JTextField replace = new JTextField();
|
||||
private JButton okButton = new JButton("确定");
|
||||
private JButton concelButton = new JButton("取消");
|
||||
|
||||
HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
|
||||
|
||||
public BatchRenameDialog(TCSession session, TCComponentScheduleTask task) throws TCException {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.session = session;
|
||||
this.task = task;
|
||||
|
||||
initUI();
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
find.setPreferredSize(new Dimension(200,30));
|
||||
replace.setPreferredSize(new Dimension(200,30));
|
||||
this.setTitle("批量修改时间表任务名称");
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
JPanel topPanel = getTopPanel();
|
||||
|
||||
JPanel btnPanel = getBtnPanel();
|
||||
|
||||
this.add(topPanel, BorderLayout.NORTH);
|
||||
// this.add(pane,BorderLayout.CENTER);
|
||||
this.add(btnPanel, BorderLayout.SOUTH);
|
||||
this.setPreferredSize(new Dimension(450, 200));
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
|
||||
int screenWidth = screenSize.width; // 获取屏幕宽度
|
||||
int screenHeight = screenSize.height; // 获取屏幕高度
|
||||
int x = (screenWidth - 450) / 2; // 计算Frame的左上角x坐标
|
||||
int y = (screenHeight - 200) / 2; // 计算Frame的左上角y坐标
|
||||
this.setLocation(x, y); // 设置Frame的位置
|
||||
|
||||
// this.setLocationRelativeTo(null);
|
||||
this.createActionEvent();
|
||||
this.pack();
|
||||
|
||||
// this.validate();
|
||||
this.setVisible(true);
|
||||
|
||||
// this.setAlwaysOnTop(true);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加监听
|
||||
public void createActionEvent() {
|
||||
|
||||
this.okButton.addActionListener(this);
|
||||
this.concelButton.addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
Object source = e.getSource();
|
||||
System.out.println("source==>+" + source);
|
||||
if (this.okButton.equals(source)) {
|
||||
String fString = find.getText();
|
||||
String rString = replace.getText();
|
||||
|
||||
if(fString.isEmpty()) {
|
||||
MessageBox.post("请填写查找内容!", "提示 ", MessageBox.INFORMATION);
|
||||
return;
|
||||
}
|
||||
|
||||
if(rString.isEmpty()) {
|
||||
MessageBox.post("请填写替换内容!", "提示 ", MessageBox.INFORMATION);
|
||||
return;
|
||||
}
|
||||
|
||||
//获取含有查找内容的个数
|
||||
int childrenCount = 0;
|
||||
try {
|
||||
childrenCount = task.getChildrenCount();
|
||||
|
||||
System.out.println("childrenCount=============="+childrenCount);
|
||||
//子个数为0
|
||||
if(childrenCount == 0) {
|
||||
MessageBox.post("该时间表对象下没有子对象!", "提示 ", MessageBox.INFORMATION);
|
||||
return;
|
||||
}
|
||||
//获取对象名称
|
||||
AIFComponentContext[] children = task.getChildren();
|
||||
HashMap<TCComponentScheduleTask, String> map = new HashMap<TCComponentScheduleTask, String>();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
InterfaceAIFComponent component = children[i].getComponent();
|
||||
if(component instanceof TCComponentScheduleTask) {
|
||||
TCComponentScheduleTask scheduleTask = (TCComponentScheduleTask)component;
|
||||
String objectName = scheduleTask.getStringProperty("object_name");
|
||||
if(objectName.contains(fString)) {
|
||||
map.put(scheduleTask, objectName.replace(fString, rString));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(map.size() == 0) {
|
||||
MessageBox.post("未匹配到含有查找内容的对象!", "提示 ", MessageBox.INFORMATION);
|
||||
return;
|
||||
}
|
||||
|
||||
//修改
|
||||
for (Entry<TCComponentScheduleTask, String> tempMap : map.entrySet()) {
|
||||
TCComponentScheduleTask key = tempMap.getKey();
|
||||
String value = tempMap.getValue();
|
||||
key.setProperty("object_name", value);
|
||||
}
|
||||
//返回修改信息
|
||||
MessageBox.post("成功修改"+map.size()+"个对象!", "提示 ", MessageBox.INFORMATION);
|
||||
this.dispose();
|
||||
} catch (TCException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} else if (this.concelButton.equals(source)) {
|
||||
this.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private JPanel getBtnPanel() {
|
||||
JPanel topPanel = new JPanel();
|
||||
topPanel.setLayout(new PropertyLayout());
|
||||
topPanel.add("1.1.center", new JLabel(""));
|
||||
topPanel.add("2.1.center", new JLabel(" "));
|
||||
topPanel.add("2.2.center", okButton);
|
||||
topPanel.add("2.3.center", new JLabel(""));
|
||||
topPanel.add("2.4.center", concelButton);
|
||||
|
||||
return topPanel;
|
||||
}
|
||||
|
||||
// 查询部分
|
||||
private JPanel getTopPanel() {
|
||||
// TODO Auto-generated method stub
|
||||
JPanel topPanel = new JPanel();
|
||||
topPanel.setLayout(new PropertyLayout());
|
||||
topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
topPanel.add("1.1.left.center", new JLabel(""));
|
||||
topPanel.add("2.1.left.center", new JLabel(""));
|
||||
topPanel.add("3.1.left.center", new JLabel(""));
|
||||
topPanel.add("4.1.left.center", new JLabel(" 查找内容:"));
|
||||
topPanel.add("4.2.left.center", find);
|
||||
|
||||
topPanel.add("5.1.left.center", new JLabel(""));
|
||||
topPanel.add("6.1.left.center", new JLabel(""));
|
||||
topPanel.add("7.1.left.center", new JLabel(""));
|
||||
topPanel.add("8.1.left.center", new JLabel(" 替换内容:"));
|
||||
|
||||
topPanel.add("8.2.left.center", replace);
|
||||
|
||||
return topPanel;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.langtech.plm.batchRename;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentSchedule;
|
||||
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class BatchRenameHandler extends AbstractHandler{
|
||||
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
try {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
InterfaceAIFComponent targetComponent = app.getTargetComponent();
|
||||
|
||||
if(targetComponent instanceof TCComponentScheduleTask) {
|
||||
try {
|
||||
TCComponentScheduleTask task = (TCComponentScheduleTask)targetComponent;
|
||||
|
||||
new BatchRenameDialog(session,task);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
MessageBox.post("Çëʱ¼ä±í¶ÔÏó£¡","Ìáʾ",2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.langtech.plm.createProjectStruct;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
|
||||
public class CheckBoxTreeCellRenderer extends JPanel implements TreeCellRenderer
|
||||
{
|
||||
protected JCheckBox check;
|
||||
protected CheckBoxTreeLabel label;
|
||||
|
||||
public CheckBoxTreeCellRenderer()
|
||||
{
|
||||
setLayout(null);
|
||||
add(check = new JCheckBox());
|
||||
add(label = new CheckBoxTreeLabel());
|
||||
check.setBackground(UIManager.getColor("Tree.textBackground"));
|
||||
label.setForeground(UIManager.getColor("Tree.textForeground"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Component getTreeCellRendererComponent(JTree tree, Object value,
|
||||
boolean selected, boolean expanded, boolean leaf, int row,
|
||||
boolean hasFocus)
|
||||
{
|
||||
String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
|
||||
setEnabled(tree.isEnabled());
|
||||
check.setSelected(((CheckBoxTreeNode)value).isSelected());
|
||||
label.setFont(tree.getFont());
|
||||
label.setText(stringValue);
|
||||
label.setSelected(selected);
|
||||
label.setFocus(hasFocus);
|
||||
if(leaf)
|
||||
//label.setIcon(UIManager.getIcon("Tree.leafIcon"));
|
||||
label.setIcon(UIManager.getIcon("Tree.openIcon"));
|
||||
else if(expanded)
|
||||
label.setIcon(UIManager.getIcon("Tree.openIcon"));
|
||||
else
|
||||
label.setIcon(UIManager.getIcon("Tree.closedIcon"));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize()
|
||||
{
|
||||
Dimension dCheck = check.getPreferredSize();
|
||||
Dimension dLabel = label.getPreferredSize();
|
||||
return new Dimension(dCheck.width + dLabel.width, dCheck.height < dLabel.height ? dLabel.height: dCheck.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doLayout()
|
||||
{
|
||||
Dimension dCheck = check.getPreferredSize();
|
||||
Dimension dLabel = label.getPreferredSize();
|
||||
int yCheck = 0;
|
||||
int yLabel = 0;
|
||||
if(dCheck.height < dLabel.height)
|
||||
yCheck = (dLabel.height - dCheck.height) / 2;
|
||||
else
|
||||
yLabel = (dCheck.height - dLabel.height) / 2;
|
||||
check.setLocation(0, yCheck);
|
||||
check.setBounds(0, yCheck, dCheck.width, dCheck.height);
|
||||
label.setLocation(dCheck.width, yLabel);
|
||||
label.setBounds(dCheck.width, yLabel, dLabel.width, dLabel.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackground(Color color)
|
||||
{
|
||||
if(color instanceof ColorUIResource)
|
||||
color = null;
|
||||
super.setBackground(color);
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.langtech.plm.createProjectStruct;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
|
||||
public class CheckBoxTreeLabel extends JLabel
|
||||
{
|
||||
private boolean isSelected;
|
||||
private boolean hasFocus;
|
||||
|
||||
public CheckBoxTreeLabel()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackground(Color color)
|
||||
{
|
||||
if(color instanceof ColorUIResource)
|
||||
color = null;
|
||||
super.setBackground(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
String str;
|
||||
if((str = getText()) != null)
|
||||
{
|
||||
if(0 < str.length())
|
||||
{
|
||||
if(isSelected)
|
||||
g.setColor(UIManager.getColor("Tree.selectionBackground"));
|
||||
else
|
||||
g.setColor(UIManager.getColor("Tree.textBackground"));
|
||||
Dimension d = getPreferredSize();
|
||||
int imageOffset = 0;
|
||||
Icon currentIcon = getIcon();
|
||||
if(currentIcon != null)
|
||||
imageOffset = currentIcon.getIconWidth() + Math.max(0, getIconTextGap() - 1);
|
||||
g.fillRect(imageOffset, 0, d.width - 1 - imageOffset, d.height);
|
||||
if(hasFocus)
|
||||
{
|
||||
g.setColor(UIManager.getColor("Tree.selectionBorderColor"));
|
||||
g.drawRect(imageOffset, 0, d.width - 1 - imageOffset, d.height - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.paint(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize()
|
||||
{
|
||||
Dimension retDimension = super.getPreferredSize();
|
||||
if(retDimension != null)
|
||||
retDimension = new Dimension(retDimension.width + 3, retDimension.height);
|
||||
return retDimension;
|
||||
}
|
||||
|
||||
public void setSelected(boolean isSelected)
|
||||
{
|
||||
this.isSelected = isSelected;
|
||||
}
|
||||
|
||||
public void setFocus(boolean hasFocus)
|
||||
{
|
||||
this.hasFocus = hasFocus;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.langtech.plm.createProjectStruct;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
public class CheckBoxTreeNodeSelectionListener extends MouseAdapter
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent event)
|
||||
{
|
||||
JTree tree = (JTree)event.getSource();
|
||||
int x = event.getX();
|
||||
int y = event.getY();
|
||||
int row = tree.getRowForLocation(x, y);
|
||||
TreePath path = tree.getPathForRow(row);
|
||||
if(path != null)
|
||||
{
|
||||
CheckBoxTreeNode node = (CheckBoxTreeNode)path.getLastPathComponent();
|
||||
if(node != null)
|
||||
{
|
||||
boolean isSelected = !node.isSelected();
|
||||
node.setSelected(isSelected);
|
||||
((DefaultTreeModel)tree.getModel()).nodeStructureChanged(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.langtech.plm.createProjectStruct;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponentFolder;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class CreateProjectStructHandler extends AbstractHandler{
|
||||
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
try {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
InterfaceAIFComponent targetComponent = app.getTargetComponent();
|
||||
|
||||
if(targetComponent instanceof TCComponentFolder) {
|
||||
new CreateProjectStructDialog(app);
|
||||
}
|
||||
else {
|
||||
MessageBox.post("请选中一个客户文件夹!", "提示 ", MessageBox.INFORMATION);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,72 @@
|
||||
package com.langtech.plm.mpart;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
|
||||
public class CheckHeaderCellRenderer implements TableCellRenderer {
|
||||
DefaultTableModel tableModel;
|
||||
JTableHeader tableHeader;
|
||||
final JCheckBox selectBox;
|
||||
|
||||
public CheckHeaderCellRenderer(final JTable table) {
|
||||
this.tableModel = (DefaultTableModel) table.getModel();
|
||||
this.tableHeader = table.getTableHeader();
|
||||
selectBox = new JCheckBox(tableModel.getColumnName(0));
|
||||
selectBox.setSelected(false);
|
||||
tableHeader.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() > 0) {
|
||||
// 获得选中列
|
||||
int selectColumn = tableHeader.columnAtPoint(e.getPoint());
|
||||
if (selectColumn == 0) {
|
||||
boolean value = !selectBox.isSelected();
|
||||
selectBox.setSelected(value);
|
||||
// tableModel.selectAllOrNull(value);
|
||||
tableHeader.repaint();
|
||||
if(value) {
|
||||
for(int i=0;i<table.getRowCount();i++) {
|
||||
table.setValueAt("1", i, 0);
|
||||
}
|
||||
}else {
|
||||
for(int i=0;i<table.getRowCount();i++) {
|
||||
table.setValueAt("0", i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
|
||||
int row, int column) {
|
||||
// TODO Auto-generated method stub
|
||||
String valueStr = (String) value;
|
||||
JLabel label = new JLabel(valueStr);
|
||||
label.setHorizontalAlignment(SwingConstants.CENTER); // 表头标签剧中
|
||||
selectBox.setHorizontalAlignment(SwingConstants.CENTER);// 表头标签剧中
|
||||
selectBox.setBorderPainted(true);
|
||||
JComponent component = (column == 0) ? selectBox : label;
|
||||
|
||||
component.setForeground(tableHeader.getForeground());
|
||||
component.setBackground(tableHeader.getBackground());
|
||||
component.setFont(tableHeader.getFont());
|
||||
component.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package com.langtech.plm.mpart;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import com.teamcenter.rac.aif.AIFDesktop;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentForm;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCException;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
import com.teamcenter.rac.util.PropertyLayout;
|
||||
|
||||
public class ChoosePartDialog extends JFrame implements ActionListener {
|
||||
|
||||
|
||||
private JComboBox<String> objectComboBox;
|
||||
private JButton okButton = new JButton("确定");
|
||||
private JButton concelButton = new JButton("取消");
|
||||
private HashMap<String, String> fieldMap = new HashMap<String, String>();
|
||||
private String revType = "";
|
||||
HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
|
||||
|
||||
public ChoosePartDialog(JComboBox<String> objectComboBox,AIFDesktop aifDesktop) {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.objectComboBox = objectComboBox;
|
||||
initUI();
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
this.setTitle("选择BOM");
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
JPanel topPanel = getTopPanel();
|
||||
|
||||
JPanel btnPanel = getBtnPanel();
|
||||
|
||||
this.add(topPanel, BorderLayout.NORTH);
|
||||
// this.add(pane,BorderLayout.CENTER);
|
||||
this.add(btnPanel, BorderLayout.SOUTH);
|
||||
this.setPreferredSize(new Dimension(550, 200));
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
|
||||
int screenWidth = screenSize.width; // 获取屏幕宽度
|
||||
int screenHeight = screenSize.height; // 获取屏幕高度
|
||||
int x = (screenWidth - 550) / 2; // 计算Frame的左上角x坐标
|
||||
int y = (screenHeight - 300) / 2; // 计算Frame的左上角y坐标
|
||||
this.setLocation(x, y); // 设置Frame的位置
|
||||
|
||||
// this.setLocationRelativeTo(null);
|
||||
this.createActionEvent();
|
||||
this.pack();
|
||||
|
||||
// this.validate();
|
||||
this.setVisible(true);
|
||||
|
||||
// this.setAlwaysOnTop(true);
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加监听
|
||||
public void createActionEvent() {
|
||||
|
||||
this.okButton.addActionListener(this);
|
||||
this.concelButton.addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
Object source = e.getSource();
|
||||
System.out.println("source==>+" + source);
|
||||
if (this.okButton.equals(source)) {
|
||||
this.dispose();
|
||||
|
||||
} else if (this.concelButton.equals(source)) {
|
||||
this.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private JPanel getBtnPanel() {
|
||||
JPanel topPanel = new JPanel();
|
||||
topPanel.setLayout(new PropertyLayout());
|
||||
topPanel.add("1.1.center", new JLabel(""));
|
||||
topPanel.add("2.1.center", new JLabel(" "));
|
||||
topPanel.add("2.2.center", okButton);
|
||||
topPanel.add("2.3.center", new JLabel(""));
|
||||
topPanel.add("2.4.center", concelButton);
|
||||
|
||||
return topPanel;
|
||||
}
|
||||
|
||||
// 查询部分
|
||||
private JPanel getTopPanel() {
|
||||
// TODO Auto-generated method stub
|
||||
JPanel topPanel = new JPanel();
|
||||
topPanel.setLayout(new PropertyLayout());
|
||||
topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
topPanel.add("1.1.left.center", new JLabel(""));
|
||||
topPanel.add("2.1.left.center", new JLabel(""));
|
||||
topPanel.add("3.1.left.center", new JLabel(""));
|
||||
topPanel.add("4.1.left.center", new JLabel(""));
|
||||
topPanel.add("5.1.left.center", new JLabel(""));
|
||||
topPanel.add("6.1.left.center", new JLabel(""));
|
||||
topPanel.add("7.1.left.center", new JLabel("选择属性来源对象:"));
|
||||
topPanel.add("7.2.left.center", objectComboBox);
|
||||
|
||||
return topPanel;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.langtech.plm.mpart;
|
||||
import javax.swing.*;
|
||||
|
||||
import com.sun.scenario.effect.impl.hw.d3d.D3DShaderSource;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class DialogFrame extends JDialog {
|
||||
|
||||
private JComboBox<String> comboBox;
|
||||
private Object syncObject;
|
||||
public DialogFrame(JFrame owner,JComboBox<String> comboBox,ArrayList<String> list) {
|
||||
super(owner, "Dialog Window", true); // 模态对话框
|
||||
this.comboBox = comboBox;
|
||||
this.syncObject = syncObject;
|
||||
JButton button = new JButton("确定");
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String selectedItem =(String) comboBox.getSelectedItem();
|
||||
if(selectedItem == null || selectedItem.isEmpty()) {
|
||||
MessageBox.post("请选择数据!", "提示 ", MessageBox.INFORMATION);
|
||||
}else {
|
||||
|
||||
System.out.println("Selected Item: " + selectedItem);
|
||||
list.add(selectedItem);
|
||||
dispose(); // 关闭对话框
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
this.setPreferredSize(new Dimension(300,100));
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new FlowLayout());
|
||||
panel.add(new JLabel("请选择:"));
|
||||
panel.add(comboBox);
|
||||
panel.add(button);
|
||||
|
||||
this.add(panel);
|
||||
this.pack();
|
||||
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
this.setLocationRelativeTo(owner); // 居中显示
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package com.langtech.plm.mpart;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MainFrame extends JFrame {
|
||||
|
||||
private JTextField textField;
|
||||
private Object syncObject = new Object();
|
||||
public MainFrame() {
|
||||
super("Main Window");
|
||||
|
||||
textField = new JTextField(20);
|
||||
JButton button = new JButton("Open Dialog");
|
||||
ArrayList<String> childrenList = new ArrayList<String>();
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 创建并显示模态对话框
|
||||
JComboBox<String> a = new JComboBox<String>();
|
||||
a.addItem("1");
|
||||
System.out.println("0");
|
||||
System.out.println(syncObject);
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
DialogFrame dialog = new DialogFrame(MainFrame.this,a,childrenList);
|
||||
dialog.setVisible(true);
|
||||
// 等待对话框关闭后执行的操作
|
||||
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(java.awt.event.WindowEvent e) {
|
||||
|
||||
System.out.println("21121212");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
System.out.println("2");
|
||||
|
||||
System.out.println(childrenList.size());
|
||||
|
||||
|
||||
|
||||
// DialogFrame dialog = new DialogFrame(MainFrame.this,a,syncObject);
|
||||
// dialog.setVisible(true);
|
||||
// // 等待对话框关闭后执行的操作
|
||||
// dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
// @Override
|
||||
// public void windowClosed(java.awt.event.WindowEvent e) {
|
||||
//
|
||||
// System.out.println("1");
|
||||
// }
|
||||
// });
|
||||
// System.out.println("2");
|
||||
// synchronized (syncObject) {
|
||||
//
|
||||
// try {
|
||||
// // Wait until notified
|
||||
// System.out.println("4");
|
||||
// syncObject.wait();
|
||||
//
|
||||
// } catch (InterruptedException ex) {
|
||||
// Thread.currentThread().interrupt(); // Restore interrupted status
|
||||
// System.err.println("Thread was interrupted.");
|
||||
// }
|
||||
// System.out.println("2");
|
||||
//
|
||||
// }
|
||||
System.out.println("3");
|
||||
}
|
||||
});
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new FlowLayout());
|
||||
panel.add(textField);
|
||||
panel.add(button);
|
||||
|
||||
this.add(panel);
|
||||
this.pack();
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLocationRelativeTo(null); // 居中显示
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(() -> {
|
||||
MainFrame frame = new MainFrame();
|
||||
frame.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.langtech.plm.mpart;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentSchedule;
|
||||
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
|
||||
import com.teamcenter.rac.kernel.TCException;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class MpartHandler extends AbstractHandler{
|
||||
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
try {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
InterfaceAIFComponent[] targetComponent = app.getTargetComponents();
|
||||
ArrayList<TCComponentItemRevision> arrayList = new ArrayList<TCComponentItemRevision>();
|
||||
|
||||
for (int i = 0; i < targetComponent.length; i++) {
|
||||
InterfaceAIFComponent component = targetComponent[i];
|
||||
if(component instanceof TCComponentItemRevision) {
|
||||
arrayList.add((TCComponentItemRevision)component);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("arrayList.size()==========="+arrayList.size());
|
||||
|
||||
if(arrayList.size() > 0) {
|
||||
try {
|
||||
new MpartDialog(session,arrayList);
|
||||
} catch (TCException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.langtech.plm.mpart;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.EventListenerList;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
|
||||
import com.teamcenter.rac.treetable.JTreeTable;
|
||||
|
||||
|
||||
public class TableCellCheckboxRenderer extends JCheckBox implements
|
||||
TableCellRenderer {
|
||||
private List<Integer> processRows;
|
||||
protected EventListenerList listenerList = new EventListenerList();
|
||||
protected ChangeEvent changeEvent = new ChangeEvent(this);
|
||||
//private TestTreeTableModel tableModel;
|
||||
|
||||
public List<Integer> getProcessRows() {
|
||||
return processRows;
|
||||
}
|
||||
|
||||
public void setProcessRows(List<Integer> processRows) {
|
||||
this.processRows = processRows;
|
||||
|
||||
}
|
||||
public TableCellCheckboxRenderer(final JTable table) {
|
||||
}
|
||||
public TableCellCheckboxRenderer(final JTreeTable table) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||
boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
// TODO Auto-generated method stub
|
||||
this.setHorizontalAlignment(SwingConstants.CENTER);// ±íÍ·±êÇ©¾çÖÐ
|
||||
// this.setBorderPainted(true);
|
||||
|
||||
if(value != null)
|
||||
{
|
||||
this.setSelected(value.toString().equals("1"));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setSelected(false);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.langtech.plm.synchronize;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
public class SynchronizeHandler extends AbstractHandler{
|
||||
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent arg0) throws ExecutionException {
|
||||
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
try {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
InterfaceAIFComponent targetComponent = app.getTargetComponent();
|
||||
if(targetComponent instanceof TCComponentItemRevision) {
|
||||
try {
|
||||
TCComponentItemRevision rev = (TCComponentItemRevision)targetComponent;
|
||||
new SynchronizeDialog(session,rev);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
MessageBox.post("ÇëÑ¡Ôñ°æ±¾¶ÔÏó£¡","Ìáʾ",2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,222 @@
|
||||
package com.langtech.plm.template;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentForm;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentScheduleTask;
|
||||
import com.teamcenter.rac.kernel.TCException;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
import com.teamcenter.rac.util.PropertyLayout;
|
||||
|
||||
public class TemplateDialog extends JFrame implements ActionListener {
|
||||
|
||||
private TCSession session;
|
||||
protected DefaultTableModel tm_part;
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private TCComponentItemRevision rev;
|
||||
private JComboBox<String> company = new JComboBox<String>();
|
||||
private JComboBox<String> template = new JComboBox<String>();
|
||||
private JButton okButton = new JButton("确定");
|
||||
private JButton concelButton = new JButton("取消");
|
||||
private HashMap<String, String> map = new HashMap<String, String>();
|
||||
HashMap<String, TCComponentItemRevision> objectMap = new HashMap<String, TCComponentItemRevision>();
|
||||
|
||||
public TemplateDialog(TCSession session, TCComponentItemRevision rev) throws TCException {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.session = session;
|
||||
this.rev = rev;
|
||||
|
||||
initUI();
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
company.setPreferredSize(new Dimension(200,30));
|
||||
template.setPreferredSize(new Dimension(200,30));
|
||||
this.setTitle("工序模版");
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
JPanel topPanel = getTopPanel();
|
||||
|
||||
JPanel btnPanel = getBtnPanel();
|
||||
|
||||
this.add(topPanel, BorderLayout.NORTH);
|
||||
// this.add(pane,BorderLayout.CENTER);
|
||||
this.add(btnPanel, BorderLayout.SOUTH);
|
||||
this.setPreferredSize(new Dimension(450, 200));
|
||||
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
|
||||
int screenWidth = screenSize.width; // 获取屏幕宽度
|
||||
int screenHeight = screenSize.height; // 获取屏幕高度
|
||||
int x = (screenWidth - 450) / 2; // 计算Frame的左上角x坐标
|
||||
int y = (screenHeight - 200) / 2; // 计算Frame的左上角y坐标
|
||||
this.setLocation(x, y); // 设置Frame的位置
|
||||
|
||||
// this.setLocationRelativeTo(null);
|
||||
this.createActionEvent();
|
||||
this.pack();
|
||||
|
||||
// this.validate();
|
||||
this.setVisible(true);
|
||||
|
||||
// this.setAlwaysOnTop(true);
|
||||
|
||||
|
||||
|
||||
String[] pref = session.getPreferenceService().getStringValues("LY6_MEOP_TemplateType");
|
||||
for (int i = 0; i < pref.length; i++) {
|
||||
String[] split = pref[i].split(":");
|
||||
company.addItem(split[0]);
|
||||
map.put(split[0], split[1]);
|
||||
}
|
||||
|
||||
String mrselectitem = (String)company.getSelectedItem();
|
||||
String mrValue = map.get(mrselectitem);
|
||||
String[] split = mrValue.split(",");
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
template.addItem(split[i]);
|
||||
}
|
||||
|
||||
//下拉值联动
|
||||
company.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
template.removeAllItems();
|
||||
String selectedItem = (String) company.getSelectedItem();
|
||||
System.out.println("Selected Item: " + selectedItem);
|
||||
// 在这里可以执行其他操作
|
||||
String value = map.get(selectedItem);
|
||||
String[] split = value.split(",");
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
template.addItem(split[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加监听
|
||||
public void createActionEvent() {
|
||||
|
||||
this.okButton.addActionListener(this);
|
||||
this.concelButton.addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
Object source = e.getSource();
|
||||
System.out.println("source==>+" + source);
|
||||
if (this.okButton.equals(source)) {
|
||||
String templateString = (String)template.getSelectedItem();
|
||||
String companyString = (String)company.getSelectedItem();
|
||||
System.out.println("templateString==="+templateString);
|
||||
System.out.println("companyString==="+companyString);
|
||||
if(companyString.isEmpty()) {
|
||||
MessageBox.post("请选择公司!", "提示 ", MessageBox.INFORMATION);
|
||||
return;
|
||||
}
|
||||
|
||||
if(templateString.isEmpty()) {
|
||||
MessageBox.post("请选择模板!", "提示 ", MessageBox.INFORMATION);
|
||||
return;
|
||||
}
|
||||
|
||||
//调用查询获取模板的dwg数据集
|
||||
try {
|
||||
TCComponent[] items = session.search("零组件...", new String[] { "零组件 ID" }, new String[] {templateString});
|
||||
System.out.println("items.length===="+items.length);
|
||||
TCComponentItem item = null;
|
||||
if(items.length > 0) {
|
||||
item = (TCComponentItem)items[0];
|
||||
}
|
||||
TCComponentItemRevision latestItemRevision = item.getLatestItemRevision();
|
||||
TCComponent[] relatedComponent = latestItemRevision.getRelatedComponents("IMAN_specification");
|
||||
System.out.println("relatedComponent========"+relatedComponent.length);
|
||||
for (int i = 0; i < relatedComponent.length; i++) {
|
||||
rev.add("IMAN_specification",relatedComponent[i]);
|
||||
}
|
||||
MessageBox.post("模板插入成功!", "提示 ", MessageBox.INFORMATION);
|
||||
this.dispose();
|
||||
return;
|
||||
} catch (Exception e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
//挂在数据集
|
||||
} else if (this.concelButton.equals(source)) {
|
||||
this.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private JPanel getBtnPanel() {
|
||||
JPanel topPanel = new JPanel();
|
||||
topPanel.setLayout(new PropertyLayout());
|
||||
topPanel.add("1.1.center", new JLabel(""));
|
||||
topPanel.add("2.1.center", new JLabel(" "));
|
||||
topPanel.add("2.2.center", okButton);
|
||||
topPanel.add("2.3.center", new JLabel(""));
|
||||
topPanel.add("2.4.center", concelButton);
|
||||
|
||||
return topPanel;
|
||||
}
|
||||
|
||||
// 查询部分
|
||||
private JPanel getTopPanel() {
|
||||
// TODO Auto-generated method stub
|
||||
JPanel topPanel = new JPanel();
|
||||
topPanel.setLayout(new PropertyLayout());
|
||||
topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
|
||||
topPanel.add("1.1.left.center", new JLabel(""));
|
||||
topPanel.add("2.1.left.center", new JLabel(""));
|
||||
topPanel.add("3.1.left.center", new JLabel(""));
|
||||
topPanel.add("4.1.left.center", new JLabel(" 公司:"));
|
||||
topPanel.add("4.2.left.center", company);
|
||||
|
||||
topPanel.add("5.1.left.center", new JLabel(""));
|
||||
topPanel.add("6.1.left.center", new JLabel(""));
|
||||
topPanel.add("7.1.left.center", new JLabel(""));
|
||||
topPanel.add("8.1.left.center", new JLabel(" 模板:"));
|
||||
|
||||
topPanel.add("8.2.left.center", template);
|
||||
|
||||
return topPanel;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.langtech.plm.tqsx;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
|
||||
import com.teamcenter.rac.aif.common.actions.AbstractAIFAction;
|
||||
import com.teamcenter.rac.util.MessageBox;
|
||||
|
||||
|
||||
public class KAction extends AbstractAIFAction {
|
||||
|
||||
|
||||
KAction(AbstractAIFUIApplication app, String string) {
|
||||
super(app,string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int ind = actionName.indexOf('#');
|
||||
String action=actionName;
|
||||
String actionData="";
|
||||
if(ind>0) {
|
||||
action=actionName.substring(0,ind);
|
||||
actionData=actionName.substring(ind+1);
|
||||
}
|
||||
Class<?> c = Class.forName(action);
|
||||
Constructor<?> constructor = c.getConstructor(AbstractAIFApplication.class, String.class,String.class);
|
||||
KCommand command = (KCommand) constructor.newInstance(this.application, action, actionData);
|
||||
command.executeModal();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MessageBox.post(e.toString(),KLocale.getString("error"),MessageBox.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.langtech.plm.tqsx;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.AbstractAIFCommand;
|
||||
|
||||
public abstract class KCommand extends AbstractAIFCommand {
|
||||
|
||||
protected AbstractAIFApplication app;
|
||||
protected String actionInfo;
|
||||
|
||||
public KCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
|
||||
this.app = app;
|
||||
this.actionInfo = actionInfo;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.langtech.plm.tqsx;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
|
||||
import com.teamcenter.rac.aifrcp.AIFUtility;
|
||||
|
||||
/**
|
||||
* Add following config to MANIFEST.MF
|
||||
* Eclipse-RegisterBuddy: k.util
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
public class KHandler extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent arg0) {
|
||||
AbstractAIFUIApplication app = AIFUtility.getCurrentApplication();
|
||||
new Thread(new KAction(app,arg0.getCommand().getId())).start();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.langtech.plm.tqsx;
|
||||
|
||||
import com.teamcenter.rac.util.Registry;
|
||||
|
||||
|
||||
public class KLocale {
|
||||
|
||||
public static final Registry reg = Registry.getRegistry(KLocale.class);
|
||||
|
||||
public static String getString(String title) {
|
||||
if (isEmpty(title)) {
|
||||
return "";
|
||||
} else {
|
||||
String res = reg.getString(title);
|
||||
return isEmpty(res) ? title : res;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isEmpty(String title) {
|
||||
return title == null || "".equals(title.trim());
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.langtech.plm.tqsx;
|
||||
|
||||
import java.awt.Dimension;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.AbstractAIFOperation;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
|
||||
import k.util.ProgressBar;
|
||||
|
||||
/*
|
||||
* do not call executeOperation yourself
|
||||
* use session.performOperation
|
||||
*/
|
||||
public abstract class KOperation extends AbstractAIFOperation {
|
||||
|
||||
protected AbstractAIFApplication app;
|
||||
protected TCSession session;
|
||||
public String messageLabel;
|
||||
|
||||
public KOperation(AbstractAIFApplication app, String opName, String messageLabel) {
|
||||
super(opName, true);
|
||||
this.app = app;
|
||||
this.session = (TCSession) app.getSession();
|
||||
this.messageLabel = messageLabel;// ½ø¶ÈÌõÐÅÏ¢
|
||||
setSession(session);
|
||||
}
|
||||
|
||||
public abstract boolean init() throws Exception;
|
||||
|
||||
public abstract void execute() throws Exception;
|
||||
|
||||
@Override
|
||||
public void executeOperation() {
|
||||
ProgressBar pb = new ProgressBar(new Dimension(250, 50), true);
|
||||
try {
|
||||
pb.showDialog();
|
||||
pb.setText(messageLabel);
|
||||
setStatus("Checking Data...");
|
||||
if (!init()) {
|
||||
pb.disposeDialog();
|
||||
return;
|
||||
}
|
||||
setStatus("Execute...");
|
||||
pb.setText(messageLabel);
|
||||
execute();
|
||||
pb.disposeDialog();
|
||||
} catch (Exception e) {
|
||||
pb.disposeDialog();
|
||||
KUtil.error(getCurrentDesktop(), "·¢ÉúÒì³££º\n" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.langtech.plm.tqsx;
|
||||
|
||||
import java.awt.Dimension;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.AbstractAIFOperation;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
|
||||
import k.util.ProgressBar;
|
||||
|
||||
/*
|
||||
* do not call executeOperation yourself
|
||||
* use session.performOperation
|
||||
*/
|
||||
public abstract class KOperation2 extends AbstractAIFOperation {
|
||||
|
||||
protected AbstractAIFApplication app;
|
||||
protected TCSession session;
|
||||
protected ProgressBar pb;
|
||||
|
||||
public KOperation2(AbstractAIFApplication app, String opName) {
|
||||
super(opName, true);
|
||||
this.app = app;
|
||||
this.session = (TCSession) app.getSession();
|
||||
setSession(session);
|
||||
}
|
||||
|
||||
public abstract boolean init() throws Exception;
|
||||
|
||||
public abstract void execute() throws Exception;
|
||||
|
||||
@Override
|
||||
public void executeOperation() {
|
||||
pb = new ProgressBar(new Dimension(250, 50), true);
|
||||
try {
|
||||
pb.showDialog();
|
||||
setStatus(KLocale.getString("initop.STATUS"));
|
||||
if (!init()) {
|
||||
pb.disposeDialog();
|
||||
return;
|
||||
}
|
||||
setStatus(KLocale.getString("exeop.STATUS"));
|
||||
execute();
|
||||
KUtil.setByPass(false);
|
||||
pb.disposeDialog();
|
||||
} catch (Exception e) {
|
||||
pb.disposeDialog();
|
||||
KUtil.setByPass(false);
|
||||
KUtil.error(getCurrentDesktop(), "·¢ÉúÒì³££º\n" + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,66 @@
|
||||
package com.langtech.plm.tqsx;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.teamcenter.rac.aif.AIFDesktop;
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentDataset;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
|
||||
|
||||
|
||||
public class PropertyToWordOrExcelCommand extends KCommand{
|
||||
|
||||
final String preName = "Connor_LY6_WordExcel_Report_ItemType";
|
||||
|
||||
public PropertyToWordOrExcelCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
|
||||
super(app, commandId, actionInfo);
|
||||
TCSession session = (TCSession) app.getSession();
|
||||
this.setRunnable(new PropertyToWordOrExcelOperation(app, "提取对象版本属性到Word Excel"));
|
||||
// InterfaceAIFComponent targetComponent = app.getTargetComponent();
|
||||
// TCComponentItemRevision revision = (TCComponentItemRevision) targetComponent;
|
||||
// try {
|
||||
// String[] prefVals = KUtil.getPrefVals(session, preName);
|
||||
// if(prefVals == null || prefVals.length == 0) {
|
||||
// KUtil.info(AIFDesktop.getActiveDesktop(), preName + "该首选项未配置,请联系管理员!");
|
||||
// return ;
|
||||
// }
|
||||
// String relatioin = prefVals[0];
|
||||
// TCComponent[] relatedComponents = revision.getRelatedComponents(relatioin);
|
||||
// if(relatedComponents == null || relatedComponents.length == 0) {
|
||||
// KUtil.info(AIFDesktop.getActiveDesktop(), "选中对象的 " + relatioin + " 关系下没有数据集");
|
||||
// return ;
|
||||
// }
|
||||
// for (TCComponent tcComponent : relatedComponents) {
|
||||
// if (tcComponent instanceof TCComponentDataset) {
|
||||
// TCComponentDataset dataset = (TCComponentDataset) tcComponent;
|
||||
// File datasetFile = KUtil.getDatasetFile(dataset);
|
||||
// System.out.println();
|
||||
// String type = tcComponent.getType();
|
||||
// switch (type) {
|
||||
// case "MSExcel":
|
||||
//
|
||||
// break;
|
||||
// case "MSExcelX":
|
||||
//
|
||||
// break;
|
||||
// case "MSWord":
|
||||
//
|
||||
// break;
|
||||
// case "MSWordX":
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,288 @@
|
||||
package com.langtech.plm.tqsx;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||
import org.apache.poi.hssf.usermodel.HSSFName;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||||
import org.apache.poi.xssf.usermodel.XSSFName;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import com.aspose.words.Bookmark;
|
||||
import com.aspose.words.Document;
|
||||
import com.aspose.words.SaveFormat;
|
||||
import com.teamcenter.rac.aif.AIFDesktop;
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.aif.kernel.AbstractAIFSession;
|
||||
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
import com.teamcenter.rac.kernel.TCComponentDataset;
|
||||
import com.teamcenter.rac.kernel.TCComponentItem;
|
||||
import com.teamcenter.rac.kernel.TCComponentItemRevision;
|
||||
import com.teamcenter.rac.kernel.TCComponentTcFile;
|
||||
import com.teamcenter.rac.kernel.TCException;
|
||||
import com.teamcenter.rac.kernel.TCProperty;
|
||||
import com.teamcenter.rac.util.FileUtility;
|
||||
|
||||
|
||||
|
||||
public class PropertyToWordOrExcelOperation extends KOperation {
|
||||
|
||||
public PropertyToWordOrExcelOperation(AbstractAIFApplication app, String opName) {
|
||||
super(app, opName, "正在执行。。。");
|
||||
}
|
||||
|
||||
final String preName = "Connor_LY6_WordExcel_Report_ItemType";
|
||||
|
||||
@Override
|
||||
public boolean init() throws Exception {
|
||||
new Thread().sleep(1000);
|
||||
InterfaceAIFComponent targetComponent = app.getTargetComponent();
|
||||
TCComponentItemRevision revision = (TCComponentItemRevision) targetComponent;
|
||||
String[] prefVals = KUtil.getPrefVals(session, preName);
|
||||
if(prefVals == null || prefVals.length == 0) {
|
||||
KUtil.info(AIFDesktop.getActiveDesktop(), preName + "该首选项未配置,请联系管理员!");
|
||||
return false;
|
||||
}
|
||||
String relatioin = prefVals[0];
|
||||
TCComponent[] relatedComponents = revision.getRelatedComponents(relatioin);
|
||||
if(relatedComponents == null || relatedComponents.length == 0) {
|
||||
KUtil.info(AIFDesktop.getActiveDesktop(), "选中对象的 " + relatioin + " 关系下没有数据集");
|
||||
return false;
|
||||
}
|
||||
//处理首选项
|
||||
HashMap<String, String> nameMap = new HashMap<String, String>();//数据集里面的名称和对象(item,rev,revMaster)集合
|
||||
if(prefVals.length >= 2) {
|
||||
for (int i = 1; i < prefVals.length; i++) {
|
||||
//Item.object_name=object_name
|
||||
String[] split = prefVals[i].split("=");
|
||||
nameMap.put(split[1],split[0]);
|
||||
}
|
||||
}
|
||||
for (TCComponent tcComponent : relatedComponents) {
|
||||
if (tcComponent instanceof TCComponentDataset) {
|
||||
TCComponentDataset dataset = (TCComponentDataset) tcComponent;
|
||||
File datasetFile = KUtil.getDatasetFile(dataset);
|
||||
String type = tcComponent.getType();
|
||||
String datasetType = "";
|
||||
String newPath = "";
|
||||
if("MSExcel".equals(type) || "MSExcelX".equals(type) || "MSWord".equals(type) || "MSWordX".equals(type)) {
|
||||
switch (type) {
|
||||
case "MSExcel":
|
||||
datasetType = "excel";
|
||||
newPath = dealExcel(datasetFile,revision,nameMap);
|
||||
break;
|
||||
case "MSExcelX":
|
||||
datasetType = "excel";
|
||||
newPath = dealExcelX(datasetFile,revision,nameMap);
|
||||
break;
|
||||
case "MSWord":
|
||||
datasetType = "word";
|
||||
newPath = dealWord2(datasetFile,revision,nameMap,"doc");
|
||||
break;
|
||||
case "MSWordX":
|
||||
datasetType = "word";
|
||||
newPath = dealWord2(datasetFile,revision,nameMap,"docx");
|
||||
break;
|
||||
}
|
||||
//给数据集设置新的命名的引用
|
||||
dataset.setFiles(new String[] {newPath}, new String[] {datasetType});
|
||||
}
|
||||
}
|
||||
}
|
||||
KUtil.info(AIFDesktop.getActiveDesktop(), "提取对象版本属性到Word Excel执行完成");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
private String dealExcel(File datasetFile, TCComponentItemRevision revision, HashMap<String, String> nameMap) throws IOException, TCException {
|
||||
FileInputStream is = new FileInputStream(datasetFile);
|
||||
HSSFWorkbook workbook = new HSSFWorkbook(is);
|
||||
List<HSSFName> allNames = workbook.getAllNames();
|
||||
for (HSSFName hssfName : allNames) {
|
||||
String name = hssfName.getNameName();
|
||||
//名称管理器存在首选项的名称
|
||||
if (nameMap.containsKey(name)) {
|
||||
CellReference cellReference = new CellReference(hssfName.getRefersToFormula());
|
||||
HSSFSheet sheet = workbook.getSheet(cellReference.getSheetName());
|
||||
HSSFRow row = sheet.getRow(cellReference.getRow());
|
||||
HSSFCell cell = row.getCell(cellReference.getCol());
|
||||
String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(name));
|
||||
System.out.println("行为:" + cellReference.getRow() + "====" + "列为:" + cellReference.getCol() + "===="
|
||||
+ "值为: " + preConfigValue);
|
||||
if(cell == null) {
|
||||
cell = row.createCell(cellReference.getCol());
|
||||
}
|
||||
cell.setCellValue(preConfigValue);
|
||||
|
||||
}
|
||||
}
|
||||
is.close();
|
||||
FileOutputStream os = new FileOutputStream(datasetFile);
|
||||
workbook.write(os);
|
||||
workbook.close();
|
||||
return datasetFile.getAbsolutePath();
|
||||
}
|
||||
|
||||
private String dealExcelX(File datasetFile, TCComponentItemRevision revision, HashMap<String, String> nameMap) throws IOException, TCException {
|
||||
FileInputStream is = new FileInputStream(datasetFile);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(is);
|
||||
List<XSSFName> allNames = workbook.getAllNames();
|
||||
for (XSSFName xssfName : allNames) {
|
||||
String name = xssfName.getNameName();
|
||||
//名称管理器存在首选项的名称
|
||||
if (nameMap.containsKey(name)) {
|
||||
CellReference cellReference = new CellReference(xssfName.getRefersToFormula());
|
||||
XSSFSheet sheet = workbook.getSheet(cellReference.getSheetName());
|
||||
XSSFRow row = sheet.getRow(cellReference.getRow());
|
||||
XSSFCell cell = row.getCell(cellReference.getCol());
|
||||
String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(name));
|
||||
System.out.println("行为:" + cellReference.getRow() + "====" + "列为:" + cellReference.getCol() + "===="
|
||||
+ "值为: " + preConfigValue);
|
||||
if(cell == null) {
|
||||
cell = row.createCell(cellReference.getCol());
|
||||
cell.setCellValue(preConfigValue);
|
||||
}
|
||||
else {
|
||||
cell.setCellValue(preConfigValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
is.close();
|
||||
FileOutputStream os = new FileOutputStream(datasetFile);
|
||||
workbook.write(os);
|
||||
workbook.close();
|
||||
return datasetFile.getAbsolutePath();
|
||||
}
|
||||
|
||||
private String dealWord(File datasetFile, TCComponentItemRevision revision, HashMap<String, String> nameMap,String type) throws IOException, TCException {
|
||||
String path = datasetFile.getAbsolutePath();
|
||||
InputStream inputStream = Files.newInputStream(Paths.get(path));
|
||||
Map<String, String> dataMap = new HashMap<>();
|
||||
for(String key : nameMap.keySet()) {
|
||||
String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(key));
|
||||
dataMap.put(key, preConfigValue);
|
||||
}
|
||||
String newPath = "";
|
||||
if(type.equals("doc")) {
|
||||
newPath = path.replace(".doc", "temp.doc");
|
||||
WordUtils.replaceBookmarksByDoc(inputStream, Files.newOutputStream(Paths.get(newPath)), dataMap);
|
||||
}
|
||||
else if(type.equals("docx")) {
|
||||
newPath = path.replace(".docx", "temp.docx");
|
||||
WordUtils.replaceBookmarksByDocx(inputStream, Files.newOutputStream(Paths.get(newPath)), dataMap);
|
||||
}
|
||||
return newPath;
|
||||
}
|
||||
|
||||
private String dealWord2(File datasetFile, TCComponentItemRevision revision, HashMap<String, String> nameMap,String type) throws FileNotFoundException, Exception {
|
||||
String path = datasetFile.getAbsolutePath();
|
||||
Document document2 = new Document(new FileInputStream(path));
|
||||
OutputStream outputStream = null;
|
||||
String newPath = path.replace(".doc", "temp.doc");
|
||||
outputStream = new FileOutputStream(newPath);
|
||||
Map<String, String> dataMap = new HashMap<>();
|
||||
for(String key : nameMap.keySet()) {
|
||||
String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(key));
|
||||
dataMap.put(key, preConfigValue);
|
||||
}
|
||||
for (Bookmark bookmark : document2.getRange().getBookmarks()) {
|
||||
String bookmarkName = bookmark.getName();
|
||||
System.out.println("书签名:"+bookmarkName);
|
||||
if(dataMap.containsKey(bookmarkName))
|
||||
{
|
||||
System.out.println("添加内容");
|
||||
bookmark.setText(dataMap.get(bookmarkName));
|
||||
}
|
||||
}
|
||||
if(type.equals("doc")) {
|
||||
document2.save(outputStream, SaveFormat.DOC);
|
||||
}else if(type.equals("docx")) {
|
||||
document2.save(outputStream, SaveFormat.DOCX);
|
||||
}
|
||||
return newPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到首选项中“=”左边对应的属性值
|
||||
* @param revision
|
||||
* @param nameMap
|
||||
* @param value
|
||||
* @return
|
||||
* @throws TCException
|
||||
*/
|
||||
private String getPreConfigValue(TCComponentItemRevision revision, HashMap<String, String> nameMap,String value) throws TCException {
|
||||
String[] split = value.split("\\.");
|
||||
String cellValue = "";
|
||||
TCProperty property = null;
|
||||
if(split.length == 2) {
|
||||
switch (split[0]) {
|
||||
case "Item":
|
||||
property = revision.getItem().getTCProperty(split[1]);
|
||||
break;
|
||||
case "Rev":
|
||||
property = revision.getTCProperty(split[1]);
|
||||
break;
|
||||
case "RevMaster":
|
||||
property = revision.getRelatedComponent("IMAN_master_form_rev").getTCProperty(split[1]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
//取关系文件夹下的属性
|
||||
else if(split.length == 3) {
|
||||
String relation = split[0];
|
||||
TCComponent relatedComponent = revision.getRelatedComponent(relation);
|
||||
TCComponentItemRevision centerRev = null;
|
||||
if(relatedComponent instanceof TCComponentItemRevision) {
|
||||
centerRev = (TCComponentItemRevision) relatedComponent;
|
||||
}else if(relatedComponent instanceof TCComponentItem) {
|
||||
centerRev = ((TCComponentItem) relatedComponent).getLatestItemRevision();
|
||||
}
|
||||
if(centerRev != null) {
|
||||
switch (split[1]) {
|
||||
case "Item":
|
||||
property = centerRev.getItem().getTCProperty(split[2]);
|
||||
break;
|
||||
case "Rev":
|
||||
property = centerRev.getTCProperty(split[2]);
|
||||
break;
|
||||
case "RevMaster":
|
||||
property = centerRev.getRelatedComponent("IMAN_master_form_rev").getTCProperty(split[2]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(property == null) {
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
cellValue = property.getDisplayValue();
|
||||
return cellValue;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
LD6_NewProdForm.FORMJAVARENDERING=com.langtech.plm.form.LD6_NewProdForm
|
Loading…
Reference in new issue