public void addItemEventHandler() {
        // add chosen item to the shopping cart.
        StockItem stockItem = (StockItem)productSelectionJComboBoxField.getSelectedItem();
        if (stockItem != null) {
            int quantity;
            try {
                quantity = Integer.parseInt(quantityField.getText());
            } catch (NumberFormatException ex) {
                quantity = 1;
            }
            
            if(quantity > 0) {
				int qtyInUse = 0;
				int itemIndex = 0;
				List<SoldItem> rows = model.getCurrentPurchaseTableModel().getTableRows();
				for(; itemIndex < rows.size(); itemIndex++) {
					if(rows.get(itemIndex).getId() == stockItem.getId()) {
						qtyInUse += rows.get(itemIndex).getQuantity();
						break;
					}
				}
				
				if(quantity + qtyInUse <= stockItem.getQuantity()) {
					model.getCurrentPurchaseTableModel().addItem(new SoldItem(stockItem, quantity));
				} else {
					JOptionPane.showMessageDialog(null,
	            		    "Warehouse has less items.",
	            		    "Error",
	            		    JOptionPane.ERROR_MESSAGE);
					}
				} else {
					JOptionPane.showMessageDialog(null,
	            		    "Quantity must be 1 or bigger.",
	            		    "Error",
	            		    JOptionPane.ERROR_MESSAGE);
				}
			}
		}