public AddInvoiceDialog(java.awt.Frame parent, boolean modal, AddInvoiceDelegate delegate) {
        super(parent, modal);
        initComponents();

        this.delegate = delegate;

        comboPriceClass.addItem("A");
        comboPriceClass.addItem("B");
        DateOutlet.add(datepicker);
        datepicker.setDate(new Date());
        number = Database.driver().getInvoiceNumber(new Date());
        txtNumber.setText("" + number);
        table = createXTable();
        tablemodel = new InvoiceItemTableModel(data, pricecode);
        table.setModel(tablemodel);
        table.getColumns().get(0).setCellRenderer(CellRendererFactory.createIngredientCellRenderer());
	table.getColumns().get(1).setCellRenderer(CellRendererFactory.createZeroDecimalDoubleCellRenderer());
        table.getColumns().get(2).setCellRenderer(CellRendererFactory.createThreeDecimalDoubleCellRenderer());
        table.getColumns().get(3).setCellRenderer(CellRendererFactory.createThreeDecimalDoubleCellRenderer());
        table.getColumns().get(4).setCellRenderer(CellRendererFactory.createThreeDecimalDoubleCellRenderer());
	
	table.getColumns().get(0).setWidth(400);
	table.getColumns().get(0).setPreferredWidth(400);
	
        JScrollPane scrollpane = new JScrollPane(table);
        table.setName("invoiceTable");
        JXTitledPanel detailstitled = new JXTitledPanel("Details");
        detailstitled.add(detailspanel);
        detail.add(detailstitled, BorderLayout.NORTH);
        JXTitledPanel articlestitled = new JXTitledPanel("Artikelen");
        articlestitled.add(artikelspanel);
        detail.add(articlestitled, BorderLayout.CENTER);
        JXTitledPanel pricetitledpanel = new JXTitledPanel("Prijs");
        pricetitledpanel.add(pricepanel);
        detail.add(pricetitledpanel, BorderLayout.SOUTH);

//	table.setSelectionMode();
	
	txtReduction.setText("0.0");
	
        articlestablepanel.add(scrollpane, BorderLayout.CENTER);
        ArrayList clients = new ArrayList();
        clients.add("");
        clients.addAll(Database.driver().getClientsAlphabetically().values());
        clientBox = new AutocompleteCombobox(clients);
        ClientOutlet.add(clientBox, BorderLayout.CENTER);

        ArrayList articles = new ArrayList();
        articles.add("");
        articles.addAll(Database.driver().getArticlesAlphabetically().values());

        TextFieldAutoHighlighter.installHighlighter(txtReduction);
        TextFieldAutoHighlighter.installHighlighter(quantityoutlet);

        autobox = new AutocompleteCombobox(articles);
        choseartickleoutlet.add(autobox, BorderLayout.CENTER);

        ArrayList articlesbycode = new ArrayList();
        articlesbycode.add("");
        articlesbycode.addAll(Database.driver().getArticlesByCode().keySet());
        codepicker = new AutocompleteCombobox(articlesbycode);
        codeoutlet.add(codepicker, BorderLayout.CENTER);

//        this.pack();
        addValidators();
        setLocationRelativeTo(null);

        clientBox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String clientname = (String) clientBox.getSelectedItem();
                client = Database.driver().getClientsAlphabetically().get(clientname.toLowerCase());
                updatePriceClass(client.getPricecode());
            }
        });
	
	clientBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {

	    @Override
	    public void keyReleased(KeyEvent e) {
		if (clientBox.getSelectedItem() instanceof Contact) {
		    client = (Contact) clientBox.getSelectedItem();
		} else {
		    String clientname = (String) clientBox.getSelectedItem();
		    client = Database.driver().getClientsAlphabetically().get(clientname.toLowerCase());
		}
                updatePriceClass(client.getPricecode());
	    }
	    
	});

        comboPriceClass.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                updatePriceClass((String) comboPriceClass.getSelectedItem());
            }
        });

        datepicker.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                number = Database.driver().getInvoiceNumber(datepicker.getDate());
                txtNumber.setText("" + number);
            }
        });

        autobox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String stringart = (String) autobox.getSelectedItem();

                Article art = Database.driver().getArticlesAlphabetically().get(stringart);
                if(art!=null){
		    codepicker.setSelectedItem(art.getCode());
		} else {
		    codepicker.setSelectedIndex(0);
		}
            }
        });

        codepicker.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
		
		System.out.println("Derp");
		
                String code = (String) codepicker.getSelectedItem();

                Article art = Database.driver().getArticlesByCode().get(code);
                if(art!=null){
		    autobox.setSelectedItem(art.getName());
		} else {
		    autobox.setSelectedIndex(0);
		}
            }
        });

        autobox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB) {
                    quantityoutlet.requestFocus();
                }
            }
	    
	     @Override
	    public void keyReleased(KeyEvent e){
		 String stringart = (String) autobox.getSelectedItem();
		Article art = Database.driver().getArticlesAlphabetically().get(stringart);
		if(art!=null){
		    codepicker.setSelectedItem(art.getCode());
		} else {
		    codepicker.setSelectedIndex(0);
		}
	    }
	});

        codepicker.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB) {
                    quantityoutlet.requestFocus();
                }
            }
	    
	    @Override
	    public void keyReleased(KeyEvent e){
		String code = (String) codepicker.getSelectedItem();
		Article art = Database.driver().getArticlesByCode().get(code);
		if(art!=null){
		    autobox.setSelectedItem(art.getName());
		} else {
		    autobox.setSelectedIndex(0);
		}
	    }
        });


    }