--- FM2SQL/Attic/FM2SQL.java 2004/02/27 11:34:53 1.21 +++ FM2SQL/Attic/FM2SQL.java 2004/06/23 10:00:06 1.40 @@ -1,3 +1,17 @@ +/* + * FM2SQL.java -- Main program Filemaker to SQL Converter + * Copyright (C) 2003 Robert Gordesch (rogo@mpiwg-berlin.mpg.de) + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. Please read license.txt for the full details. A copy of + * the GPL may be found at http://www.gnu.org/copyleft/lgpl.html You should + * have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA Created on 15.09.2003 by + * rogo + */ + import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; @@ -18,6 +32,7 @@ import java.io.FileWriter; import java.io.PrintStream; import java.sql.SQLException; import java.sql.Statement; +import java.text.ParseException; import java.util.Collections; import java.util.Iterator; import java.util.Vector; @@ -67,16 +82,19 @@ import javax.swing.table.TableModel; */ public class FM2SQL extends JFrame implements ActionListener, TableModelListener { + private JMenuItem delimiterItem; private JCheckBoxMenuItem convertItem; private JCheckBoxMenuItem appendItem; private JCheckBoxMenuItem updateItem; private JCheckBoxMenuItem deleteItem; - + private JCheckBoxMenuItem useNormanToUnicodeMapper; int mode = -1; - final static int ID_INDEX = 1; - final static int SELECT_INDEX = 2; - final static int CREATE_INDEX = 3; - final static int LAYOUT_INDEX = 4; + final static int STATUS_INDEX = 0; + final static int NAME_INDEX = 1; + final static int ID_INDEX = 2; + final static int SELECT_INDEX = 3; + final static int CREATE_INDEX = 4; + final static int LAYOUT_INDEX = 5; @@ -136,6 +154,8 @@ public class FM2SQL extends JFrame imple int oldWidth = 0, oldHeight = 0; boolean resize = true; static FileWriter logFile; + String delimiter = ""; + Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); JFileChooser configExportFileChooser; JFileChooser configImportFileChooser; @@ -594,6 +614,13 @@ public class FM2SQL extends JFrame imple { } } + if (command.equals("Delimiter")) + { + new DelimiterDialog(fmInstance).setVisible(true); + //delimiter = JOptionPane.showInputDialog(fmInstance,"Enter delimiter String",delimiter); + + } + if (command == "Convert Mode") { System.out.println("Convert Mode selected"); @@ -627,7 +654,10 @@ public class FM2SQL extends JFrame imple convert.setToolTipText("Deletes data that has been deleted in source"); mode = Convert.DataBase.DELETE_MODE; } - +if(command.equals("use NormanToUnicodeMapper")) +{ + if(bean!=null) bean.setUseNormanToUnicodeMapper(useNormanToUnicodeMapper.isSelected()); +} //writing config if (command.equals("save XML Config")) { @@ -729,6 +759,21 @@ public class FM2SQL extends JFrame imple }; thread.start(); } + if (command.equals("Delete Tables")) + { + + Thread thread = new Thread() + { + public void run() + { + setEnabled(false); + delete(); + setEnabled(true); + } + + }; + thread.start(); + } if (command.equals("show Tables")) { @@ -822,6 +867,40 @@ public class FM2SQL extends JFrame imple } } + public void delete() + { + Vector vectors[] = getListFromTable(); + Convert.user = bean.user; + Convert.passwd = bean.passwd; + Convert.userDest = destBean.user; + Convert.passwdDest = destBean.passwd; + try + { + + fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + fmInstance.setEnabled(false); + Convert.delete(bean.url, destURLBox.getSelectedItem().toString(), vectors[0], vectors[1], vectors[2], vectors[3],vectors[4], mode); + + destBean.setConnection((String) destURLBox.getSelectedItem()); + DefaultListModel model = new DefaultListModel(); + tables = destBean.getTableNames(); + for (int j = 0; j < tables.size(); ++j) + model.addElement(tables.get(j)); + if (debug) + System.out.println("hallo" + tables + " "); + tListDest.setModel(model); + fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } catch (Exception e4) + { + ByteArrayOutputStream b = new ByteArrayOutputStream(); + PrintStream stream = new PrintStream(b); + e4.printStackTrace(stream); + showErrorDialog(b.toString(), "Delete of table failed"); + fmInstance.setEnabled(true); + } + + } + /** * Copys the content of source to destination and makes new table if necessary */ @@ -837,8 +916,7 @@ public class FM2SQL extends JFrame imple { fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); fmInstance.setEnabled(false); - Convert.convert(bean.url, destURLBox.getSelectedItem().toString(), vectors[0], vectors[1],vectors[2],vectors[3],vectors[4],mode); - + Convert.convert(bean.url, destURLBox.getSelectedItem().toString(), vectors[0], vectors[1],vectors[2],vectors[3],vectors[4],mode,delimiter); destBean.setConnection((String) destURLBox.getSelectedItem()); DefaultListModel model = new DefaultListModel(); tables = destBean.getTableNames(); @@ -868,10 +946,14 @@ public class FM2SQL extends JFrame imple if(appendItem.isSelected()) mode = Convert.DataBase.APPEND_MODE; else if(updateItem.isSelected()) mode = Convert.DataBase.UPDATE_MODE; + else + if(deleteItem.isSelected()) mode = Convert.DataBase.DELETE_MODE; + // TODO add id vector in table and write it out 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); - + source.delimiter =delimiter; + source.useNormanToUnicodeMapper=useNormanToUnicodeMapper.isSelected(); try { Convert.writeConfig(file,source,destination); @@ -913,26 +995,22 @@ public class FM2SQL extends JFrame imple if (database.mode == Convert.DataBase.CONVERT_MODE) { - convertItem.setSelected(true); - convert.setText("Convert Tables"); - convert.setActionCommand("Convert Tables"); - mode = Convert.DataBase.CONVERT_MODE; + convertItem.doClick(); } else if (database.mode == Convert.DataBase.APPEND_MODE) { - appendItem.setSelected(true); - convert.setText("Append Tables"); - convert.setActionCommand("Append Tables"); - mode = Convert.DataBase.APPEND_MODE; + appendItem.doClick(); } else if (database.mode == Convert.DataBase.UPDATE_MODE) { - updateItem.setSelected(true); - convert.setText("Update Tables"); - convert.setActionCommand("Update Tables"); - mode = Convert.DataBase.UPDATE_MODE; + updateItem.doClick(); + } else if (database.mode == Convert.DataBase.DELETE_MODE) + { + deleteItem.doClick(); } + delimiter=database.delimiter; database.bean.getConnection(); - + bean = database.bean; + if(bean.isUseNormanToUnicodeMapper()) useNormanToUnicodeMapper.setSelected(true); Object obj =bean.url; ((DefaultComboBoxModel) sourceURLBox.getModel()).removeElement(obj); ((DefaultComboBoxModel) sourceURLBox.getModel()).insertElementAt(obj,0); @@ -957,7 +1035,22 @@ public class FM2SQL extends JFrame imple Object idcomboBox=tC.tableModel.getValueAt(index,ID_INDEX); indices[i] = index; - if(comboBox!=null) ((JComboBox)comboBox).setSelectedItem(database.layouts.get(i)); + if (comboBox != null) + { + String layout = database.layouts.get(i).toString(); + ((JComboBox) comboBox).setSelectedItem(layout); + if (layout != "") + { + bean.makeQuery("select * from" + bean.getQC() + table + bean.getQC() + " layout " + bean.getQC() + layout + bean.getQC(), 1); + + Vector idVec = bean.getColumnNames(); + if (idVec == null) + idVec = new Vector(); + idVec.add(0, ""); + ((JComboBox) idcomboBox).setModel(new DefaultComboBoxModel(idVec)); + } + + } if(idcomboBox!=null)((JComboBox)idcomboBox).setSelectedItem(bean.ids.get(i)); tC.tableModel.fireTableDataChanged(); noDBUpdate = false; @@ -967,8 +1060,10 @@ public class FM2SQL extends JFrame imple // add Selections ListSelectionModel lm = tC.table.getSelectionModel(); for(int i=0;i