package com.connor.jd.plm.dialogs;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.RowSorter;
import javax.swing.filechooser.FileSystemView;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;

import com.connor.jd.plm.beans.BOMLogBean;
import com.connor.jd.plm.beans.BOMManageTableBean;
import com.connor.jd.plm.beans.CheckBoxPo;
import com.connor.jd.plm.beans.CustomLovBean;
import com.connor.jd.plm.beans.ResultData;
import com.connor.jd.plm.table.MyCellEditor4;
import com.connor.jd.plm.table.MyCellRenderer;
import com.connor.jd.plm.utils.DBConnectionUtil;
import com.connor.jd.plm.utils.DBUtil;
import com.connor.jd.plm.utils.DatePickerUtil;
import com.connor.jd.plm.utils.DialogUtil;
import com.connor.jd.plm.utils.JDMethodUtil;
import com.connor.jd.plm.utils.KeyValComboBox;
import com.connor.jd.plm.utils.StringCreateUtil;
import com.eltima.components.ui.DatePicker;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentBOMWindow;
import com.teamcenter.rac.kernel.TCComponentBOMWindowType;
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.workflow.commands.newprocess.NewProcessCommand;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.sql.Condition;

public class BOMManagementFrame extends JFrame {
	private AbstractAIFApplication app;
	private TCSession session;
	private CardLayout rootSwitch = new CardLayout();
	private String[] colDisplayNames = new String[] { "ѡ", "", "Ӽ", "λ", "", "״̬" };
	private String[] colDisplayNames2 = new String[] { "", "޸û", "ʱ", "" };
	private JPanel root;
	private Map<String, BOMManageTableBean> tableDataMap = new HashMap<String, BOMManageTableBean>();
	private BOMManagementFrame $this;
	private List<Entity> logDataList;
	private Map<String, TCComponentBOMWindow> winMap = new HashMap<String, TCComponentBOMWindow>();
	private TCComponentItemRevision targetRev;
	private TCComponentItemRevision targetRev2;
	private boolean isLogcreated = false;
	private int doIndex = 0;
	private boolean complate = false;
	private List<String> checkItemType = new ArrayList<String>();
	private JButton[] topBtns;
	private TCComponentBOMWindowType winType;
	private int width = 1200;
	private int height = 800;
	private int widthOffset = 0;
	private int heightOffset = 0;
	private JLabel p1TargetLabel;
	private JButton p1TargetBtn;
	private JLabel p1ReplaceLabel;
	private JButton p1ReplaceBtn;
	private JLabel p1UnitLabel;
	private KeyValComboBox p1UnitCombo;
	private JLabel p1NumLabel;
	private JTextField p1NumText;
	private JCheckBox p1SelectAll;
	private JTable p1Table;
	private JScrollPane p1jsp;
	private JButton p1BottomBtn1;
	private JButton p1BottomBtn2;
	private JButton p1BottomBtn3;
	private JButton p1BottomBtn4;
	private JPanel p1Left;
	private JScrollPane p1TreePanel;
	private JPanel p1Right;
	private JLabel p2TargetLabel;
	private JButton p2TargetBtn;
	private JLabel p2ChangeNumLabel;
	private JTextField p2NumText;
	private JCheckBox p2SelectAll;
	private JTable p2Table;
	private JScrollPane p2jsp;
	private JButton p2BottomBtn1;
	private JButton p2BottomBtn2;
	private JButton p2BottomBtn3;
	private JButton p2BottomBtn4;
	private JPanel p2Left;
	private JScrollPane p2TreePanel;
	private JPanel p2Right;
	private JLabel p3TargetLabel;
	private JButton p3TargetBtn;
	private JLabel p3AddLabel;
	private JButton p3AddBtn;
	private JLabel p3UnitLabel;
	private KeyValComboBox p3UnitCombo;
	private JLabel p3NumLabel;
	private JTextField p3NumText;
	private JCheckBox p3SelectAll;
	private JTable p3Table;
	private JScrollPane p3jsp;
	private JButton p3BottomBtn1;
	private JButton p3BottomBtn2;
	private JButton p3BottomBtn3;
	private JButton p3BottomBtn4;
	private JPanel p3Left;
	private JScrollPane p3TreePanel;
	private JPanel p3Right;
	private JLabel p4TargetLabel;
	private JButton p4TargetBtn;
	private JCheckBox p4SelectAll;
	private JTable p4Table;
	private JScrollPane p4jsp;
	private JButton p4BottomBtn1;
	private JButton p4BottomBtn2;
	private JButton p4BottomBtn3;
	private JButton p4BottomBtn4;
	private JPanel p4Left;
	private JScrollPane p4TreePanel;
	private JPanel p4Right;
	private JLabel p5UserLabel;
	private JTextField p5UserText;
	private JLabel p5TimeLabel;
	private DatePicker p5TimeStartText;
	private JLabel toLabel;
	private DatePicker p5TimeEndText;
	private JLabel p5ContentLabel;
	private JTextArea p5ContentText;
	private JScrollPane p5Contentjsp;
	private JButton p5Search;
	private JButton p5Download;
	private JTable p5Table;
	private JScrollPane p5jsp;
	private Map<String, int[]> uiSize = new HashMap<>();
	private JPanel p1;
	private JPanel p2;
	private JPanel p3;
	private JPanel p4;
	private JPanel p5;
	private Set<TCComponentItemRevision> addedBOMLine = new HashSet<>();

	public BOMManagementFrame(AbstractAIFApplication app) {
		super();
		this.app = app;
		this.session = (TCSession) app.getSession();
		$this = this;
		String[] prefArray = JDMethodUtil.getPrefStrArray("connor_bom_check_type", session);
		if (prefArray != null) {
			checkItemType = Arrays.asList(prefArray);
		}
		TCTypeService service = session.getTypeService();
		try {
			this.winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow");
		} catch (TCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		init();
	}

	private void init() {
		this.setTitle("BOM");
		this.setSize(new Dimension(1200, 800));
		this.setLayout(new BorderLayout());
		this.setResizable(true);
		this.setAlwaysOnTop(true);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setLocationRelativeTo(null);
		this.addComponentListener(new ComponentAdapter() {
			@Override
			public void componentResized(ComponentEvent e) {
				// TODO Auto-generated method stub
				super.componentResized(e);
				Component comp = e.getComponent();
				$this.widthOffset = comp.getWidth() - $this.width;
				$this.heightOffset = comp.getHeight() - $this.height;
				if ($this.widthOffset != 0 || $this.heightOffset != 0) {
					System.out.println("width===>" + comp.getWidth());
					System.out.println("height===>" + comp.getHeight());
					$this.width = comp.getWidth();
					$this.height = comp.getHeight();
					$this.resize();
				}
			}
		});
		this.addFocusListener(new FocusListener() {

			@Override
			public void focusLost(FocusEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void focusGained(FocusEvent e) {
				// TODO Auto-generated method stub
				$this.setAlwaysOnTop(true);
			}
		});

		Container container = this.getContentPane();
		container.setLayout(new BorderLayout());
		container.setSize(new Dimension(1200, 800));

		TCTypeService typeService = session.getTypeService();
		Vector<CheckBoxPo> unitVector = new Vector<CheckBoxPo>();
		try {
			TCComponent[] uomArray = typeService.getTypeComponent("UnitOfMeasure").extent();
			unitVector.add(new CheckBoxPo(" ", " "));
			for (TCComponent comp : uomArray) {
				unitVector.add(new CheckBoxPo(comp.toString(), comp));
			}

		} catch (TCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// ͷ
		JPanel topBtnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		topBtns = new JButton[5];
		topBtns[0] = new JButton("滻");
		topBtns[1] = new JButton("");
		topBtns[2] = new JButton("");
		topBtns[3] = new JButton("ɾ");
		topBtns[4] = new JButton("־");
//		topBtns[5] = new JButton("԰ť");
		topBtns[0].setSelected(true);
		for (JButton btn : topBtns) {
			topBtnPanel.add(btn);
			btn.addActionListener(panelSwitch());
		}
		container.add(topBtnPanel, BorderLayout.NORTH);

		// root
		root = new JPanel(rootSwitch);

		// 滻
		p1 = new JPanel();
		p1.setLayout(null);

		// 滻
		p1Left = new JPanel();
		p1Left.setLayout(null);
		p1Left.setBounds(0, 0, 800, 800);
		p1Left.setBorder(BorderFactory.createEtchedBorder());

		p1TargetLabel = new JLabel("Ŀϱ");
		p1TargetLabel.setBounds(20, 20, 100, 25);
		p1TargetBtn = new JButton();
		p1TargetBtn.setBounds(130, 20, 400, 25);
		p1ReplaceLabel = new JLabel("滻ϱ");
		p1ReplaceLabel.setBounds(20, 60, 100, 25);
		p1ReplaceBtn = new JButton();
		p1ReplaceBtn.setBounds(130, 60, 400, 25);
		p1UnitLabel = new JLabel("λ");
		p1UnitLabel.setBounds(560, 60, 50, 25);
		p1UnitCombo = new KeyValComboBox(unitVector);
		p1UnitCombo.setBounds(610, 60, 50, 25);
		p1NumLabel = new JLabel("");
		p1NumLabel.setBounds(680, 60, 50, 25);
		p1NumText = new JTextField();
		p1NumText.setBounds(730, 60, 50, 25);
		p1SelectAll = new JCheckBox("ȫѡ");
		p1SelectAll.setBounds(20, 100, 100, 25);
		DefaultTableModel p1model = new DefaultTableModel(colDisplayNames, 0) {
			@Override
			public boolean isCellEditable(int paramInt1, int paramInt2) {
				if (paramInt2 == 0) {
					return true;
				}
				return false;
			}

			@Override
			public Class<?> getColumnClass(int paramInt) {
				// TODO Auto-generated method stub
				if (paramInt == 0) {
					return Integer.class;
				}
				return super.getColumnClass(paramInt);
			}
		};
		p1Table = new JTable(p1model);
		p1Table.getColumnModel().getColumn(0).setMinWidth(60);
		p1Table.getColumnModel().getColumn(0).setMaxWidth(60);
		p1Table.getColumnModel().getColumn(1).setMinWidth(200);
		p1Table.getColumnModel().getColumn(2).setMinWidth(200);
		p1Table.getColumnModel().getColumn(3).setMinWidth(100);
		p1Table.getColumnModel().getColumn(4).setMinWidth(100);
		p1Table.getColumnModel().getColumn(5).setMinWidth(100);
		p1Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer());
		p1Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField()));
		p1Table.setRowHeight(25);
		p1Table.setAutoscrolls(true);
		p1Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		p1Table.getTableHeader().setReorderingAllowed(false);
		p1Table.putClientProperty("terminateEditOnFocusLost", true);
		RowSorter<DefaultTableModel> p1sorter = new TableRowSorter<DefaultTableModel>(p1model);
		p1Table.setRowSorter(p1sorter);
		p1jsp = new JScrollPane(p1Table);
		p1jsp.setBounds(20, 130, 760, 500);

		p1BottomBtn1 = new JButton("");
		p1BottomBtn1.setBounds(80, 650, 100, 25);
		p1BottomBtn2 = new JButton("滻");
		p1BottomBtn2.setBounds(260, 650, 100, 25);
		p1BottomBtn3 = new JButton("");
		p1BottomBtn3.setBounds(440, 650, 100, 25);
		p1BottomBtn4 = new JButton("ȡ");
		p1BottomBtn4.setBounds(620, 650, 100, 25);

		p1Left.add(p1TargetLabel);
		p1Left.add(p1TargetBtn);
		p1Left.add(p1ReplaceLabel);
		p1Left.add(p1ReplaceBtn);
		p1Left.add(p1UnitLabel);
		p1Left.add(p1UnitCombo);
		p1Left.add(p1NumLabel);
		p1Left.add(p1NumText);
		p1Left.add(p1SelectAll);
		p1Left.add(p1jsp);
		p1Left.add(p1BottomBtn1);
		p1Left.add(p1BottomBtn2);
		p1Left.add(p1BottomBtn3);
		p1Left.add(p1BottomBtn4);

		// 滻ұ
		p1Right = new JPanel();
		p1Right.setLayout(null);
		p1Right.setBounds(800, 0, 400, 800);
		p1Right.setBorder(BorderFactory.createEtchedBorder());

		p1TreePanel = new JScrollPane();
		p1TreePanel.setBounds(20, 130, 360, 500);
		p1Right.add(p1TreePanel);

		// ¼
		p1SelectAll.addItemListener(selectAll(p1Table));
		p1Table.addMouseListener(showTree(p1Right));
		p1BottomBtn4.addActionListener(cancel());
		p1BottomBtn1.addActionListener(batchRevise(p1Table, p1SelectAll));
		p1BottomBtn2.addActionListener(batchReplace());
		p1BottomBtn3.addActionListener(startWorkFlow(p1Table));
		p1TargetBtn.addActionListener(clickSearch(p1Table, p1SelectAll));
		p1ReplaceBtn.addActionListener(clickSearch(null, null));

		p1.add(p1Left);
		p1.add(p1Right);

		// 
		p2 = new JPanel();
		p2.setLayout(null);

		// 
		p2Left = new JPanel();
		p2Left.setLayout(null);
		p2Left.setBounds(0, 0, 800, 800);
		p2Left.setBorder(BorderFactory.createEtchedBorder());

		p2TargetLabel = new JLabel("Ŀϱ");
		p2TargetLabel.setBounds(20, 20, 100, 25);
		p2TargetBtn = new JButton();
		p2TargetBtn.setBounds(130, 20, 400, 25);
		p2ChangeNumLabel = new JLabel("");
		p2ChangeNumLabel.setBounds(20, 60, 100, 25);
		p2NumText = new JTextField();
		p2NumText.setBounds(130, 60, 50, 25);

		p2SelectAll = new JCheckBox("ȫѡ");
		p2SelectAll.setBounds(20, 100, 100, 25);
		DefaultTableModel p2model = new DefaultTableModel(colDisplayNames, 0) {
			@Override
			public boolean isCellEditable(int paramInt1, int paramInt2) {
				if (paramInt2 == 0) {
					return true;
				}
				return false;
			}

			@Override
			public Class<?> getColumnClass(int paramInt) {
				// TODO Auto-generated method stub
				if (paramInt == 0) {
					return Integer.class;
				}
				return super.getColumnClass(paramInt);
			}
		};
		p2Table = new JTable(p2model);
		p2Table.getColumnModel().getColumn(0).setMinWidth(60);
		p2Table.getColumnModel().getColumn(0).setMaxWidth(60);
		p2Table.getColumnModel().getColumn(1).setMinWidth(200);
		p2Table.getColumnModel().getColumn(2).setMinWidth(200);
		p2Table.getColumnModel().getColumn(3).setMinWidth(100);
		p2Table.getColumnModel().getColumn(4).setMinWidth(100);
		p2Table.getColumnModel().getColumn(5).setMinWidth(100);
		p2Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer());
		p2Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField()));
		p2Table.setRowHeight(25);
		p2Table.setAutoscrolls(true);
		p2Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		p2Table.getTableHeader().setReorderingAllowed(false);
		p2Table.putClientProperty("terminateEditOnFocusLost", true);
		RowSorter<DefaultTableModel> p2sorter = new TableRowSorter<DefaultTableModel>(p2model);
		p2Table.setRowSorter(p2sorter);
		p2jsp = new JScrollPane(p2Table);
		p2jsp.setBounds(20, 130, 760, 500);

		p2BottomBtn1 = new JButton("");
		p2BottomBtn1.setBounds(80, 650, 100, 25);
		p2BottomBtn2 = new JButton("");
		p2BottomBtn2.setBounds(260, 650, 100, 25);
		p2BottomBtn3 = new JButton("");
		p2BottomBtn3.setBounds(440, 650, 100, 25);
		p2BottomBtn4 = new JButton("ȡ");
		p2BottomBtn4.setBounds(620, 650, 100, 25);

		p2Left.add(p2TargetLabel);
		p2Left.add(p2TargetBtn);
		p2Left.add(p2ChangeNumLabel);
		p2Left.add(p2NumText);
		p2Left.add(p2SelectAll);
		p2Left.add(p2jsp);
		p2Left.add(p2BottomBtn1);
		p2Left.add(p2BottomBtn2);
		p2Left.add(p2BottomBtn3);
		p2Left.add(p2BottomBtn4);

		// ұ
		p2Right = new JPanel();
		p2Right.setLayout(null);
		p2Right.setBounds(800, 0, 400, 800);
		p2Right.setBorder(BorderFactory.createEtchedBorder());

		p2TreePanel = new JScrollPane();
		p2TreePanel.setBounds(20, 130, 360, 500);
		p2Right.add(p2TreePanel);

		// ¼
		p2SelectAll.addItemListener(selectAll(p2Table));
		p2Table.addMouseListener(showTree(p2Right));
		p2BottomBtn4.addActionListener(cancel());
		p2BottomBtn1.addActionListener(batchRevise(p2Table, p2SelectAll));
		p2BottomBtn2.addActionListener(batchModify());
		p2BottomBtn3.addActionListener(startWorkFlow(p2Table));
		p2TargetBtn.addActionListener(clickSearch(p2Table, p2SelectAll));

		p2.add(p2Left);
		p2.add(p2Right);

		// 
		p3 = new JPanel();
		p3.setLayout(null);

		// 
		p3Left = new JPanel();
		p3Left.setLayout(null);
		p3Left.setBounds(0, 0, 800, 800);
		p3Left.setBorder(BorderFactory.createEtchedBorder());

		p3TargetLabel = new JLabel("οϱ");
		p3TargetLabel.setBounds(20, 20, 100, 25);
		p3TargetBtn = new JButton();
		p3TargetBtn.setBounds(130, 20, 400, 25);
		p3AddLabel = new JLabel("ϱ");
		p3AddLabel.setBounds(20, 60, 100, 25);
		p3AddBtn = new JButton();
		p3AddBtn.setBounds(130, 60, 400, 25);
		p3UnitLabel = new JLabel("λ");
		p3UnitLabel.setBounds(560, 60, 50, 25);
		p3UnitCombo = new KeyValComboBox(unitVector);
		p3UnitCombo.setBounds(610, 60, 50, 25);
		p3NumLabel = new JLabel("");
		p3NumLabel.setBounds(680, 60, 50, 25);
		p3NumText = new JTextField();
		p3NumText.setBounds(730, 60, 50, 25);

		p3SelectAll = new JCheckBox("ȫѡ");
		p3SelectAll.setBounds(20, 100, 100, 25);
		DefaultTableModel p3model = new DefaultTableModel(colDisplayNames, 0) {
			@Override
			public boolean isCellEditable(int paramInt1, int paramInt2) {
				if (paramInt2 == 0) {
					return true;
				}
				return false;
			}

			@Override
			public Class<?> getColumnClass(int paramInt) {
				// TODO Auto-generated method stub
				if (paramInt == 0) {
					return Integer.class;
				}
				return super.getColumnClass(paramInt);
			}
		};
		p3Table = new JTable(p3model);
		p3Table.getColumnModel().getColumn(0).setMinWidth(60);
		p3Table.getColumnModel().getColumn(0).setMaxWidth(60);
		p3Table.getColumnModel().getColumn(1).setMinWidth(200);
		p3Table.getColumnModel().getColumn(2).setMinWidth(200);
		p3Table.getColumnModel().getColumn(3).setMinWidth(100);
		p3Table.getColumnModel().getColumn(4).setMinWidth(100);
		p3Table.getColumnModel().getColumn(5).setMinWidth(100);
		p3Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer());
		p3Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField()));
		p3Table.setRowHeight(25);
		p3Table.setAutoscrolls(true);
		p3Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		p3Table.getTableHeader().setReorderingAllowed(false);
		p3Table.putClientProperty("terminateEditOnFocusLost", true);
		RowSorter<DefaultTableModel> p3sorter = new TableRowSorter<DefaultTableModel>(p3model);
		p3Table.setRowSorter(p3sorter);
		p3jsp = new JScrollPane(p3Table);
		p3jsp.setBounds(20, 130, 760, 500);

		p3BottomBtn1 = new JButton("");
		p3BottomBtn1.setBounds(80, 650, 100, 25);
		p3BottomBtn2 = new JButton("");
		p3BottomBtn2.setBounds(260, 650, 100, 25);
		p3BottomBtn3 = new JButton("");
		p3BottomBtn3.setBounds(440, 650, 100, 25);
		p3BottomBtn4 = new JButton("ȡ");
		p3BottomBtn4.setBounds(620, 650, 100, 25);

		p3Left.add(p3TargetLabel);
		p3Left.add(p3TargetBtn);
		p3Left.add(p3AddLabel);
		p3Left.add(p3AddBtn);
		p3Left.add(p3UnitLabel);
		p3Left.add(p3UnitCombo);
		p3Left.add(p3NumLabel);
		p3Left.add(p3NumText);
		p3Left.add(p3SelectAll);
		p3Left.add(p3jsp);
		p3Left.add(p3BottomBtn1);
		p3Left.add(p3BottomBtn2);
		p3Left.add(p3BottomBtn3);
		p3Left.add(p3BottomBtn4);

		// ұ
		p3Right = new JPanel();
		p3Right.setLayout(null);
		p3Right.setBounds(800, 0, 400, 800);
		p3Right.setBorder(BorderFactory.createEtchedBorder());

		p3TreePanel = new JScrollPane();
		p3TreePanel.setBounds(20, 130, 360, 500);
		p3Right.add(p3TreePanel);

		// ¼
		p3SelectAll.addItemListener(selectAll(p3Table));
		p3Table.addMouseListener(showTree(p3Right));
		p3BottomBtn4.addActionListener(cancel());
		p3BottomBtn1.addActionListener(batchRevise(p3Table, p3SelectAll));
		p3BottomBtn2.addActionListener(batchAdd());
		p3BottomBtn3.addActionListener(startWorkFlow(p3Table));
		p3TargetBtn.addActionListener(clickSearch(p3Table, p3SelectAll));
		p3AddBtn.addActionListener(clickSearch(null, null));

		p3.add(p3Left);
		p3.add(p3Right);

		// ɾ
		p4 = new JPanel();
		p4.setLayout(null);

		// ɾ
		p4Left = new JPanel();
		p4Left.setLayout(null);
		p4Left.setBounds(0, 0, 800, 800);
		p4Left.setBorder(BorderFactory.createEtchedBorder());

		p4TargetLabel = new JLabel("Ŀϱ");
		p4TargetLabel.setBounds(20, 20, 100, 25);
		p4TargetBtn = new JButton();
		p4TargetBtn.setBounds(130, 20, 400, 25);

		p4SelectAll = new JCheckBox("ȫѡ");
		p4SelectAll.setBounds(20, 100, 100, 25);
		DefaultTableModel p4model = new DefaultTableModel(colDisplayNames, 0) {
			@Override
			public boolean isCellEditable(int paramInt1, int paramInt2) {
				if (paramInt2 == 0) {
					return true;
				}
				return false;
			}

			@Override
			public Class<?> getColumnClass(int paramInt) {
				// TODO Auto-generated method stub
				if (paramInt == 0) {
					return Integer.class;
				}
				return super.getColumnClass(paramInt);
			}
		};
		p4Table = new JTable(p4model);
		p4Table.getColumnModel().getColumn(0).setMinWidth(60);
		p4Table.getColumnModel().getColumn(0).setMaxWidth(60);
		p4Table.getColumnModel().getColumn(1).setMinWidth(200);
		p4Table.getColumnModel().getColumn(2).setMinWidth(200);
		p4Table.getColumnModel().getColumn(3).setMinWidth(100);
		p4Table.getColumnModel().getColumn(4).setMinWidth(100);
		p4Table.getColumnModel().getColumn(5).setMinWidth(100);
		p4Table.getColumnModel().getColumn(0).setCellRenderer(new MyCellRenderer());
		p4Table.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor4(new JTextField()));
		p4Table.setRowHeight(25);
		p4Table.setAutoscrolls(true);
		p4Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		p4Table.getTableHeader().setReorderingAllowed(false);
		p4Table.putClientProperty("terminateEditOnFocusLost", true);
		RowSorter<DefaultTableModel> p4sorter = new TableRowSorter<DefaultTableModel>(p4model);
		p4Table.setRowSorter(p4sorter);
		p4jsp = new JScrollPane(p4Table);
		p4jsp.setBounds(20, 130, 760, 500);

		p4BottomBtn1 = new JButton("");
		p4BottomBtn1.setBounds(80, 650, 100, 25);
		p4BottomBtn2 = new JButton("ɾ");
		p4BottomBtn2.setBounds(260, 650, 100, 25);
		p4BottomBtn3 = new JButton("");
		p4BottomBtn3.setBounds(440, 650, 100, 25);
		p4BottomBtn4 = new JButton("ȡ");
		p4BottomBtn4.setBounds(620, 650, 100, 25);

		p4Left.add(p4TargetLabel);
		p4Left.add(p4TargetBtn);
		p4Left.add(p4SelectAll);
		p4Left.add(p4jsp);
		p4Left.add(p4BottomBtn1);
		p4Left.add(p4BottomBtn2);
		p4Left.add(p4BottomBtn3);
		p4Left.add(p4BottomBtn4);

		// ұ
		p4Right = new JPanel();
		p4Right.setLayout(null);
		p4Right.setBounds(800, 0, 400, 800);
		p4Right.setBorder(BorderFactory.createEtchedBorder());

		p4TreePanel = new JScrollPane();
		p4TreePanel.setBounds(20, 130, 360, 500);
		p4Right.add(p4TreePanel);

		// ¼
		p4SelectAll.addItemListener(selectAll(p4Table));
		p4Table.addMouseListener(showTree(p4Right));
		p4BottomBtn4.addActionListener(cancel());
		p4BottomBtn1.addActionListener(batchRevise(p4Table, p4SelectAll));
		p4BottomBtn2.addActionListener(batchRemove());
		p4BottomBtn3.addActionListener(startWorkFlow(p4Table));
		p4TargetBtn.addActionListener(clickSearch(p4Table, p4SelectAll));

		p4.add(p4Left);
		p4.add(p4Right);

		// ־
		p5 = new JPanel();
		p5.setLayout(null);

		p5UserLabel = new JLabel("޸û");
		p5UserLabel.setBounds(20, 40, 70, 25);
		p5UserText = new JTextField();
		p5UserText.setBounds(100, 40, 150, 25);
		p5TimeLabel = new JLabel("޸ʱ");
		p5TimeLabel.setBounds(300, 40, 70, 25);
		p5TimeStartText = DatePickerUtil.getDatePicker(null);
		p5TimeStartText.setBounds(380, 40, 100, 25);
		toLabel = new JLabel("");
		toLabel.setBounds(490, 40, 20, 25);
		p5TimeEndText = DatePickerUtil.getDatePicker(null);
		p5TimeEndText.setBounds(520, 40, 100, 25);
		p5ContentLabel = new JLabel("޸");
		p5ContentLabel.setBounds(670, 40, 70, 25);
		p5ContentText = new JTextArea();
		p5ContentText.setLineWrap(true);
		p5ContentText.setWrapStyleWord(true);
		p5Contentjsp = new JScrollPane(p5ContentText);
		p5Contentjsp.setBounds(750, 20, 200, 80);
		p5Search = new JButton("");
		p5Search.setBounds(1000, 40, 60, 25);
		p5Download = new JButton("־");
		p5Download.setBounds(1080, 40, 100, 25);

		DefaultTableModel p5model = new DefaultTableModel(colDisplayNames2, 0) {
			@Override
			public boolean isCellEditable(int paramInt1, int paramInt2) {
				return false;
			}

			@Override
			public Class<?> getColumnClass(int paramInt) {
				// TODO Auto-generated method stub
				if (paramInt == 0) {
					return Integer.class;
				}
				return super.getColumnClass(paramInt);
			}
		};
		p5Table = new JTable(p5model);
		p5Table.getColumnModel().getColumn(0).setMinWidth(60);
		p5Table.getColumnModel().getColumn(0).setMaxWidth(60);
		p5Table.getColumnModel().getColumn(1).setMinWidth(200);
		p5Table.getColumnModel().getColumn(2).setMinWidth(200);
		p5Table.getColumnModel().getColumn(3).setMinWidth(700);
		p5Table.setRowHeight(25);
		p5Table.setAutoscrolls(true);
		p5Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		p5Table.getTableHeader().setReorderingAllowed(false);
		RowSorter<DefaultTableModel> p5sorter = new TableRowSorter<DefaultTableModel>(p5model);
		p5Table.setRowSorter(p5sorter);
		p5jsp = new JScrollPane(p5Table);
		p5jsp.setBounds(20, 130, 1160, 580);

		// ¼
		p5Search.addActionListener(searchLog());
		p5Download.addActionListener(downloadLog(p5Table));
		p5UserText.addKeyListener(logSearchEnter());
		p5TimeStartText.addKeyListener(logSearchEnter());
		p5TimeEndText.addKeyListener(logSearchEnter());

		p5.add(p5UserLabel);
		p5.add(p5UserText);
		p5.add(p5TimeLabel);
		p5.add(p5TimeStartText);
		p5.add(toLabel);
		p5.add(p5TimeEndText);
		p5.add(p5ContentLabel);
		p5.add(p5Contentjsp);
		p5.add(p5Search);
		p5.add(p5Download);
		p5.add(p5jsp);

		root.add("batchReplace", p1);
		root.add("batchModify", p2);
		root.add("batchAdd", p3);
		root.add("batchRemove", p4);
		root.add("updateLog", p5);

		rootSwitch.show(root, "batchReplace");
		container.add(root, BorderLayout.CENTER);
		this.setVisible(true);
	}

	private ActionListener panelSwitch() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String text = ((JButton) e.getSource()).getText();
				for (int i = 0; i < topBtns.length; i++) {
					topBtns[i].setSelected(topBtns[i].getText().equals(text));
				}
				switch (text) {
				case "滻":
					clearTable(p1Table, p1SelectAll);
					p1Right.removeAll();
					JScrollPane panel1 = new JScrollPane();
					panel1.setBounds(p1TreePanel.getX(), p1TreePanel.getY(), p1TreePanel.getWidth(),
							p1TreePanel.getHeight());
					p1TreePanel = panel1;
					p1Right.add(panel1);
					p1Right.revalidate();
					p1Right.repaint();
					rootSwitch.show(root, "batchReplace");
					break;
				case "":
					clearTable(p2Table, p2SelectAll);
					p2Right.removeAll();
					JScrollPane panel2 = new JScrollPane();
					panel2.setBounds(p2TreePanel.getX(), p2TreePanel.getY(), p2TreePanel.getWidth(),
							p2TreePanel.getHeight());
					p2TreePanel = panel2;
					p2Right.add(panel2);
					p2Right.revalidate();
					p2Right.repaint();
					rootSwitch.show(root, "batchModify");
					break;
				case "":
					clearTable(p3Table, p3SelectAll);
					p3Right.removeAll();
					JScrollPane panel3 = new JScrollPane();
					panel3.setBounds(p3TreePanel.getX(), p3TreePanel.getY(), p3TreePanel.getWidth(),
							p3TreePanel.getHeight());
					p3TreePanel = panel3;
					p3Right.add(panel3);
					p3Right.revalidate();
					p3Right.repaint();
					rootSwitch.show(root, "batchAdd");
					break;
				case "ɾ":
					clearTable(p4Table, p4SelectAll);
					p4Right.removeAll();
					JScrollPane panel4 = new JScrollPane();
					panel4.setBounds(p4TreePanel.getX(), p4TreePanel.getY(), p4TreePanel.getWidth(),
							p4TreePanel.getHeight());
					p4TreePanel = panel4;
					p4Right.add(panel4);
					p4Right.revalidate();
					p4Right.repaint();
					rootSwitch.show(root, "batchRemove");
					break;
				case "־":
					createLogDataSourceTable();
					clearTable(p5Table, null);
					rootSwitch.show(root, "updateLog");
					break;
				default:
//					createLogDataSourceTable();
				}
			}
		};
	}

	private void showWhereUesd(JTable table, JCheckBox selectAll) {
		DefaultTableModel model = (DefaultTableModel) table.getModel();
		// TODO Auto-generated method stub
		clearTable(table, selectAll);
		if (table == null || targetRev == null) {
			return;
		}
		long startTime = System.currentTimeMillis();
		List<Object[]> tableDataList = new ArrayList<Object[]>();
		try {
			String revString = targetRev.getProperty("object_string");
			TCComponent[] usedComps = targetRev.whereUsed((short) 0);
			System.out.println("װ======>" + usedComps.length);

			tableDataMap.clear();
//			Map<String, TCComponentItemRevision> usedMap = usedFilter(usedComps);
//			for (Entry<String, TCComponentItemRevision> entry : usedMap.entrySet()) {
			for (TCComponentItemRevision parentRev : usedFilter(usedComps)) {
//				TCComponentItemRevision parentRev = entry.getValue();
				String parentString = parentRev.getProperty("object_string");
				TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list");
				String status = "";
				if (statusArray != null && statusArray.length > 0) {
					status = statusArray[statusArray.length - 1].getProperty("object_name");
				}
				TCComponentBOMWindow win = winType.create(null);
				TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null);
				winMap.put(parentString, win);
				AIFComponentContext[] aifs = topLine.getChildren();
				for (AIFComponentContext aif : aifs) {
					TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent();
					if (revString.equals(child.getItemRevision().getProperty("object_string"))) {

						String unit = child.getProperty("bl_uom");
						String num = child.getProperty("bl_quantity");

						Object[] rowData = new Object[] { new JCheckBox(), parentString, revString, unit, num, status };
						rowPrint(rowData);
						tableDataList.add(rowData);
						tableDataMap.put(parentString,
								new BOMManageTableBean(parentString, revString, parentRev, targetRev, topLine, child));
						// TODO bomһchildܻ쳣ֻӰһ
						break;
					}
				}
			}
		} catch (TCException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		if (tableDataList == null || tableDataList.size() == 0) {
			JOptionPane.showMessageDialog($this, "ҵӦ󣬵öûκװװöľ°汾ȷϱǷȷ", "ʾ",
					JOptionPane.WARNING_MESSAGE);
			return;
		}

		for (Object[] rowData : tableDataList) {
			model.addRow(rowData);
		}
		table.revalidate();
		table.repaint();
		System.out.println("װʾɣʱ" + (System.currentTimeMillis() - startTime) + "ms");
	}

	private MouseAdapter showTree(JPanel panelRight) {
		return new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
					JTable table = (JTable) e.getSource();
					String parentString = table.getValueAt(table.getSelectedRow(), 1).toString();
					System.out.println("select row=====>" + table.getSelectedRow());
					System.out.println("parentName=====>" + parentString);
					CustomLovBean lovBean = null;
					try {
						lovBean = new CustomLovBean(tableDataMap.get(parentString).getChildString());
						CustomLovBean subBean = new CustomLovBean(parentString);
						lovBean.addSub(subBean);
						getTreeData(tableDataMap.get(parentString).getParentRev(), subBean);
					} catch (TCException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}

					panelRight.removeAll();
					JTree tree = createTree(lovBean);
					JScrollPane treePanel = new JScrollPane(tree);
					treePanel.setBounds(20, 130, 360, 500);
					panelRight.add(treePanel);
					panelRight.revalidate();
					panelRight.repaint();
				}
			}
		};
	}

	private void getTreeData(TCComponent rev, CustomLovBean lov) throws TCException {
		TCComponent[] comps = rev.whereUsed((short) 0);
		if (comps == null || comps.length == 0) {
			return;
		}
		for (TCComponent comp : comps) {
			CustomLovBean sub = new CustomLovBean(comp.getProperty("object_string"));
			System.out.println(sub.displayName);
			lov.addSub(sub);
			getTreeData(comp, sub);
		}
	}

	private void clearTable(JTable table, JCheckBox selectAll) {
		DefaultTableModel model = (DefaultTableModel) table.getModel();
		int cnt = model.getRowCount();
		for (int i = 0; i < cnt; i++) {
			model.removeRow(0);
		}
		table.revalidate();
		table.repaint();
		if (selectAll != null) {
			selectAll.setSelected(false);
		}
		tableDataMap.clear();
		addedBOMLine.clear();
		try {
			closeWin();
		} catch (TCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private JTree createTree(CustomLovBean lovData) {
		if (lovData == null || "".equals(lovData.displayName)) {
			return new JTree();
		}
		DefaultMutableTreeNode root = new DefaultMutableTreeNode(lovData.displayName);
		DefaultMutableTreeNode parent = root;
		DefaultTreeModel treeModel = new DefaultTreeModel(root);

		initTree(lovData, parent, treeModel);

		JTree tree = new JTree(treeModel);
		tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
		DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
		cellRenderer.setTextNonSelectionColor(Color.black);
		cellRenderer.setTextSelectionColor(Color.blue);
		return tree;
	}

	private void initTree(CustomLovBean lovData, DefaultMutableTreeNode parent, DefaultTreeModel treeModel) {
		if (!lovData.hasChild()) {
			return;
		}
		List<CustomLovBean> subList = lovData.getSub();
		for (CustomLovBean sub : subList) {
			DefaultMutableTreeNode temp = new DefaultMutableTreeNode(sub.displayName);
			treeModel.insertNodeInto(temp, parent, parent.getChildCount());
			initTree(sub, temp, treeModel);
		}
	}

	private ItemListener selectAll(JTable table) {
		return new ItemListener() {

			@Override
			public void itemStateChanged(ItemEvent e) {
				// TODO Auto-generated method stub
				boolean select = ((JCheckBox) e.getSource()).isSelected();
				for (int i = 0; i < table.getRowCount(); i++) {
					JCheckBox checkBox = (JCheckBox) table.getValueAt(i, 0);
					checkBox.setSelected(select);
					table.revalidate();
					table.repaint();
				}
			}
		};
	}

	private ActionListener cancel() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				$this.dispose();
			}
		};
	}

	private ActionListener batchRevise(JTable table, JCheckBox selectAll) {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				List<BOMManageTableBean> selectedRowList = getselectedRow(table);
				if (selectedRowList.size() == 0) {
					return;
				}
				if (!checkAccess(selectedRowList).isRes()) {
					return;
				}
				List<String[]> msgData = new ArrayList<String[]>();
				for (int i = 0; i < selectedRowList.size(); i++) {
					try {
						TCComponentItemRevision newRev = selectedRowList.get(i).getParentRev().saveAs(null);
						String parentString = newRev.getProperty("object_string");
						selectedRowList.get(i).setParentRev(newRev);
						selectedRowList.get(i).setParentString(parentString);
						msgData.add(new String[] { msgData.size() + 1 + "", selectedRowList.get(i).getParentString(),
								newRev.getProperty("object_string"), "ɹ" });
					} catch (TCException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
						JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
						return;
					}
				}

//				showWhereUesd(table, selectAll);
				updateSelectedRow(table, selectedRowList);
				JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "汾(ǰ)", "汾()", "" },
						msgData).panel;
				JOptionPane.showMessageDialog($this, jsp, "", JOptionPane.PLAIN_MESSAGE);
			}
		};
	}

	private List<TCComponentItemRevision> usedFilter(TCComponent[] comps) throws TCException {
//		Map<String, TCComponentItemRevision> sameParentUsedMap = new HashMap<String, TCComponentItemRevision>();
		List<TCComponentItemRevision> list = new ArrayList<>();
		for (TCComponent comp : comps) {
			if (comp instanceof TCComponentItemRevision) {
				TCComponentItemRevision rev = (TCComponentItemRevision) comp;
//				String itemId;
//				if (sameParentUsedMap.containsKey(itemId = comp.getProperty("item_id"))) {
//					if (sameParentUsedMap.get(itemId).getProperty("item_revision_id")
//							.compareTo(comp.getProperty("item_revision_id")) < 0) {
//						sameParentUsedMap.put(itemId, rev);
//					}
//				} else {
				if (rev.getItem().getLatestItemRevision().getUid().equals(rev.getUid())) {
					list.add(rev);
				}
//					sameParentUsedMap.put(itemId, rev);
//				}
			}
		}
		return list;
	}

	private void createLogDataSourceTable() {
		if (isLogcreated) {
			return;
		}
		String sql1 = "CREATE TABLE JD2_BOMManageLog ( id NUMBER ( 38, 0 ) primary key, modify_user VARCHAR2 ( 200 ), modify_time DATE, modify_content VARCHAR2 ( 500 ), target1 VARCHAR2 ( 100 ), target2 VARCHAR2 ( 100 ), parent VARCHAR2 ( 100 ), operation VARCHAR2 ( 50 ), unit VARCHAR2 ( 100 ), num VARCHAR2 ( 100 ))";
		String sql2 = "CREATE sequence JD2_BOMManageLog_seq minvalue 1 maxvalue 99999999 INCREMENT BY 1 START WITH 1";
		String sql3 = "CREATE OR REPLACE TRIGGER JD2_BOMManageLog_tri before INSERT ON JD2_BOMManageLog FOR each ROW BEGIN SELECT JD2_BOMManageLog_seq.nextval INTO : new.id FROM dual; END;";
		try {
			List<Entity> temp = null;
			temp = Db.use(DBUtil.getDataSource(session)).findBy("user_tables",
					new Condition("table_name", "JD2_BOMMANAGELOG"));
			if (temp == null || temp.size() == 0) {
				Db.use(DBUtil.getDataSource(session)).execute(sql1);
				System.out.println("JD2_BOMMANAGELOG create success");
			}
			temp = null;
			temp = Db.use(DBUtil.getDataSource(session)).findBy("user_sequences",
					new Condition("sequence_name", "JD2_BOMMANAGELOG_SEQ"));
			if (temp == null || temp.size() == 0) {
				Db.use(DBUtil.getDataSource(session)).execute(sql2);
				System.out.println("JD2_BOMMANAGELOG_SEQ create success");
			}
			temp = null;
			temp = Db.use(DBUtil.getDataSource(session)).findBy("all_triggers",
					new Condition("trigger_name", "JD2_BOMMANAGELOG_TRI"));
			if (temp == null || temp.size() == 0) {
				DBConnectionUtil.dbConn(session).createStatement().execute(sql3);
				System.out.println("JD2_BOMManageLog_tri create success");
			}
			isLogcreated = true;
			System.out.println("init log success");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			JOptionPane.showMessageDialog($this, "ݿʧܣѡjd2_db_settings", "", JOptionPane.ERROR_MESSAGE);
			e.printStackTrace();
		}
	}

	private ActionListener searchLog() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String username = p5UserText.getText().trim();
				String content = p5ContentText.getText();
				if (username == null || "".equals(username)) {
					return;
				}

				String sql = "select * from JD2_BOMMANAGELOG where ";
				if (!"*".equals(username)) {
					sql += "modify_user like '%" + username + "%' and";
				}
				sql += " modify_time between to_date('" + p5TimeStartText.getText()
						+ " 00:00:00','yyyy-MM-dd hh24:mi:ss') and to_date('" + p5TimeEndText.getText()
						+ " 23:59:59','yyyy-MM-dd hh24:mi:ss')";
				if (content != null && !"".equals(content)) {
					sql += " and modify_content like '%" + content + "%'";
				}
				sql += "order by MODIFY_TIME asc";
				System.out.println(sql);
				try {
					logDataList = Db.use(DBUtil.getDataSource(session)).query(sql);
					System.out.println("log size=====>" + logDataList.size());
					DefaultTableModel model = (DefaultTableModel) p5Table.getModel();
					for (Entity entity : logDataList) {
						Object[] objArr = new Object[] { entity.get("ID"), entity.get("MODIFY_USER"),
								entity.get("MODIFY_TIME"), entity.get("MODIFY_CONTENT") };
						model.addRow(objArr);
					}
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					return;
				}
				p5Table.revalidate();
				p5Table.repaint();
			}
		};
	}

	private ActionListener downloadLog(JTable table) {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if (table.getRowCount() > 0) {
					JFileChooser chooser = new JFileChooser();
					chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
					chooser.setMultiSelectionEnabled(false);
					chooser.setCurrentDirectory(FileSystemView.getFileSystemView().getHomeDirectory());
					chooser.showOpenDialog($this);
					File folder = chooser.getSelectedFile();
					FileWriter fileWriter = null;
					String fileName = "BOM־-" + new SimpleDateFormat("yyyyMMddHHmm").format(new Date()) + ".txt";
					try {
						fileWriter = new FileWriter(folder.getPath() + File.separator + fileName);// ıļ
						String temp;
						System.out.println(logDataList.size());
						for (Entity entity : logDataList) {
							fileWriter.write((temp = entity.get("ID").toString())
									+ StringCreateUtil.createBlank(10 - temp.length())
									+ (temp = entity.get("MODIFY_USER").toString())
									+ StringCreateUtil.createBlank(20 - temp.length())
									+ (temp = entity.get("MODIFY_TIME").toString())
									+ StringCreateUtil.createBlank(30 - temp.length())
									+ entity.get("MODIFY_CONTENT").toString() + "\r\n");
						}
						fileWriter.flush();
						fileWriter.close();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
						return;
					}

					JOptionPane.showMessageDialog($this, "־ɹ\r\n·" + folder + File.separator + fileName, "ʾ",
							JOptionPane.WARNING_MESSAGE);
				}
			}
		};

	}

	private ActionListener batchReplace() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String numStr = p1NumText.getText().trim();
				String text = p1UnitCombo.getSelectedText().trim();
				Object value = p1UnitCombo.getSelectedValue();
				System.out.println(numStr);
				if ("".equals(numStr) || "".equals(text) || targetRev2 == null) {
					JOptionPane.showMessageDialog($this, "δдϢд", "ʾ", JOptionPane.WARNING_MESSAGE);
					return;
				}
				List<BOMManageTableBean> selectedRowList = getselectedRow(p1Table);
				if (selectedRowList.size() == 0) {
					return;
				}
				if (!checkTargetAndSelect(targetRev, selectedRowList)) {
					return;
				}
				long startTime = System.currentTimeMillis();
				updateTitleShowProgress(selectedRowList);
				List<String[]> msgData = new ArrayList<String[]>();
				List<BOMLogBean> logData = new ArrayList<BOMLogBean>();
				L1: for (int i = 0; i < selectedRowList.size(); i++) {
					try {
						doIndex++;
						BOMManageTableBean bean = selectedRowList.get(i);
						System.out.println(value.toString());
						if (!addedBOMLine.add(targetRev2)) {
							continue L1;
						}
						AIFComponentContext[] aifs = bean.getParentLine().getChildren();
						for (AIFComponentContext aif : aifs) {
							String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision()
									.getProperty("object_string");
							if (objStr.equals(targetRev2.getProperty("object_string"))) {
								msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(),
										bean.getChildString(), targetRev2.getProperty("object_string"),
										value.toString(), numStr, "ʧܣѴͬӼ" });
								continue L1;
							}
						}
						String seq = selectedRowList.get(i).getChildLine().getProperty("bl_sequence_no");
						bean.getParentLine().remove("", bean.getChildLine());
						TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null,
								false, "");
						childLine.setReferenceProperty("bl_uom", (TCComponent) value);
						childLine.setProperties(new String[] { "bl_quantity", "bl_sequence_no" },
								new String[] { numStr, seq });
						msgData.add(
								new String[] { msgData.size() + 1 + "", bean.getParentString(), bean.getChildString(),
										targetRev2.getProperty("object_string"), value.toString(), numStr, "ɹ" });
						BOMLogBean logBean = new BOMLogBean(bean.getChildString(),
								targetRev2.getProperty("object_string"), bean.getParentString(), "滻", value.toString(),
								"", numStr);
						logData.add(logBean);
						selectedRowList.get(i).setChildString(targetRev2.getProperty("object_string"));
						selectedRowList.get(i).setChildRev(targetRev2);
						selectedRowList.get(i).setChildLine(childLine);
					} catch (TCException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
						JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
						complate = true;
						return;
					}
				}
				try {
					saveWin();
				} catch (TCException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
					return;
				} finally {
					complate = true;
				}
				long endTime = System.currentTimeMillis();
				System.out.println("滻ִϣʱ" + (endTime - startTime) + "ms");
				doLog("滻", logData);
				JScrollPane jsp = DialogUtil
						.createTableMsg(new String[] { "", "", "ԭӼ", "滻Ӽ", "λ", "", "" }, msgData).panel;
				JOptionPane
						.showMessageDialog(
								$this, jsp, "滻 ɹ(" + getResultNum(msgData, true) + ") ʧ("
										+ getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms",
								JOptionPane.PLAIN_MESSAGE);
				updateSelectedRow2(p1Table, selectedRowList);
			}
		};
	}

	private ActionListener batchModify() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String numStr = p2NumText.getText();
				List<BOMManageTableBean> selectedRowList = getselectedRow(p2Table);
				if (selectedRowList.size() == 0) {
					return;
				}
				if (!checkTargetAndSelect(targetRev, selectedRowList)) {
					return;
				}
				long startTime = System.currentTimeMillis();
				updateTitleShowProgress(selectedRowList);
				List<String[]> msgData = new ArrayList<String[]>();
				List<BOMLogBean> logData = new ArrayList<>();
				for (BOMManageTableBean bean : selectedRowList) {
					String oldNumStr = "";
					try {
						doIndex++;
						oldNumStr = bean.getChildLine().getProperty("bl_quantity");
						bean.getChildLine().setProperties(new String[] { "bl_quantity" }, new String[] { numStr });
						msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(),
								bean.getChildString(), oldNumStr, numStr, "ɹ" });
						BOMLogBean logBean = new BOMLogBean(bean.getChildString(),
								targetRev2.getProperty("object_string"), bean.getParentString(), "޸", "", oldNumStr,
								numStr);
						logData.add(logBean);
					} catch (TCException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
						JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
						complate = true;
						return;
					}
				}
				try {
					saveWin();
				} catch (TCException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
					return;
				} finally {
					complate = true;
				}
				long endTime = System.currentTimeMillis();
				System.out.println("ִϣʱ" + (endTime - startTime) + "ms");
				doLog("޸", logData);
				JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "", "Ӽ", "ԭ", "", "" },
						msgData).panel;
				JOptionPane
						.showMessageDialog(
								$this, jsp, "Ľ ɹ(" + getResultNum(msgData, true) + ") ʧ("
										+ getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms",
								JOptionPane.PLAIN_MESSAGE);
				updateSelectedRow(p2Table, selectedRowList);
			}
		};
	}

	private ActionListener batchAdd() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String numStr = p3NumText.getText().trim();
				String text = p3UnitCombo.getSelectedText().trim();
				Object value = p3UnitCombo.getSelectedValue();
				System.out.println(numStr);
				if ("".equals(numStr) || "".equals(text) || targetRev2 == null) {
					JOptionPane.showMessageDialog($this, "δдϢд", "ʾ", JOptionPane.WARNING_MESSAGE);
					return;
				}
				List<BOMManageTableBean> selectedRowList = getselectedRow(p3Table);
				if (selectedRowList.size() == 0) {
					return;
				}
				if (!checkTargetAndSelect(targetRev, selectedRowList)) {
					return;
				}
				long startTime = System.currentTimeMillis();
				updateTitleShowProgress(selectedRowList);
				List<String[]> msgData = new ArrayList<String[]>();
				List<BOMLogBean> logData = new ArrayList<>();
				L1: for (BOMManageTableBean bean : selectedRowList) {
					try {
						doIndex++;
						System.out.println(value.toString());
						if (!addedBOMLine.add(targetRev2)) {
							continue L1;
						}
						AIFComponentContext[] aifs = bean.getParentLine().getChildren();
						for (AIFComponentContext aif : aifs) {
							String objStr = ((TCComponentBOMLine) aif.getComponent()).getItemRevision()
									.getProperty("object_string");
							if (objStr.equals(targetRev2.getProperty("object_string"))) {
								msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(),
										targetRev2.getProperty("object_string"), value.toString(), numStr,
										"ʧܣѴͬӼ" });
								continue L1;
							}
						}
						TCComponentBOMLine childLine = bean.getParentLine().add(targetRev2.getItem(), targetRev2, null,
								false, "");
						childLine.setReferenceProperty("bl_uom", (TCComponent) value);
						childLine.setProperties(new String[] { "bl_quantity" }, new String[] { numStr });
						msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(),
								targetRev2.getProperty("object_string"), value.toString(), numStr, "ɹ" });
						BOMLogBean logBean = new BOMLogBean(bean.getChildString(),
								targetRev2.getProperty("object_string"), bean.getParentString(), "", value.toString(),
								"", numStr);
						logData.add(logBean);
					} catch (TCException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
						JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
						complate = true;
						return;
					}
				}
				try {
					saveWin();
				} catch (TCException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
					return;
				} finally {
					complate = true;
				}
				long endTime = System.currentTimeMillis();
				System.out.println("ִϣʱ" + (endTime - startTime) + "ms");
				doLog("", logData);
				JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "", "Ӽ", "λ", "", "" },
						msgData).panel;
				JOptionPane
						.showMessageDialog(
								$this, jsp, " ɹ(" + getResultNum(msgData, true) + ") ʧ("
										+ getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms",
								JOptionPane.PLAIN_MESSAGE);
//				showWhereUesd(p3Table, p3SelectAll);
			}
		};
	}

	private ActionListener batchRemove() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				List<BOMManageTableBean> selectedRowList = getselectedRow(p4Table);
				if (selectedRowList.size() == 0) {
					return;
				}
				if (!checkTargetAndSelect(targetRev, selectedRowList)) {
					return;
				}
				long startTime = System.currentTimeMillis();
				updateTitleShowProgress(selectedRowList);
				List<String[]> msgData = new ArrayList<String[]>();
				List<BOMLogBean> logData = new ArrayList<>();
				for (BOMManageTableBean bean : selectedRowList) {
					try {
						doIndex++;
						if (bean.getChildLine() == null) {
							msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(),
									bean.getChildString(), "bomLineڣѾɹɾ" });
						} else {
							bean.getParentLine().remove("", bean.getChildLine());
							msgData.add(new String[] { msgData.size() + 1 + "", bean.getParentString(),
									bean.getChildString(), "ɹ" });
							BOMLogBean logBean = new BOMLogBean(bean.getChildString(),
									targetRev2.getProperty("object_string"), bean.getParentString(), "ɾ", "", "", "");
							logData.add(logBean);
						}
					} catch (TCException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
						JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
						complate = true;
						return;
					}
				}
				try {
					saveWin();
				} catch (TCException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog($this, e1.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
					return;
				} finally {
					complate = true;
				}
				long endTime = System.currentTimeMillis();
				System.out.println("ɾִϣʱ" + (endTime - startTime) + "ms");
				doLog("ɾ", logData);
				JScrollPane jsp = DialogUtil.createTableMsg(new String[] { "", "", "ɾӼ", "" }, msgData).panel;
				JOptionPane
						.showMessageDialog(
								$this, jsp, "ɾ ɹ(" + getResultNum(msgData, true) + ") ʧ("
										+ getResultNum(msgData, false) + ") ʱ" + (endTime - startTime) + "ms",
								JOptionPane.PLAIN_MESSAGE);
//				removeSelectRow(p4Table);
				updateSelectedRow3(p4Table, selectedRowList);
			}
		};
	}

	private List<BOMManageTableBean> getselectedRow(JTable table) {
		List<BOMManageTableBean> selectedList = new ArrayList<BOMManageTableBean>();
		for (int i = 0; i < table.getRowCount(); i++) {
			JCheckBox select = (JCheckBox) table.getValueAt(i, 0);
			if (select.isSelected()) {
				System.out.println("select=====>" + table.getValueAt(i, 1));
				selectedList.add(tableDataMap.get(table.getValueAt(i, 1)));
			}
		}
		return selectedList;
	}

	private void updateSelectedRow(JTable table, List<BOMManageTableBean> newRowData) {
		int index = 0;
		for (int i = 0; i < table.getRowCount(); i++) {
			JCheckBox select = (JCheckBox) table.getValueAt(i, 0);
			if (select.isSelected()) {
				try {
					TCComponentItemRevision parentRev = newRowData.get(index).getParentRev();
					String parentString = newRowData.get(index).getParentString();
					TCComponentBOMWindow win = winType.create(null);
					TCComponentBOMLine topLine = win.setWindowTopLine(parentRev.getItem(), parentRev, null, null);
					winMap.get(table.getValueAt(i, 1).toString()).close();
					winMap.remove(table.getValueAt(i, 1));
					winMap.put(parentString, win);
					tableDataMap.remove(table.getValueAt(i, 1).toString());
					TCComponent[] statusArray = parentRev.getRelatedComponents("release_status_list");
					String status = "";
					if (statusArray != null && statusArray.length > 0) {
						status = statusArray[statusArray.length - 1].getProperty("object_name");
					}
					AIFComponentContext[] aifs = topLine.getChildren();
					for (AIFComponentContext aif : aifs) {
						TCComponentBOMLine child = (TCComponentBOMLine) aif.getComponent();
						if (newRowData.get(index).getChildString()
								.equals(child.getItemRevision().getProperty("object_string"))) {

							String unit = child.getProperty("bl_uom");
							String num = child.getProperty("bl_quantity");

							JCheckBox selected = new JCheckBox();
							selected.setSelected(true);
							Object[] rowData = new Object[] { selected, parentString,
									newRowData.get(index).getChildString(), unit, num, status };
							rowPrint(rowData);
							for (int ii = 0; ii < rowData.length; ii++) {
								table.setValueAt(rowData[ii], i, ii);
							}
							tableDataMap.put(parentString, new BOMManageTableBean(parentString,
									newRowData.get(index).getChildString(), parentRev, targetRev, topLine, child));
							break;
						}
					}
					index++;
				} catch (TCException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		table.revalidate();
		table.repaint();
	}

	private void updateSelectedRow2(JTable table, List<BOMManageTableBean> newRowData) {
		int index = 0;
		for (int i = 0; i < table.getRowCount(); i++) {
			JCheckBox select = (JCheckBox) table.getValueAt(i, 0);
			if (select.isSelected()) {
				BOMManageTableBean bean = newRowData.get(index);
				try {
					TCComponentBOMLine child = bean.getChildLine();
					String unit = child.getProperty("bl_uom");
					String num = child.getProperty("bl_quantity");
					table.setValueAt(bean.getChildString(), i, 2);
					table.setValueAt(unit, index, 3);
					table.setValueAt(num, index, 4);
					tableDataMap.get(bean.getParentString()).setChildRev(bean.getChildRev());
					tableDataMap.get(bean.getParentString()).setChildString(bean.getChildString());
					tableDataMap.get(bean.getParentString()).setChildLine(child);
				} catch (TCException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				index++;
			}
		}
		table.revalidate();
		table.repaint();
	}

	private void updateSelectedRow3(JTable table, List<BOMManageTableBean> newRowData) {
		int index = 0;
		for (int i = 0; i < table.getRowCount(); i++) {
			JCheckBox select = (JCheckBox) table.getValueAt(i, 0);
			if (select.isSelected()) {
				BOMManageTableBean bean = newRowData.get(index);
				table.setValueAt("", i, 2);
				table.setValueAt("", index, 3);
				table.setValueAt("", index, 4);
				tableDataMap.get(bean.getParentString()).setChildLine(null);
				index++;
			}
		}
		table.revalidate();
		table.repaint();
	}

	private void removeSelectRow(JTable table) {
		DefaultTableModel model = (DefaultTableModel) table.getModel();
		int i = 0;
		while (i < table.getRowCount()) {
			JCheckBox select = (JCheckBox) table.getValueAt(i, 0);
			if (select.isSelected()) {
				model.removeRow(i);
				continue;
			}
			i++;
		}
		table.revalidate();
		table.repaint();
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

		new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				try {
					closeWin();
					System.out.println("closed");
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}).start();

		super.dispose();
	}

	private void saveWin() throws TCException {
		for (Entry<String, TCComponentBOMWindow> entry : winMap.entrySet()) {
			if (entry.getValue() != null) {
				entry.getValue().save();
			}

		}
	}

	private void closeWin() throws TCException {
		saveWin();

		for (Entry<String, TCComponentBOMWindow> entry : winMap.entrySet()) {
			entry.getValue().close();
		}
		winMap.clear();
	}

	private void doLog(String operation, List<BOMLogBean> logData) {
		createLogDataSourceTable();
		String username = "";
		try {
			username = session.getUser().getUserName() + "(" + session.getUser().getUserId() + ")";
		} catch (TCException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

		List<String> sqls = new ArrayList<String>();
		for (BOMLogBean bean : logData) {
			StringBuilder builder = new StringBuilder();
			builder.append(
					"insert into JD2_BOMMANAGELOG (MODIFY_USER,MODIFY_TIME,MODIFY_CONTENT,TARGET1,TARGET2,PARENT,OPERATION,UNIT,NUM) VALUES ('");
			builder.append(username);
			builder.append("',to_date('");
			builder.append(datetime);
			builder.append("','yyyy-MM-dd hh24:mi:ss'),'");
			if ("滻".equals(operation)) {
				String temp = String.format("%sӼ%s滻Ϊ%s;%s;%s", bean.getParent(), bean.getTarget1(),
						bean.getTarget2(), bean.getUnit(), bean.getNum());
				builder.append(temp + "','");
			} else if ("޸".equals(operation)) {
				String temp = String.format("%sӼ%s%sΪ%s", bean.getParent(), bean.getTarget1(), bean.getOldNum(),
						bean.getNum());
				builder.append(temp + "','");
			} else if ("".equals(operation)) {
				String temp = String.format("%sӼ%s;%s;%s", bean.getParent(), bean.getTarget2(), bean.getUnit(),
						bean.getNum());
				builder.append(temp + "','");
			} else if ("ɾ".equals(operation)) {
				String temp = String.format("%sɾӼ%s", bean.getParent(), bean.getTarget1());
				builder.append(temp + "','");
			}
			builder.append(bean.getTarget1() + "','");
			builder.append(bean.getTarget2() + "','");
			builder.append(bean.getParent() + "','");
			builder.append(bean.getUnit() + "','");
			builder.append(operation + "','");
			builder.append(bean.getNum() + "');");
			sqls.add(builder.toString());
		}

		try {
			Db.use(DBUtil.getDataSource(session)).executeBatch(sqls.toArray(new String[sqls.size()]));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private ActionListener clickSearch(JTable table, JCheckBox selectAll) {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				JDialog content = DialogUtil.createSearchAndSelectRevDialog($this, table, selectAll,
						(JButton) e.getSource());
			}
		};
	}

	public void okCallback(JTable revTable, JTable table, JCheckBox selectAll, JButton field) {
		// TODO Auto-generated method stub
		int rowIndex = revTable.getSelectedRow();
		if (rowIndex < 0) {
			return;
		}
		String text = revTable.getValueAt(rowIndex, 0).toString();
		System.out.println(text);
		field.setText(text);
		if ("".equals(text)) {
			return;
		}
		if (table != null) {
			targetRev = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5);
			showWhereUesd(table, selectAll);
		} else {
			targetRev2 = (TCComponentItemRevision) revTable.getValueAt(rowIndex, 5);
		}
	}

	private KeyAdapter logSearchEnter() {
		return new KeyAdapter() {
			@Override
			public void keyTyped(KeyEvent e) {
				// TODO Auto-generated method stub
				super.keyTyped(e);
				if (e.getKeyChar() == KeyEvent.VK_ENTER) {
					p5Search.doClick();
				}
			}
		};
	}

	private void updateTitleShowProgress(List<BOMManageTableBean> list) {
		new Thread(new Runnable() {

			@Override
			public void run() {
				int num = 1;
				String temp;
				doIndex = 0;
				while (!complate) {
					$this.setTitle("ڴ" + (temp = StringCreateUtil.createPoint(num % 3))
							+ StringCreateUtil.createBlank(5 - temp.length()) + list.get(doIndex).getParentString()
							+ "     " + (doIndex + 1) + "/" + list.size());
					try {
						Thread.sleep(200);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					num++;
				}
				$this.setTitle("BOM");
				doIndex = -1;
				complate = false;
			}
		}).start();
	}

	private boolean checkReleaseStatus(TCComponentItemRevision rev) {
		try {
			System.out.println("item type======>" + rev.getItem().getType());
			if (checkItemType.contains(rev.getItem().getType())) {
				return true;
			}
			TCComponent form = rev.getRelatedComponents("IMAN_master_form_rev")[0];
			TCComponent[] statusArray = form.getRelatedComponents("release_status_list");
			String status = "";
			if (statusArray != null && statusArray.length > 0) {
				status = statusArray[statusArray.length - 1].getProperty("object_name");
			}
			if ("".equals(status) || "JD2_DJJY".equals(status) || "JD2_DJKY".equals(status)) {
				return false;
			}
		} catch (TCException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return true;
	}

	private ResultData checkAccess(List<BOMManageTableBean> data) {
		for (BOMManageTableBean bean : data) {
			boolean isAccess = true;
			try {
				isAccess = session.getTCAccessControlService().checkPrivilege(bean.getParentLine(), "WRITE");
			} catch (TCException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (!isAccess) {
				try {
					return new ResultData(false, "ǰûûж" + bean.getParentLine().getProperty("object_string") + "дȨ",
							bean.getParentLine());
				} catch (TCException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return new ResultData(true, "", null);
	}

	private boolean checkTargetAndSelect(TCComponentItemRevision rev, List<BOMManageTableBean> data) {
		if (!checkReleaseStatus(rev)) {
			JOptionPane.showMessageDialog($this, "Ŀδߴڶ״̬޷BOM", "ʾ", JOptionPane.WARNING_MESSAGE);
			return false;
		}
		ResultData res = checkAccess(data);
		if (!res.isRes()) {
			JOptionPane.showMessageDialog($this, res.getMessage(), "ʾ", JOptionPane.WARNING_MESSAGE);
			return false;
		}
		return true;
	}

	private ActionListener startWorkFlow(JTable table) {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				List<BOMManageTableBean> select = getselectedRow(table);
				List<TCComponentItemRevision> parentRev = new ArrayList<>();
				for (BOMManageTableBean bean : select) {
					parentRev.add(bean.getParentRev());
				}
				$this.setExtendedState(JFrame.ICONIFIED);
				NewProcessCommand command = new NewProcessCommand(AIFUtility.getActiveDesktop(), app,
						parentRev.toArray(new TCComponentItemRevision[parentRev.size()]));
			}
		};
	}

	private void rowPrint(Object[] arr) {
		StringBuilder sb = new StringBuilder();
		sb.append("[");
		for (Object obj : arr) {
			if (obj instanceof JCheckBox) {
				sb.append(((JCheckBox) obj).isSelected());
			} else {
				sb.append(obj.toString());
			}
			sb.append(",");
		}
		if (sb.length() > 1) {
			sb.deleteCharAt(sb.length() - 1);
		}
		sb.append("]");
		System.out.println(sb.toString());
	}

	private void resize() {
		double left = 2 * this.widthOffset / 3.0;
		double right = this.widthOffset - left;

		int bottom1 = p1BottomBtn2.getX() - p1BottomBtn1.getX() - p1BottomBtn1.getWidth();
		int bottom2 = p1BottomBtn3.getX() - p1BottomBtn2.getX() - p1BottomBtn2.getWidth();
		int botttom3 = p1BottomBtn4.getX() - p1BottomBtn3.getX() - p1BottomBtn3.getWidth();

		// p1
		int p1x1 = p1TargetBtn.getX() - p1TargetLabel.getX() - p1TargetLabel.getWidth();
		int p1x2 = p1ReplaceBtn.getX() - p1ReplaceLabel.getX() - p1ReplaceLabel.getWidth();
		int p1x3 = p1UnitLabel.getX() - p1ReplaceBtn.getX() - p1ReplaceBtn.getWidth();
		int p1x4 = p1NumLabel.getX() - p1UnitCombo.getX() - p1UnitCombo.getWidth();
		p1TargetLabel.setBounds(p1TargetLabel.getX() + getOffset(left, 20, 800), 20,
				p1TargetLabel.getWidth() + getOffset(left, 100, 800), 25);
		p1TargetBtn.setBounds(p1TargetLabel.getX() + p1TargetLabel.getWidth() + p1x1 + getOffset(left, 10, 800), 20,
				p1TargetBtn.getWidth() + getOffset(left, 400, 800), 25);
		p1ReplaceLabel.setBounds(p1ReplaceLabel.getX() + getOffset(left, 20, 800), 60,
				p1ReplaceLabel.getWidth() + getOffset(left, 100, 800), 25);
		p1ReplaceBtn.setBounds(p1ReplaceLabel.getX() + p1ReplaceLabel.getWidth() + p1x2 + getOffset(left, 10, 800), 60,
				p1ReplaceBtn.getWidth() + getOffset(left, 400, 800), 25);
		p1UnitLabel.setBounds(p1ReplaceBtn.getX() + p1ReplaceBtn.getWidth() + p1x3 + getOffset(left, 30, 800), 60,
				p1UnitLabel.getWidth() + getOffset(left, 50, 800), 25);
		p1UnitCombo.setBounds(p1UnitLabel.getX() + p1UnitLabel.getWidth(), 60,
				p1UnitCombo.getWidth() + getOffset(left, 50, 800), 25);
		p1NumLabel.setBounds(p1UnitCombo.getX() + p1UnitCombo.getWidth() + p1x4 + getOffset(left, 20, 800), 60,
				p1NumLabel.getWidth() + getOffset(left, 50, 800), 25);
		p1NumText.setBounds(p1NumLabel.getX() + p1NumLabel.getWidth(), 60,
				p1NumText.getWidth() + getOffset(left, 50, 800), 25);
		p1SelectAll.setBounds(p1SelectAll.getX() + getOffset(left, 20, 800), 100,
				p1SelectAll.getWidth() + getOffset(left, 100, 800), 25);
		p1jsp.setBounds(p1jsp.getX() + getOffset(left, 20, 800), p1jsp.getY(),
				p1jsp.getWidth() + getOffset(left, 760, 800), p1jsp.getHeight() + this.heightOffset);
		p1BottomBtn1.setBounds(p1BottomBtn1.getX() + getOffset(left, 80, 800), p1BottomBtn1.getY() + this.heightOffset,
				p1BottomBtn1.getWidth() + getOffset(left, 100, 800), 25);
		p1BottomBtn2.setBounds(p1BottomBtn1.getX() + p1BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800),
				p1BottomBtn2.getY() + this.heightOffset, p1BottomBtn2.getWidth() + getOffset(left, 100, 800), 25);
		p1BottomBtn3.setBounds(p1BottomBtn2.getX() + p1BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800),
				p1BottomBtn3.getY() + this.heightOffset, p1BottomBtn3.getWidth() + getOffset(left, 100, 800), 25);
		p1BottomBtn4.setBounds(p1BottomBtn3.getX() + p1BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800),
				p1BottomBtn4.getY() + this.heightOffset, p1BottomBtn4.getWidth() + getOffset(left, 100, 800), 25);
		p1Left.setBounds(0, 0, p1Left.getWidth() + getOffset(this.widthOffset, 800, 1200),
				p1Left.getHeight() + this.heightOffset);
		p1TreePanel.setBounds(p1TreePanel.getX() + getOffset(right, 20, 400), 130,
				p1TreePanel.getWidth() + getOffset(right, 360, 400), p1TreePanel.getHeight() + this.heightOffset);
		p1Right.setBounds(p1Left.getX() + p1Left.getWidth(), 0,
				p1Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p1Right.getHeight() + this.heightOffset);
		p1.revalidate();
		p1.repaint();

		// p2
		int p2x1 = p2TargetBtn.getX() - p2TargetLabel.getX() - p2TargetLabel.getWidth();
		int p2x2 = p2NumText.getX() - p2ChangeNumLabel.getX() - p2ChangeNumLabel.getWidth();
		p2TargetLabel.setBounds(p2TargetLabel.getX() + getOffset(left, 20, 800), 20,
				p2TargetLabel.getWidth() + getOffset(left, 100, 800), 25);
		p2TargetBtn.setBounds(p2TargetLabel.getX() + p2TargetLabel.getWidth() + p2x1 + getOffset(left, 10, 800), 20,
				p2TargetBtn.getWidth() + getOffset(left, 400, 800), 25);
		p2ChangeNumLabel.setBounds(p2ChangeNumLabel.getX() + getOffset(left, 20, 800), 60,
				p2ChangeNumLabel.getWidth() + getOffset(left, 100, 800), 25);
		p2NumText.setBounds(p2ChangeNumLabel.getX() + p2ChangeNumLabel.getWidth() + p2x2 + getOffset(left, 10, 800), 60,
				p2NumText.getWidth() + getOffset(left, 50, 800), 25);
		p2SelectAll.setBounds(p2SelectAll.getX() + getOffset(left, 20, 800), 100,
				p2SelectAll.getWidth() + getOffset(left, 100, 800), 25);
		p2jsp.setBounds(p2jsp.getX() + getOffset(left, 20, 800), p2jsp.getY(),
				p2jsp.getWidth() + getOffset(left, 760, 800), p2jsp.getHeight() + this.heightOffset);
		p2BottomBtn1.setBounds(p2BottomBtn1.getX() + getOffset(left, 80, 800), p2BottomBtn1.getY() + this.heightOffset,
				p2BottomBtn1.getWidth() + getOffset(left, 100, 800), 25);
		p2BottomBtn2.setBounds(p2BottomBtn1.getX() + p2BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800),
				p2BottomBtn2.getY() + this.heightOffset, p2BottomBtn2.getWidth() + getOffset(left, 100, 800), 25);
		p2BottomBtn3.setBounds(p2BottomBtn2.getX() + p2BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800),
				p2BottomBtn3.getY() + this.heightOffset, p2BottomBtn3.getWidth() + getOffset(left, 100, 800), 25);
		p2BottomBtn4.setBounds(p2BottomBtn3.getX() + p2BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800),
				p2BottomBtn4.getY() + this.heightOffset, p2BottomBtn4.getWidth() + getOffset(left, 100, 800), 25);
		p2Left.setBounds(0, 0, p2Left.getWidth() + getOffset(this.widthOffset, 800, 1200),
				p2Left.getHeight() + this.heightOffset);
		p2TreePanel.setBounds(p2TreePanel.getX() + getOffset(right, 20, 400), 130,
				p2TreePanel.getWidth() + getOffset(right, 360, 400), p2TreePanel.getHeight() + this.heightOffset);
		p2Right.setBounds(p2Left.getX() + p2Left.getWidth(), 0,
				p2Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p2Right.getHeight() + this.heightOffset);
		p2.revalidate();
		p2.repaint();

		// p3
		int p3x1 = p3TargetBtn.getX() - p3TargetLabel.getX() - p3TargetLabel.getWidth();
		int p3x2 = p3AddBtn.getX() - p3AddLabel.getX() - p3AddLabel.getWidth();
		int p3x3 = p3UnitLabel.getX() - p3AddBtn.getX() - p3AddBtn.getWidth();
		int p3x4 = p3NumLabel.getX() - p3UnitCombo.getX() - p3UnitCombo.getWidth();
		p3TargetLabel.setBounds(p3TargetLabel.getX() + getOffset(left, 20, 800), 20,
				p3TargetLabel.getWidth() + getOffset(left, 100, 800), 25);
		p3TargetBtn.setBounds(p3TargetLabel.getX() + p3TargetLabel.getWidth() + p3x1 + getOffset(left, 10, 800), 20,
				p3TargetBtn.getWidth() + getOffset(left, 400, 800), 25);
		p3AddLabel.setBounds(p3AddLabel.getX() + getOffset(left, 20, 800), 60,
				p3AddLabel.getWidth() + getOffset(left, 100, 800), 25);
		p3AddBtn.setBounds(p3AddLabel.getX() + p3AddLabel.getWidth() + p3x2 + getOffset(left, 10, 800), 60,
				p3AddBtn.getWidth() + getOffset(left, 400, 800), 25);
		p3UnitLabel.setBounds(p3AddBtn.getX() + p3AddBtn.getWidth() + p3x3 + getOffset(left, 30, 800), 60,
				p3UnitLabel.getWidth() + getOffset(left, 50, 800), 25);
		p3UnitCombo.setBounds(p3UnitLabel.getX() + p3UnitLabel.getWidth(), 60,
				p3UnitCombo.getWidth() + getOffset(left, 50, 800), 25);
		p3NumLabel.setBounds(p3UnitCombo.getX() + p3UnitCombo.getWidth() + p3x4 + getOffset(left, 20, 800), 60,
				p3NumLabel.getWidth() + getOffset(left, 50, 800), 25);
		p3NumText.setBounds(p3NumLabel.getX() + p3NumLabel.getWidth(), 60,
				p3NumText.getWidth() + getOffset(left, 50, 800), 25);
		p3SelectAll.setBounds(p3SelectAll.getX() + getOffset(left, 20, 800), 100,
				p3SelectAll.getWidth() + getOffset(left, 100, 800), 25);
		p3jsp.setBounds(p3jsp.getX() + getOffset(left, 20, 800), p3jsp.getY(),
				p3jsp.getWidth() + getOffset(left, 760, 800), p3jsp.getHeight() + this.heightOffset);
		p3BottomBtn1.setBounds(p3BottomBtn1.getX() + getOffset(left, 80, 800), p3BottomBtn1.getY() + this.heightOffset,
				p3BottomBtn1.getWidth() + getOffset(left, 100, 800), 25);
		p3BottomBtn2.setBounds(p3BottomBtn1.getX() + p3BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800),
				p3BottomBtn2.getY() + this.heightOffset, p3BottomBtn2.getWidth() + getOffset(left, 100, 800), 25);
		p3BottomBtn3.setBounds(p3BottomBtn2.getX() + p3BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800),
				p3BottomBtn3.getY() + this.heightOffset, p3BottomBtn3.getWidth() + getOffset(left, 100, 800), 25);
		p3BottomBtn4.setBounds(p3BottomBtn3.getX() + p3BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800),
				p3BottomBtn4.getY() + this.heightOffset, p3BottomBtn4.getWidth() + getOffset(left, 100, 800), 25);
		p3Left.setBounds(0, 0, p3Left.getWidth() + getOffset(this.widthOffset, 800, 1200),
				p3Left.getHeight() + this.heightOffset);
		p3TreePanel.setBounds(p3TreePanel.getX() + getOffset(right, 20, 400), 130,
				p3TreePanel.getWidth() + getOffset(right, 360, 400), p3TreePanel.getHeight() + this.heightOffset);
		p3Right.setBounds(p3Left.getX() + p3Left.getWidth(), 0,
				p3Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p3Right.getHeight() + this.heightOffset);
		p3.revalidate();
		p3.repaint();

		// p4
		int p4x1 = p4TargetBtn.getX() - p4TargetLabel.getX() - p4TargetLabel.getWidth();
		p4TargetLabel.setBounds(p4TargetLabel.getX() + getOffset(left, 20, 800), 20,
				p4TargetLabel.getWidth() + getOffset(left, 100, 800), 25);
		p4TargetBtn.setBounds(p4TargetLabel.getX() + p4TargetLabel.getWidth() + p4x1 + getOffset(left, 10, 800), 20,
				p4TargetBtn.getWidth() + getOffset(left, 400, 800), 25);
		p4SelectAll.setBounds(p4SelectAll.getX() + getOffset(left, 20, 800), 100,
				p4SelectAll.getWidth() + getOffset(left, 100, 800), 25);
		p4jsp.setBounds(p4jsp.getX() + getOffset(left, 20, 800), p4jsp.getY(),
				p4jsp.getWidth() + getOffset(left, 760, 800), p4jsp.getHeight() + this.heightOffset);
		p4BottomBtn1.setBounds(p4BottomBtn1.getX() + getOffset(left, 80, 800), p4BottomBtn1.getY() + this.heightOffset,
				p4BottomBtn1.getWidth() + getOffset(left, 100, 800), 25);
		p4BottomBtn2.setBounds(p4BottomBtn1.getX() + p4BottomBtn1.getWidth() + bottom1 + getOffset(left, 80, 800),
				p4BottomBtn2.getY() + this.heightOffset, p4BottomBtn2.getWidth() + getOffset(left, 100, 800), 25);
		p4BottomBtn3.setBounds(p4BottomBtn2.getX() + p4BottomBtn2.getWidth() + bottom2 + getOffset(left, 80, 800),
				p4BottomBtn3.getY() + this.heightOffset, p4BottomBtn3.getWidth() + getOffset(left, 100, 800), 25);
		p4BottomBtn4.setBounds(p4BottomBtn3.getX() + p4BottomBtn3.getWidth() + botttom3 + getOffset(left, 80, 800),
				p4BottomBtn4.getY() + this.heightOffset, p4BottomBtn4.getWidth() + getOffset(left, 100, 800), 25);
		p4Left.setBounds(0, 0, p4Left.getWidth() + getOffset(this.widthOffset, 800, 1200),
				p4Left.getHeight() + this.heightOffset);
		p4TreePanel.setBounds(p4TreePanel.getX() + getOffset(right, 20, 400), 130,
				p4TreePanel.getWidth() + getOffset(right, 360, 400), p4TreePanel.getHeight() + this.heightOffset);
		p4Right.setBounds(p4Left.getX() + p4Left.getWidth(), 0,
				p4Right.getWidth() + getOffset(this.widthOffset, 400, 1200), p4Right.getHeight() + this.heightOffset);
		p4.revalidate();
		p4.repaint();

		// p5
		int p5x1 = p5UserText.getX() - p5UserLabel.getX() - p5UserLabel.getWidth();
		int p5x2 = p5TimeLabel.getX() - p5UserText.getX() - p5UserText.getWidth();
		int p5x3 = p5TimeStartText.getX() - p5TimeLabel.getX() - p5TimeLabel.getWidth();
		int p5x4 = toLabel.getX() - p5TimeStartText.getX() - p5TimeStartText.getWidth();
		int p5x5 = p5TimeEndText.getX() - toLabel.getX() - toLabel.getWidth();
		int p5x6 = p5ContentLabel.getX() - p5TimeEndText.getX() - p5TimeEndText.getWidth();
		int p5x7 = p5Contentjsp.getX() - p5ContentLabel.getX() - p5ContentLabel.getWidth();
		int p5x8 = p5Search.getX() - p5Contentjsp.getX() - p5Contentjsp.getWidth();
		int p5x9 = p5Download.getX() - p5Search.getX() - p5Search.getWidth();
		p5UserLabel.setBounds(p5UserLabel.getX(), 40, p5UserLabel.getWidth() + getOffset(this.widthOffset, 70, 1200),
				25);
		p5UserText.setBounds(p5UserLabel.getX() + p5UserLabel.getWidth() + p5x1 + getOffset(this.widthOffset, 10, 1200),
				40, p5UserText.getWidth() + getOffset(this.widthOffset, 150, 1200), 25);
		p5TimeLabel.setBounds(p5UserText.getX() + p5UserText.getWidth() + p5x2 + getOffset(this.widthOffset, 50, 1200),
				40, p5TimeLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25);
		p5TimeStartText.setBounds(
				p5TimeLabel.getX() + p5TimeLabel.getWidth() + p5x3 + getOffset(this.widthOffset, 10, 1200), 40,
				p5TimeStartText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25);
		toLabel.setBounds(
				p5TimeStartText.getX() + p5TimeStartText.getWidth() + p5x4 + getOffset(this.widthOffset, 10, 1200), 40,
				toLabel.getWidth() + getOffset(this.widthOffset, 20, 1200), 25);
		p5TimeEndText.setBounds(toLabel.getX() + toLabel.getWidth() + p5x5 + getOffset(this.widthOffset, 10, 1200), 40,
				p5TimeEndText.getWidth() + getOffset(this.widthOffset, 100, 1200), 25);
		p5ContentLabel.setBounds(
				p5TimeEndText.getX() + p5TimeEndText.getWidth() + p5x6 + getOffset(this.widthOffset, 50, 1200), 40,
				p5ContentLabel.getWidth() + getOffset(this.widthOffset, 70, 1200), 25);
		p5Contentjsp.setBounds(
				p5ContentLabel.getX() + p5ContentLabel.getWidth() + p5x7 + getOffset(this.widthOffset, 10, 1200), 20,
				p5Contentjsp.getWidth() + getOffset(this.widthOffset, 200, 1200), 80);
		p5Search.setBounds(p5Contentjsp.getX() + p5Contentjsp.getWidth() + p5x8 + getOffset(this.widthOffset, 50, 1200),
				40, p5Search.getWidth() + getOffset(this.widthOffset, 60, 1200), 25);
		p5Download.setBounds(p5Search.getX() + p5Search.getWidth() + p5x9 + getOffset(this.widthOffset, 20, 1200), 40,
				p5Download.getWidth() + getOffset(this.widthOffset, 100, 1200), 25);
		p5jsp.setBounds(p5jsp.getX() + getOffset(this.widthOffset, 20, 1200), p5jsp.getY(),
				p5jsp.getWidth() + getOffset(this.widthOffset, 1160, 1200), p5jsp.getHeight() + this.heightOffset);
		p5.revalidate();
		p5.repaint();
	}

	private int getOffset(double num1, int num2, int num3) {
		return (int) (num1 * num2 / num3);
	}

	private int getResultNum(List<String[]> msgData, boolean success) {
		int num = 0;
		String str = success ? "ɹ" : "ʧ";
		for (String[] row : msgData) {
			if (row[row.length - 1].contains(str)) {
				num++;
			}
		}
		return num;
	}
}
