Diff for /FM2SQL/Attic/FM2SQL.java between versions 1.35 and 1.44

version 1.35, 2004/05/26 11:37:32 version 1.44, 2004/10/19 11:57:26
Line 32  import java.io.FileWriter; Line 32  import java.io.FileWriter;
 import java.io.PrintStream;  import java.io.PrintStream;
 import java.sql.SQLException;  import java.sql.SQLException;
 import java.sql.Statement;  import java.sql.Statement;
   import java.text.ParseException;
 import java.util.Collections;  import java.util.Collections;
 import java.util.Iterator;  import java.util.Iterator;
 import java.util.Vector;  import java.util.Vector;
Line 70  import javax.swing.table.TableModel; Line 71  import javax.swing.table.TableModel;
  *   *
  * <br>   * <br>
  * <h2>FileMaker Test (JDBC Database Driver Test)</h2>   * <h2>FileMaker Test (JDBC Database Driver Test)</h2>
  * Main class :   * Main class : contains the main Frame, all event handlers etc <br>
  * contains the main Frame, all event handlers etc   * The Database access is made over DBBean class all other classes are just for
  * <br>   * the visualization of the data
  * The Database access is made over DBBean class   * 
  * all other classes are just for the visualization of the data  
  *  @version 0.3( first stable release)   *  @version 0.3( first stable release)
  *  @author rogo   *  @author rogo
  *   *
Line 86  public class FM2SQL extends JFrame imple Line 86  public class FM2SQL extends JFrame imple
   private JCheckBoxMenuItem appendItem;    private JCheckBoxMenuItem appendItem;
   private JCheckBoxMenuItem updateItem;    private JCheckBoxMenuItem updateItem;
   private JCheckBoxMenuItem deleteItem;    private JCheckBoxMenuItem deleteItem;
         private JCheckBoxMenuItem useNormanToUnicodeMapper;
   int mode = -1;    int mode = -1;
   final static int STATUS_INDEX = 0;    final static int STATUS_INDEX = 0;
   final static int NAME_INDEX = 1;    final static int NAME_INDEX = 1;
Line 95  public class FM2SQL extends JFrame imple Line 95  public class FM2SQL extends JFrame imple
   final static int CREATE_INDEX = 4;    final static int CREATE_INDEX = 4;
   final static int LAYOUT_INDEX = 5;    final static int LAYOUT_INDEX = 5;
       
     
    
   /**    /**
   * The database Bean instance.    * The database Bean instance.
   *    *
Line 112  public class FM2SQL extends JFrame imple Line 110  public class FM2SQL extends JFrame imple
    *  tList - Tablenames to choose from     *  tList - Tablenames to choose from
    */     */
   
   JList tList = new JList(new String[] { "no database", "connection", "" });      JList tList = new JList(new String[]
   JList tListDest = new JList(new String[] { "no database connection", "", "" });      {"no database", "connection", ""});
       JList tListDest = new JList(new String[]
       {"no database connection", "", ""});
   
   /**    /**
   *  sourceUrl - Database URL ComboBox    *  sourceUrl - Database URL ComboBox
Line 158  public class FM2SQL extends JFrame imple Line 158  public class FM2SQL extends JFrame imple
   Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();    Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
   JFileChooser configExportFileChooser;    JFileChooser configExportFileChooser;
   JFileChooser configImportFileChooser;    JFileChooser configImportFileChooser;
       private JCheckBoxMenuItem synchronizeItem;
     
   /**    /**
    * tries to connect to database specified in url-Variable.       * tries to connect to database specified in url-Variable. initializes all GUI
    * initializes all GUI components, then fails throws an exception       * components, then fails throws an exception
    *     *
    */     */
   public FM2SQL() throws Exception    public FM2SQL() throws Exception
Line 172  public class FM2SQL extends JFrame imple Line 173  public class FM2SQL extends JFrame imple
   public void initializeGUI() throws Exception    public void initializeGUI() throws Exception
   {    {
     Image local = getToolkit().getImage(FM2SQL.class.getResource("icons/fm.jpg"));      Image local = getToolkit().getImage(FM2SQL.class.getResource("icons/fm.jpg"));
     if (local != null);          if (local != null)
               ;
     setIconImage(local);      setIconImage(local);
     bean = new DBBean();      bean = new DBBean();
     destBean = new DBBean();      destBean = new DBBean();
     sourceURLBox = new JComboBox(new String[] { "jdbc:fmpro:http://141.14.237.74:8050", "jdbc:fmpro:http://localhost", "jdbc:postgresql://foxridge/test" });          sourceURLBox = new JComboBox(new String[]
           {"jdbc:fmpro:http://141.14.237.74:8050", "jdbc:fmpro:http://localhost", "jdbc:postgresql://foxridge/test", "jdbc:sequelink://r583-3:2399"});
     sourceURLBox.setEditable(true);      sourceURLBox.setEditable(true);
     sourceURLBox.setFont(new Font("Times New Roman",Font.PLAIN,14));      sourceURLBox.setFont(new Font("Times New Roman",Font.PLAIN,14));
     destURLBox = new JComboBox(new String[] { "jdbc:postgresql://foxridge/test", "jdbc:postgresql://erebos/test1" });          destURLBox = new JComboBox(new String[]
           {"jdbc:postgresql://foxridge/test", "jdbc:postgresql://erebos/test1"});
     destURLBox.setEditable(true);      destURLBox.setEditable(true);
     destURLBox.addActionListener(this);      destURLBox.addActionListener(this);
     destURLBox.setFont(new Font("Times New Roman",Font.PLAIN,14));      destURLBox.setFont(new Font("Times New Roman",Font.PLAIN,14));
Line 333  public class FM2SQL extends JFrame imple Line 337  public class FM2SQL extends JFrame imple
     {      {
       public void windowClosing(WindowEvent e)        public void windowClosing(WindowEvent e)
       {        {
                   bean.closeAllConnections();
                   destBean.closeAllConnections();
         System.exit(0);          System.exit(0);
       }        }
     });      });
Line 362  public class FM2SQL extends JFrame imple Line 368  public class FM2SQL extends JFrame imple
             setSize(getWidth(), table.table.getPreferredSize().height + 2 * size);              setSize(getWidth(), table.table.getPreferredSize().height + 2 * size);
           // System.out.println("size" + size);            // System.out.println("size" + size);
         }          }
         //   listPanel.setMaximumSize(new Dimension(getPreferredSize().width - 5, 550));                  //   listPanel.setMaximumSize(new Dimension(getPreferredSize().width - 5,
         //   listPanel.setMinimumSize(new Dimension(getPreferredSize().width - 5, 200));                  // 550));
         //    listPanel.setPreferredSize(new Dimension(getPreferredSize().width - 5, 370));                  //   listPanel.setMinimumSize(new Dimension(getPreferredSize().width - 5,
                   // 200));
                   //    listPanel.setPreferredSize(new Dimension(getPreferredSize().width -
                   // 5, 370));
         tC.tableScroller.revalidate();          tC.tableScroller.revalidate();
         Dimension dim = getSize();          Dimension dim = getSize();
         tC.tableScroller.setMinimumSize(new Dimension(dim.width-400, dim.height - topPanel.getPreferredSize().height - 100));          tC.tableScroller.setMinimumSize(new Dimension(dim.width-400, dim.height - topPanel.getPreferredSize().height - 100));
Line 419  public class FM2SQL extends JFrame imple Line 428  public class FM2SQL extends JFrame imple
       fmInstance = new FM2SQL();        fmInstance = new FM2SQL();
       fmInstance.table.tableModel.addTableModelListener(fmInstance);        fmInstance.table.tableModel.addTableModelListener(fmInstance);
       fmInstance.setVisible(true);        fmInstance.setVisible(true);
       /*   if (!new File("./html").exists())              /*
            new File("./html").mkdirs();               * if (!new File("./html").exists()) new File("./html").mkdirs(); logFile =
          logFile = new FileWriter("./html/index.html");               * new FileWriter("./html/index.html"); openLog();
          openLog();  
       */        */
     } catch (Exception e)          }
           catch (Exception e)
     {      {
       JOptionPane pane = new JOptionPane(e.getMessage() + "  \n URL: " + url, JOptionPane.ERROR_MESSAGE);        JOptionPane pane = new JOptionPane(e.getMessage() + "  \n URL: " + url, JOptionPane.ERROR_MESSAGE);
   
Line 466  public class FM2SQL extends JFrame imple Line 475  public class FM2SQL extends JFrame imple
         
         ((DefaultComboBoxModel) sourceURLBox.getModel()).insertElementAt(insObj, 0);          ((DefaultComboBoxModel) sourceURLBox.getModel()).insertElementAt(insObj, 0);
         sourceURLBox.setSelectedItem(insObj);          sourceURLBox.setSelectedItem(insObj);
       } else if (src == destURLBox)              }
               else if (src == destURLBox)
       {        {
         if (debug)          if (debug)
           System.out.println("hey" + destURLBox.getSelectedItem());            System.out.println("hey" + destURLBox.getSelectedItem());
         //((DefaultComboBoxModel) box4.getModel()).insertElementAt(box4.getSelectedItem(), 0);                  //((DefaultComboBoxModel)
                   // box4.getModel()).insertElementAt(box4.getSelectedItem(), 0);
         try          try
         {          {
           String selected = (String) destURLBox.getSelectedItem();            String selected = (String) destURLBox.getSelectedItem();
Line 483  public class FM2SQL extends JFrame imple Line 494  public class FM2SQL extends JFrame imple
           }            }
           destURLBox.setModel(new DefaultComboBoxModel(urls));            destURLBox.setModel(new DefaultComboBoxModel(urls));
           destURLBox.setSelectedItem(selected);            destURLBox.setSelectedItem(selected);
         } catch (Exception e5)                  }
                   catch (Exception e5)
         {          {
         }          }
       }        }
Line 519  public class FM2SQL extends JFrame imple Line 531  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);
                 //  System.out.println("hallo" + tables + " ");                  //  System.out.println("hallo" + tables + " ");
               } catch (Exception e5)                              }
                               catch (Exception e5)
               {                {
                 ByteArrayOutputStream b = new ByteArrayOutputStream();                  ByteArrayOutputStream b = new ByteArrayOutputStream();
                 PrintStream stream = new PrintStream(b);                  PrintStream stream = new PrintStream(b);
Line 542  public class FM2SQL extends JFrame imple Line 555  public class FM2SQL extends JFrame imple
             }              }
           };            };
           thread.start();            thread.start();
         } else if (src == destURLBox&&!noUserUpdate)                  }
                   else if (src == destURLBox && !noUserUpdate)
         {          {
           Thread thread = new Thread()            Thread thread = new Thread()
           {            {
Line 568  public class FM2SQL extends JFrame imple Line 582  public class FM2SQL extends JFrame imple
                 //  System.out.println("hallo" + tables + " ");                  //  System.out.println("hallo" + tables + " ");
                 fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));                  fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                                 fmInstance.setEnabled(true);                                  fmInstance.setEnabled(true);
               } catch (Exception e5)                              }
                               catch (Exception e5)
               {                {
                 ByteArrayOutputStream b = new ByteArrayOutputStream();                  ByteArrayOutputStream b = new ByteArrayOutputStream();
                 PrintStream stream = new PrintStream(b);                  PrintStream stream = new PrintStream(b);
Line 589  public class FM2SQL extends JFrame imple Line 604  public class FM2SQL extends JFrame imple
         setTitle("Filemaker 2 SQL Conversion Tool ");          setTitle("Filemaker 2 SQL Conversion Tool ");
         // pack();          // pack();
   
       } catch (Exception e4)              }
               catch (Exception e4)
       {        {
         ByteArrayOutputStream b = new ByteArrayOutputStream();          ByteArrayOutputStream b = new ByteArrayOutputStream();
         PrintStream stream = new PrintStream(b);          PrintStream stream = new PrintStream(b);
Line 609  public class FM2SQL extends JFrame imple Line 625  public class FM2SQL extends JFrame imple
         result.title = "Database features";          result.title = "Database features";
         result.setVisible(true);          result.setVisible(true);
         String name = result.writeResult();          String name = result.writeResult();
       } catch (Exception e2)              }
               catch (Exception e2)
       {        {
       }        }
     }      }
     if (command.equals("Delimiter"))      if (command.equals("Delimiter"))
     {      {
             new DelimiterDialog(fmInstance).setVisible(true);               new DelimiterDialog(fmInstance).setVisible(true); 
       //delimiter =  JOptionPane.showInputDialog(fmInstance,"Enter delimiter String",delimiter);               //delimiter = JOptionPane.showInputDialog(fmInstance,"Enter delimiter
               // String",delimiter);
               
     }      }
   
Line 653  public class FM2SQL extends JFrame imple Line 671  public class FM2SQL extends JFrame imple
       convert.setToolTipText("Deletes data that has been deleted in source");        convert.setToolTipText("Deletes data that has been deleted in source");
       mode = Convert.DataBase.DELETE_MODE;         mode = Convert.DataBase.DELETE_MODE; 
     }      }
           if (command == "Synchronize Mode")
           {
               System.out.println("Synchronize Mode selected");
               convert.setText("Synchronize Tables");
               convert.setActionCommand("Synchronize Tables");
               convert.setToolTipText("Synchronize data with destination table");
               mode = Convert.DataBase.SYNCHRONIZE_MODE;
           }
   
           if (command.equals("use NormanToUnicodeMapper"))
           {
               if (bean != null)
                   bean.setUseNormanToUnicodeMapper(useNormanToUnicodeMapper.isSelected());
           }
    //writing config     //writing config
     if (command.equals("save XML Config"))      if (command.equals("save XML Config"))
     {      {
Line 724  public class FM2SQL extends JFrame imple Line 755  public class FM2SQL extends JFrame imple
         
     }      }
               
        
     if (command.equals("Convert Tables")||command.equals("Append Tables"))      if (command.equals("Convert Tables")||command.equals("Append Tables"))
     {      {
   
Line 770  public class FM2SQL extends JFrame imple Line 800  public class FM2SQL extends JFrame imple
        };         };
        thread.start();         thread.start();
      }       }
           if (command.equals("Synchronize Tables"))
           {
   
               Thread thread = new Thread()
               {
                   public void run()
                   {
                       setEnabled(false);
                       synchronize();
                       setEnabled(true);
                   }
   
               };
               thread.start();
           }
   
     if (command.equals("show Tables"))      if (command.equals("show Tables"))
     {      {
Line 820  public class FM2SQL extends JFrame imple Line 865  public class FM2SQL extends JFrame imple
     }      }
   if(command.equals("Quit"))    if(command.equals("Quit"))
    {     {
               bean.closeAllConnections();
               destBean.closeAllConnections();
      fmInstance.dispose();       fmInstance.dispose();
      System.exit(0);       System.exit(0);
       
Line 827  public class FM2SQL extends JFrame imple Line 874  public class FM2SQL extends JFrame imple
         
   }    }
     /**      /**
      * Updates the content of source to destination and makes new table if necessary       *  
        */
       protected void synchronize()
       {
           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);
               // TODO indexList vector weiter reichen
               Convert.synchronize(bean.url, destURLBox.getSelectedItem().toString(), vectors[0], vectors[1], vectors[2], vectors[3], vectors[4], mode, delimiter, new Vector());
   
               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(), "Synchronize of table failed");
               fmInstance.setEnabled(true);
           }
   
       }
       /**
        * Updates the content of source to destination and makes new table if
        * necessary
      */       */
   
   public void update()     public void update() 
Line 853  public class FM2SQL extends JFrame imple Line 939  public class FM2SQL extends JFrame imple
         System.out.println("hallo" + tables + " ");          System.out.println("hallo" + tables + " ");
       tListDest.setModel(model);        tListDest.setModel(model);
       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));        fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
     } catch (Exception e4)          }
           catch (Exception e4)
     {      {
       ByteArrayOutputStream b = new ByteArrayOutputStream();        ByteArrayOutputStream b = new ByteArrayOutputStream();
       PrintStream stream = new PrintStream(b);        PrintStream stream = new PrintStream(b);
Line 886  public class FM2SQL extends JFrame imple Line 973  public class FM2SQL extends JFrame imple
          System.out.println("hallo" + tables + " ");           System.out.println("hallo" + tables + " ");
        tListDest.setModel(model);         tListDest.setModel(model);
        fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));         fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      } catch (Exception e4)          }
           catch (Exception e4)
      {       {
        ByteArrayOutputStream b = new ByteArrayOutputStream();         ByteArrayOutputStream b = new ByteArrayOutputStream();
        PrintStream stream = new PrintStream(b);         PrintStream stream = new PrintStream(b);
Line 922  public class FM2SQL extends JFrame imple Line 1010  public class FM2SQL extends JFrame imple
         System.out.println("hallo" + tables + " ");          System.out.println("hallo" + tables + " ");
       tListDest.setModel(model);        tListDest.setModel(model);
       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));        fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
     } catch (Exception e4)          }
           catch (Exception e4)
     {      {
       ByteArrayOutputStream b = new ByteArrayOutputStream();        ByteArrayOutputStream b = new ByteArrayOutputStream();
       PrintStream stream = new PrintStream(b);        PrintStream stream = new PrintStream(b);
Line 937  public class FM2SQL extends JFrame imple Line 1026  public class FM2SQL extends JFrame imple
     fmInstance.setEnabled(false);      fmInstance.setEnabled(false);
   
     Vector vectors[] = getListFromTable();      Vector vectors[] = getListFromTable();
     if(convertItem.isSelected()) mode = Convert.DataBase.CONVERT_MODE;          if (convertItem.isSelected())
     else              mode = Convert.DataBase.CONVERT_MODE;
         if(appendItem.isSelected()) mode = Convert.DataBase.APPEND_MODE;          else if (appendItem.isSelected())
         else              mode = Convert.DataBase.APPEND_MODE;
         if(updateItem.isSelected()) mode = Convert.DataBase.UPDATE_MODE;          else if (updateItem.isSelected())
     else              mode = Convert.DataBase.UPDATE_MODE;
     if(deleteItem.isSelected()) mode = Convert.DataBase.DELETE_MODE;          else if (deleteItem.isSelected())
               mode = Convert.DataBase.DELETE_MODE;
           else if (synchronizeItem.isSelected())
               mode = Convert.DataBase.SYNCHRONIZE_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;      source.delimiter =delimiter;
           source.useNormanToUnicodeMapper = useNormanToUnicodeMapper.isSelected();
     try      try
     {      {
       Convert.writeConfig(file,source,destination);        Convert.writeConfig(file,source,destination);
       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));        fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
       fmInstance.setEnabled(true);        fmInstance.setEnabled(true);
   
     } catch (Exception e)          }
           catch (Exception e)
     {      {
       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));        fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
       fmInstance.setEnabled(true);        fmInstance.setEnabled(true);
Line 991  public class FM2SQL extends JFrame imple Line 1085  public class FM2SQL extends JFrame imple
         if (database.mode == Convert.DataBase.CONVERT_MODE)          if (database.mode == Convert.DataBase.CONVERT_MODE)
         {          {
           convertItem.doClick();            convertItem.doClick();
         } else if (database.mode == Convert.DataBase.APPEND_MODE)                  }
                   else if (database.mode == Convert.DataBase.APPEND_MODE)
         {          {
           appendItem.doClick();            appendItem.doClick();
         } else if (database.mode == Convert.DataBase.UPDATE_MODE)                  }
                   else if (database.mode == Convert.DataBase.UPDATE_MODE)
         {          {
           updateItem.doClick();            updateItem.doClick();
         } else if (database.mode == Convert.DataBase.DELETE_MODE)                  }
                   else if (database.mode == Convert.DataBase.DELETE_MODE)
         {          {
           deleteItem.doClick();            deleteItem.doClick();
         }          }
                   else if (database.mode == Convert.DataBase.SYNCHRONIZE_MODE)
                   {
                       synchronizeItem.doClick();
                   }
   
         delimiter=database.delimiter;          delimiter=database.delimiter;
         database.bean.getConnection();          database.bean.getConnection();
                         
         bean = database.bean;          bean = database.bean;
                   if (bean.isUseNormanToUnicodeMapper())
                       useNormanToUnicodeMapper.setSelected(true);
         Object obj =bean.url;          Object obj =bean.url;
         ((DefaultComboBoxModel) sourceURLBox.getModel()).removeElement(obj);          ((DefaultComboBoxModel) sourceURLBox.getModel()).removeElement(obj);
         ((DefaultComboBoxModel) sourceURLBox.getModel()).insertElementAt(obj,0);          ((DefaultComboBoxModel) sourceURLBox.getModel()).insertElementAt(obj,0);
Line 1017  public class FM2SQL extends JFrame imple Line 1121  public class FM2SQL extends JFrame imple
         {          {
           String table = (String) database.tables.get(i);            String table = (String) database.tables.get(i);
           int index=tables.indexOf(table);            int index=tables.indexOf(table);
           if(index<0) throw new RuntimeException("Error table \""+table+"\" does no longer exist\n at server "+bean.url +"\n or you mispelled the tablename.");                      if (index < 0)
                           throw new RuntimeException("Error table \"" + table + "\" does no longer exist\n at server " + bean.url + "\n or you mispelled the tablename.");
           noDBUpdate = true;            noDBUpdate = true;
           tC.tableModel.setValueAt(new TableComponent.SQLCommand(database.selects.get(i).toString()),index,SELECT_INDEX);            tC.tableModel.setValueAt(new TableComponent.SQLCommand(database.selects.get(i).toString()),index,SELECT_INDEX);
                                           
           String create =database.creates.get(i).toString();            String create =database.creates.get(i).toString();
           tC.tableModel.setValueAt(new TableComponent.SQLCommand(create.equals("") ? create:"           "+create),index,CREATE_INDEX);            tC.tableModel.setValueAt(new TableComponent.SQLCommand(create.equals("") ? create:"           "+create),index,CREATE_INDEX);
                     // tC.tableModel.setValueAt(new TableComponent.SQLCommand(bean.ids.get(i).toString()),index,ID_INDEX);                      // tC.tableModel.setValueAt(new
                       // TableComponent.SQLCommand(bean.ids.get(i).toString()),index,ID_INDEX);
   
           Object comboBox=tC.tableModel.getValueAt(index,LAYOUT_INDEX);            Object comboBox=tC.tableModel.getValueAt(index,LAYOUT_INDEX);
           Object idcomboBox=tC.tableModel.getValueAt(index,ID_INDEX);            Object idcomboBox=tC.tableModel.getValueAt(index,ID_INDEX);
Line 1045  public class FM2SQL extends JFrame imple Line 1151  public class FM2SQL extends JFrame imple
             }              }
                       
           }            }
           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;
           noUserUpdate = false;            noUserUpdate = false;
Line 1071  public class FM2SQL extends JFrame imple Line 1178  public class FM2SQL extends JFrame imple
                             
       }        }
                 
     } catch (Exception e)          }
           catch (Exception e)
     {      {
       noUserUpdate = false;        noUserUpdate = false;
       noDBUpdate = false;        noDBUpdate = false;
Line 1094  public class FM2SQL extends JFrame imple Line 1202  public class FM2SQL extends JFrame imple
     fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));      fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     String query = new String();      String query = new String();
     Object[] objs = tListDest.getSelectedValues();      Object[] objs = tListDest.getSelectedValues();
     Vector[] vectors = getListFromTable();          Vector[] vectors = (list == 0) ? getListFromTable() : null;
     Vector tables = (list == 0) ? vectors[0] : new Vector();      Vector tables = (list == 0) ? vectors[0] : new Vector();
     if (list > 0)      if (list > 0)
       for (int i = 0; i < objs.length; ++i)        for (int i = 0; i < objs.length; ++i)
Line 1128  public class FM2SQL extends JFrame imple Line 1236  public class FM2SQL extends JFrame imple
        query = "select * from " + bean.getQC() +tables.get(i).toString() + bean.getQC();         query = "select * from " + bean.getQC() +tables.get(i).toString() + bean.getQC();
     else      else
     query = "select * from " + destBean.getQC() +tables.get(i).toString() + destBean.getQC();      query = "select * from " + destBean.getQC() +tables.get(i).toString() + destBean.getQC();
  if(list==0) query = vectors[2].get(i).toString();              if (list == 0)
                   query = vectors[2].get(i).toString();
       if (list == 0 && vectors[1].get(i) != null)        if (list == 0 && vectors[1].get(i) != null)
         if (vectors[1].get(i).toString() != "")          if (vectors[1].get(i).toString() != "")
           {            {
Line 1147  public class FM2SQL extends JFrame imple Line 1256  public class FM2SQL extends JFrame imple
   
       try        try
       {        {
         if ((query.toLowerCase().indexOf("insert") >= 0)                  if ((query.toLowerCase().indexOf("insert") >= 0) || (query.toLowerCase().indexOf("delete") >= 0) || (query.toLowerCase().indexOf("alter") >= 0) || (query.toLowerCase().indexOf("update") >= 0))
           || (query.toLowerCase().indexOf("delete") >= 0)  
           || (query.toLowerCase().indexOf("alter") >= 0)  
           || (query.toLowerCase().indexOf("update") >= 0))  
         {          {
           Statement stm = (list > 0) ? destBean.getConnection().createStatement() : bean.getConnection().createStatement();            Statement stm = (list > 0) ? destBean.getConnection().createStatement() : bean.getConnection().createStatement();
           stm.executeUpdate(query);            stm.executeUpdate(query);
Line 1166  public class FM2SQL extends JFrame imple Line 1272  public class FM2SQL extends JFrame imple
           //window.pack();            //window.pack();
           //  window.setVisible(true);            //  window.setVisible(true);
   
         } else                  }
                   else
         {          {
           Vector[] vecs = (list > 0) ? destBean.getQueryData(query, dialog, 50) : bean.getQueryData(query, dialog, 50);            Vector[] vecs = (list > 0) ? destBean.getQueryData(query, dialog, 50) : bean.getQueryData(query, dialog, 50);
           if (vecs[1].isEmpty())            if (vecs[1].isEmpty())
Line 1180  public class FM2SQL extends JFrame imple Line 1287  public class FM2SQL extends JFrame imple
   
         //window.setVisible(true);          //window.setVisible(true);
   
       } catch (Exception e)              }
               catch (Exception e)
       {        {
         System.out.println("Exception occured");          System.out.println("Exception occured");
         e.printStackTrace();          e.printStackTrace();
Line 1230  public class FM2SQL extends JFrame imple Line 1338  public class FM2SQL extends JFrame imple
       {        {
         Statement stm = destBean.getConnection().createStatement();          Statement stm = destBean.getConnection().createStatement();
         stm.executeUpdate(query);          stm.executeUpdate(query);
       } catch (Exception e)              }
               catch (Exception e)
       {        {
         ByteArrayOutputStream b = new ByteArrayOutputStream();          ByteArrayOutputStream b = new ByteArrayOutputStream();
         PrintStream stream = new PrintStream(b);          PrintStream stream = new PrintStream(b);
Line 1248  public class FM2SQL extends JFrame imple Line 1357  public class FM2SQL extends JFrame imple
         model.addElement(tables.get(j));          model.addElement(tables.get(j));
       System.out.println("hallo" + tables + " ");        System.out.println("hallo" + tables + " ");
       tListDest.setModel(model);        tListDest.setModel(model);
     } catch (Exception e4)          }
           catch (Exception e4)
     {      {
     }      }
   
Line 1272  public class FM2SQL extends JFrame imple Line 1382  public class FM2SQL extends JFrame imple
       String columnName = model.getColumnName(col);        String columnName = model.getColumnName(col);
       Object test = model.getValueAt(row, col);        Object test = model.getValueAt(row, col);
       String idVal = (test == null) ? "" : test.toString();        String idVal = (test == null) ? "" : test.toString();
       String value = (test == null) ? "" : test.toString();;              String value = (test == null) ? "" : test.toString();
               ;
   
       System.out.println("Got in " + columnName +" "+idVal);        System.out.println("Got in " + columnName +" "+idVal);
       try        try
Line 1288  public class FM2SQL extends JFrame imple Line 1399  public class FM2SQL extends JFrame imple
           System.out.println("table" +table+" layout "+layout+" query "+query);            System.out.println("table" +table+" layout "+layout+" query "+query);
           if(!create.equals(""))            if(!create.equals(""))
           {            {
             Object[] options = { "Yes","No"};                          Object[] options =
                           {"Yes", "No"};
             int option=showDialog("Create Statement not empty! Do you want to overwrite?","create statement",options );               int option=showDialog("Create Statement not empty! Do you want to overwrite?","create statement",options ); 
             if(option==0)               if(option==0) 
             model.setValueAt(createStatement(table,destBean,layout,query),row,CREATE_INDEX);              model.setValueAt(createStatement(table,destBean,layout,query),row,CREATE_INDEX);
Line 1310  public class FM2SQL extends JFrame imple Line 1422  public class FM2SQL extends JFrame imple
           }            }
                 
         }          }
 /*        Statement stm = bean.getConnection().createStatement();                  /*
         //  stm.executeUpdate("DELETE FROM \""+fm.tables.get(0)+"\" WHERE \"erstellt von\"='rogo') ");                   * Statement stm = bean.getConnection().createStatement(); //
                    * stm.executeUpdate("DELETE FROM \""+fm.tables.get(0)+"\" WHERE
         if (idVal == "")                   * \"erstellt von\"='rogo') ");
           stm.executeUpdate("INSERT  INTO " + DBBean.quoteChar + box.getSelectedItem() + DBBean.quoteChar + " (" + DBBean.quoteChar + columnName + DBBean.quoteChar + ")  VALUES ('" + value + "') ");                   * 
         else                   * if (idVal == "") stm.executeUpdate("INSERT INTO " + DBBean.quoteChar +
           stm.executeUpdate(                   * box.getSelectedItem() + DBBean.quoteChar + " (" + DBBean.quoteChar +
             "UPDATE   " + DBBean.quoteChar + box.getSelectedItem() + DBBean.quoteChar + " SET  " + DBBean.quoteChar + columnName + DBBean.quoteChar + "='" + value + "' WHERE ID='" + idVal + "' ");                   * columnName + DBBean.quoteChar + ") VALUES ('" + value + "') "); else
                    * stm.executeUpdate( "UPDATE " + DBBean.quoteChar +
                    * box.getSelectedItem() + DBBean.quoteChar + " SET " + DBBean.quoteChar +
                    * columnName + DBBean.quoteChar + "='" + value + "' WHERE ID='" + idVal + "'
                    * ");
   */    */
           } catch (Exception e2)              }
               catch (Exception e2)
            {             {
              fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));               fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              ByteArrayOutputStream b = new ByteArrayOutputStream();               ByteArrayOutputStream b = new ByteArrayOutputStream();
Line 1396  public class FM2SQL extends JFrame imple Line 1513  public class FM2SQL extends JFrame imple
     bgrp.add(deleteItem);      bgrp.add(deleteItem);
   
     menu.add(deleteItem);      menu.add(deleteItem);
           synchronizeItem = new JCheckBoxMenuItem("Synchronize Mode");
           synchronizeItem.setToolTipText("Synchronizes data with an existing table \n Data wich has been added or removed will be deleted or addded to the destination table. The rest will be updated");
           synchronizeItem.addActionListener(fm);
   
           bgrp.add(synchronizeItem);
   
           menu.add(synchronizeItem);
           useNormanToUnicodeMapper = new JCheckBoxMenuItem("use NormanToUnicodeMapper");
           useNormanToUnicodeMapper.setToolTipText("maps characters in norman encoding to unicode characters");
           useNormanToUnicodeMapper.addActionListener(fm);
           menu.add(useNormanToUnicodeMapper);
   
         menubar.add(menu);          menubar.add(menu);
     item = new JMenuItem("show Driver features");      item = new JMenuItem("show Driver features");
Line 1474  public class FM2SQL extends JFrame imple Line 1602  public class FM2SQL extends JFrame imple
     dialog.setSize(600, 300);      dialog.setSize(600, 300);
     dialog.setLocationRelativeTo(fmInstance);      dialog.setLocationRelativeTo(fmInstance);
     dialog.show();      dialog.show();
     //JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);          //JOptionPane.showMessageDialog(null, message, title,
           // JOptionPane.ERROR_MESSAGE);
   }    }
   public static class ProgressDialog extends JDialog    public static class ProgressDialog extends JDialog
   {    {
Line 1533  public class FM2SQL extends JFrame imple Line 1662  public class FM2SQL extends JFrame imple
           try            try
           {            {
             ProgressDialog.this.bean.getConnection().close();              ProgressDialog.this.bean.getConnection().close();
           } catch (SQLException e1)                      }
                       catch (SQLException e1)
           {            {
             // TODO Auto-generated catch block              // TODO Auto-generated catch block
             e1.printStackTrace();              e1.printStackTrace();
           } catch (Exception e1)                      }
                       catch (Exception e1)
           {            {
             // TODO Auto-generated catch block              // TODO Auto-generated catch block
             e1.printStackTrace();              e1.printStackTrace();
Line 1651  public class FM2SQL extends JFrame imple Line 1782  public class FM2SQL extends JFrame imple
                 sbuff.append("\\");                  sbuff.append("\\");
               }                }
                                           
                     if(i<length-1) ++i;                      if (i < length - 1)
                           ++i;
                   
         } else sbuff.append(str.charAt(i));                  }
                   else
                       sbuff.append(str.charAt(i));
             }              }
           
       return sbuff.toString();        return sbuff.toString();
     }      }
     }      }
   
   
   public static class PasswordDialog extends JDialog    public static class PasswordDialog extends JDialog
   {    {
     JLabel table = new JLabel("    ");      JLabel table = new JLabel("    ");
Line 1752  public class FM2SQL extends JFrame imple Line 1885  public class FM2SQL extends JFrame imple
   public void fillTable()    public void fillTable()
   {    {
     noDBUpdate = true;      noDBUpdate = true;
           bean.setUseNormanToUnicodeMapper(useNormanToUnicodeMapper.isSelected());
     Vector tableNames = bean.getTableNames();      Vector tableNames = bean.getTableNames();
     Collections.sort(tableNames, String.CASE_INSENSITIVE_ORDER);      Collections.sort(tableNames, String.CASE_INSENSITIVE_ORDER);
     Vector[] data = new Vector[2];      Vector[] data = new Vector[2];
Line 1774  public class FM2SQL extends JFrame imple Line 1908  public class FM2SQL extends JFrame imple
       {        {
         bean.makeQuery("select * from"+bean.getQC()+name+bean.getQC(),1);          bean.makeQuery("select * from"+bean.getQC()+name+bean.getQC(),1);
         layouts = bean.getLayoutNames(name);          layouts = bean.getLayoutNames(name);
       } catch (SQLException e)              }
               catch (SQLException e)
       {        {
         layouts = new Vector();          layouts = new Vector();
       }        }
               
       idVec = bean.getColumnNames();         idVec = bean.getColumnNames(); 
       if(idVec==null) idVec=new Vector();              if (idVec == null)
                   idVec = new Vector();
       idVec.add(0,"");        idVec.add(0,"");
       Vector dataRow = new Vector(6);        Vector dataRow = new Vector(6);
               
Line 1794  public class FM2SQL extends JFrame imple Line 1930  public class FM2SQL extends JFrame imple
            else             else
              dataRow.set(LAYOUT_INDEX,null);               dataRow.set(LAYOUT_INDEX,null);
             
   
       // create row        // create row
       dataRow.set(CREATE_INDEX,new TableComponent.SQLCommand(""));        dataRow.set(CREATE_INDEX,new TableComponent.SQLCommand(""));
       // id row        // id row
       dataRow.set(ID_INDEX,new TableComponent.IDComboBox(idVec));//new TableComponent.SQLCommand(""));              dataRow.set(ID_INDEX, new TableComponent.IDComboBox(idVec));//new
               // TableComponent.SQLCommand(""));
       bean.ids.add("");        bean.ids.add("");
       data[0].add(dataRow);        data[0].add(dataRow);
   
Line 1860  public class FM2SQL extends JFrame imple Line 1996  public class FM2SQL extends JFrame imple
     destURLBox.setEnabled(state);      destURLBox.setEnabled(state);
   
   }    }
   public TableComponent.SQLCommand createStatement(String table,DBBean beanDest,String layout,String query)  throws SQLException      public TableComponent.SQLCommand createStatement(String table, DBBean beanDest, String layout, String query) throws SQLException, ParseException
   {    {
     fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));      fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                   
     if(beanDest.url.equals("")) beanDest.url=destURLBox.getSelectedItem().toString();          if (beanDest.url.equals(""))
               beanDest.url = destURLBox.getSelectedItem().toString();
     StringBuffer command = new StringBuffer(50);      StringBuffer command = new StringBuffer(50);
     command.append("\n           CREATE TABLE ");      command.append("\n           CREATE TABLE ");
     command.append(beanDest.getQC());      command.append(beanDest.getQC());

Removed from v.1.35  
changed lines
  Added in v.1.44


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