Скачиваний:
62
Добавлен:
15.06.2014
Размер:
26.49 Кб
Скачать
package magazinehelper;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import lists.DepartmentListModel;
import tables.BoughtProductsTableModel;
import tables.FilterByDepartmentTableModelFBP;
import tables.FilterByDepartmentTableModelFUBP;
import tables.MyMainTableModel;
import workingwithfiles.BaseProductFileWriter;
import dialogs.AddProductDialog;
import dialogs.BoughtProductsDialog;
import dialogs.BuyProductDialog;
import dialogs.SearchProductDialog;

public class ABS
implements ActionListener {
//add product dialog object
private AddProductDialog addproductDialog;

//buy products
BuyProductDialog buyproductDialog;

//add search by dialog
private SearchProductDialog searchproductDialog;

//main frame of our application
private JFrame myapplication;

//main table model
private MyMainTableModel main_tablemodel;

//department list model
private DepartmentListModel department_list_model_for_unbought_products;
private DepartmentListModel department_list_model_for_bought_products;
//department list
private JList department_list_for_unbought_products;
private JList department_list_for_bought_products;

//mouse listener for JList
private MouseListener mouseListenerForUnBoughtProducts;
private MouseListener mouseListenerForBoughtProducts;

private JTable main_table;

private JScrollPane main_jscrollpane;

//our GUI constructor
ABS() {

main_tablemodel = new MyMainTableModel();
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();

//create new JFrame container
myapplication = new JFrame("ABS(Assistant by shop)");
//set start frame size
myapplication.setSize(900,600);
//when user close application
myapplication.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//set minimum size of main app window
myapplication.setMinimumSize(new Dimension(800,600));

ImageIcon icon = new ImageIcon("shop2.jpg");
myapplication.setIconImage(icon.getImage());

//create JPanel
JPanel mainpanel = new JPanel();
//add panel to frame
myapplication.add(mainpanel);
//create BorderLayout object
BorderLayout borderlayout = new BorderLayout();
//add to the panel BorderLayout Manager
mainpanel.setLayout(borderlayout);

//set any elements
//JButton but1 = new JButton("1");
//but1.setMinimumSize(new Dimension(250,0));
//JButton but2 = new JButton("2");

//JToolBar but2 = new JToolBar();

//but2.setMinimumSize(new Dimension(50,0));
//but2.add(new JButton("1"));

//ADD JTABBEDPANE
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setMinimumSize(new Dimension(220,0));
JComponent panel1 = createBoughtProductsPanel();
JComponent panel2 = createOnSalePanel();
tabbedPane.add("On Sale",panel2);
tabbedPane.add("Bought Products",panel1);

/*
JComponent panel3 = makeTextPanel("Panel #3");
tabbedPane.add("Tab 3",panel3);
JComponent panel4 = makeTextPanel("Panel #4");
tabbedPane.add("Tab 4",panel4);
*/

////////////////////////////////////////////////


//Create main table and main table model and add it to JScrollPane
///////////////////////////////////////////////////////////////////

main_table = new JTable(main_tablemodel);
main_jscrollpane = new JScrollPane(main_table);

///////////////////////////////////////////////////////////////////

//ADD JSPLITPANE
JSplitPane main_splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,tabbedPane,main_jscrollpane);

//CREATE MAIN MENU IN OUR PROGRAM
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
JMenuBar menubar = new JMenuBar();

//create "File" menu
JMenu filemenu = new JMenu("File");
//"File" menu includes sub-menu
JMenuItem openItem = new JMenuItem("Open");
JMenuItem saveItem = new JMenuItem("Save");
JMenuItem saveasItem = new JMenuItem("Save as");
JMenuItem exitItem = new JMenuItem("Exit");
JMenuItem testItem = new JMenuItem("Test");
//including items into "File" menu
filemenu.add(openItem);
filemenu.add(saveItem);
filemenu.add(saveasItem);
filemenu.add(exitItem);
filemenu.add(testItem);
//create "Edit" menu
JMenu editmenu = new JMenu("Edit");
//"Edit" menu includes sub-menu
JMenuItem copyItem = new JMenuItem("Copy");
JMenuItem pasteItem = new JMenuItem("Paste");
JMenuItem cutItem = new JMenuItem("Cut");
//including items into "Edit" menu
editmenu.add(copyItem);
editmenu.add(pasteItem);
editmenu.add(cutItem);

//create "Magazine" menu
JMenu magazinemenu = new JMenu("Magazine");
//"Magazine" menu includes sub-menu
JMenuItem magazinesItem = new JMenuItem("Magazines");
JMenuItem addmagazineItem = new JMenuItem("Add magazine");
JMenuItem deletemagazineItem = new JMenuItem("Delete magazine");
JMenuItem searchmagazineItem = new JMenuItem("Search magazine");
//including items into "Magazine" menu
magazinemenu.add(magazinesItem);
magazinemenu.add(addmagazineItem);
magazinemenu.add(deletemagazineItem);
magazinemenu.add(searchmagazineItem);

//create "Department" menu
JMenu departmentmenu = new JMenu("Department");
//"Department" menu includes sub-menu
JMenuItem departmentsItem = new JMenuItem("Departments");
JMenuItem adddepartmentItem = new JMenuItem("Add department");
JMenuItem deletedepartmentItem = new JMenuItem("Delete department");
JMenuItem searchdepartmentItem = new JMenuItem("Search department");
JMenuItem updatedepartmentsItem = new JMenuItem("Update departments");
//including items into "Department" menu
departmentmenu.add(departmentsItem);
departmentmenu.add(adddepartmentItem);
departmentmenu.add(deletedepartmentItem);
departmentmenu.add(searchdepartmentItem);
departmentmenu.add(updatedepartmentsItem);

//create "Product" menu
JMenu productmenu = new JMenu("Product");
//"Product" menu includes sub-menu
JMenuItem addproductItem = new JMenuItem("Add product");
JMenuItem deleteproductItem = new JMenuItem("Delete product");
//including items into "Product" menu
productmenu.add(addproductItem);
productmenu.add(deleteproductItem);

//create "Search" menu
JMenu searchmenu = new JMenu("Search");
//"Search" menu includes sub-menu
JMenuItem searchbyItem = new JMenuItem("Search by");

//including items into "Search" menu
searchmenu.add(searchbyItem);

//create "Sorting" menu
JMenu sortingmenu = new JMenu("Sorting");
//"Sorting" menu includes sub-menu
JMenuItem sortbynameItem = new JMenuItem("Sort by name");
JMenuItem sortbyarrivaldateItem = new JMenuItem("Sort by arrival date");
JMenuItem sortbymakerItem = new JMenuItem("Sort by maker");
JMenuItem sortbypriceItem = new JMenuItem("Sort by price");
JMenuItem sortbytypeItem = new JMenuItem("Sort by type");
JMenuItem sortbyshelflifeItem = new JMenuItem("Sort by shelflife");
JMenuItem sortbyweightItem = new JMenuItem("Sort by weight");
JMenuItem sortbynumberItem = new JMenuItem("Sort by number");
JMenuItem sortbycountryItem = new JMenuItem("Sort by country");
JMenuItem sortbymakeraddressItem = new JMenuItem("Sort by maker address");
JMenuItem sortbymakersiteItem = new JMenuItem("Sort by maker site");
JMenuItem sortbymakermailItem = new JMenuItem("Sort by maker mail");
JMenuItem sortbymakerphoneItem = new JMenuItem("Sort by maker phone");
JMenuItem sortbydepartmentItem = new JMenuItem("Sort by department");
//including items into "Sorting" menu
sortingmenu.add(sortbynameItem);
sortingmenu.add(sortbyarrivaldateItem);
sortingmenu.add(sortbymakerItem);
sortingmenu.add(sortbypriceItem);
sortingmenu.add(sortbytypeItem);
sortingmenu.add(sortbyshelflifeItem);
sortingmenu.add(sortbyweightItem);
sortingmenu.add(sortbynumberItem);
sortingmenu.add(sortbycountryItem);
sortingmenu.add(sortbymakeraddressItem);
sortingmenu.add(sortbymakersiteItem);
sortingmenu.add(sortbymakermailItem);
sortingmenu.add(sortbymakerphoneItem);
sortingmenu.add(sortbydepartmentItem);

//create "Buy" menu
JMenu buymenu = new JMenu("Buy");
//"Buy" menu includes sub-menu
JMenuItem buyItem = new JMenuItem("Buy products");
JMenuItem showboughtproductsItem = new JMenuItem("Show bought products");
//including items into "Buy" menu
buymenu.add(buyItem);
buymenu.add(showboughtproductsItem);

//create "Profit" menu
JMenu profitmenu = new JMenu("Profit");
//"Profit" menu includes sub-menu
JMenuItem gettotalprofit = new JMenuItem("Get total profit");
JMenuItem getprofitbymagazine = new JMenuItem("Get profit by magazine");
JMenuItem getprofitbydepartment = new JMenuItem("Get profit by department");
JMenuItem getalistofitemssold = new JMenuItem("Get a list of items sold");
//including items into "Profit" menu
profitmenu.add(gettotalprofit);
profitmenu.add(getprofitbymagazine);
profitmenu.add(getprofitbydepartment);
profitmenu.add(getalistofitemssold);

//create "Options" menu
JMenuItem optionsmenu = new JMenu("Options");
//"Options" menu includes sub-menus
JMenuItem windowoptionsItem = new JMenuItem("Window options");
JMenuItem languageoptionsItem = new JMenuItem("Language options");
JMenuItem propertiesoptionsItem = new JMenuItem("Properties options");
//including items into "Options" menu
optionsmenu.add(windowoptionsItem);
optionsmenu.add(languageoptionsItem);
optionsmenu.add(propertiesoptionsItem);

//create "Help" menu
JMenu helpmenu = new JMenu("Help");
//"Help" menu includes sub-menus
JMenuItem helpItem = new JMenuItem("Help");
JMenuItem aboutItem = new JMenuItem("About");
//including items into "Help" menu
helpmenu.add(helpItem);
helpmenu.add(aboutItem);

//link menus into menu bar
menubar.add(filemenu);
menubar.add(editmenu);
menubar.add(magazinemenu);
menubar.add(departmentmenu);
menubar.add(productmenu);
menubar.add(searchmenu);
menubar.add(sortingmenu);
menubar.add(buymenu);
menubar.add(profitmenu);
menubar.add(optionsmenu);
menubar.add(helpmenu);
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////

//BINDING AN EVENT HANDLER TO THE MENU
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////

//"File" menu
//for exit from program
exitItem.addActionListener(this);
//for test item
testItem.addActionListener(this);

//for adding product
addproductItem.addActionListener(this);

//"Department" menu
updatedepartmentsItem.addActionListener(this);

//"Buy" menu
buyItem.addActionListener(this);
showboughtproductsItem.addActionListener(this);

//"Sorting" menu
//for sorting by name
sortbynameItem.addActionListener(this);
//for sorting by number
sortbynumberItem.addActionListener(this);
//for sorting by price
sortbypriceItem.addActionListener(this);
//for sorting by country
sortbycountryItem.addActionListener(this);
//for sorting by type
sortbytypeItem.addActionListener(this);
//for sorting by weight
sortbyweightItem.addActionListener(this);
//for sorting by maker site
sortbymakersiteItem.addActionListener(this);
//for sorting by maker mail
sortbymakermailItem.addActionListener(this);
//for sorting by shelf life
sortbyshelflifeItem.addActionListener(this);
//for sorting by maker phone
sortbymakerphoneItem.addActionListener(this);
//for sorting by maker address
sortbymakeraddressItem.addActionListener(this);
//for sorting by department
sortbydepartmentItem.addActionListener(this);
//for sorting by maker
sortbymakerItem.addActionListener(this);
//for sorting by arrival date
sortbyarrivaldateItem.addActionListener(this);


//"Search" menu
searchbyItem.addActionListener(this);

///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////



//mainpanel.add(but2,BorderLayout.NORTH);
//mainpanel.add(but1,BorderLayout.WEST);
mainpanel.add(main_splitpane,BorderLayout.CENTER);

//add menu to JFrame
myapplication.setJMenuBar(menubar);
//set visible our application
myapplication.setVisible(true);
}

//EVENT HANDLING ACTIONS FOR MENU ITEMS
public void actionPerformed(ActionEvent event) {
String pushedItem = event.getActionCommand();

//if was pushed exit item
if(pushedItem.equals("Exit"))
System.exit(0);

if(pushedItem.equals("Test")) {
main_tablemodel.getDepartmentContainer().updateDepartmentNamesForUnboughtProducts();
main_tablemodel.getDepartmentContainer().showInConsoleDepartmentNames();
}

//if was pushed add product item
if(pushedItem.equals("Add product")) {
addproductDialog = new AddProductDialog(myapplication,"Add product",true,main_tablemodel,department_list_model_for_unbought_products);
}

//"SORTING MENU"
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//if was pushed "Sort by name" item
if(pushedItem.equals("Sort by name")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByName();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by number" item
if(pushedItem.equals("Sort by number")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByNumber();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by price" item
if(pushedItem.equals("Sort by price")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByPrice();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by country" item
if(pushedItem.equals("Sort by country")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByCountry();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by type" item
if(pushedItem.equals("Sort by type")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByType();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by weight" item
if(pushedItem.equals("Sort by weight")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByWeight();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by maker site" item
if(pushedItem.equals("Sort by maker site")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByMakerSite();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by maker mail" item
if(pushedItem.equals("Sort by maker mail")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByMakerMail();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by shelf life" item
if(pushedItem.equals("Sort by shelflife")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByShelfLife();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by maker phone" item
if(pushedItem.equals("Sort by maker phone")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByMakerPhone();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by maker phone" item
if(pushedItem.equals("Sort by maker address")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByMakerAddress();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by department" item
if(pushedItem.equals("Sort by department")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByDepartment();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by maker" item
if(pushedItem.equals("Sort by maker")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByMaker();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
//if was pushed "Sort by arrival date" item
if(pushedItem.equals("Sort by arrival date")) {
main_tablemodel.getDepartmentContainer().getAllProductsContainer().sortingByArrivalDate();
//write to file
BaseProductFileWriter baseproductfilewriter = new BaseProductFileWriter();
baseproductfilewriter.writeToFile(main_tablemodel.getDepartmentContainer().getAllProductsContainer(), "baseproductdata.xml");
main_tablemodel.getDepartmentContainer().generalUpdateDepartmentContainer();
main_tablemodel.updateAllTable();
}
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

//SEARCH MENU
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

if(pushedItem.equals("Search by")) {
searchproductDialog = new SearchProductDialog(myapplication,"Search by",true,main_tablemodel);

}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

//"DEPARTMENT" MENU
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

if(pushedItem.equals("Update departments")) {
//department_list_model.addElement("5");
department_list_model_for_unbought_products.updateAllNames(main_tablemodel.getDepartmentContainer().getDepartmentNamesForUnboughtProducts());
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////


//"BUY" MENU
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

if(pushedItem.equals("Buy products")) {
buyproductDialog = new BuyProductDialog(myapplication,"Buy",true,main_tablemodel,department_list_model_for_unbought_products,department_list_model_for_bought_products);

}

if(pushedItem.equals("Show bought products")) {
BoughtProductsDialog dlg = new BoughtProductsDialog(myapplication,"Bought products",true);
}

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//WebLookAndFeel.install();
//WebLookAndFeel.setDecorateAllWindows(true);
//WebLookAndFeel.setDecorateDialogs(true);
//WebLookAndFeel.setDecorateFrames(true);

new ABS();
}
});
}

public JComponent createOnSalePanel() {
JPanel panel = new JPanel(false);

department_list_model_for_unbought_products = new DepartmentListModel(main_tablemodel.getDepartmentContainer().getDepartmentNamesForUnboughtProducts(),"All products");
department_list_for_unbought_products = new JList(department_list_model_for_unbought_products);
mouseListenerForUnBoughtProducts = new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
if(event.getClickCount() == 1) {
String selectedItem = (String)department_list_for_unbought_products.getSelectedValue();
if(selectedItem.equals("On sale")) {
//set standart table model for all products
main_table.setModel(main_tablemodel);
}
else {
//create and set new model
FilterByDepartmentTableModelFUBP model = new FilterByDepartmentTableModelFUBP(selectedItem);
main_table.setModel(model);
}
}
}
};
department_list_for_unbought_products.addMouseListener(mouseListenerForUnBoughtProducts);

panel.setLayout(new GridLayout(1, 1));
panel.add(department_list_for_unbought_products);
return panel;
}

public JComponent createBoughtProductsPanel() {
JPanel panel = new JPanel(false);

department_list_model_for_bought_products = new DepartmentListModel(main_tablemodel.getDepartmentContainer().getDepartmentNamesForBoughtProducts(),"All bought products");
department_list_for_bought_products = new JList(department_list_model_for_bought_products);
mouseListenerForBoughtProducts = new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
if(event.getClickCount() == 1) {
String selectedItem = (String)department_list_for_bought_products.getSelectedValue();
if(selectedItem.equals("All bought products")) {
BoughtProductsTableModel model = new BoughtProductsTableModel();
main_table.setModel(model);
}
else {
//create and set new model
System.out.println(selectedItem);
FilterByDepartmentTableModelFBP model = new FilterByDepartmentTableModelFBP(selectedItem);
model.getDepartmentContainer().getBoughtProductsContainer().showInConsole();
main_table.setModel(model);
}
}
}
};
department_list_for_bought_products.addMouseListener(mouseListenerForBoughtProducts);

panel.setLayout(new GridLayout(1, 1));
panel.add(department_list_for_bought_products);
return panel;
}
}