rentalshop.Window.java Source code

Java tutorial

Introduction

Here is the source code for rentalshop.Window.java

Source

package rentalshop;

import java.awt.Component;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.sql.Date;
import java.sql.SQLException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.DataSource;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.apache.commons.dbcp.BasicDataSource;

public class Window extends javax.swing.JFrame {

    private static final long serialVersionUID = 1L;
    public static DataSource ds;
    public static FileHandler logg = null;
    private static final Logger logger = Logger.getLogger(Window.class.getName());

    private static DataSource prepareDataSource() throws SQLException {
        BasicDataSource bds = new BasicDataSource();

        bds.setUrl(java.util.ResourceBundle.getBundle("Resource/Database").getString("URL"));
        return bds;
    }

    int carRow = -1, custRow = -1, orderRow = -1;

    /**
     * Creates new form Window
     *
     * @throws SQLException
     * @throws MalformedURLException
     * @throws IOException  
     */
    public Window() throws SQLException, MalformedURLException, IOException {
        logg = new FileHandler("log.txt");
        logger.addHandler(logg);
        ds = prepareDataSource();
        DBUtils.tryCreateTables(ds, Window.class.getResource("rentalshop.sql"));
        initComponents();
        updateCbxs();
        logger.log(Level.INFO, "Window created");
    }

    @SuppressWarnings("unchecked")
    private void updateCbxs() {
        CarTableModel car = (CarTableModel) carTable.getModel();
        CustomerTableModel customer = (CustomerTableModel) customerTable.getModel();

        cbxCar.removeAllItems();
        int i = cbxCar.getItemCount();
        while (i < car.getRowCount()) {
            cbxCar.addItem(car.getValueAt(i, 1) + " " + car.getValueAt(i, 2) + " - " + car.getValueAt(i, 3));
            i++;
        }

        cbxCust.removeAllItems();
        int j = cbxCust.getItemCount();
        while (j < customer.getRowCount()) {
            cbxCust.addItem(customer.getValueAt(j, 2) + " " + customer.getValueAt(j, 1));
            j++;
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jButton1 = new javax.swing.JButton();
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        producerText = new javax.swing.JTextField();
        modelText = new javax.swing.JTextField();
        spzText = new javax.swing.JTextField();
        priceText = new javax.swing.JTextField();
        manufacturedText = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        carTable = new javax.swing.JTable();
        carTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent lse) {
                if (!lse.getValueIsAdjusting()) {
                    carRow = carTable.getSelectedRow();
                    //System.out.println("Selection Changed on car: "+carRow+" row");

                    if (carRow != -1) {
                        carLabel.setText(
                                java.util.ResourceBundle.getBundle("Resource/Czech").getString("Edit row"));
                        carSave.setText(java.util.ResourceBundle.getBundle("Resource/Czech").getString("Edit row"));

                        producerText.setText((String) carTable.getValueAt(carRow, 1));
                        modelText.setText((String) carTable.getValueAt(carRow, 2));
                        spzText.setText((String) carTable.getValueAt(carRow, 3));
                        manufacturedText.setText((String) carTable.getValueAt(carRow, 4).toString());
                        priceText.setText((String) carTable.getValueAt(carRow, 5).toString());
                    }
                }
            }
        });
        carLabel = new javax.swing.JLabel();
        carSave = new javax.swing.JButton();
        carClear = new javax.swing.JButton();
        carDeleteRow = new javax.swing.JButton();
        carCancel = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        nameText = new javax.swing.JTextField();
        surnameText = new javax.swing.JTextField();
        dlnText = new javax.swing.JTextField();
        debtsText = new javax.swing.JTextField();
        icnText = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        customerTable = new javax.swing.JTable();
        customerTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent lse) {
                if (!lse.getValueIsAdjusting()) {
                    custRow = customerTable.getSelectedRow();
                    //System.out.println("Selection Changed on customer: "+custRow+" row");

                    if (custRow != -1) {
                        custLabel.setText(
                                java.util.ResourceBundle.getBundle("Resource/Czech").getString("Edit row"));
                        customerSave.setText(
                                java.util.ResourceBundle.getBundle("Resource/Czech").getString("Edit row"));

                        nameText.setText((String) customerTable.getValueAt(custRow, 1));
                        surnameText.setText((String) customerTable.getValueAt(custRow, 2));
                        dlnText.setText((String) customerTable.getValueAt(custRow, 3).toString());
                        icnText.setText((String) customerTable.getValueAt(custRow, 4).toString());
                        debtsText.setText((String) customerTable.getValueAt(custRow, 5).toString());
                    }
                }
            }
        });
        custLabel = new javax.swing.JLabel();
        customerSave = new javax.swing.JButton();
        customerClear = new javax.swing.JButton();
        custDeleteRow = new javax.swing.JButton();
        custCancel = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        fromText = new javax.swing.JTextField();
        toText = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        orderTable = new javax.swing.JTable();
        orderTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent lse) {
                if (!lse.getValueIsAdjusting()) {
                    orderRow = orderTable.getSelectedRow();
                    //System.out.println("Selection Changed on order: "+orderRow+" row");

                    if (orderRow != -1) {
                        orderLabel.setText(
                                java.util.ResourceBundle.getBundle("Resource/Czech").getString("Edit row"));
                        orderSave.setText(
                                java.util.ResourceBundle.getBundle("Resource/Czech").getString("Edit row"));

                        fromText.setText((String) orderTable.getValueAt(orderRow, 1).toString());
                        toText.setText((String) orderTable.getValueAt(orderRow, 2).toString());
                        //cbxCar.setSelectedIndex();
                        //cbxCust.setSelectedIndex();
                    }
                }
            }
        });
        orderLabel = new javax.swing.JLabel();
        orderSave = new javax.swing.JButton();
        orderClear = new javax.swing.JButton();
        cbxCar = new javax.swing.JComboBox();
        cbxCust = new javax.swing.JComboBox();
        orderDeleteRow = new javax.swing.JButton();
        orderCancel = new javax.swing.JButton();

        jMenu1.setText("jMenu1");

        jMenu2.setText("jMenu2");

        jMenu3.setText("jMenu3");

        jMenuItem1.setText("jMenuItem1");

        jButton1.setText("jButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("Resource/Czech"); // NOI18N
        setTitle(bundle.getString("RentalShop")); // NOI18N
        setResizable(false);

        java.util.ResourceBundle bundle1 = java.util.ResourceBundle.getBundle("Resource/Czech_cs"); // NOI18N
        jTabbedPane1.setName(bundle1.getString("Order")); // NOI18N

        jPanel1.setPreferredSize(new java.awt.Dimension(850, 458));

        jLabel1.setText(bundle.getString("Producer")); // NOI18N

        jLabel2.setText(bundle.getString("Model")); // NOI18N

        jLabel3.setText(bundle1.getString("SPZ")); // NOI18N

        jLabel4.setText(bundle.getString("Manufactured")); // NOI18N

        jLabel5.setText(bundle.getString("Price")); // NOI18N

        carTable.setModel(new CarTableModel());
        jScrollPane1.setViewportView(carTable);

        carLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        carLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        carLabel.setText(bundle.getString("Add")); // NOI18N

        carSave.setText(bundle.getString("Save")); // NOI18N
        carSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carSaveActionPerformed(evt);
            }
        });

        carClear.setText(bundle.getString("Clear")); // NOI18N
        carClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carClearActionPerformed(evt);
            }
        });

        carDeleteRow.setText(bundle1.getString("Delete row")); // NOI18N
        carDeleteRow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carDeleteRowActionPerformed(evt);
            }
        });

        carCancel.setText(bundle1.getString("cancel")); // NOI18N
        carCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                carCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane1)
                        .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout
                                        .createSequentialGroup()
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel3).addComponent(jLabel1))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(producerText,
                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 250,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(spzText, javax.swing.GroupLayout.Alignment.TRAILING,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                        jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addComponent(carLabel, javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout
                                                        .createSequentialGroup().addComponent(jLabel5)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addComponent(priceText,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addComponent(carSave, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 400,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(0, 0, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66,
                                        Short.MAX_VALUE)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(carClear, javax.swing.GroupLayout.PREFERRED_SIZE, 400,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout
                                                .createSequentialGroup().addComponent(jLabel2)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(modelText, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        250, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout
                                                .createSequentialGroup().addComponent(jLabel4)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(manufacturedText,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 250,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout
                                                .createSequentialGroup()
                                                .addComponent(carCancel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(carDeleteRow, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        250, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(carDeleteRow).addComponent(carCancel))
                                .addComponent(carLabel, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(jPanel1Layout.createSequentialGroup()
                                                        .addComponent(jLabel2)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(jLabel4).addGap(13, 13, 13))
                                                .addGroup(jPanel1Layout.createSequentialGroup()
                                                        .addGroup(jPanel1Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.BASELINE)
                                                                .addComponent(producerText,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(jLabel1))
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(jPanel1Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.BASELINE)
                                                                .addComponent(spzText,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(jLabel3))
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                                .addGroup(jPanel1Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel5).addComponent(priceText,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout
                                        .createSequentialGroup()
                                        .addComponent(modelText, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(manufacturedText, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(29, 29, 29)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(carSave).addComponent(carClear))
                        .addContainerGap()));

        jTabbedPane1.addTab(bundle.getString("Car"), jPanel1); // NOI18N

        jLabel8.setText(bundle.getString("Name")); // NOI18N

        jLabel9.setText(bundle.getString("Surname")); // NOI18N

        jLabel10.setText(bundle.getString("Driving")); // NOI18N

        jLabel11.setText(bundle.getString("Identification")); // NOI18N

        jLabel12.setText(bundle.getString("Debts")); // NOI18N

        customerTable.setModel(new CustomerTableModel());
        jScrollPane2.setViewportView(customerTable);

        custLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        custLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        custLabel.setText(bundle1.getString("Add")); // NOI18N

        customerSave.setText(bundle.getString("Save")); // NOI18N
        customerSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerSaveActionPerformed(evt);
            }
        });

        customerClear.setText(bundle.getString("Clear")); // NOI18N
        customerClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerClearActionPerformed(evt);
            }
        });

        custDeleteRow.setText(bundle1.getString("Delete row")); // NOI18N
        custDeleteRow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                custDeleteRowActionPerformed(evt);
            }
        });

        custCancel.setText(bundle1.getString("cancel")); // NOI18N
        custCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                custCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane2)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel3Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addGroup(jPanel3Layout.createSequentialGroup()
                                                        .addComponent(jLabel8)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addComponent(nameText,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addComponent(customerSave, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        400, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGroup(jPanel3Layout.createSequentialGroup()
                                                        .addComponent(jLabel12)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addComponent(debtsText,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(jPanel3Layout.createSequentialGroup()
                                                        .addComponent(jLabel10,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 119,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addComponent(dlnText,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addComponent(custLabel))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66,
                                                Short.MAX_VALUE)
                                        .addGroup(jPanel3Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout
                                                        .createSequentialGroup()
                                                        .addComponent(custCancel,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(custDeleteRow,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout
                                                        .createSequentialGroup().addComponent(jLabel9)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addComponent(surnameText,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(jPanel3Layout.createSequentialGroup()
                                                                .addComponent(jLabel11).addGap(71, 71, 71)
                                                                .addComponent(icnText,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addComponent(customerClear,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 400,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addContainerGap()));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(custLabel)
                                .addGroup(jPanel3Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(custDeleteRow).addComponent(custCancel)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(nameText, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel8).addComponent(jLabel9).addComponent(surnameText,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(dlnText, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel10).addComponent(jLabel11).addComponent(icnText,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel12)
                                .addComponent(debtsText, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(customerClear).addComponent(customerSave))
                        .addContainerGap()));

        custLabel.getAccessibleContext().setAccessibleName(bundle1.getString("Add")); // NOI18N

        jTabbedPane1.addTab(bundle.getString("Customer"), jPanel3); // NOI18N

        jLabel15.setText(bundle.getString("from")); // NOI18N

        jLabel16.setText(bundle.getString("to")); // NOI18N

        jLabel17.setText(bundle.getString("Car")); // NOI18N

        jLabel18.setText(bundle.getString("Customer")); // NOI18N

        orderTable.setModel(new OrderTableModel());
        jScrollPane3.setViewportView(orderTable);

        orderLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        orderLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        orderLabel.setText(bundle1.getString("Add")); // NOI18N

        orderSave.setText(bundle.getString("Save")); // NOI18N
        orderSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orderSaveActionPerformed(evt);
            }
        });

        orderClear.setText(bundle.getString("Clear")); // NOI18N
        orderClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orderClearActionPerformed(evt);
            }
        });

        orderDeleteRow.setText(bundle1.getString("Delete row")); // NOI18N
        orderDeleteRow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orderDeleteRowActionPerformed(evt);
            }
        });

        orderCancel.setText(bundle1.getString("cancel")); // NOI18N
        orderCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orderCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(jPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap().addGroup(jPanel4Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane3)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel4Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addComponent(orderSave, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 400,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGroup(jPanel4Layout.createSequentialGroup()
                                                        .addGroup(jPanel4Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(jLabel15).addComponent(jLabel17,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 37,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addGroup(jPanel4Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                        false)
                                                                .addComponent(fromText,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 250,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(cbxCar, 0,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE))))
                                        .addComponent(orderLabel))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66,
                                                Short.MAX_VALUE)
                                        .addGroup(jPanel4Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout
                                                        .createSequentialGroup()
                                                        .addComponent(orderCancel,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(orderDeleteRow,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 250,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addComponent(orderClear, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        400, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout
                                                        .createSequentialGroup()
                                                        .addGroup(jPanel4Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(jLabel16).addComponent(jLabel18))
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addGroup(jPanel4Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                        false)
                                                                .addComponent(toText,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 250,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(cbxCust, 0,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE))))))
                        .addContainerGap()));
        jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 336,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(orderLabel).addComponent(orderDeleteRow).addComponent(orderCancel))
                        .addGap(4, 4, 4)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(toText, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel16)
                                .addComponent(fromText, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel18).addComponent(jLabel17)
                                .addComponent(cbxCar, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                                .addComponent(cbxCust, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(orderSave).addComponent(orderClear))
                        .addContainerGap()));

        jTabbedPane1.addTab(bundle1.getString("Order"), jPanel4); // NOI18N

        getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);
        jTabbedPane1.getAccessibleContext().setAccessibleName(bundle.getString("Car")); // NOI18N

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void customerClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerClearActionPerformed
        nameText.setText(null);
        surnameText.setText(null);
        dlnText.setText(null);
        icnText.setText(null);
        debtsText.setText(null);
    }//GEN-LAST:event_customerClearActionPerformed

    private CustomerSaveWorker customerSaveWorker;

    private class CustomerSaveWorker extends SwingWorker<Integer, Void> {

        @Override
        protected Integer doInBackground() throws Exception {
            // TODO add your handling code here:
            Customer cust = new Customer();
            try {
                cust.setName(nameText.getText());
                cust.setSurname(surnameText.getText());
                cust.setDrivingLicenseNumber(Integer.valueOf(dlnText.getText()));
                cust.setIdentificationCardNumber(Integer.valueOf(icnText.getText()));
                cust.setDebts(BigDecimal.valueOf(Double.valueOf(debtsText.getText())));

                CustomerTableModel model = (CustomerTableModel) customerTable.getModel();
                if (custRow == -1) {
                    model.addCustomer(cust);
                    logger.log(Level.INFO, "{0} added to customers", cust);
                } else {
                    model.updateCustomer((Long) carTable.getValueAt(custRow, 0), custRow, cust);
                    logger.log(Level.INFO, "{0} updated to customers", cust);
                }
                updateCbxs();
            } catch (NumberFormatException ex) {
                Component frame = null;
                JOptionPane.showMessageDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("Wrong input, check values"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                        JOptionPane.ERROR_MESSAGE);
                logger.log(Level.WARNING, "Error adding customer in Card number", ex);
            } catch (IllegalArgumentException ex) {
                Component frame = null;
                JOptionPane.showMessageDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("Wrong input, check values"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                        JOptionPane.ERROR_MESSAGE);
                logger.log(Level.WARNING, "Error adding customer, wrong values", ex);
            }
            return 0;
        }

        @Override
        protected void done() {
            customerSaveWorker = null;
        }
    }

    private void customerSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerSaveActionPerformed
        if (customerSaveWorker != null) {
            throw new IllegalStateException("Operation is already in progress");
        }
        customerSaveWorker = new CustomerSaveWorker();
        customerSaveWorker.execute();
    }//GEN-LAST:event_customerSaveActionPerformed

    private void carClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carClearActionPerformed
        producerText.setText(null);
        modelText.setText(null);
        spzText.setText(null);
        manufacturedText.setText(null);
        priceText.setText(null);
    }//GEN-LAST:event_carClearActionPerformed

    private CarSaveWorker carSaveWorker;

    private class CarSaveWorker extends SwingWorker<Integer, Void> {

        @Override
        protected Integer doInBackground() throws Exception {
            // TODO add your handling code here:
            Car car = new Car();
            try {
                //car.setID(1);
                if (new Integer(priceText.getText()) > 10000) {
                    throw new IllegalArgumentException("Price is greather than 10000");
                }
                car.setProducer(producerText.getText());
                car.setModel(modelText.getText());
                car.setSpz(spzText.getText());

                //Calendar cal = new GregorianCalendar();
                //cal.set(Integer.valueOf(manufacturedText.getText()), 1, 1);
                //Date date = new Date(cal.getTimeInMillis());
                //car.setManufactured(date);
                car.setManufactured(stringToDate(manufacturedText.getText()));

                car.setPrice(new BigDecimal(priceText.getText()));

                CarTableModel model = (CarTableModel) carTable.getModel();
                if (carRow == -1) {
                    model.addCar(car);
                    logger.log(Level.INFO, "{0} added to cars", car);
                } else {
                    model.updateCar((Long) carTable.getValueAt(carRow, 0), carRow, car);
                    logger.log(Level.INFO, "{0} updated to cars", car);
                }
                updateCbxs();
            } catch (IllegalArgumentException ex) {
                Component frame = null;
                JOptionPane.showMessageDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("Wrong input, check values"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                        JOptionPane.ERROR_MESSAGE);
                logger.log(Level.WARNING, "Error adding customer, wrong values", ex);
            }
            return 0;
        }

        @Override
        protected void done() {
            carSaveWorker = null;
        }
    }

    private void carSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carSaveActionPerformed
        if (carSaveWorker != null) {
            throw new IllegalStateException("Operation is already in progress");
        }
        carSaveWorker = new CarSaveWorker();
        carSaveWorker.execute();

        //car.setPrice(new BigDecimal(priceText.getText()));

    }//GEN-LAST:event_carSaveActionPerformed

    private OrderSaveWorker orderSaveWorker;

    private class OrderSaveWorker extends SwingWorker<Integer, Void> {

        @Override
        protected Integer doInBackground() throws Exception {
            // TODO add your handling code here:
            Order order = new Order();
            try {
                CarTableModel car = (CarTableModel) carTable.getModel();
                CustomerTableModel customer = (CustomerTableModel) customerTable.getModel();

                order.setFrom(stringToDate(fromText.getText()));
                order.setTo(stringToDate(toText.getText()));

                CustomerManagerImpl cust = new CustomerManagerImpl();
                cust.setCon(ds);
                CarManagerImpl carM = new CarManagerImpl();
                carM.setCon(ds);

                order.setCar(carM.readAll().get(cbxCar.getSelectedIndex()));
                order.setCustomer(cust.readAll().get(cbxCust.getSelectedIndex()));

                OrderTableModel model = (OrderTableModel) orderTable.getModel();
                if (orderRow == -1) {
                    model.addOrder(order);
                    logger.log(Level.INFO, "{0} added to orders", order);
                } else {
                    model.updateOrder((Long) carTable.getValueAt(orderRow, 0), orderRow, order);
                    logger.log(Level.INFO, "{0} updated to orders", order);
                }
                updateCbxs();
            } catch (NumberFormatException ex) {
                Component frame = null;
                JOptionPane.showMessageDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("Wrong input, check values"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                        JOptionPane.ERROR_MESSAGE);
                logger.log(Level.WARNING, "Wrong date format", ex);
            } catch (IllegalArgumentException ex) {
                Component frame = null;
                JOptionPane.showMessageDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("Wrong input, check values"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                        JOptionPane.ERROR_MESSAGE);
                logger.log(Level.WARNING, "Error adding order, wrong values", ex);
            } catch (ArrayIndexOutOfBoundsException ex) {
                Component frame = null;
                JOptionPane.showMessageDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("Wrong input, check values"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                        JOptionPane.ERROR_MESSAGE);
                logger.log(Level.WARNING, "Error adding order, wrong values", ex);
            }

            return 0;
        }

        @Override
        protected void done() {
            orderSaveWorker = null;
        }
    }

    private void orderSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderSaveActionPerformed
        if (orderSaveWorker != null) {
            throw new IllegalStateException("Operation is already in progress");
        }
        orderSaveWorker = new OrderSaveWorker();
        orderSaveWorker.execute();
    }//GEN-LAST:event_orderSaveActionPerformed

    private Date stringToDate(String s) {
        Date date = Date.valueOf(s);
        // Calendar cal = new GregorianCalendar();
        // cal.set(Integer.valueOf(from[0]), Integer.valueOf(from[1]), Integer.valueOf(from[2]));
        // Date date = new Date(cal.getTimeInMillis());
        return date;
    }

    private void orderClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderClearActionPerformed
        fromText.setText(null);
        toText.setText(null);
    }//GEN-LAST:event_orderClearActionPerformed

    private CarDeleteWorker carDeleteWorker;

    private class CarDeleteWorker extends SwingWorker<Integer, Void> {

        @Override
        protected Integer doInBackground() throws Exception {
            Component frame = null;
            if (carRow == -1) {
                JOptionPane.showMessageDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("no select"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                        JOptionPane.ERROR_MESSAGE);
                logger.log(Level.WARNING, "Error deleting car");
            } else {

                Long id = (Long) carTable.getValueAt(carRow, 0);
                OrderTableModel model = (OrderTableModel) orderTable.getModel();
                for (int i = 0; i < model.getRowCount(); i++) {

                    if (id == ((Car) model.getValueAt(i, 3)).getID()) {
                        JOptionPane.showMessageDialog(frame,
                                java.util.ResourceBundle.getBundle("Resource/Czech").getString("car used"),
                                java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                                JOptionPane.ERROR_MESSAGE);
                        return 1;
                    }
                }
                Object[] options = { java.util.ResourceBundle.getBundle("Resource/Czech").getString("Yes"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("No") };

                int response = JOptionPane.showOptionDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech")
                                .getString("Do you want to delete this item"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("Car"),
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

                if (response == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("JOptionPane closed");
                } else if (response == JOptionPane.NO_OPTION) {
                    //System.out.println("No button clicked");
                } else if (response == JOptionPane.YES_OPTION) {
                    logger.log(Level.INFO, "Car row {0} has been deleted.", carRow);
                    CarTableModel modelC = (CarTableModel) carTable.getModel();
                    modelC.deleteCar(id, carRow);
                    updateCbxs();
                }
            }

            return 0;
        }

        @Override
        protected void done() {
            carDeleteWorker = null;
        }
    }

    private void carDeleteRowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carDeleteRowActionPerformed
        if (carDeleteWorker != null) {
            throw new IllegalStateException("Operation is already in progress");
        }
        carDeleteWorker = new CarDeleteWorker();
        carDeleteWorker.execute();
    }//GEN-LAST:event_carDeleteRowActionPerformed

    private OrderDeleteWorker orderDeleteWorker;

    private class OrderDeleteWorker extends SwingWorker<Integer, Void> {

        @Override
        protected Integer doInBackground() throws Exception {
            Component frame = null;
            if (orderRow == -1) {
                JOptionPane.showMessageDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("no select"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                        JOptionPane.ERROR_MESSAGE);
                logger.log(Level.WARNING, "Error deleting order");
            } else {
                Object[] options = { java.util.ResourceBundle.getBundle("Resource/Czech").getString("Yes"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("No") };
                int response = JOptionPane.showOptionDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech")
                                .getString("Do you want to delete this item"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("Order"),
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

                if (response == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("JOptionPane closed");
                } else if (response == JOptionPane.NO_OPTION) {
                    //System.out.println("No button clicked");
                } else if (response == JOptionPane.YES_OPTION) {
                    logger.log(Level.INFO, "Order row {0} has been deleted.", orderRow);
                    OrderTableModel model = (OrderTableModel) orderTable.getModel();
                    model.deleteOrder((Long) orderTable.getValueAt(orderRow, 0), orderRow);
                    updateCbxs();
                }
            }

            return 0;
        }

        @Override
        protected void done() {
            orderDeleteWorker = null;
        }
    }

    private void orderDeleteRowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderDeleteRowActionPerformed
        if (orderDeleteWorker != null) {
            throw new IllegalStateException("Operation is already in progress");
        }
        orderDeleteWorker = new OrderDeleteWorker();
        orderDeleteWorker.execute();
    }//GEN-LAST:event_orderDeleteRowActionPerformed

    private CustDeleteWorker custDeleteWorker;

    private class CustDeleteWorker extends SwingWorker<Integer, Void> {

        @Override
        protected Integer doInBackground() throws Exception {
            Component frame = null;
            if (custRow == -1) {
                JOptionPane.showMessageDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("no select"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                        JOptionPane.ERROR_MESSAGE);
                logger.log(Level.WARNING, "Error deleting customer");
            } else {
                Long id = (Long) customerTable.getValueAt(custRow, 0);
                CustomerTableModel model = (CustomerTableModel) customerTable.getModel();
                OrderTableModel modelT = (OrderTableModel) orderTable.getModel();
                for (int i = 0; i < modelT.getRowCount(); i++) {
                    if (id == ((Customer) modelT.getValueAt(i, 4)).getID()) {
                        JOptionPane.showMessageDialog(frame,
                                java.util.ResourceBundle.getBundle("Resource/Czech").getString("cust used"),
                                java.util.ResourceBundle.getBundle("Resource/Czech").getString("error"),
                                JOptionPane.ERROR_MESSAGE);
                        return 1;
                    }
                }
                Object[] options = { java.util.ResourceBundle.getBundle("Resource/Czech").getString("Yes"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("No") };
                int response = JOptionPane.showOptionDialog(frame,
                        java.util.ResourceBundle.getBundle("Resource/Czech")
                                .getString("Do you want to delete this item"),
                        java.util.ResourceBundle.getBundle("Resource/Czech").getString("Customer"),
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

                if (response == JOptionPane.CLOSED_OPTION) {
                    //System.out.println("JOptionPane closed");
                } else if (response == JOptionPane.NO_OPTION) {
                    //System.out.println("No button clicked");
                } else if (response == JOptionPane.YES_OPTION) {
                    logger.log(Level.INFO, "Customer row {0} has been deleted.", custRow);
                    model.deleteCustomer(id, custRow);
                    updateCbxs();
                }
            }
            return 0;
        }

        @Override
        protected void done() {
            custDeleteWorker = null;
        }
    }

    private void custDeleteRowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_custDeleteRowActionPerformed
        if (custDeleteWorker != null) {
            throw new IllegalStateException("Operation is already in progress");
        }
        custDeleteWorker = new CustDeleteWorker();
        custDeleteWorker.execute();
    }//GEN-LAST:event_custDeleteRowActionPerformed

    private void carCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_carCancelActionPerformed
        carRow = -1;
        carLabel.setText(java.util.ResourceBundle.getBundle("Resource/Czech").getString("Add"));
        carSave.setText(java.util.ResourceBundle.getBundle("Resource/Czech").getString("Save"));
        producerText.setText(null);
        modelText.setText(null);
        spzText.setText(null);
        manufacturedText.setText(null);
        priceText.setText(null);
        carTable.getSelectionModel().clearSelection();
    }//GEN-LAST:event_carCancelActionPerformed

    private void custCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_custCancelActionPerformed
        custRow = -1;
        custLabel.setText(java.util.ResourceBundle.getBundle("Resource/Czech").getString("Add"));
        customerSave.setText(java.util.ResourceBundle.getBundle("Resource/Czech").getString("Save"));
        nameText.setText(null);
        surnameText.setText(null);
        dlnText.setText(null);
        icnText.setText(null);
        debtsText.setText(null);
        customerTable.getSelectionModel().clearSelection();
    }//GEN-LAST:event_custCancelActionPerformed

    private void orderCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderCancelActionPerformed
        orderRow = -1;
        orderLabel.setText(java.util.ResourceBundle.getBundle("Resource/Czech").getString("Add"));
        orderSave.setText(java.util.ResourceBundle.getBundle("Resource/Czech").getString("Save"));
        fromText.setText(null);
        toText.setText(null);
        orderTable.getSelectionModel().clearSelection();
    }//GEN-LAST:event_orderCancelActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Window.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Window.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Window.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Window.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>
        //Locale.setDefault(Locale.FRENCH);
        //Locale.setDefault(Locale.ENGLISH);
        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                try {
                    new Window().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
                } catch (MalformedURLException ex) {
                    Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.JButton carCancel;
    private javax.swing.JButton carClear;
    private javax.swing.JButton carDeleteRow;
    private javax.swing.JLabel carLabel;
    private javax.swing.JButton carSave;
    private javax.swing.JTable carTable;
    private javax.swing.JComboBox cbxCar;
    private javax.swing.JComboBox cbxCust;
    private javax.swing.JButton custCancel;
    private javax.swing.JButton custDeleteRow;
    private javax.swing.JLabel custLabel;
    private javax.swing.JButton customerClear;
    private javax.swing.JButton customerSave;
    private javax.swing.JTable customerTable;
    private javax.swing.JTextField debtsText;
    private javax.swing.JTextField dlnText;
    private javax.swing.JTextField fromText;
    private javax.swing.JTextField icnText;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField manufacturedText;
    private javax.swing.JTextField modelText;
    private javax.swing.JTextField nameText;
    private javax.swing.JButton orderCancel;
    private javax.swing.JButton orderClear;
    private javax.swing.JButton orderDeleteRow;
    private javax.swing.JLabel orderLabel;
    private javax.swing.JButton orderSave;
    private javax.swing.JTable orderTable;
    private javax.swing.JTextField priceText;
    private javax.swing.JTextField producerText;
    private javax.swing.JTextField spzText;
    private javax.swing.JTextField surnameText;
    private javax.swing.JTextField toText;
    // End of variables declaration//GEN-END:variables
}