package goodsbase.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.sql.SQLException;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;

public class MainWindow {


	/**
	 * Launch the application.
	 */
	public static void launch() {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainWindow window = new MainWindow();
					window.frmGoodsBase.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 * @throws SQLException 
	 */
	public MainWindow() throws SQLException {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 * @throws SQLException 
	 */
	private void initialize() throws SQLException {
		frmGoodsBase = new JFrame();
		frmGoodsBase.setTitle("Goods Base");
		frmGoodsBase.setIconImage(Toolkit.getDefaultToolkit().getImage(MainWindow.class.getResource("/Coin - Stacks (Silver)_24x24.gif")));
		frmGoodsBase.setBounds(100, 100, 800, 600);
		frmGoodsBase.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JMenuBar menuBar = new JMenuBar();
		frmGoodsBase.setJMenuBar(menuBar);
		
		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);
		
		JMenuItem mntmOpen = new JMenuItem("Open");
		mnFile.add(mntmOpen);
		
		JMenuItem mntmAbout = new JMenuItem("About");
		mntmAbout.setHorizontalAlignment(SwingConstants.TRAILING);
		mntmAbout.setHorizontalTextPosition(SwingConstants.LEFT);
		mntmAbout.setSize(new Dimension(77, 2));
		menuBar.add(mntmAbout);
		
		JSplitPane splitPane = new JSplitPane();
		splitPane.setResizeWeight(0.15);
		frmGoodsBase.getContentPane().add(splitPane, BorderLayout.CENTER);
		
		/*product table*/
		productTable = new JTable();
		productTable.setAutoCreateRowSorter(true);
		productTable.addMouseListener( new ProductTableMouseAdapter(this));
		productTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		/*product table popup menu*/
		JPopupMenu tablePopupMenu = new JPopupMenu();		
		JMenuItem item = new JMenuItem("Add Product");
		item.setActionCommand("addProduct");
		tablePopupMenu.add(item);
		item = new JMenuItem("Edit Product");
		item.setActionCommand("editProduct");
		tablePopupMenu.add(item);
		item = new JMenuItem("Remove Product");
		item.setActionCommand("removeProduct");
		tablePopupMenu.add(item);
		item = new JMenuItem("View at warehouse (double click)");
		item.setActionCommand("viewProductAtWh");
		tablePopupMenu.add(item);
		productTable.setComponentPopupMenu(tablePopupMenu);
		
		catTree = new CategoryTree();		
		catTree.addMouseListener(new CategoryTreeMouseAdapter(this));
	
		JScrollPane catScrollPane = new JScrollPane(catTree);
		splitPane.setLeftComponent(catScrollPane);
		
		JScrollPane prodScrollPane = new JScrollPane(productTable);
		splitPane.setRightComponent(prodScrollPane);
		
		JPanel statusBar = new JPanel();
		frmGoodsBase.getContentPane().add(statusBar, BorderLayout.SOUTH);
	}
	

	public JFrame getFrmGoodsBase() {
		return frmGoodsBase;
	}

	public JTable getProductTable() {
		return productTable;
	}

	public CategoryTree getCatTree() {
		return catTree;
	}


	private JFrame frmGoodsBase;
	private JTable productTable;
	private CategoryTree catTree;

}

@@ -14,24 +14,59 @@
 base.ui;%0D%0A%0D%0A
+import goodsbase.model.Product;%0D%0A%0D%0A
 import java.
@@ -163,24 +163,59 @@
 t.Toolkit;%0D%0A
+import java.awt.event.MouseEvent;%0D%0A
 import java.
@@ -2195,16 +2195,367 @@
 JTable()
+%7B%0D%0A%09%09%09@Override%0D%0A%09%09%09public String getToolTipText(MouseEvent event) %7B%0D%0A%09%09%09%09java.awt.Point p = event.getPoint();%0D%0A                int rowIndex = rowAtPoint(p);%0D%0A                if(rowIndex!=-1) %7B%0D%0A                %09return ((Product)getValueAt(rowIndex, 0))%0D%0A                %09%09%09%09.getDescription();%0D%0A                %7D%0D%0A                return %22%22;%0D%0A%09%09%09%7D%0D%0A%09%09%7D
 ;%0D%0A%09%09pro

add tooltips to table