--- FM2SQL/Attic/FM2SQL.java 2004/03/15 12:31:30 1.31 +++ FM2SQL/Attic/FM2SQL.java 2004/06/22 10:33:53 1.39 @@ -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; @@ -72,12 +87,14 @@ public class FM2SQL extends JFrame imple 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; @@ -637,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")) { @@ -926,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); @@ -971,33 +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; - } else if (database.mode == Convert.DataBase.UPDATE_MODE) + updateItem.doClick(); + } else if (database.mode == Convert.DataBase.DELETE_MODE) { - deleteItem.setSelected(true); - convert.setText("Delete Tables"); - convert.setActionCommand("Delete Tables"); - 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); @@ -1047,8 +1060,10 @@ public class FM2SQL extends JFrame imple // add Selections ListSelectionModel lm = tC.table.getSelectionModel(); for(int i=0;i 0) ? destBean.getQueryData(query, dialog, 50) : bean.getQueryData(query, dialog, 50); + Vector[] vecs = (list > 0) ? destBean.getQueryData(query, dialog, 0) : bean.getQueryData(query, dialog, 0); if (vecs[1].isEmpty()) throw new Exception("Wrong columnname or Empty Layout"); window.updateResult(vecs[0], vecs[1]); @@ -1270,7 +1285,7 @@ public class FM2SQL extends JFrame imple { if(columnName.equals("select")||columnName.equals("Layouts")) { - String table = model.getValueAt(row,0).toString(); + String table = model.getValueAt(row,NAME_INDEX).toString(); String layout = (model.getValueAt(row,LAYOUT_INDEX)!=null) ?((JComboBox)model.getValueAt(row,LAYOUT_INDEX)).getSelectedItem().toString():""; String query = model.getValueAt(row,SELECT_INDEX).toString(); String create = model.getValueAt(row,CREATE_INDEX).toString(); @@ -1387,6 +1402,10 @@ public class FM2SQL extends JFrame imple bgrp.add(deleteItem); menu.add(deleteItem); + useNormanToUnicodeMapper = new JCheckBoxMenuItem("use NormanToUnicodeMapper"); + useNormanToUnicodeMapper.setToolTipText("maps characters in norman encoding to unicode characters"); + useNormanToUnicodeMapper.addActionListener(fm); + menu.add(useNormanToUnicodeMapper); menubar.add(menu); item = new JMenuItem("show Driver features"); @@ -1481,9 +1500,12 @@ public class FM2SQL extends JFrame imple JProgressBar progress = new JProgressBar(); JButton cancel = new JButton("Cancel"); Thread thread; - public ProgressDialog(JFrame frame) + DBBean bean; + public ProgressDialog(JFrame frame,DBBean bean) { super(frame); + this.bean = bean; + content = new JPanel(true); //content.setBorder(BorderFactory.createRaisedBevelBorder()); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); @@ -1518,6 +1540,18 @@ public class FM2SQL extends JFrame imple fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); fmInstance.setEnabled(true); setVisible(false); + try + { + ProgressDialog.this.bean.getConnection().close(); + } catch (SQLException e1) + { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (Exception e1) + { + // TODO Auto-generated catch block + e1.printStackTrace(); + } thread.stop(); } }); @@ -1728,12 +1762,14 @@ public class FM2SQL extends JFrame imple public void fillTable() { noDBUpdate = true; + bean.setUseNormanToUnicodeMapper(useNormanToUnicodeMapper.isSelected()); Vector tableNames = bean.getTableNames(); Collections.sort(tableNames, String.CASE_INSENSITIVE_ORDER); Vector[] data = new Vector[2]; - data[1] = new Vector(5); - data[1].setSize(5); - data[1].set(0," source Tablename "); + data[1] = new Vector(6); + data[1].setSize(6); + data[1].set(STATUS_INDEX," "); + data[1].set(NAME_INDEX," source Tablename "); data[1].set(LAYOUT_INDEX,"Layouts"); data[1].set(SELECT_INDEX,"select"); data[1].set(CREATE_INDEX,"create"); @@ -1757,10 +1793,11 @@ public class FM2SQL extends JFrame imple idVec = bean.getColumnNames(); if(idVec==null) idVec=new Vector(); idVec.add(0,""); - Vector dataRow = new Vector(5); + Vector dataRow = new Vector(6); - dataRow.setSize(5); - dataRow.set(0,name); + dataRow.setSize(6); + dataRow.set(STATUS_INDEX,Boolean.FALSE); + dataRow.set(NAME_INDEX,name); dataRow.set(SELECT_INDEX,new TableComponent.SQLCommand("select * from " + bean.getQC() + name + bean.getQC())); if (!layouts.isEmpty()) @@ -1779,6 +1816,7 @@ public class FM2SQL extends JFrame imple //System.out.println(dataRow); } + tC.booleanRenderer.renderFalseEmpty=true; tC.tableModel.setDataVector(data[0], data[1]); //@TODO new sizeToFit method needed //tC.sizeToFit(450, 250); @@ -1797,18 +1835,27 @@ public class FM2SQL extends JFrame imple vec[2] = new Vector(); vec[3] = new Vector(); vec[4] = new Vector(); + for(int i=0;i