Diff for /FM2SQL/Attic/FM2SQL.java between versions 1.20 and 1.34

version 1.20, 2004/02/23 10:59:53 version 1.34, 2004/04/05 10:14:01
Line 1 Line 1
   /*
    * FM2SQL.java -- Main program Filemaker to SQL Converter 
    * Copyright (C) 2003 Robert Gordesch (rogo@mpiwg-berlin.mpg.de
    * This program is free software; you can redistribute it and/or modify it
    * under the terms of the GNU General Public License as published by the Free
    * Software Foundation; either version 2 of the License, or (at your option)
    * any later version.  Please read license.txt for the full details. A copy of
    * the GPL may be found at http://www.gnu.org/copyleft/lgpl.html  You should
    * have received a copy of the GNU General Public License along with this
    * program; if not, write to the Free Software Foundation, Inc., 59 Temple
    * Place, Suite 330, Boston, MA 02111-1307 USA  Created on 15.09.2003 by
    * rogo  
    */
   
 import java.awt.Cursor;  import java.awt.Cursor;
 import java.awt.Dimension;  import java.awt.Dimension;
 import java.awt.Font;  import java.awt.Font;
Line 67  import javax.swing.table.TableModel; Line 81  import javax.swing.table.TableModel;
  */   */
 public class FM2SQL extends JFrame implements ActionListener, TableModelListener  public class FM2SQL extends JFrame implements ActionListener, TableModelListener
 {  {
     private JMenuItem delimiterItem;
   private JCheckBoxMenuItem convertItem;    private JCheckBoxMenuItem convertItem;
   private JCheckBoxMenuItem appendItem;    private JCheckBoxMenuItem appendItem;
   private JCheckBoxMenuItem updateItem;    private JCheckBoxMenuItem updateItem;
     private JCheckBoxMenuItem deleteItem;
     
   int mode = -1;    int mode = -1;
   final static int ID_INDEX = 1;    final static int ID_INDEX = 1;
   final static int SELECT_INDEX = 2;    final static int SELECT_INDEX = 2;
Line 134  public class FM2SQL extends JFrame imple Line 151  public class FM2SQL extends JFrame imple
   int oldWidth = 0, oldHeight = 0;    int oldWidth = 0, oldHeight = 0;
   boolean resize = true;    boolean resize = true;
   static FileWriter logFile;    static FileWriter logFile;
       String delimiter = "";
   
   Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();    Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
   JFileChooser configExportFileChooser;    JFileChooser configExportFileChooser;
   JFileChooser configImportFileChooser;    JFileChooser configImportFileChooser;
Line 592  public class FM2SQL extends JFrame imple Line 611  public class FM2SQL extends JFrame imple
       {        {
       }        }
     }      }
       if (command.equals("Delimiter"))
       {
               new DelimiterDialog(fmInstance).setVisible(true); 
         //delimiter =  JOptionPane.showInputDialog(fmInstance,"Enter delimiter String",delimiter); 
         
       }
   
     if (command == "Convert Mode")      if (command == "Convert Mode")
     {      {
       System.out.println("Convert Mode selected");        System.out.println("Convert Mode selected");
             convert.setText("Convert Tables");              convert.setText("Convert Tables");
             convert.setActionCommand("Convert Tables");              convert.setActionCommand("Convert Tables");
         convert.setToolTipText("Normal table conversion  existing table will be deleted");
       mode = Convert.DataBase.CONVERT_MODE;        mode = Convert.DataBase.CONVERT_MODE;
     }      }
     if (command == "Append Mode")      if (command == "Append Mode")
Line 604  public class FM2SQL extends JFrame imple Line 631  public class FM2SQL extends JFrame imple
       System.out.println("Append Mode selected");        System.out.println("Append Mode selected");
             convert.setText("Append Tables");              convert.setText("Append Tables");
             convert.setActionCommand("Append Tables");              convert.setActionCommand("Append Tables");
        convert.setToolTipText("Appends data to an existing table");
   
       mode = Convert.DataBase.APPEND_MODE;         mode = Convert.DataBase.APPEND_MODE; 
     }      }
     if (command == "Update Mode")      if (command == "Update Mode")
Line 611  public class FM2SQL extends JFrame imple Line 640  public class FM2SQL extends JFrame imple
       System.out.println("Update Mode selected");        System.out.println("Update Mode selected");
             convert.setText("Update Tables");              convert.setText("Update Tables");
             convert.setActionCommand("Update Tables");              convert.setActionCommand("Update Tables");
         convert.setToolTipText("Updates data that has been changed in source");
       mode = Convert.DataBase.UPDATE_MODE;         mode = Convert.DataBase.UPDATE_MODE; 
     }      }
       if (command == "Delete Mode")
       {
         System.out.println("Delete Mode selected");
         convert.setText("Delete Tables");
         convert.setActionCommand("Delete Tables");
         convert.setToolTipText("Deletes data that has been deleted in source");
         mode = Convert.DataBase.DELETE_MODE; 
       }
   
    //writing config     //writing config
     if (command.equals("save XML Config"))      if (command.equals("save XML Config"))
     {      {
Line 714  public class FM2SQL extends JFrame imple Line 753  public class FM2SQL extends JFrame imple
              };               };
              thread.start();               thread.start();
          }           }
       if (command.equals("Delete Tables"))
        {
   
          Thread thread = new Thread()
          {
            public void run()
            {
              setEnabled(false);
              delete();
              setEnabled(true);
            }
   
          };
          thread.start();
        }
   
     if (command.equals("show Tables"))      if (command.equals("show Tables"))
     {      {
Line 807  public class FM2SQL extends JFrame imple Line 861  public class FM2SQL extends JFrame imple
     }      }
   
   }    }
     public void delete() 
      {
        Vector vectors[] = getListFromTable();
        Convert.user = bean.user;
        Convert.passwd = bean.passwd;
        Convert.userDest = destBean.user;
        Convert.passwdDest = destBean.passwd;
        try
        {
         
          fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
          fmInstance.setEnabled(false);
          Convert.delete(bean.url, destURLBox.getSelectedItem().toString(), vectors[0], vectors[1], vectors[2], vectors[3],vectors[4], mode);
   
          destBean.setConnection((String) destURLBox.getSelectedItem());
          DefaultListModel model = new DefaultListModel();
          tables = destBean.getTableNames();
          for (int j = 0; j < tables.size(); ++j)
            model.addElement(tables.get(j));
          if (debug)
            System.out.println("hallo" + tables + " ");
          tListDest.setModel(model);
          fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        } catch (Exception e4)
        {
          ByteArrayOutputStream b = new ByteArrayOutputStream();
          PrintStream stream = new PrintStream(b);
          e4.printStackTrace(stream);
          showErrorDialog(b.toString(), "Delete of table failed");
          fmInstance.setEnabled(true);
        }
   
      }
   
   /**    /**
    * Copys the content of source to destination and makes new table if necessary     * Copys the content of source to destination and makes new table if necessary
    */     */
Line 822  public class FM2SQL extends JFrame imple Line 910  public class FM2SQL extends JFrame imple
     {      {
       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));        fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
       fmInstance.setEnabled(false);        fmInstance.setEnabled(false);
       Convert.convert(bean.url, destURLBox.getSelectedItem().toString(), vectors[0], vectors[1],vectors[2],vectors[3],vectors[4],mode);        Convert.convert(bean.url, destURLBox.getSelectedItem().toString(), vectors[0], vectors[1],vectors[2],vectors[3],vectors[4],mode,delimiter);
   
       destBean.setConnection((String) destURLBox.getSelectedItem());        destBean.setConnection((String) destURLBox.getSelectedItem());
       DefaultListModel model = new DefaultListModel();        DefaultListModel model = new DefaultListModel();
       tables = destBean.getTableNames();        tables = destBean.getTableNames();
Line 853  public class FM2SQL extends JFrame imple Line 940  public class FM2SQL extends JFrame imple
         if(appendItem.isSelected()) mode = Convert.DataBase.APPEND_MODE;          if(appendItem.isSelected()) mode = Convert.DataBase.APPEND_MODE;
         else          else
         if(updateItem.isSelected()) mode = Convert.DataBase.UPDATE_MODE;          if(updateItem.isSelected()) mode = Convert.DataBase.UPDATE_MODE;
       else
       if(deleteItem.isSelected()) mode = Convert.DataBase.DELETE_MODE;
   
     // TODO add id vector in table and write it out      // TODO add id vector in table and write it out
     Convert.DataBase source = new Convert.DataBase(bean,vectors[0],vectors[1],vectors[2],vectors[3],vectors[4],mode);      Convert.DataBase source = new Convert.DataBase(bean,vectors[0],vectors[1],vectors[2],vectors[3],vectors[4],mode);
     Convert.DataBase destination = new Convert.DataBase(destBean,new Vector(),new Vector(),new Vector(),new Vector(),new Vector(),-1);      Convert.DataBase destination = new Convert.DataBase(destBean,new Vector(),new Vector(),new Vector(),new Vector(),new Vector(),-1);
          source.delimiter =delimiter;
     try      try
     {      {
       Convert.writeConfig(file,source,destination);        Convert.writeConfig(file,source,destination);
Line 898  public class FM2SQL extends JFrame imple Line 988  public class FM2SQL extends JFrame imple
                   
         if (database.mode == Convert.DataBase.CONVERT_MODE)          if (database.mode == Convert.DataBase.CONVERT_MODE)
         {          {
           convertItem.setSelected(true);            convertItem.doClick();
           convert.setText("Convert Tables");  
           convert.setActionCommand("Convert Tables");  
           mode = Convert.DataBase.CONVERT_MODE;  
         } else if (database.mode == Convert.DataBase.APPEND_MODE)          } else if (database.mode == Convert.DataBase.APPEND_MODE)
         {          {
           appendItem.setSelected(true);            appendItem.doClick();
           convert.setText("Append Tables");  
           convert.setActionCommand("Append Tables");  
           mode = Convert.DataBase.APPEND_MODE;  
         } else if (database.mode == Convert.DataBase.UPDATE_MODE)          } else if (database.mode == Convert.DataBase.UPDATE_MODE)
         {          {
           updateItem.setSelected(true);            updateItem.doClick();
           convert.setText("Update Tables");          } else if (database.mode == Convert.DataBase.DELETE_MODE)
           convert.setActionCommand("Update Tables");          {
           mode = Convert.DataBase.UPDATE_MODE;            deleteItem.doClick();
         }          }
           delimiter=database.delimiter;
         database.bean.getConnection();          database.bean.getConnection();
                   
         bean = database.bean;          bean = database.bean;
Line 942  public class FM2SQL extends JFrame imple Line 1027  public class FM2SQL extends JFrame imple
           Object idcomboBox=tC.tableModel.getValueAt(index,ID_INDEX);            Object idcomboBox=tC.tableModel.getValueAt(index,ID_INDEX);
               
           indices[i] = index;            indices[i] = index;
           if(comboBox!=null) ((JComboBox)comboBox).setSelectedItem(database.layouts.get(i));              if (comboBox != null)
             {
               String layout = database.layouts.get(i).toString();
               ((JComboBox) comboBox).setSelectedItem(layout);
               if (layout != "")
               {
                 bean.makeQuery("select * from" + bean.getQC() + table + bean.getQC() + " layout " + bean.getQC() + layout + bean.getQC(), 1);
   
                 Vector idVec = bean.getColumnNames();
                 if (idVec == null)
                   idVec = new Vector();
                 idVec.add(0, "");
                  ((JComboBox) idcomboBox).setModel(new DefaultComboBoxModel(idVec));
               }
             
             }
           if(idcomboBox!=null)((JComboBox)idcomboBox).setSelectedItem(bean.ids.get(i));            if(idcomboBox!=null)((JComboBox)idcomboBox).setSelectedItem(bean.ids.get(i));
           tC.tableModel.fireTableDataChanged();            tC.tableModel.fireTableDataChanged();
           noDBUpdate = false;            noDBUpdate = false;
Line 983  public class FM2SQL extends JFrame imple Line 1083  public class FM2SQL extends JFrame imple
   }    }
   public boolean showTable(int list)    public boolean showTable(int list)
   {    {
     ProgressDialog dialog = new ProgressDialog(fm);      ProgressDialog dialog = new ProgressDialog(fm,bean);
     dialog.setTitle("Preparing tables to be displayed");      dialog.setTitle("Preparing tables to be displayed");
     dialog.thread = Thread.currentThread();      dialog.thread = Thread.currentThread();
     dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));      dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Line 1192  public class FM2SQL extends JFrame imple Line 1292  public class FM2SQL extends JFrame imple
           if (columnName.equals("Layouts"))            if (columnName.equals("Layouts"))
           {            {
                           
             bean.makeQuery("select * from"+bean.getQC()+table+bean.getQC(),1);              bean.makeQuery("select * from"+bean.getQC()+table+bean.getQC()+" layout "+bean.getQC()+layout+bean.getQC(),1);
   
             Vector idVec = bean.getColumnNames();              Vector idVec = bean.getColumnNames();
             if (idVec == null)              if (idVec == null)
Line 1201  public class FM2SQL extends JFrame imple Line 1301  public class FM2SQL extends JFrame imple
             JComboBox box = ((JComboBox) model.getValueAt(row, ID_INDEX));              JComboBox box = ((JComboBox) model.getValueAt(row, ID_INDEX));
             box.setModel(new DefaultComboBoxModel(idVec));              box.setModel(new DefaultComboBoxModel(idVec));
             box.setSelectedItem(id);              box.setSelectedItem(id);
               
              tC.tableModel.fireTableCellUpdated(row,ID_INDEX);
           }            }
                 
         }          }
Line 1257  public class FM2SQL extends JFrame imple Line 1359  public class FM2SQL extends JFrame imple
     menu = new JMenu("Options");      menu = new JMenu("Options");
     menu.setMnemonic('O');      menu.setMnemonic('O');
         
     item = new JMenuItem("show Driver features");  
         item.setToolTipText("shows the features of the selected driver");  
     item.addActionListener(fm);  
     menu.add(item);  
     menubar.add(menu);  
   
     ButtonGroup bgrp = new ButtonGroup();      ButtonGroup bgrp = new ButtonGroup();
     convertItem = new JCheckBoxMenuItem("Convert Mode");      convertItem = new JCheckBoxMenuItem("Convert Mode");
         convertItem.setToolTipText("Normal table conversion  existing table will be deleted");          convertItem.setToolTipText("Normal table conversion  existing table will be deleted");
Line 1289  public class FM2SQL extends JFrame imple Line 1385  public class FM2SQL extends JFrame imple
         bgrp.add(updateItem);          bgrp.add(updateItem);
   
         menu.add(updateItem);          menu.add(updateItem);
         menubar.add(menu);      deleteItem = new JCheckBoxMenuItem("Delete Mode");
       deleteItem.setToolTipText("Deletes data in an existing table \n that has been deleted in source table");
       deleteItem.addActionListener(fm);
   
       bgrp.add(deleteItem);
   
       menu.add(deleteItem);
       
           menubar.add(menu);
       item = new JMenuItem("show Driver features");
       item.setToolTipText("shows the features of the selected driver");
     item.addActionListener(fm);      item.addActionListener(fm);
     menu.add(item);      menu.add(item);
       menubar.add(menu);
       delimiterItem = new JMenuItem("Delimiter");
       delimiterItem.setToolTipText("Delimiter for FM Arrayfields");
       delimiterItem.addActionListener(fm);
       menu.add(delimiterItem);
       menubar.add(menu);
   
    //   item.addActionListener(fm);
   //    menu.add(item);
       
     menubar.add(menu);      menubar.add(menu);
       
Line 1372  public class FM2SQL extends JFrame imple Line 1486  public class FM2SQL extends JFrame imple
     JProgressBar progress = new JProgressBar();      JProgressBar progress = new JProgressBar();
     JButton cancel = new JButton("Cancel");      JButton cancel = new JButton("Cancel");
     Thread thread;      Thread thread;
     public ProgressDialog(JFrame frame)      DBBean bean;
       public ProgressDialog(JFrame frame,DBBean bean)
     {      {
       super(frame);        super(frame);
         this.bean = bean; 
         
       content = new JPanel(true);        content = new JPanel(true);
       //content.setBorder(BorderFactory.createRaisedBevelBorder());        //content.setBorder(BorderFactory.createRaisedBevelBorder());
       content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));        content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
Line 1409  public class FM2SQL extends JFrame imple Line 1526  public class FM2SQL extends JFrame imple
           fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));            fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                     fmInstance.setEnabled(true);                      fmInstance.setEnabled(true);
           setVisible(false);            setVisible(false);
             try
             {
               ProgressDialog.this.bean.getConnection().close();
             } catch (SQLException e1)
             {
               // TODO Auto-generated catch block
               e1.printStackTrace();
             } catch (Exception e1)
             {
               // TODO Auto-generated catch block
               e1.printStackTrace();
             }
           thread.stop();            thread.stop();
         }          }
       });        });
Line 1417  public class FM2SQL extends JFrame imple Line 1546  public class FM2SQL extends JFrame imple
     }      }
   
   }    }
       public static class DelimiterDialog extends JDialog
       {
           JLabel table = new JLabel("    ");
           JLabel status = new JLabel("    ");
           JLabel title = new JLabel("     ");
           JPanel content = new JPanel();
           JPanel titlePanel = new JPanel();
           JPanel delimiterPanel = new JPanel();
           JPanel buttonPanel = new JPanel();
           JTextField delimiter = new JTextField(10);
       
           JButton cancel = new JButton("Cancel");
           JButton ok = new JButton("Ok");
           Thread thread;
           public DelimiterDialog(JFrame frame)
           {
               super(frame);
               setTitle("Delimiter Editor");
               setModal(true);
               content = new JPanel(true);
               delimiter.setText(fmInstance.delimiter);
               ActionListener al = new ActionListener()
               {
                   public void actionPerformed(ActionEvent e)
                   {
                       fmInstance.delimiter=parseDelimiter(delimiter.getText());
                       setVisible(false);
                   }
   
               };
               this.addWindowListener(new WindowAdapter()
               {
                   public void windowClosing(WindowEvent e)
                   {
                       cancel.doClick();
                   }
               });
   
               //delimiter.setText(fmInstance.delimiter);
               delimiter.addActionListener(al);
               content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
               title = new JLabel("Enter Delimiter ");
               title.setHorizontalTextPosition(title.CENTER);
               titlePanel.add(title);
               buttonPanel.add(ok);
               buttonPanel.add(cancel);
               content.add(titlePanel);
               content.add(Box.createRigidArea(new java.awt.Dimension(0, 15)));
           
               content.add(new JLabel(""));
               content.add(delimiterPanel);
               content.add(buttonPanel);
               content.add(Box.createRigidArea(new java.awt.Dimension(0, 15)));
               
               delimiterPanel.add(new JLabel("Delimiter:  "));
               delimiterPanel.add(delimiter);
           getContentPane().add(titlePanel, "North");
               getContentPane().add(content, "Center");
               ok.addActionListener(al);
               cancel.addActionListener(new ActionListener()
               {
                   public void actionPerformed(ActionEvent e)
                   {
                       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                       fmInstance.setEnabled(true);
                       setVisible(false);
                   //  thread.stop();
                   }
   
               });
               pack();
         setLocationRelativeTo(fmInstance);
           }
       public String parseDelimiter(Object o)
       {
         String str = o.toString();
         StringBuffer sbuff = new StringBuffer();
         int length = str.length();
         for(int i = 0;i<length;++i)
         {
                   
                   if(str.charAt(i)=='\\')
           {
             System.out.println(str.charAt(i));
             if (str.charAt(i + 1) == 'r')
             {
               sbuff.append("\r");
             }
             if (str.charAt(i + 1) == 't')
             {
               sbuff.append("\t");
             }  
               if (str.charAt(i + 1) == 'n')
               {
                 sbuff.append("\n");
               } 
                 if (str.charAt(i + 1) == '\\')
                 {
                   sbuff.append("\\");
                 }
                       
                       if(i<length-1) ++i;
           
           } else sbuff.append(str.charAt(i));
               }
       
         return sbuff.toString();
       }
       }
   
   
   public static class PasswordDialog extends JDialog    public static class PasswordDialog extends JDialog
   {    {
     JLabel table = new JLabel("    ");      JLabel table = new JLabel("    ");

Removed from v.1.20  
changed lines
  Added in v.1.34


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>