File:  [Repository] / FM2SQL / Attic / FM2SQL.java
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Fri Dec 5 11:46:39 2003 UTC (20 years, 7 months ago) by rogo
Branches: MAIN
CVS tags: HEAD
Initial revision

    1: import javax.swing.*;
    2: import javax.swing.event.*;
    3: import javax.swing.table.TableModel;
    4: 
    5: import Convert.DataBase;
    6: 
    7: import java.awt.event.*;
    8: import java.awt.Dimension;
    9: import java.awt.FlowLayout;
   10: import java.awt.*;
   11: import java.sql.*;
   12: import java.util.*;
   13: import java.io.*;
   14: /**
   15:  *
   16:  * <br>
   17:  * <h2>FileMaker Test (JDBC Database Driver Test)</h2>
   18:  * Main class :
   19:  * contains the main Frame, all event handlers etc
   20:  * <br>
   21:  * The Database access is made over DBBean class
   22:  * all other classes are just for the visualization of the data
   23:  *  @version 0.2( first stable release)
   24:  *  @author rogo
   25:  *
   26:  */
   27: public class FM2SQL extends JFrame implements ActionListener, TableModelListener
   28: {
   29:   /**
   30:   * The database Bean instance.
   31:   *
   32:   */
   33:   DBBean bean;
   34:   /**
   35:    * The database destination Bean instance.
   36:    *
   37:    */
   38:   DBBean destBean;
   39: 
   40:   /**
   41:    *  box - Tablenames
   42:    */
   43: 
   44:   JComboBox box;
   45:   /**
   46:    *  tList - Tablenames to choose from
   47:    */
   48: 
   49:   JList tList = new JList(new String[] { "no database", "connection", "" });
   50:   JList tListDest = new JList(new String[] { "no database connection", "", "" });
   51: 
   52:   /**
   53:    *  box2 - Layout names
   54:    */
   55: 
   56:   JComboBox box2;
   57:   /**
   58:   *  box3 - Database URLs
   59:   */
   60:   JComboBox box3;
   61:   /**
   62:   *  box4 - Database URLs
   63:   */
   64:   JComboBox box4;
   65: 
   66:   TableComponent table, tC;
   67:   Vector tables = new Vector();
   68:   Vector layouts = new Vector();
   69:   JPanel listPanel;
   70:   JPanel topPanel, contentPanel;
   71:   FM2SQL fm = this;
   72:   boolean noDBUpdate = false;
   73:   boolean noUserUpdate = false;
   74:   int id = 0;
   75:   static boolean debug = false;
   76:   /**
   77:   * The result window used for query results
   78:   */
   79:   MultiResultWindow window;
   80:   /**
   81:    * The result window used for query results
   82:    */
   83:   MultiResultWindow windowDest;
   84: 
   85:   static FM2SQL fmInstance;
   86:   static String url = "jdbc:fmpro:http://141.14.237.42";
   87:   JButton showTables = new JButton(), showTables1 = new JButton();
   88:   JButton convert  = new JButton();
   89:   JButton dropTables  = new JButton();
   90: 
   91:   int oldWidth = 0, oldHeight = 0;
   92:   boolean resize = true;
   93:   static FileWriter logFile;
   94:   Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
   95:   JFileChooser configExportFileChooser;
   96:   JFileChooser configImportFileChooser;
   97:  
   98:   /**
   99:    * tries to connect to database specified in url-Variable.
  100:    * initializes all GUI components, then fails throws an exception
  101:    *
  102:    */
  103:   public FM2SQL() throws Exception
  104:   {
  105:     Image local = getToolkit().getImage(getClass().getResource("icons/fm.jpg"));
  106:     if (local != null);
  107:     setIconImage(local);
  108:     bean = new DBBean();
  109:     destBean = new DBBean();
  110:     box2 = new JComboBox();
  111:     box3 = new JComboBox(new String[] { "jdbc:fmpro:http://141.14.237.74:8050", "jdbc:fmpro:http://localhost", "jdbc:postgresql://foxridge/test" });
  112:     box3.setEditable(true);
  113:     box4 = new JComboBox(new String[] {"jdbc:postgresql://foxridge/test","jdbc:postgresql://erebos/test1" });
  114:     box4.setEditable(true);
  115:     box4.addActionListener(this);
  116:     table = new TableComponent();
  117:     box = new JComboBox(tables);
  118:     box.addActionListener(this);
  119:     box2.addActionListener(this);
  120:     box3.addActionListener(this);
  121: 
  122:     contentPanel = new JPanel();
  123:     contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
  124:     topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5));
  125:     topPanel.add(Box.createRigidArea(new Dimension(10, 0)));
  126:     topPanel.add(new JLabel("FileMaker DB "));
  127:     topPanel.add(new JLabel("PostgresSQL "));
  128:     //tListDest.setMinimumSize(new Dimension(120, 250));
  129:     //tListDest.setMaximumSize(new Dimension(230, 250));
  130:     //tListDest.setPreferredSize(new Dimension(230, 250));
  131: 
  132:     box3.setMinimumSize(new Dimension(200, 20));
  133:     box3.setMaximumSize(new Dimension(320, 20));
  134:     box3.setPreferredSize(new Dimension(320, 20));
  135:     box4.setMinimumSize(new Dimension(200, 20));
  136:     box4.setMaximumSize(new Dimension(320, 20));
  137:     box4.setPreferredSize(new Dimension(330, 20));
  138: 
  139:     tC = new TableComponent();
  140:     tC.sizeToFit(450, 250);
  141:     tC.tableModel.addTableModelListener(this);
  142:     JPanel dataBasePanel = new JPanel();
  143:     dataBasePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 2));
  144:     dataBasePanel.add(Box.createRigidArea(new Dimension(10, 0)));
  145:     dataBasePanel.add(new JLabel("Choose src database: "));
  146:     dataBasePanel.add(box3);
  147:     dataBasePanel.add(Box.createRigidArea(new Dimension(10, 0)));
  148:     dataBasePanel.add(new JLabel("Choose dest database : "));
  149:     dataBasePanel.add(Box.createRigidArea(new Dimension(5, 0)));
  150: 
  151:     dataBasePanel.add(box4);
  152:     dataBasePanel.add(Box.createRigidArea(new Dimension(10, 0)));
  153:     listPanel = new JPanel();
  154:     listPanel.setLayout(new java.awt.GridBagLayout());
  155:     java.awt.GridBagConstraints gbc = new java.awt.GridBagConstraints();
  156:     JScrollPane pane = new JScrollPane(tList);
  157:     tC.tableScroller.setPreferredSize(new Dimension(450, 265));
  158:     tC.table.revalidate();
  159:     tC.setMinimumSize(tC.tableScroller.getPreferredSize());
  160:     tC.setMaximumSize(tC.tableScroller.getPreferredSize());
  161: 
  162:     //gbc.gridx=GridBagConstraints.RELATIVE;   
  163:     gbc.gridx = 0;
  164:     gbc.weightx = 1.0;
  165:     gbc.weighty = 0.0;
  166:     gbc.gridwidth = 2;
  167:     gbc.gridheight = 1;
  168:     gbc.anchor = GridBagConstraints.NORTHWEST;
  169:     listPanel.add(new JLabel("  select Tables to Convert  ", JLabel.LEFT), gbc);
  170:     gbc.gridx = 2;
  171:     listPanel.add(new JLabel("  Tables in database  ", JLabel.CENTER), gbc);
  172: 
  173:     gbc.anchor = GridBagConstraints.WEST;
  174:     gbc.gridy = 1;
  175:     gbc.gridx = 0;
  176:     gbc.gridwidth = 1;
  177:     gbc.weightx = 0.0;
  178:     listPanel.add(tC, gbc);
  179:     JScrollPane paneDest = new JScrollPane(tListDest);
  180:     showTables1 = new JButton("show Tables");
  181:     showTables1.setActionCommand("show Tables source");
  182:     gbc.anchor = GridBagConstraints.NORTH;
  183:     gbc.weightx = 0.0;
  184:     gbc.gridx = 1;
  185:     listPanel.add(showTables1, gbc);
  186:     paneDest.setPreferredSize(new Dimension(250, 265));
  187:     paneDest.setMinimumSize(paneDest.getPreferredSize());
  188:     paneDest.setMaximumSize(paneDest.getPreferredSize());
  189:     gbc.anchor = GridBagConstraints.WEST;
  190:     gbc.gridy = 1;
  191:     gbc.gridx = 2;
  192:     gbc.weightx = 0.2;
  193:     listPanel.add(paneDest, gbc);
  194:     JPanel buttonPanel = new JPanel();
  195:     buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
  196:     convert = new JButton("Convert Tables");
  197:     showTables = new JButton("show Tables");
  198:     dropTables = new JButton("drop Tables");
  199:     //   System.out.println(convert.getPreferredSize());
  200:     showTables.setMinimumSize(convert.getPreferredSize());
  201:     dropTables.setMinimumSize(convert.getPreferredSize());
  202:     showTables.setMaximumSize(convert.getPreferredSize());
  203:     dropTables.setMaximumSize(convert.getPreferredSize());
  204:     showTables.setPreferredSize(convert.getPreferredSize());
  205:     dropTables.setPreferredSize(convert.getPreferredSize());
  206: 
  207:     showTables.addActionListener(fm);
  208:     showTables1.addActionListener(fm);
  209: 
  210:     buttonPanel.add(showTables);
  211:     buttonPanel.add(convert);
  212:     convert.addActionListener(fm);
  213:     dropTables.addActionListener(fm);
  214:     buttonPanel.add(dropTables);
  215:     gbc.gridx = 3;
  216:     gbc.anchor = GridBagConstraints.NORTHWEST;
  217:     gbc.gridy = 1;
  218:     gbc.weightx = 1.0;
  219:     listPanel.add(buttonPanel, gbc);
  220:     contentPanel.add(dataBasePanel);
  221:     contentPanel.add(listPanel);
  222:     listPanel.setMaximumSize(new Dimension(getPreferredSize().width, 550));
  223:     listPanel.setMinimumSize(new Dimension(getPreferredSize().width, 150));
  224:     listPanel.setPreferredSize(new Dimension(getPreferredSize().width, 350));
  225: 
  226:     getContentPane().add(contentPanel, "Center");
  227:     this.addWindowListener(new WindowAdapter()
  228:     {
  229:       public void windowClosing(WindowEvent e)
  230:       {
  231:         System.exit(0);
  232:       }
  233:     });
  234:     addComponentListener(new ComponentAdapter()
  235:     {
  236:       public void componentResized(ComponentEvent e)
  237:       {
  238: 
  239:         if (oldWidth != getWidth() || oldHeight != getHeight())
  240:         {
  241:           table.sizeToFit(getWidth(), getHeight());
  242: 
  243:           Dimension dim = table.table.getPreferredSize();
  244:           int size = contentPanel.getPreferredSize().height + new JScrollBar().getPreferredSize().height + new JMenuBar().getPreferredSize().height + 10;
  245: 
  246:           table.tableScroller.setPreferredSize(new Dimension(getWidth() - 15, getHeight() - size));
  247:           Dimension d2 = table.tableScroller.getPreferredSize();
  248: 
  249:           oldWidth = getWidth();
  250:           oldHeight = getHeight();
  251: 
  252:           table.setPreferredSize(new Dimension(d2.width + 15, d2.height + 5));
  253:           table.table.revalidate();
  254:           table.tableScroller.revalidate();
  255:           table.revalidate();
  256:           if (getHeight() > table.table.getPreferredSize().height + (2 * size))
  257:             setSize(getWidth(), table.table.getPreferredSize().height + 2 * size);
  258:           // System.out.println("size" + size);
  259:         }
  260:         listPanel.setMaximumSize(new Dimension(getPreferredSize().width - 5, 550));
  261:         listPanel.setMinimumSize(new Dimension(getPreferredSize().width - 5, 200));
  262:         listPanel.setPreferredSize(new Dimension(getPreferredSize().width - 5, 370));
  263: 
  264:         ((JPanel) getContentPane()).revalidate();
  265:         repaint();
  266:         setTitle("Filemaker To Postgres Conversion Tool ");
  267: 
  268:       }
  269:     });
  270: 
  271:     setMenu();
  272:     //setSize(800, 600);
  273:     pack();
  274:     setLocation((screenSize.width - getWidth()) / 2, (screenSize.height - getHeight()) / 2);
  275:     //setVisible(true);
  276:     validate();
  277: 
  278:     // repaint();
  279: 
  280:   }
  281: 
  282:   /**
  283:    *
  284:    */
  285:   public static void main(String[] args)
  286:   {
  287:     try
  288:     {
  289:       System.setErr(System.out);
  290: //         Properties prop = System.getProperties();
  291:   // Enumeration enum= prop.keys();
  292: //  while(enum.hasMoreElements())
  293: //System.out.println(enum.nextElement());
  294:      
  295:       if (System.getProperty("os.name").startsWith("W"))
  296:         // javax.swing.UIManager.setLookAndFeel(
  297:         //    new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
  298:         javax.swing.UIManager.put("Table.focusCellHighlightBorder", new javax.swing.border.LineBorder(java.awt.Color.black));
  299:       javax.swing.UIManager.put("Table.focusCellBackground", new java.awt.Color(227, 227, 227, 127));
  300: 
  301:       fmInstance = new FM2SQL();
  302:       fmInstance.table.tableModel.addTableModelListener(fmInstance);
  303:       fmInstance.setVisible(true);
  304:       /*   if (!new File("./html").exists())
  305:            new File("./html").mkdirs();
  306:          logFile = new FileWriter("./html/index.html");
  307:          openLog();
  308:       */
  309:     } catch (Exception e)
  310:     {
  311:       JOptionPane pane = new JOptionPane(e.getMessage() + "  \n URL: " + url, JOptionPane.ERROR_MESSAGE);
  312: 
  313:       JDialog dialog = pane.createDialog(null, " Exception occured while connecting");
  314:       e.printStackTrace();
  315:       dialog.addWindowListener(new WindowAdapter()
  316:       {
  317:         public void windowClosing(WindowEvent e)
  318:         {
  319:           System.exit(0);
  320:         }
  321:       });
  322:       dialog.addComponentListener(new ComponentAdapter()
  323:       {
  324: 
  325:         public void componentHidden(ComponentEvent e)
  326:         {
  327: 
  328:           System.exit(0);
  329:         }
  330:       });
  331:       dialog.show();
  332:     }
  333:   }
  334:   public void actionPerformed(ActionEvent e)
  335:   {
  336:     String command = e.getActionCommand();
  337:     if (debug)
  338:       System.out.println("command " + command);
  339:     if (command == "comboBoxEdited")
  340:     {
  341:       Object src = e.getSource();
  342:       if (src == box3)
  343:       {
  344:         if (debug)
  345:           System.out.println("hey" + box3.getSelectedItem());
  346:         Object insObj =box3.getSelectedItem();
  347:         ((DefaultComboBoxModel) box3.getModel()).removeElement(insObj);
  348:    
  349:         ((DefaultComboBoxModel) box3.getModel()).insertElementAt(insObj, 0);
  350:         box3.setSelectedItem(insObj);
  351:       } else if (src == box4)
  352:       {
  353:         if (debug)
  354:           System.out.println("hey" + box4.getSelectedItem());
  355:         //((DefaultComboBoxModel) box4.getModel()).insertElementAt(box4.getSelectedItem(), 0);
  356:         try
  357:         {
  358:           String selected = (String) box4.getSelectedItem();
  359:           destBean.setConnection(selected);
  360:           Vector catalogs = destBean.getCatalogs();
  361:           Vector urls = new Vector();
  362:           for (int i = 0; i < catalogs.size(); ++i)
  363:           {
  364:             urls.add(destBean.url.substring(0, destBean.url.lastIndexOf("/") + 1) + catalogs.get(i));
  365:           }
  366:           box4.setModel(new DefaultComboBoxModel(urls));
  367:           box4.setSelectedItem(selected);
  368:         } catch (Exception e5)
  369:         {
  370:         }
  371:       }
  372:     }
  373:     if (command == "comboBoxChanged")
  374:     {
  375:       try
  376:       {
  377:         //System.out.println("hallo " + (e.getSource() == box3));
  378: 
  379:         Object src = e.getSource();
  380:         if (src == box3&&!noUserUpdate)
  381:         {
  382:           Thread thread = new Thread()
  383:           {
  384:             public void run()
  385:             {
  386: 
  387:               try
  388:               {
  389:                 PasswordDialog dialog = new PasswordDialog(fmInstance, bean);
  390:                 dialog.setLocationRelativeTo(box3);
  391:                 dialog.thread = Thread.currentThread();
  392:                 fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  393:                 fmInstance.setEnabled(false);
  394:                 dialog.setVisible(true);
  395:                 String url = box3.getSelectedItem().toString();
  396:                 bean.url = (url != null) ? url : bean.url;
  397:                 bean.connection = null;
  398:                 bean.getConnection();
  399:                 tables = bean.getTableNames();
  400:                 fillTable();
  401:                 fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  402: 								fmInstance.setEnabled(true);
  403:                 //  System.out.println("hallo" + tables + " ");
  404:               } catch (Exception e5)
  405:               {
  406:                 ByteArrayOutputStream b = new ByteArrayOutputStream();
  407:                 PrintStream stream = new PrintStream(b);
  408:                 e5.printStackTrace(stream);
  409:                 fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  410: 								fmInstance.setEnabled(true);
  411:                 Vector header = new Vector();
  412:                 header.add("no database");
  413:                 header.add("connection");
  414:                 Vector rows = new Vector();
  415:                 //rows.add(header);
  416:                 noDBUpdate=true;
  417:                 tC.tableModel.setDataVector(rows, header);
  418:                 tC.tableModel.setRowCount(20);
  419:                 tC.revalidate();
  420:                 tC.tableModel.fireTableDataChanged();
  421:                 noDBUpdate=false;
  422:                 showErrorDialog(b.toString(), "Error occured !");
  423:               }
  424:             }
  425:           };
  426:           thread.start();
  427:         } else if (src == box4&&!noUserUpdate)
  428:         {
  429:           Thread thread = new Thread()
  430:           {
  431:             public void run()
  432:             {
  433: 
  434:               try
  435:               {
  436: 
  437:                 PasswordDialog dialog = new PasswordDialog(fmInstance, destBean);
  438:                 dialog.setLocationRelativeTo(box4);
  439:                 dialog.thread = Thread.currentThread();
  440:                 fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  441: 								fmInstance.setEnabled(false);
  442:                 dialog.setVisible(true);
  443:                 destBean.setConnection((String) box4.getSelectedItem());
  444:                 DefaultListModel model = new DefaultListModel();
  445:                 Vector tables = destBean.getTableNames();
  446:                 for (int j = 0; j < tables.size(); ++j)
  447:                   model.addElement(tables.get(j));
  448:                 //  System.out.println("hallo" + tables + " ");
  449:                 tListDest.setModel(model);
  450:                 //  System.out.println("hallo" + tables + " ");
  451:                 fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  452: 								fmInstance.setEnabled(true);
  453:               } catch (Exception e5)
  454:               {
  455:                 ByteArrayOutputStream b = new ByteArrayOutputStream();
  456:                 PrintStream stream = new PrintStream(b);
  457:                 e5.printStackTrace(stream);
  458: 								fmInstance.setEnabled(true);
  459:                 fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  460:                 DefaultListModel model = new DefaultListModel();
  461:                 model.addElement("no database connection");
  462:                 tListDest.setModel(model);
  463: 
  464:                 showErrorDialog(b.toString(), "Error occured !");
  465:               }
  466:             }
  467:           };
  468:           thread.start();
  469: 
  470:         }
  471:         setTitle("Filemaker To Postgres Conversion Tool ");
  472:         // pack();
  473: 
  474:       } catch (Exception e4)
  475:       {
  476:         ByteArrayOutputStream b = new ByteArrayOutputStream();
  477:         PrintStream stream = new PrintStream(b);
  478:         e4.printStackTrace(stream);
  479:         showErrorDialog(b.toString(), "Open of table failed");
  480: 
  481:       }
  482:     }
  483:     if (command == "show Driver features")
  484:     {
  485:       ResultWindow result = new ResultWindow(this);
  486:       try
  487:       {
  488:         Vector[] vecs = bean.TestDB(bean.getConnection().getMetaData());
  489:         result.updateResult(vecs[0], vecs[1]);
  490:         // result.pack();
  491:         result.title = "Database features";
  492:         result.setVisible(true);
  493:         String name = result.writeResult();
  494:       } catch (Exception e2)
  495:       {
  496:       }
  497:     }
  498:    //writing config
  499:     if (command.equals("export XML Config"))
  500:     {
  501:       if (configExportFileChooser == null)
  502:       {
  503:         configExportFileChooser = new JFileChooser();
  504:         configExportFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
  505:         configExportFileChooser.setFileFilter(new XMLFilter());
  506:         configExportFileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
  507:         configExportFileChooser.addActionListener(new ActionListener()
  508:         {
  509:           public void actionPerformed(ActionEvent e2)
  510:           {
  511:             System.out.println(e2.getActionCommand());
  512:             if (!e2.getActionCommand().toString().equals("ApproveSelection"))
  513:               return;
  514: 
  515:             Thread thread = new Thread()
  516:             {
  517:               public void run()
  518:               {
  519:                 File configFile = configExportFileChooser.getSelectedFile();
  520:                 writeConfig(configFile.toString());
  521: 
  522:               }
  523:             };
  524:             thread.start();
  525: 
  526:           }
  527:         });
  528:       }
  529:       configExportFileChooser.rescanCurrentDirectory();
  530:       configExportFileChooser.showDialog(fmInstance, " Save ");
  531:    
  532:     }
  533:     if (command.equals("import XML Config"))
  534:     {
  535:       if (configImportFileChooser == null)
  536:       {
  537:         configImportFileChooser = new JFileChooser();
  538:         configImportFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
  539:         configImportFileChooser.setFileFilter(new XMLFilter());
  540:         configImportFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
  541:         configImportFileChooser.addActionListener(new ActionListener()
  542:         {
  543:           public void actionPerformed(ActionEvent e2)
  544:           {
  545:             System.out.println(e2.getActionCommand());
  546:             if (!e2.getActionCommand().toString().equals("ApproveSelection"))
  547:               return;
  548: 
  549:             Thread thread = new Thread()
  550:             {
  551:               public void run()
  552:               {
  553:                 File configFile = configImportFileChooser.getSelectedFile();
  554:                 readXMLConfig(configFile.toString());
  555: 
  556:               }
  557:             };
  558:             thread.start();
  559: 
  560:           }
  561:         });
  562:       }
  563:       configImportFileChooser.rescanCurrentDirectory();
  564:       configImportFileChooser.showDialog(fmInstance, " Open ");
  565:    
  566:     }
  567:       
  568:      
  569:     if (command.equals("Convert Tables"))
  570:     {
  571: 
  572:       Thread thread = new Thread()
  573:       {
  574:         public void run()
  575:         {
  576:           setEnabled(false);
  577:           convert();
  578:           setEnabled(true);
  579:         }
  580: 
  581:       };
  582:       thread.start();
  583:     }
  584:     if (command.equals("show Tables"))
  585:     {
  586:       Thread thread = new Thread()
  587:       {
  588:         public void run()
  589:         {
  590: 					fmInstance.setEnabled(false);
  591:           boolean visible = showTable(1);
  592:           window.validate();
  593:           window.setVisible(visible);
  594: 					fmInstance.setEnabled(true);
  595: 
  596:         }
  597:       };
  598:       thread.start();
  599:       //  System.out.println("hello");
  600: 
  601:     }
  602:     if (command.equals("show Tables source"))
  603:     {
  604:       Thread thread = new Thread()
  605:       {
  606:         public void run()
  607:         {
  608: 					fmInstance.setEnabled(false);
  609:           boolean visible = showTable(0);
  610:           window.validate();
  611:           window.setVisible(visible);
  612: 					fmInstance.setEnabled(true);
  613:         }
  614:       };
  615:       thread.start();
  616:       //		System.out.println("hello"+thread);
  617: 
  618:     }
  619: 
  620:     if (command.equals("drop Tables"))
  621:     {
  622:       Thread thread = new Thread()
  623:       {
  624:         public void run()
  625:         {
  626:           dropTable();
  627:         }
  628:       };
  629:       thread.start();
  630:     }
  631:   }
  632:   /**
  633:    * Copys the content of source to destination and makes new table if necessary
  634:    */
  635:   public void convert()
  636:   {
  637: 
  638:     Vector vectors[] = getListFromTable();
  639:     Convert.user = bean.user;
  640:     Convert.passwd = bean.passwd;
  641:     Convert.userDest = destBean.user;
  642:     Convert.passwdDest = destBean.passwd;
  643:     try
  644:     {
  645:       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  646:       fmInstance.setEnabled(false);
  647:       Convert.convert(bean.url, box4.getSelectedItem().toString(), vectors[0], vectors[1],vectors[2],vectors[3]);
  648: 
  649:       destBean.setConnection((String) box4.getSelectedItem());
  650:       DefaultListModel model = new DefaultListModel();
  651:       tables = destBean.getTableNames();
  652:       for (int j = 0; j < tables.size(); ++j)
  653:         model.addElement(tables.get(j));
  654:       if (debug)
  655:         System.out.println("hallo" + tables + " ");
  656:       tListDest.setModel(model);
  657:       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  658:     } catch (Exception e4)
  659:     {
  660:       ByteArrayOutputStream b = new ByteArrayOutputStream();
  661:       PrintStream stream = new PrintStream(b);
  662:       e4.printStackTrace(stream);
  663:       showErrorDialog(b.toString(), "Conversion of table failed");
  664:       fmInstance.setEnabled(true);
  665:     }
  666:   }
  667:   public void writeConfig(String file)
  668:   {
  669:     fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  670:     fmInstance.setEnabled(false);
  671: 
  672:     Vector vectors[] = getListFromTable();
  673:     Convert.DataBase source = new Convert.DataBase(bean,vectors[0],vectors[1],vectors[2],vectors[3]);
  674:     Convert.DataBase destination = new Convert.DataBase(destBean,new Vector(),new Vector(),new Vector(),new Vector());
  675:    
  676:     try
  677:     {
  678:       Convert.writeConfig(file,source,destination);
  679:       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  680:       fmInstance.setEnabled(true);
  681: 
  682:     } catch (Exception e)
  683:     {
  684:       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  685:       fmInstance.setEnabled(true);
  686: 
  687:       ByteArrayOutputStream b = new ByteArrayOutputStream();
  688:       PrintStream stream = new PrintStream(b);
  689:       e.printStackTrace(stream);
  690:       showErrorDialog(b.toString(), "Error while writing xml config  !");
  691:   }
  692:   
  693:   }
  694:   public void readXMLConfig(String file)
  695:   {
  696:      
  697:     try
  698:     {
  699:       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  700:       fmInstance.setEnabled(false);
  701:       Vector databases = Convert.getXMLConfig(file);
  702:       DataBase destBase = (DataBase) databases.lastElement();
  703:       //destBase.bean.getConnection();
  704:       noUserUpdate = true;
  705:       destBean=destBase.bean;
  706:       Object destObj =destBean.url;
  707:       ((DefaultComboBoxModel) box4.getModel()).removeElement(destObj);
  708:       ((DefaultComboBoxModel) box4.getModel()).insertElementAt(destObj,0);
  709:        box4.setSelectedItem(destObj);
  710:       //@TODO comboBox action Events should do nothing on config file read+combox in table should be updated
  711:       databases.remove(destBase);
  712:       for (Iterator iter = databases.iterator(); iter.hasNext();)
  713:       {
  714:         Convert.DataBase database = (Convert.DataBase) iter.next();
  715:         database.bean.getConnection();
  716:         bean = database.bean;
  717:         Object obj =bean.url;
  718:         ((DefaultComboBoxModel) box3.getModel()).removeElement(obj);
  719:         ((DefaultComboBoxModel) box3.getModel()).insertElementAt(obj,0);
  720:         box3.setSelectedItem(obj);
  721:         fillTable();
  722:         Vector tables=database.bean.getTableNames();
  723:         Collections.sort(tables,String.CASE_INSENSITIVE_ORDER);
  724:         for (int i =0;i<database.tables.size();++i)
  725:         {
  726:           String table = (String) database.tables.get(i);
  727:           int index=tables.indexOf(table);
  728:           if(index<0) throw new RuntimeException("Error table \""+table+"\" does no longer exist\n at server "+bean.url +"\n or you mispelled the tablename.");
  729:           noDBUpdate = true;
  730:           tC.tableModel.setValueAt(new TableComponent.SQLCommand(database.selects.get(i).toString()),index,2);
  731:           String create =database.creates.get(i).toString();
  732:           tC.tableModel.setValueAt(new TableComponent.SQLCommand(create.equals("") ? create:"           "+create),index,3);
  733:           Object comboBox=tC.tableModel.getValueAt(index,1);
  734:           if(comboBox!=null) ((JComboBox)comboBox).setSelectedItem(database.layouts.get(i));  
  735:           tC.tableModel.fireTableDataChanged();
  736:           noDBUpdate = false;
  737:           noUserUpdate = false;
  738:         
  739:         }
  740:        destBean.getConnection();
  741:       
  742:         DefaultListModel model = new DefaultListModel();
  743:          tables = destBean.getTableNames();
  744:         for (int j = 0; j < tables.size(); ++j)
  745:           model.addElement(tables.get(j));
  746:         //  System.out.println("hallo" + tables + " ");
  747:         tListDest.setModel(model);
  748:         fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  749:         fmInstance.setEnabled(true);
  750:              
  751:       }
  752:        
  753:     } catch (Exception e)
  754:     {
  755:       noUserUpdate = false;
  756:       noDBUpdate = false;
  757:       fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  758:       fmInstance.setEnabled(true);
  759:    
  760:       ByteArrayOutputStream b = new ByteArrayOutputStream();
  761:       PrintStream stream = new PrintStream(b);
  762:       e.printStackTrace(stream);
  763:       showErrorDialog(b.toString(), "Error while reading xml config  !");
  764:     }
  765: 
  766:   }
  767:   public boolean showTable(int list)
  768:   {
  769:     ProgressDialog dialog = new ProgressDialog(fm);
  770:     dialog.setTitle("Preparing tables to be displayed");
  771:     dialog.thread = Thread.currentThread();
  772:     dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  773:     fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  774:     String query = new String();
  775:     Object[] objs = tListDest.getSelectedValues();
  776:     Vector[] vectors = getListFromTable();
  777:     Vector tables = (list == 0) ? vectors[0] : new Vector();
  778:     if (list > 0)
  779:       for (int i = 0; i < objs.length; ++i)
  780:       {
  781:         if (debug)
  782:           System.out.println(objs[i]);
  783:         tables.add(objs[i]);
  784:       }
  785:     if (window != null)
  786:       window.dispose();
  787:     if (windowDest != null)
  788:       windowDest.dispose();
  789: 
  790:     window = new MultiResultWindow(fm);
  791:     if (list > 0)
  792:     {
  793:       windowDest = new MultiResultWindow(fm);
  794:       window = windowDest;
  795:     }
  796:     dialog.setLocation(FM2SQL.fmInstance.getLocationOnScreen().x + (FM2SQL.fmInstance.getWidth() - 500) / 2, FM2SQL.fmInstance.getLocationOnScreen().y + (FM2SQL.fmInstance.getHeight() - 250) / 2);
  797:     dialog.setSize(500, 250);
  798:     if (!tables.isEmpty())
  799:       dialog.show();
  800:     dialog.title.setText("Preparing tables to be diplayed");
  801:     for (int i = 0; i < tables.size(); ++i)
  802:     {
  803:       dialog.table.setText("Getting table " + tables.get(i));
  804:       dialog.status.setText("Table " + (i + 1) + " of " + tables.size());
  805: 
  806:        if(list==0)
  807:        query = "select * from " + bean.getQC() +tables.get(i).toString() + bean.getQC();
  808:     else
  809:     query = "select * from " + destBean.getQC() +tables.get(i).toString() + destBean.getQC();
  810:  if(list==0) query = vectors[2].get(i).toString();
  811:       if (list == 0 && vectors[1].get(i) != null)
  812:         if (vectors[1].get(i).toString() != "")
  813:           {
  814: 						String layout =" layout " + bean.getQC() + vectors[1].get(i).toString() + bean.getQC();
  815:             String name = tables.get(i).toString();
  816:             StringBuffer queryLayout=new StringBuffer(query);
  817:             queryLayout.insert(queryLayout.indexOf(name)+name.length()+1," "+layout);
  818:             query=queryLayout.toString();
  819:           }
  820:        if(debug)
  821:        showErrorDialog("query in show tables is "+query,"Hello");
  822:       window.title = " Table ;-) " + (String) tables.get(i);
  823:       //    break;
  824:       //  } else
  825:       //    window.title = "Error! - No valid tablename found";
  826: 
  827:       try
  828:       {
  829:         if ((query.toLowerCase().indexOf("insert") >= 0)
  830:           || (query.toLowerCase().indexOf("delete") >= 0)
  831:           || (query.toLowerCase().indexOf("alter") >= 0)
  832:           || (query.toLowerCase().indexOf("update") >= 0))
  833:         {
  834:           Statement stm = (list > 0) ? destBean.getConnection().createStatement() : bean.getConnection().createStatement();
  835:           stm.executeUpdate(query);
  836:           Vector vec = new Vector();
  837:           Vector vec2 = new Vector();
  838:           Vector vec3 = new Vector();
  839:           vec2.add(query);
  840:           vec3.add(vec2);
  841:           vec.add("Insert, update, etc done! No results available");
  842:           // vec.add("no Results were produced");
  843: 
  844:           window.updateResult(vec3, vec);
  845:           //window.pack();
  846:           //  window.setVisible(true);
  847: 
  848:         } else
  849:         {
  850:           Vector[] vecs = (list > 0) ? destBean.getQueryData(query, dialog, 50) : bean.getQueryData(query, dialog, 50);
  851:           if (vecs[1].isEmpty())
  852:             throw new Exception("Wrong columnname or Empty Layout");
  853:           window.updateResult(vecs[0], vecs[1]);
  854: 
  855:           //window.pack();
  856:           //String name = window.writeResult();
  857:           //appendLog(window.title, name);
  858:         }
  859: 
  860:         //window.setVisible(true);
  861: 
  862:       } catch (Exception e)
  863:       {
  864:         System.out.println("Exception occured");
  865:         e.printStackTrace();
  866:         Vector vec = new Vector();
  867:         Vector vec2 = new Vector();
  868:         Vector vec3 = new Vector();
  869:         vec2.add(e.getMessage());
  870:         vec3.add(vec2);
  871:         vec.add("Exception occured! No results available");
  872:         //vec.add("no Results were produced");
  873: 
  874:         window.updateResult(vec3, vec);
  875:         //window.pack();
  876:         // window.setVisible(true);
  877:         fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  878: 
  879:       }
  880:     } // to for
  881:     window.pack();
  882:     window.setSize(700, 600);
  883: 
  884:     window.oldTabCount = 10000;
  885:     dialog.dispose();
  886:     fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  887: 
  888:     return !tables.isEmpty();
  889: 
  890:   }
  891: 
  892:   public void dropTable()
  893:   {
  894:     String query = new String();
  895:     Object[] objs = tListDest.getSelectedValues();
  896:     Vector tables = new Vector();
  897:     for (int i = 0; i < objs.length; ++i)
  898:     {
  899:       System.out.println(objs[i]);
  900:       tables.add(objs[i]);
  901:     }
  902: 
  903:     for (int i = 0; i < tables.size(); ++i)
  904:     {
  905: 
  906:       query = "drop table "+destBean.getQC() + tables.get(i) + destBean.getQC();
  907: 
  908:       try
  909:       {
  910:         Statement stm = destBean.getConnection().createStatement();
  911:         stm.executeUpdate(query);
  912:       } catch (Exception e)
  913:       {
  914:         ByteArrayOutputStream b = new ByteArrayOutputStream();
  915:         PrintStream stream = new PrintStream(b);
  916:         e.printStackTrace(stream);
  917:         showErrorDialog(b.toString(), "Open of table failed");
  918: 
  919:       }
  920:     } // to for
  921:     try
  922:     {
  923:       destBean.setConnection((String) box4.getSelectedItem());
  924:       DefaultListModel model = new DefaultListModel();
  925:       tables = destBean.getTableNames();
  926:       for (int j = 0; j < tables.size(); ++j)
  927:         model.addElement(tables.get(j));
  928:       System.out.println("hallo" + tables + " ");
  929:       tListDest.setModel(model);
  930:     } catch (Exception e4)
  931:     {
  932:     }
  933: 
  934:   }
  935:   /**
  936:    * invoked then the user changes the table or the tableModel changes
  937:    */
  938:   public void tableChanged(TableModelEvent e)
  939:   {
  940:     //  if (e.getType() == e.INSERT)
  941:     //System.out.println("Insert done");
  942:     // if (e.getType() == e.UPDATE)
  943:     // System.out.println("Update done");
  944:     //if (e.getType() == e.DELETE)
  945:    // System.out.println("Delete done");
  946:     if (e.getType() == e.UPDATE && !noDBUpdate)
  947:     {
  948:       int row = e.getFirstRow(), col = e.getColumn();
  949:       System.out.println("Got in " + row + " " + col );
  950:       TableModel model =  (TableModel)e.getSource();
  951:       String columnName = model.getColumnName(col);
  952:       Object test = model.getValueAt(row, col);
  953:       String idVal = (test == null) ? "" : test.toString();
  954:       String value = (test == null) ? "" : test.toString();;
  955: 
  956:       System.out.println("Got in " + columnName +" "+idVal);
  957:       try
  958:       {
  959:         if(columnName.equals("select")||columnName.equals("Layouts"))
  960:         {
  961:           String table = model.getValueAt(row,0).toString();
  962:           String layout = (model.getValueAt(row,1)!=null) ?((JComboBox)model.getValueAt(row,1)).getSelectedItem().toString():"";
  963:           String query =  model.getValueAt(row,2).toString();
  964:           String create = model.getValueAt(row,3).toString();
  965:           System.out.println("table" +table+" layout "+layout+" query "+query);
  966:           if(!create.equals(""))
  967:           {
  968:             Object[] options = { "Yes","No"};
  969:             int option=showDialog("Create Statement not empty! Do you want to overwrite?","create statement",options ); 
  970:             if(option==0) 
  971:             model.setValueAt(createStatement(table,destBean,layout,query),row,3);
  972:           }
  973:        
  974:        
  975:         }
  976: /*        Statement stm = bean.getConnection().createStatement();
  977:         //  stm.executeUpdate("DELETE FROM \""+fm.tables.get(0)+"\" WHERE \"erstellt von\"='rogo') ");
  978: 
  979:         if (idVal == "")
  980:           stm.executeUpdate("INSERT  INTO " + DBBean.quoteChar + box.getSelectedItem() + DBBean.quoteChar + " (" + DBBean.quoteChar + columnName + DBBean.quoteChar + ")  VALUES ('" + value + "') ");
  981:         else
  982:           stm.executeUpdate(
  983:             "UPDATE   " + DBBean.quoteChar + box.getSelectedItem() + DBBean.quoteChar + " SET  " + DBBean.quoteChar + columnName + DBBean.quoteChar + "='" + value + "' WHERE ID='" + idVal + "' ");
  984:   */
  985:           } catch (Exception e2)
  986:            {
  987:              fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  988:              ByteArrayOutputStream b = new ByteArrayOutputStream();
  989:              PrintStream stream = new PrintStream(b);
  990:              e2.printStackTrace(stream);
  991:              showErrorDialog(b.toString(), "Error while updating table  !");
  992:            }
  993:     }
  994:   }
  995: 
  996:   /**
  997:    * initialize the menubar
  998:    */
  999:   private void setMenu()
 1000:   {
 1001:     JMenuBar menubar = new JMenuBar();
 1002:     JMenu menu = new JMenu("File");
 1003:    
 1004:     JMenuItem item = new JMenuItem("import XML Config");
 1005:     item.addActionListener(fm);
 1006:     menu.add(item);
 1007:     item = new JMenuItem("export XML Config");
 1008:     item.addActionListener(fm);
 1009:     menu.add(item);
 1010:     menubar.add(menu);
 1011:     menu = new JMenu("Options");
 1012:   
 1013:     item = new JMenuItem("show Driver features");
 1014:     item.addActionListener(fm);
 1015:     menu.add(item);
 1016:     menubar.add(menu);
 1017:   
 1018:     item.addActionListener(fm);
 1019:     menu.add(item);
 1020:   
 1021:     menubar.add(menu);
 1022:   
 1023:     menu.setBackground(fm.getBackground());
 1024:     menubar.setBackground(fm.getBackground());
 1025:     setJMenuBar(menubar);
 1026:   }
 1027:   /**
 1028:    *  open the log  file (index.html)
 1029:    */
 1030: 
 1031:   public static void openLog() throws Exception
 1032:   {
 1033: 
 1034:     StringBuffer buff = new StringBuffer();
 1035:     buff.append("<html>");
 1036:     buff.append("<head>");
 1037:     buff.append("\n<title>");
 1038:     buff.append("FileMaker Test");
 1039:     buff.append("</title>\n");
 1040:     buff.append("</head>\n");
 1041: 
 1042:     buff.append("<body>\n");
 1043:     buff.append("<center>\n");
 1044:     buff.append("\n<h3>");
 1045:     buff.append("FileMaker Test");
 1046:     buff.append("</h3>\n");
 1047: 
 1048:     logFile.write(TableComponent.convertUml(buff).toString());
 1049:     logFile.flush();
 1050:   }
 1051:   /**
 1052:    * Append one entry to the log file(index.html)
 1053:    */
 1054:   public static void appendLog(String entry, String name) throws Exception
 1055:   {
 1056:     logFile.write("<a href=\"./" + name.substring(name.lastIndexOf("/") + 1) + "\">");
 1057:     logFile.write(entry + "</a>");
 1058:     logFile.write("<br>\n<br>\n");
 1059:     logFile.flush();
 1060:   }
 1061:   /**
 1062:    * closes the log file invoked then the application closes
 1063:    */
 1064:   public static void closeLog() throws Exception
 1065:   {
 1066:     logFile.write("\n</body>");
 1067:     logFile.write("\n</html>");
 1068: 
 1069:     logFile.close();
 1070:   }
 1071:   public static void showErrorDialog(String message, String title)
 1072:   {
 1073:     JDialog dialog = new JDialog(fmInstance);
 1074:     dialog.setTitle(title);
 1075:     JTextArea text = new JTextArea();
 1076:     JScrollPane scroller = new JScrollPane(text);
 1077:     dialog.getContentPane().add(scroller);
 1078:     text.append(message);
 1079:     dialog.setSize(600, 300);
 1080:     dialog.setLocationRelativeTo(fmInstance);
 1081:     dialog.show();
 1082:     //JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
 1083:   }
 1084:   public static class ProgressDialog extends JDialog
 1085:   {
 1086:     JLabel table = new JLabel("    ");
 1087:     JLabel status = new JLabel("    ");
 1088:     JLabel title = new JLabel("     ");
 1089:     JPanel content = new JPanel();
 1090:     JPanel titlePanel = new JPanel();
 1091:     JPanel labelPanel = new JPanel();
 1092:     JPanel statusPanel = new JPanel();
 1093:     JPanel buttonPanel = new JPanel();
 1094: 
 1095:     JProgressBar progress = new JProgressBar();
 1096:     JButton cancel = new JButton("Cancel");
 1097:     Thread thread;
 1098:     public ProgressDialog(JFrame frame)
 1099:     {
 1100:       super(frame);
 1101:       content = new JPanel(true);
 1102:       //content.setBorder(BorderFactory.createRaisedBevelBorder());
 1103:       content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
 1104:       title = new JLabel("Progress of conversion");
 1105:       title.setHorizontalTextPosition(title.CENTER);
 1106:       titlePanel.add(title);
 1107:       buttonPanel.add(cancel);
 1108:       // content.add(titlePanel);
 1109:       content.add(Box.createRigidArea(new java.awt.Dimension(0, 15)));
 1110:       content.add(labelPanel);
 1111:       content.add(new JLabel(""));
 1112:       content.add(progress);
 1113:       content.add(statusPanel);
 1114:       content.add(buttonPanel);
 1115:       content.add(Box.createRigidArea(new java.awt.Dimension(0, 15)));
 1116:       labelPanel.add(table);
 1117:       statusPanel.add(status);
 1118:       getContentPane().add(titlePanel, "North");
 1119:       getContentPane().add(content, "Center");
 1120:       this.addWindowListener(new WindowAdapter()
 1121:       {
 1122:         public void windowClosing(WindowEvent e)
 1123:         {
 1124:           cancel.doClick();
 1125:         }
 1126:       });
 1127: 
 1128:       cancel.addActionListener(new ActionListener()
 1129:       {
 1130:         public void actionPerformed(ActionEvent e)
 1131:         {
 1132:           fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 1133: 					fmInstance.setEnabled(true);
 1134:           setVisible(false);
 1135:           thread.stop();
 1136:         }
 1137:       });
 1138:       pack();
 1139: 
 1140:     }
 1141: 
 1142:   }
 1143:   public static class PasswordDialog extends JDialog
 1144:   {
 1145:     JLabel table = new JLabel("    ");
 1146:     JLabel status = new JLabel("    ");
 1147:     JLabel title = new JLabel("     ");
 1148:     JPanel content = new JPanel();
 1149:     JPanel titlePanel = new JPanel();
 1150:     JPanel userPanel = new JPanel();
 1151:     JPanel passwordPanel = new JPanel();
 1152:     JPanel buttonPanel = new JPanel();
 1153:     JTextField user = new JTextField(10);
 1154:     JTextField passwd = new JPasswordField(10);
 1155: 
 1156:     JButton cancel = new JButton("Cancel");
 1157:     JButton ok = new JButton("Ok");
 1158:     DBBean bean = null;
 1159:     Thread thread;
 1160:     public PasswordDialog(JFrame frame, DBBean localBean)
 1161:     {
 1162:       super(frame);
 1163:       setTitle("PasswordDialog");
 1164:       setModal(true);
 1165:       content = new JPanel(true);
 1166:       this.bean = localBean;
 1167:       //content.setBorder(BorderFactory.createRaisedBevelBorder());
 1168:       ActionListener al = new ActionListener()
 1169:       {
 1170:         public void actionPerformed(ActionEvent e)
 1171:         {
 1172:           bean.setUserAndPasswd(user.getText(), passwd.getText());
 1173:           setVisible(false);
 1174:         }
 1175: 
 1176:       };
 1177:       this.addWindowListener(new WindowAdapter()
 1178:       {
 1179:         public void windowClosing(WindowEvent e)
 1180:         {
 1181:           cancel.doClick();
 1182:         }
 1183:       });
 1184: 
 1185:       user.setText(localBean.user);
 1186:       passwd.setText(localBean.passwd);
 1187:       user.addActionListener(al);
 1188:       passwd.addActionListener(al);
 1189:       content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
 1190:       title = new JLabel("Enter user and password ");
 1191:       title.setHorizontalTextPosition(title.CENTER);
 1192:       titlePanel.add(title);
 1193:       buttonPanel.add(ok);
 1194:       buttonPanel.add(cancel);
 1195:       content.add(titlePanel);
 1196:       content.add(Box.createRigidArea(new java.awt.Dimension(0, 15)));
 1197:       // content.add(labelPanel);
 1198:       content.add(new JLabel(""));
 1199:       content.add(userPanel);
 1200:       content.add(passwordPanel);
 1201:       content.add(buttonPanel);
 1202:       content.add(Box.createRigidArea(new java.awt.Dimension(0, 15)));
 1203:       //labelPanel.add(table);
 1204:       userPanel.add(new JLabel("Username:  "));
 1205:       userPanel.add(user);
 1206:       passwordPanel.add(new JLabel("Password:  "));
 1207:       passwordPanel.add(passwd);
 1208:       passwd.setPreferredSize(user.getPreferredSize());
 1209:       passwd.setMinimumSize(passwd.getPreferredSize());
 1210:       passwd.setMaximumSize(passwd.getPreferredSize());
 1211:       passwd.setSize(passwd.getPreferredSize());
 1212:         getContentPane().add(titlePanel, "North");
 1213:       getContentPane().add(content, "Center");
 1214:       ok.addActionListener(al);
 1215:       cancel.addActionListener(new ActionListener()
 1216:       {
 1217:         public void actionPerformed(ActionEvent e)
 1218:         {
 1219:           fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 1220: 					fmInstance.setEnabled(true);
 1221:           setVisible(false);
 1222:           thread.stop();
 1223:         }
 1224: 
 1225:       });
 1226:       pack();
 1227: 
 1228:     }
 1229: 
 1230:   }
 1231:   public void fillTable()
 1232:   {
 1233:     noDBUpdate = true;
 1234:     Vector tableNames = bean.getTableNames();
 1235:     Collections.sort(tableNames, String.CASE_INSENSITIVE_ORDER);
 1236:     Vector[] data = new Vector[2];
 1237:     data[1] = new Vector();
 1238:     data[1].add("Table");
 1239:     data[1].add("Layouts");
 1240: 		data[1].add("select");
 1241:     data[1].add("create");
 1242:    
 1243:     data[0] = new Vector();
 1244: 
 1245:     for (int i = 0; i < tableNames.size(); i++)
 1246:     {
 1247:       String name = tableNames.get(i).toString();
 1248:       Vector layouts = new Vector();
 1249:       try
 1250:       {
 1251:         layouts = bean.getLayoutNames(name);
 1252:       } catch (SQLException e)
 1253:       {
 1254:         layouts = new Vector();
 1255:       }
 1256:       Vector dataRow = new Vector();
 1257:       dataRow.add(name);
 1258:       if (!layouts.isEmpty())
 1259:         dataRow.add(new JComboBox(layouts));
 1260:       else
 1261:         dataRow.add(null);
 1262:       dataRow.add(new TableComponent.SQLCommand("select * from "+bean.getQC()+name+bean.getQC()));
 1263:      
 1264:         data[0].add(dataRow);
 1265:     dataRow.add(new TableComponent.SQLCommand(""));
 1266:       //System.out.println(dataRow);
 1267:     }
 1268:     tC.tableModel.setDataVector(data[0], data[1]);
 1269:     tC.revalidate();
 1270:     tC.tableModel.fireTableDataChanged();
 1271:     noDBUpdate = false;
 1272:   
 1273:   }
 1274:   public Vector[] getListFromTable()
 1275:   {
 1276:     Vector[] vec = new Vector[4];
 1277:     vec[0] = new Vector();
 1278:     vec[1] = new Vector();
 1279: 		vec[2] = new Vector();
 1280:     vec[3] = new Vector();
 1281:     int[] rows = tC.table.getSelectedRows();
 1282:     for (int i = 0; i < rows.length; i++)
 1283:     {
 1284:       //System.out.println(tC.tableModel.getValueAt(rows[i],1));
 1285:       vec[0].add(tC.tableModel.getValueAt(rows[i], 0));
 1286:       JComboBox box = ((JComboBox) tC.tableModel.getValueAt(rows[i], 1));
 1287:       String layoutName = (box != null) ? box.getSelectedItem().toString() : "";
 1288:       vec[1].add(layoutName);
 1289:       vec[2].add(tC.tableModel.getValueAt(rows[i], 2).toString());
 1290:       vec[3].add(tC.tableModel.getValueAt(rows[i], 3).toString());
 1291:   
 1292:     }
 1293:     return vec;
 1294:   }
 1295:   public void setEnabled(boolean state)
 1296:   {
 1297:     showTables.setEnabled(state);
 1298:     showTables1.setEnabled(state);
 1299:     convert.setEnabled(state);
 1300:     dropTables.setEnabled(state);
 1301:     box3.setEnabled(state);
 1302:     box4.setEnabled(state);
 1303: 
 1304:   }
 1305:   public TableComponent.SQLCommand createStatement(String table,DBBean beanDest,String layout,String query)  throws SQLException
 1306:   {
 1307:     fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 1308:         
 1309:     if(beanDest.url.equals("")) beanDest.url=box4.getSelectedItem().toString();
 1310:     StringBuffer command = new StringBuffer(50);
 1311:     command.append("\n           CREATE TABLE ");
 1312:     command.append(beanDest.getQC());
 1313:     command.append(Convert.convertText(table));
 1314:     command.append(beanDest.getQC());
 1315:     command.append("\n             ( ");
 1316:     String type = null;
 1317:    // String query = "select * from " + bean.getQC() +table + bean.getQC();
 1318:    if (!layout.equals(""))
 1319:      {
 1320:        layout = " layout " + bean.getQC() + layout + bean.getQC();
 1321:        StringBuffer queryLayout = new StringBuffer(query);
 1322:        queryLayout.insert(queryLayout.indexOf(table) + table.length() + 1, " " + layout);
 1323:        query = queryLayout.toString();
 1324:        System.out.println("added layout  "+ query);
 1325:         
 1326:      }
 1327:       Vector[] result=bean.getQueryData(query,1);
 1328:     for (int i = 0; i < result[1].size() - 1; ++i)
 1329:     {
 1330:       type = bean.metaData.getColumnTypeName(i + 1);
 1331:       //   System.out.println(i+" "+result[1].get(i)+" "+type);
 1332:       type = (type.equals("NUMBER")) ? "INT4" : type;
 1333:       type = (type.equals("CONTAINER")) ? "TEXT" : type;
 1334:       type = type.toUpperCase(); 
 1335:       if(i==0)
 1336:       command.append(beanDest.getQC() + Convert.convertText((String) result[1].get(i)) + beanDest.getQC() + " " + type + ", ");
 1337:       else
 1338:       command.append("               "+beanDest.getQC() + Convert.convertText((String) result[1].get(i)) + beanDest.getQC() + " " + type + ", ");
 1339:       command.append("\n");
 1340:     }
 1341:     type = bean.metaData.getColumnTypeName(result[1].size());
 1342:     type = (type.equals("NUMBER")) ? "INT4" : type;
 1343:     type = (type.equals("CONTAINER")) ? "TEXT" : type;
 1344:     type = type.toUpperCase(); 
 1345:     command.append("               "+beanDest.getQC() + Convert.convertText((String) result[1].get(result[1].size() - 1)) + beanDest.getQC() + " " + type);
 1346:     command.append("\n             )\n");
 1347:     fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 1348:    
 1349:    return new TableComponent.SQLCommand(command.toString());
 1350:   }
 1351:   static class XMLFilter extends javax.swing.filechooser.FileFilter
 1352:   {
 1353:     public boolean accept(java.io.File file)
 1354:     {
 1355:       if (file.getName().toLowerCase().endsWith(".xml") || file.isDirectory())
 1356:         return true;
 1357:       else
 1358:         return false;
 1359:     }
 1360:     public String getDescription()
 1361:     {
 1362:       return "Batch Convert XML File";
 1363:     }
 1364: 
 1365:   }
 1366:   public static int showDialog(String message, String title, Object[] options)
 1367:   {
 1368:     int option = JOptionPane.showOptionDialog(null, message, title, JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
 1369:     return option;
 1370:   
 1371:   }
 1372: 
 1373: }

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