private void saveDocument()
    {
        if (currentFile == null)
            saveAsDocument();
        else
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    OutputStream out = null;

                    try
                    {
                        setEnabled(false);
                        setCursor(Cursor
                                .getPredefinedCursor(Cursor.WAIT_CURSOR));
                        out = new FileOutputStream(currentFile);

                        JTable table = getTable();
                        com.eteks.codec.JeksCodec codec = new com.eteks.codec.JeksCodec(
                                table, state);
                        codec.encode(out, table);

                        setTitle(TITLE_BASE + " - " + currentFile.getName());
                        if (tableChanged)
                            table.getModel().addTableModelListener(
                                    changeListener);
                        tableChanged = false;
                    } catch (IOException e)
                    {
                        JOptionPane.showMessageDialog(JeksFrame.this,
                                e.getMessage(),
                                resourceBundle.getString("FILE_SAVE_MENU"),
                                JOptionPane.ERROR_MESSAGE);
                    } finally
                    {
                        try
                        {
                            if (out != null)
                                out.close();
                        } catch (IOException e)
                        {
                        }
                        setCursor(Cursor.getDefaultCursor());
                        setEnabled(true);
                    }
                    InputStream in = null;
                    try
                    {
                        // TODO: HANDLE null pointer exception
                        JeksTable tbl = (JeksTable) JeksFrame.this.getTable();
                        in = new FileInputStream(currentFile);
                        com.eteks.codec.JeksCodec codec = com.eteks.codec.JeksCodecFactory
                                .getCodecInstance(tbl, state);
                        codec.update(in);

                    } catch (IOException e)
                    {
                        JOptionPane.showMessageDialog(JeksFrame.this,
                                e.getMessage(),
                                resourceBundle.getString("FILE_SAVE_MENU"),
                                JOptionPane.ERROR_MESSAGE);
                    } finally
                    {
                        try
                        {
                            if (in != null)
                                in.close();
                        } catch (IOException e)
                        {
                        }
                    }
                }
            });
    }