|
|
|
@ -0,0 +1,829 @@
|
|
|
|
|
package com.connor.jd.plm.dialogs;
|
|
|
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
|
|
import java.awt.Checkbox;
|
|
|
|
|
import java.awt.Dimension;
|
|
|
|
|
import java.awt.FlowLayout;
|
|
|
|
|
import java.awt.HeadlessException;
|
|
|
|
|
import java.awt.Label;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
import java.awt.event.AdjustmentEvent;
|
|
|
|
|
import java.awt.event.AdjustmentListener;
|
|
|
|
|
import java.awt.event.ItemEvent;
|
|
|
|
|
import java.awt.event.ItemListener;
|
|
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
|
|
import java.awt.event.MouseEvent;
|
|
|
|
|
import java.awt.event.MouseWheelEvent;
|
|
|
|
|
import java.awt.event.MouseWheelListener;
|
|
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
|
import java.awt.event.WindowListener;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory;
|
|
|
|
|
import javax.swing.ComboBoxModel;
|
|
|
|
|
import javax.swing.DefaultComboBoxModel;
|
|
|
|
|
import javax.swing.JButton;
|
|
|
|
|
import javax.swing.JCheckBox;
|
|
|
|
|
import javax.swing.JComboBox;
|
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
import javax.swing.JPopupMenu;
|
|
|
|
|
import javax.swing.JScrollBar;
|
|
|
|
|
import javax.swing.JScrollPane;
|
|
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
import javax.swing.JTree;
|
|
|
|
|
import javax.swing.ScrollPaneConstants;
|
|
|
|
|
import javax.swing.event.MenuKeyEvent;
|
|
|
|
|
import javax.swing.event.MenuKeyListener;
|
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
|
|
import javax.swing.tree.TreeModel;
|
|
|
|
|
import javax.swing.tree.TreeNode;
|
|
|
|
|
import javax.swing.tree.TreePath;
|
|
|
|
|
|
|
|
|
|
import com.connor.jd.plm.beans.TransformBomBean;
|
|
|
|
|
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
|
|
|
|
import com.teamcenter.rac.aif.AbstractAIFDialog;
|
|
|
|
|
import com.teamcenter.rac.aif.AbstractAIFUIApplication;
|
|
|
|
|
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentBOMLine;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentBOMViewRevision;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
|
|
|
|
|
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.kernel.TCTypeService;
|
|
|
|
|
import com.teamcenter.rac.util.ButtonLayout;
|
|
|
|
|
import com.teamcenter.rac.util.MessageBox;
|
|
|
|
|
import com.teamcenter.rac.util.PropertyLayout;
|
|
|
|
|
import com.teamcenter.soaictstubs.transientTicketInfo_s;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TransformDesignToPartDialog extends AbstractAIFDialog implements ActionListener {
|
|
|
|
|
private AbstractAIFApplication app;
|
|
|
|
|
private TCSession session;
|
|
|
|
|
private TCComponentBOMLine topBomline;
|
|
|
|
|
private JButton okButton;
|
|
|
|
|
private JButton celButton;
|
|
|
|
|
private JTree tree;
|
|
|
|
|
private CheckBoxTreeNode topTree;
|
|
|
|
|
private List<JComboBox<String>> comboxList;
|
|
|
|
|
private JPanel rightJPanel;
|
|
|
|
|
private Map<CheckBoxTreeNode, JComboBox<String>> checkBoxTreeNodelMap;
|
|
|
|
|
private Map<JComboBox<String>, JButton> boxJButtonMap;
|
|
|
|
|
private JPanel leftJPanel;
|
|
|
|
|
private int index = 1;
|
|
|
|
|
private String[] types;
|
|
|
|
|
TCComponentBOMWindow win;
|
|
|
|
|
public TransformDesignToPartDialog(AbstractAIFApplication app, TCComponentBOMLine topBomline,String[] types) {
|
|
|
|
|
// TODO Auto-generated constructor stub
|
|
|
|
|
System.out.println("step:-3------------------");
|
|
|
|
|
comboxList = new ArrayList<>();
|
|
|
|
|
this.app = app;
|
|
|
|
|
this.session = (TCSession) app.getSession();
|
|
|
|
|
this.topBomline = topBomline;
|
|
|
|
|
this.types=types;
|
|
|
|
|
createWindow();
|
|
|
|
|
|
|
|
|
|
initUI();
|
|
|
|
|
}
|
|
|
|
|
private void createWindow() {
|
|
|
|
|
try {
|
|
|
|
|
TCTypeService service = session.getTypeService();
|
|
|
|
|
TCComponentBOMWindowType winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow");
|
|
|
|
|
win = winType.create(null);
|
|
|
|
|
} catch (TCException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 界面初始化
|
|
|
|
|
*/
|
|
|
|
|
private void initUI() {
|
|
|
|
|
this.setTitle("DBOM转EBOM");
|
|
|
|
|
this.setSize(new Dimension(700, 400));
|
|
|
|
|
JPanel rightroot = new JPanel(new BorderLayout());
|
|
|
|
|
rightJPanel = new JPanel(new PropertyLayout());
|
|
|
|
|
rightroot.setBorder(BorderFactory.createTitledBorder("物料"));
|
|
|
|
|
leftJPanel = new JPanel(new BorderLayout());
|
|
|
|
|
leftJPanel.setBorder(BorderFactory.createTitledBorder("图纸"));
|
|
|
|
|
leftJPanel.setPreferredSize(new Dimension(350, 300));
|
|
|
|
|
rightroot.setPreferredSize(new Dimension(350, 300));
|
|
|
|
|
getBOMTreeAndwl();
|
|
|
|
|
JScrollPane leftpane = new JScrollPane(tree);
|
|
|
|
|
leftpane.setBorder(null);
|
|
|
|
|
leftJPanel.add(leftpane);
|
|
|
|
|
JScrollPane rightpane = new JScrollPane(rightJPanel);
|
|
|
|
|
rightroot.add(rightpane);
|
|
|
|
|
rightpane.setBorder(null);
|
|
|
|
|
final JScrollBar bar2 = rightpane.getVerticalScrollBar();
|
|
|
|
|
final JScrollBar bar1 = leftpane.getVerticalScrollBar();
|
|
|
|
|
rightpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
|
|
|
|
leftpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
|
|
|
|
bar2.addAdjustmentListener(new AdjustmentListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void adjustmentValueChanged(AdjustmentEvent e) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
if (e.getValueIsAdjusting()) {
|
|
|
|
|
bar1.setValue(e.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bar1.addAdjustmentListener(new AdjustmentListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void adjustmentValueChanged(AdjustmentEvent e) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
if (e.getValueIsAdjusting()) {
|
|
|
|
|
bar2.setValue(e.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
leftpane.getVerticalScrollBar().setUnitIncrement(10);
|
|
|
|
|
leftpane.addMouseWheelListener(new MouseWheelListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
|
|
|
|
if (e.getScrollType() == e.WHEEL_UNIT_SCROLL && bar1.getValue() >= 0
|
|
|
|
|
&& bar1.getValue() <= bar1.getVisibleAmount()) {
|
|
|
|
|
int scroll = e.getUnitsToScroll();
|
|
|
|
|
bar2.setValue(scroll * bar1.getUnitIncrement());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rightpane.getVerticalScrollBar().setUnitIncrement(10);
|
|
|
|
|
rightpane.addMouseWheelListener(new MouseWheelListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
|
|
|
|
if (e.getScrollType() == e.WHEEL_UNIT_SCROLL && bar1.getValue() >= 0
|
|
|
|
|
&& bar1.getValue() <= bar1.getVisibleAmount()) {
|
|
|
|
|
int scroll = e.getUnitsToScroll();
|
|
|
|
|
bar1.setValue(scroll * bar2.getUnitIncrement());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
JPanel botomJPanel = new JPanel(new ButtonLayout());
|
|
|
|
|
okButton = new JButton("转换");
|
|
|
|
|
okButton.addActionListener(this);
|
|
|
|
|
celButton = new JButton("退出");
|
|
|
|
|
celButton.addActionListener(this);
|
|
|
|
|
|
|
|
|
|
botomJPanel.add("1.1.left.top", okButton);
|
|
|
|
|
botomJPanel.add("1.2.left.top", new JLabel(" "));
|
|
|
|
|
botomJPanel.add("1.3.left.top", celButton);
|
|
|
|
|
JPanel rootJPanel = new JPanel(new PropertyLayout());
|
|
|
|
|
rootJPanel.add("1.1.left.top", leftJPanel);
|
|
|
|
|
rootJPanel.add("1.2.left.top", rightroot);
|
|
|
|
|
|
|
|
|
|
this.setLayout(new BorderLayout());
|
|
|
|
|
this.add(rootJPanel, BorderLayout.CENTER);
|
|
|
|
|
this.add(botomJPanel, BorderLayout.SOUTH);
|
|
|
|
|
this.pack();
|
|
|
|
|
this.centerToScreen();
|
|
|
|
|
this.showDialog();
|
|
|
|
|
this.setResizable(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param line
|
|
|
|
|
* 所有BOM添加到树结构
|
|
|
|
|
* @param node
|
|
|
|
|
* @throws TCException
|
|
|
|
|
*/
|
|
|
|
|
public void treeModel(TCComponentBOMLine line, CheckBoxTreeNode node) throws TCException {
|
|
|
|
|
System.out.println(line.getProperty("object_string") + "-------------------");
|
|
|
|
|
AIFComponentContext[] children = line.getChildren();
|
|
|
|
|
for (AIFComponentContext conetext : children) {
|
|
|
|
|
TCComponentBOMLine childLine = (TCComponentBOMLine) conetext.getComponent();
|
|
|
|
|
final CheckBoxTreeNode childNode = new CheckBoxTreeNode(new TransformBomBean(childLine));
|
|
|
|
|
childNode.setSelectable(false);
|
|
|
|
|
node.add(childNode);
|
|
|
|
|
setCombox(childLine, childNode);
|
|
|
|
|
treeModel(childLine, childNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void getBOMTreeAndwl() {
|
|
|
|
|
try {
|
|
|
|
|
checkBoxTreeNodelMap = new HashMap<>();
|
|
|
|
|
boxJButtonMap = new HashMap<>();
|
|
|
|
|
topTree = new CheckBoxTreeNode(new TransformBomBean(topBomline));
|
|
|
|
|
setCombox(topBomline, topTree);
|
|
|
|
|
System.out.println("##########" + topTree.toString() + "##########");
|
|
|
|
|
treeModel(topBomline, topTree);
|
|
|
|
|
tree = new JTree();
|
|
|
|
|
tree.setEnabled(false);
|
|
|
|
|
tree.setRowHeight(30);
|
|
|
|
|
DefaultTreeModel model = new DefaultTreeModel(topTree);
|
|
|
|
|
tree.addMouseListener(new CheckBoxTreeNodeSelectionListener());
|
|
|
|
|
tree.setModel(model);
|
|
|
|
|
tree.setCellRenderer(new CheckBoxTreeCellRenderer());
|
|
|
|
|
tree.putClientProperty("JTree.lineStyle", "Angled");
|
|
|
|
|
topTree.setSelectable(false);
|
|
|
|
|
tree.expandPath(new TreePath(topTree.getPath()));
|
|
|
|
|
Enumeration<?> enumeration = topTree.preorderEnumeration();
|
|
|
|
|
while (enumeration.hasMoreElements()) {
|
|
|
|
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode) enumeration.nextElement();
|
|
|
|
|
if (!node.isLeaf()) {
|
|
|
|
|
TreePath path = new TreePath(node.getPath());
|
|
|
|
|
tree.expandPath(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (TCException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
if (e.getSource().equals(okButton)) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("进行转换");
|
|
|
|
|
if(win==null)
|
|
|
|
|
createWindow();
|
|
|
|
|
createMaterialBom(topTree);
|
|
|
|
|
MessageBox.post("转换bom成功", "提示", MessageBox.INFORMATION);
|
|
|
|
|
this.dispose();
|
|
|
|
|
} catch (TCException e1) {
|
|
|
|
|
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
MessageBox.post(e1.getMessage(),"转换bom失败" , MessageBox.INFORMATION);
|
|
|
|
|
e1.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
win.close();
|
|
|
|
|
win=null;
|
|
|
|
|
} catch (TCException e1) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e1.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (e.getSource().equals(celButton)) {
|
|
|
|
|
|
|
|
|
|
dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 讲Tree对应的item选中
|
|
|
|
|
*
|
|
|
|
|
* @param wl
|
|
|
|
|
*//*
|
|
|
|
|
* private void checkSelected(String wl) { for (TransformBomBean bean :
|
|
|
|
|
* bomlist) { if (bean.map.containsKey(wl)) { bean.selectCount++; if
|
|
|
|
|
* (bean.selectCount > 1) { MessageBox.post("只能为当前图纸选择一个物料进行设计BOM的转换!",
|
|
|
|
|
* "警告", MessageBox.WARNING); return; }
|
|
|
|
|
* System.out.println(bean.displayName + "选中显示名");
|
|
|
|
|
* System.out.println(checkBoxTreeNodelMap.containsKey(bean.displayName)
|
|
|
|
|
* ); checkBoxTreeNodelMap.get(bean.displayName).setSelected(true);
|
|
|
|
|
* findInTree(bean.displayName); TransformBomBean bean1 =
|
|
|
|
|
* (TransformBomBean)
|
|
|
|
|
* checkBoxTreeNodelMap.get(bean.displayName).getUserObject();
|
|
|
|
|
* bean1.selectRev = (TCComponentItemRevision) bean.map.get(wl); } } }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 讲Tree对应的item取消选中
|
|
|
|
|
*
|
|
|
|
|
* @param wl
|
|
|
|
|
*//*
|
|
|
|
|
* private void checkDisSelected(String wl) { for (TransformBomBean bean
|
|
|
|
|
* : bomlist) { if (bean.map.containsKey(wl)) { bean.selectCount--;
|
|
|
|
|
* checkBoxTreeNodelMap.get(bean.displayName).setSelected(false); } } }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 搭建BOM
|
|
|
|
|
*
|
|
|
|
|
* @param node
|
|
|
|
|
* @throws TCException
|
|
|
|
|
*/
|
|
|
|
|
private void createMaterialBom(CheckBoxTreeNode node) throws TCException {
|
|
|
|
|
// System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
|
|
|
|
|
TransformBomBean bean = (TransformBomBean) node.getUserObject();
|
|
|
|
|
TCComponentItemRevision materialRev = bean.selectRev;
|
|
|
|
|
// 存在已经发布的物料的bom
|
|
|
|
|
/*
|
|
|
|
|
* if (WXMethodUtil.isRevBomReleased(materialRev)) {
|
|
|
|
|
* System.out.println("发布"); return; }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (isLoopBom(node)) {
|
|
|
|
|
MessageBox.post("存在循环BOM结构", "警告", MessageBox.WARNING);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int childCount = node.getChildCount();
|
|
|
|
|
List<TCComponentItemRevision> childrenList = new ArrayList<>();
|
|
|
|
|
List<String> quantityList = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
|
CheckBoxTreeNode childNode = (CheckBoxTreeNode) node.getChildAt(i);
|
|
|
|
|
if (childNode.isSelected()) {
|
|
|
|
|
TransformBomBean bean1 = (TransformBomBean) childNode.getUserObject();
|
|
|
|
|
childrenList.add(bean1.selectRev);
|
|
|
|
|
quantityList.add(bean1.line.getProperty("bl_quantity"));
|
|
|
|
|
// 判断是否发布
|
|
|
|
|
if (isRevBomReleased(bean1.selectRev)) {
|
|
|
|
|
// 发布就搭建原来的bom
|
|
|
|
|
System.out.println("原来搭建》》》》》》》》》》》》》》》");
|
|
|
|
|
if (isLoopBom(childNode)) {
|
|
|
|
|
MessageBox.post("存在循环BOM结构", "警告", MessageBox.WARNING);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
createMaterialBom(childNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
createBom(materialRev, childrenList, null, quantityList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TreePath findInPath(TreePath treePath, String str) {
|
|
|
|
|
Object object = treePath.getLastPathComponent();
|
|
|
|
|
if (object == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String value = object.toString();
|
|
|
|
|
if (str.equals(value)) {
|
|
|
|
|
return treePath;
|
|
|
|
|
} else {
|
|
|
|
|
TreeModel model = tree.getModel();
|
|
|
|
|
int n = model.getChildCount(object);
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
Object child = model.getChild(object, i);
|
|
|
|
|
TreePath path = treePath.pathByAddingChild(child);
|
|
|
|
|
path = findInPath(path, str);
|
|
|
|
|
if (path != null) {
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void findInTree(String str) {
|
|
|
|
|
Object root = tree.getModel().getRoot();
|
|
|
|
|
TreePath treePath = new TreePath(root);
|
|
|
|
|
treePath = findInPath(treePath, str);
|
|
|
|
|
if (treePath != null) {
|
|
|
|
|
tree.setSelectionPath(treePath);
|
|
|
|
|
CheckBoxTreeNode node = (CheckBoxTreeNode) tree.getLastSelectedPathComponent();
|
|
|
|
|
tree.scrollPathToVisible(treePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param line
|
|
|
|
|
* @param childNode
|
|
|
|
|
* @return 返回关联物料数组
|
|
|
|
|
*/
|
|
|
|
|
public String[] getBomRef(TCComponentBOMLine line, CheckBoxTreeNode childNode) {
|
|
|
|
|
try {
|
|
|
|
|
if (line == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
AIFComponentContext[] aifContext = line.getItemRevision().whereReferencedByTypeRelation(
|
|
|
|
|
types, new String[] { "TC_Is_Represented_By" });
|
|
|
|
|
if (aifContext == null || aifContext.length == 0) {
|
|
|
|
|
return new String[] { "" };
|
|
|
|
|
} else {
|
|
|
|
|
AIFComponentContext[] newContext = isNewRev(aifContext);
|
|
|
|
|
String[] wl = new String[newContext.length];
|
|
|
|
|
TransformBomBean bean = (TransformBomBean) childNode.getUserObject();
|
|
|
|
|
for (int i = 0; i < wl.length; i++) {
|
|
|
|
|
TCComponentItemRevision comp = (TCComponentItemRevision) newContext[i].getComponent();
|
|
|
|
|
wl[i] = comp.getProperty("object_string");
|
|
|
|
|
bean.map.put(wl[i], comp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return wl;
|
|
|
|
|
}
|
|
|
|
|
} catch (TCException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return new String[] { "" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 下拉框选择物料
|
|
|
|
|
*
|
|
|
|
|
* @param childLine
|
|
|
|
|
* @param childNode
|
|
|
|
|
*/
|
|
|
|
|
private void setCombox(TCComponentBOMLine childLine, final CheckBoxTreeNode childNode) {
|
|
|
|
|
try {
|
|
|
|
|
System.out.println(childLine.getItemRevision().getType() + "<<<<<<<<<<");
|
|
|
|
|
final String[] bomRef = getBomRef(childLine, childNode);
|
|
|
|
|
final DefaultComboBoxModel model = new DefaultComboBoxModel();
|
|
|
|
|
model.addElement("");
|
|
|
|
|
for (String str : bomRef) {
|
|
|
|
|
model.addElement(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final JComboBox<String> childbox = new JComboBox();
|
|
|
|
|
|
|
|
|
|
// 模糊搜索按钮
|
|
|
|
|
final JButton search = new JButton("搜索");
|
|
|
|
|
checkBoxTreeNodelMap.put(childNode, childbox);
|
|
|
|
|
boxJButtonMap.put(childbox, search);
|
|
|
|
|
childbox.setModel(model);
|
|
|
|
|
childbox.setSelectedIndex(-1);
|
|
|
|
|
childbox.setEditable(true);
|
|
|
|
|
|
|
|
|
|
if (childbox.getItemCount() <= 2 && !childbox.getItemAt(1).equals("")) {
|
|
|
|
|
childbox.setSelectedIndex(1);
|
|
|
|
|
childbox.setEditable(false);
|
|
|
|
|
childNode.setSelected(true);
|
|
|
|
|
search.setEnabled(false);
|
|
|
|
|
childbox.enable(false);
|
|
|
|
|
TransformBomBean bean = (TransformBomBean) childNode.getUserObject();
|
|
|
|
|
bean.selectRev = bean.map.get(childbox.getSelectedItem().toString());
|
|
|
|
|
} else if (childbox.getItemCount() <= 2) {
|
|
|
|
|
childbox.setEditable(false);
|
|
|
|
|
search.setEnabled(false);
|
|
|
|
|
childbox.enable(false);
|
|
|
|
|
}
|
|
|
|
|
if (childLine.getItemRevision().getType().equals("PartRevision")) {
|
|
|
|
|
childbox.setEditable(false);
|
|
|
|
|
search.setEnabled(false);
|
|
|
|
|
childNode.setSelected(true);
|
|
|
|
|
childbox.enable(false);
|
|
|
|
|
TransformBomBean bean = (TransformBomBean) childNode.getUserObject();
|
|
|
|
|
bean.selectRev = childLine.getItemRevision();
|
|
|
|
|
}
|
|
|
|
|
childbox.setPreferredSize(new Dimension(240, 23));
|
|
|
|
|
search.addMouseListener(new MouseAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
if (childbox.isEditable() && search.isEnabled()) {
|
|
|
|
|
String str = childbox.getEditor().getItem().toString();
|
|
|
|
|
model.removeAllElements();
|
|
|
|
|
model.addElement("");
|
|
|
|
|
for (int i = 0; i < bomRef.length; i++) {
|
|
|
|
|
if (bomRef[i].contains(str)) {
|
|
|
|
|
model.addElement(bomRef[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
childbox.setModel(model);
|
|
|
|
|
childbox.setPopupVisible(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
childbox.addItemListener(new ItemListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void itemStateChanged(ItemEvent e) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
try {
|
|
|
|
|
if (e.getStateChange() == 1) {
|
|
|
|
|
if (childbox.getSelectedIndex() > 0) {
|
|
|
|
|
TransformBomBean bean = (TransformBomBean) childNode.getUserObject();
|
|
|
|
|
bean.selectRev = bean.map.get(childbox.getSelectedItem().toString());
|
|
|
|
|
childNode.setSelected(true);
|
|
|
|
|
System.out.println("-----------" + bean.displayName);
|
|
|
|
|
// 判断是否布 发布子类全部不可选择
|
|
|
|
|
boolean released = isReleased(bean.selectRev, childNode);
|
|
|
|
|
System.out.println("<<<<<<<<<<是否发布:" + released);
|
|
|
|
|
tree.repaint();
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("<<<<<<<<<<选择空:");
|
|
|
|
|
restoreSelect(childNode);
|
|
|
|
|
childNode.setSelected(false);
|
|
|
|
|
tree.repaint();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (TCException e1) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e1.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
comboxList.add(childbox);
|
|
|
|
|
rightJPanel.add((index) + ".1.left.top", childbox);
|
|
|
|
|
rightJPanel.add((index++) + ".2.left.top", search);
|
|
|
|
|
|
|
|
|
|
} catch (TCException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否发布
|
|
|
|
|
*
|
|
|
|
|
* @param rev
|
|
|
|
|
* @param childNode
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean isReleased(TCComponentItemRevision rev, CheckBoxTreeNode childNode) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("执行判断" + rev.getProperty("object_name"));
|
|
|
|
|
if (rev != null && isRevBomReleased(rev)) {
|
|
|
|
|
setUnable(childNode);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
restoreSelect(childNode);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} catch (TCException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setUnable(CheckBoxTreeNode childNode) {
|
|
|
|
|
int childCount = childNode.getChildCount();
|
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
|
CheckBoxTreeNode node = (CheckBoxTreeNode) childNode.getChildAt(i);
|
|
|
|
|
JComboBox<String> box = checkBoxTreeNodelMap.get(node);
|
|
|
|
|
box.setSelectedIndex(-1);
|
|
|
|
|
box.setEditable(false);
|
|
|
|
|
box.setEnabled(false);
|
|
|
|
|
node.setSelected(false);
|
|
|
|
|
boxJButtonMap.get(box).setEnabled(false);
|
|
|
|
|
setUnable(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 复原
|
|
|
|
|
*
|
|
|
|
|
* @param childNode
|
|
|
|
|
* @throws TCException
|
|
|
|
|
*/
|
|
|
|
|
private void restoreSelect(CheckBoxTreeNode childNode) throws TCException {
|
|
|
|
|
int childCount = childNode.getChildCount();
|
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
|
CheckBoxTreeNode node = (CheckBoxTreeNode) childNode.getChildAt(i);
|
|
|
|
|
JComboBox<String> childbox = checkBoxTreeNodelMap.get(node);
|
|
|
|
|
TransformBomBean bean = (TransformBomBean) node.getUserObject();
|
|
|
|
|
childbox.setEditable(true);
|
|
|
|
|
childbox.setEnabled(true);
|
|
|
|
|
childbox.setSelectedIndex(-1);
|
|
|
|
|
if (childbox.getItemCount() <= 2 && !childbox.getItemAt(1).equals("")) {
|
|
|
|
|
childbox.setSelectedIndex(1);
|
|
|
|
|
childbox.setEditable(false);
|
|
|
|
|
childbox.setEnabled(false);
|
|
|
|
|
node.setSelected(true);
|
|
|
|
|
boxJButtonMap.get(childbox).setEnabled(false);
|
|
|
|
|
bean.selectRev = bean.map.get(childbox.getSelectedItem().toString());
|
|
|
|
|
} else if (childbox.getItemCount() <= 2) {
|
|
|
|
|
childbox.setEditable(false);
|
|
|
|
|
childbox.setEnabled(false);
|
|
|
|
|
boxJButtonMap.get(childbox).setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
if (bean.line.getItemRevision().isTypeOf("PartRevision")) {
|
|
|
|
|
childbox.setEditable(false);
|
|
|
|
|
boxJButtonMap.get(childbox).setEnabled(false);
|
|
|
|
|
node.setSelected(true);
|
|
|
|
|
childbox.setEnabled(false);
|
|
|
|
|
bean.selectRev = bean.line.getItemRevision();
|
|
|
|
|
}
|
|
|
|
|
restoreSelect(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否为最新版本 剔除旧版本
|
|
|
|
|
*
|
|
|
|
|
* @param aifContext
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private AIFComponentContext[] isNewRev(AIFComponentContext[] aifContext) {
|
|
|
|
|
try {
|
|
|
|
|
List<AIFComponentContext> list = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < aifContext.length; i++) {
|
|
|
|
|
TCComponentItemRevision rev = (TCComponentItemRevision) aifContext[i].getComponent();
|
|
|
|
|
if (rev.getItem().getLatestItemRevision().equals(rev)) {
|
|
|
|
|
list.add(aifContext[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AIFComponentContext[] newContext = new AIFComponentContext[list.size()];
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
newContext[i] = list.get(i);
|
|
|
|
|
}
|
|
|
|
|
return newContext;
|
|
|
|
|
} catch (TCException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断循环
|
|
|
|
|
* @param node
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean isLoopBom(CheckBoxTreeNode node) {
|
|
|
|
|
try {
|
|
|
|
|
HashSet<TCComponentItemRevision> loopSet = new HashSet<>();
|
|
|
|
|
boolean checkLoop = checkLoop(node, loopSet);
|
|
|
|
|
return checkLoop;
|
|
|
|
|
} catch (TCException e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 向上找父类,判断是否有相同的物料
|
|
|
|
|
* @param node
|
|
|
|
|
* @param loopSet
|
|
|
|
|
* @return
|
|
|
|
|
* @throws TCException
|
|
|
|
|
*/
|
|
|
|
|
private boolean checkLoop(CheckBoxTreeNode node, HashSet<TCComponentItemRevision> loopSet) throws TCException {
|
|
|
|
|
TransformBomBean bean = (TransformBomBean) node.getUserObject();
|
|
|
|
|
TCComponentItemRevision materialRev = bean.selectRev;
|
|
|
|
|
boolean add = loopSet.add(materialRev);
|
|
|
|
|
if (!add) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
CheckBoxTreeNode parent = (CheckBoxTreeNode) node.getParent();
|
|
|
|
|
if (parent == null) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return checkLoop(parent, loopSet);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void getAllBomItemByBomline(TCComponentBOMLine line, List<TCComponentItem> itemList)
|
|
|
|
|
throws TCException {
|
|
|
|
|
if (line == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
itemList.add(line.getItem());
|
|
|
|
|
AIFComponentContext[] contextS = line.getChildren();
|
|
|
|
|
for (AIFComponentContext context : contextS) {
|
|
|
|
|
TCComponentBOMLine child = (TCComponentBOMLine) context.getComponent();
|
|
|
|
|
getAllBomItemByBomline(child, itemList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 搭建bom
|
|
|
|
|
*
|
|
|
|
|
* @param selectIndex
|
|
|
|
|
* @throws TCException
|
|
|
|
|
*/
|
|
|
|
|
public void createBom(TCComponentItemRevision parentRev, List<TCComponentItemRevision> childRevList,
|
|
|
|
|
List<String> queryNoList, List<String> countNoList) throws TCException {
|
|
|
|
|
if (childRevList == null || childRevList.size() == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (parentRev == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String[] setProps = { "bl_quantity" };
|
|
|
|
|
TCComponentBOMLine line = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null);
|
|
|
|
|
AIFComponentContext[] childrenContext = line.getChildren();
|
|
|
|
|
|
|
|
|
|
win.lock();
|
|
|
|
|
// 移出所有的子bomline
|
|
|
|
|
if (childrenContext.length != 0) {
|
|
|
|
|
for (AIFComponentContext child : childrenContext) {
|
|
|
|
|
line.lock();
|
|
|
|
|
line.remove("", (TCComponent) child.getComponent());
|
|
|
|
|
line.save();
|
|
|
|
|
line.unlock();
|
|
|
|
|
}
|
|
|
|
|
// return;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < childRevList.size(); i++) {
|
|
|
|
|
TCComponentItemRevision rev = childRevList.get(i);
|
|
|
|
|
line.lock();
|
|
|
|
|
TCComponentBOMLine childBomLine = line.add(rev.getItem(), rev, null, false, "");
|
|
|
|
|
line.save();
|
|
|
|
|
line.unlock();
|
|
|
|
|
|
|
|
|
|
if (countNoList.get(i) != null && !countNoList.get(i).equals("")) {
|
|
|
|
|
childBomLine.lock();
|
|
|
|
|
childBomLine.setProperties(setProps, new String[] { countNoList.get(i) });
|
|
|
|
|
childBomLine.save();
|
|
|
|
|
childBomLine.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
win.save();
|
|
|
|
|
win.unlock();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查对象是否已经发布
|
|
|
|
|
*
|
|
|
|
|
* @param comp
|
|
|
|
|
* @return
|
|
|
|
|
* @throws TCException
|
|
|
|
|
*/
|
|
|
|
|
public boolean isCompReleased(TCComponent comp) throws TCException {
|
|
|
|
|
TCComponent[] comps = comp.getRelatedComponents("release_status_list");
|
|
|
|
|
if (comps != null && comps.length > 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 是否有BOM
|
|
|
|
|
*
|
|
|
|
|
* @param rev
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean isRevHadBom(TCComponentItemRevision rev) {
|
|
|
|
|
boolean isHad = false;
|
|
|
|
|
if (rev != null) {
|
|
|
|
|
try {
|
|
|
|
|
TCComponentBOMLine topLine = win.setWindowTopLine(rev.getItem(), rev, null, null);
|
|
|
|
|
if (topLine != null) {
|
|
|
|
|
if (topLine.getChildren().length > 0) {
|
|
|
|
|
isHad = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (TCException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return isHad;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断已经发布的对象是否有BOM
|
|
|
|
|
*
|
|
|
|
|
* @param rev
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean isRevBomReleased(TCComponentItemRevision rev) {
|
|
|
|
|
boolean isReleased = false;
|
|
|
|
|
try {
|
|
|
|
|
if (isCompReleased(rev)) {
|
|
|
|
|
win.setWindowTopLine(rev.getItem(), rev, null, null);
|
|
|
|
|
// TCComponentBOMLine line = window.getTopBOMLine();
|
|
|
|
|
// if(line.getChildren().length!=0){
|
|
|
|
|
// isReleased = true;
|
|
|
|
|
// }
|
|
|
|
|
if ( isRevHadBom(rev)) {
|
|
|
|
|
TCComponentBOMViewRevision bvr = win.askBvr();
|
|
|
|
|
if (bvr != null) {
|
|
|
|
|
TCComponent[] status = bvr.getReferenceListProperty("release_status_list");
|
|
|
|
|
if (status != null && status.length != 0) {
|
|
|
|
|
isReleased = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (TCException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
isReleased = true;
|
|
|
|
|
}
|
|
|
|
|
return isReleased;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|