--- FM2SQL/Attic/FM2SQL.java 2004/01/12 13:23:09 1.9 +++ FM2SQL/Attic/FM2SQL.java 2004/02/10 12:52:30 1.15 @@ -26,6 +26,7 @@ public class FM2SQL extends JFrame imple private JCheckBoxMenuItem convertItem; private JCheckBoxMenuItem appendItem; private JCheckBoxMenuItem updateItem; + int mode = -1; /** * The database Bean instance. * @@ -116,9 +117,11 @@ public class FM2SQL extends JFrame imple box2 = new JComboBox(); box3 = new JComboBox(new String[] { "jdbc:fmpro:http://141.14.237.74:8050", "jdbc:fmpro:http://localhost", "jdbc:postgresql://foxridge/test" }); box3.setEditable(true); + box3.setFont(new Font("Times New Roman",Font.PLAIN,12)); box4 = new JComboBox(new String[] { "jdbc:postgresql://foxridge/test", "jdbc:postgresql://erebos/test1" }); box4.setEditable(true); box4.addActionListener(this); + box4.setFont(new Font("Times New Roman",Font.PLAIN,12)); table = new TableComponent(); box = new JComboBox(tables); box.addActionListener(this); @@ -553,20 +556,21 @@ public class FM2SQL extends JFrame imple System.out.println("Convert Mode selected"); convert.setText("Convert Tables"); convert.setActionCommand("Convert Tables"); - + mode = Convert.DataBase.CONVERT_MODE; } if (command == "Append Mode") { System.out.println("Append Mode selected"); convert.setText("Append Tables"); convert.setActionCommand("Append Tables"); - + mode = Convert.DataBase.APPEND_MODE; } if (command == "Update Mode") { System.out.println("Update Mode selected"); convert.setText("Update Tables"); convert.setActionCommand("Update Tables"); + mode = Convert.DataBase.UPDATE_MODE; } //writing config if (command.equals("save XML Config")) @@ -639,7 +643,7 @@ public class FM2SQL extends JFrame imple } - if (command.equals("Convert Tables")) + if (command.equals("Convert Tables")||command.equals("Append Tables")) { Thread thread = new Thread() @@ -654,6 +658,22 @@ public class FM2SQL extends JFrame imple }; thread.start(); } + if (command.equals("Update Tables")) + { + + Thread thread = new Thread() + { + public void run() + { + setEnabled(false); + update(); + setEnabled(true); + } + + }; + thread.start(); + } + if (command.equals("show Tables")) { Thread thread = new Thread() @@ -709,6 +729,42 @@ public class FM2SQL extends JFrame imple } } + /** + * Updates the content of source to destination and makes new table if necessary + */ + + public void update() + { + 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.update(bean.url, box4.getSelectedItem().toString(), vectors[0], vectors[1], vectors[2], vectors[3],vectors[4], mode); + + destBean.setConnection((String) box4.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(), "Conversion of table failed"); + fmInstance.setEnabled(true); + } + + } /** * Copys the content of source to destination and makes new table if necessary */ @@ -724,7 +780,7 @@ public class FM2SQL extends JFrame imple { fmInstance.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); fmInstance.setEnabled(false); - Convert.convert(bean.url, box4.getSelectedItem().toString(), vectors[0], vectors[1],vectors[2],vectors[3]); + Convert.convert(bean.url, box4.getSelectedItem().toString(), vectors[0], vectors[1],vectors[2],vectors[3],vectors[4],mode); destBean.setConnection((String) box4.getSelectedItem()); DefaultListModel model = new DefaultListModel(); @@ -750,15 +806,14 @@ public class FM2SQL extends JFrame imple fmInstance.setEnabled(false); Vector vectors[] = getListFromTable(); - int mode =-1; if(convertItem.isSelected()) mode = Convert.DataBase.CONVERT_MODE; else if(appendItem.isSelected()) mode = Convert.DataBase.APPEND_MODE; else if(updateItem.isSelected()) mode = Convert.DataBase.UPDATE_MODE; - - Convert.DataBase source = new Convert.DataBase(bean,vectors[0],vectors[1],vectors[2],vectors[3],mode); - Convert.DataBase destination = new Convert.DataBase(destBean,new Vector(),new Vector(),new Vector(),new Vector(),-1); + // 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); try { @@ -798,30 +853,26 @@ public class FM2SQL extends JFrame imple for (Iterator iter = databases.iterator(); iter.hasNext();) { Convert.DataBase database = (Convert.DataBase) iter.next(); - int mode = -1; + if (database.mode == Convert.DataBase.CONVERT_MODE) { convertItem.setSelected(true); convert.setText("Convert Tables"); convert.setActionCommand("Convert Tables"); - - } else - if (database.mode == Convert.DataBase.APPEND_MODE) - { - appendItem.setSelected(true); - convert.setText("Append Tables"); - convert.setActionCommand("Append Tables"); - - } else - if (database.mode == Convert.DataBase.UPDATE_MODE) - { - updateItem.setSelected(true); - convert.setText("Update Tables"); - convert.setActionCommand("Update Tables"); - - } - - + mode = Convert.DataBase.CONVERT_MODE; + } else if (database.mode == Convert.DataBase.APPEND_MODE) + { + appendItem.setSelected(true); + convert.setText("Append Tables"); + convert.setActionCommand("Append Tables"); + mode = Convert.DataBase.APPEND_MODE; + } else if (database.mode == Convert.DataBase.UPDATE_MODE) + { + updateItem.setSelected(true); + convert.setText("Update Tables"); + convert.setActionCommand("Update Tables"); + mode = Convert.DataBase.UPDATE_MODE; + } database.bean.getConnection(); bean = database.bean; @@ -840,8 +891,11 @@ public class FM2SQL extends JFrame imple 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; tC.tableModel.setValueAt(new TableComponent.SQLCommand(database.selects.get(i).toString()),index,2); + String create =database.creates.get(i).toString(); tC.tableModel.setValueAt(new TableComponent.SQLCommand(create.equals("") ? create:" "+create),index,3); + tC.tableModel.setValueAt(new TableComponent.SQLCommand(bean.ids.get(i).toString()),index,4); + Object comboBox=tC.tableModel.getValueAt(index,1); indices[i] = index; if(comboBox!=null) ((JComboBox)comboBox).setSelectedItem(database.layouts.get(i)); @@ -1185,6 +1239,7 @@ public class FM2SQL extends JFrame imple menu.setBackground(fm.getBackground()); menubar.setBackground(fm.getBackground()); + convertItem.doClick(); setJMenuBar(menubar); } /** @@ -1402,9 +1457,9 @@ public class FM2SQL extends JFrame imple data[1].add("Layouts"); data[1].add("select"); data[1].add("create"); - + data[1].add(" id "); + // TODO add id vector DBBean data[0] = new Vector(); - for (int i = 0; i < tableNames.size(); i++) { String name = tableNames.get(i).toString(); @@ -1425,7 +1480,12 @@ public class FM2SQL extends JFrame imple dataRow.add(new TableComponent.SQLCommand("select * from "+bean.getQC()+name+bean.getQC())); data[0].add(dataRow); + + // create row dataRow.add(new TableComponent.SQLCommand("")); + // id row + dataRow.add(new TableComponent.SQLCommand("")); + bean.ids.add(""); //System.out.println(dataRow); } tC.tableModel.setDataVector(data[0], data[1]); @@ -1436,11 +1496,12 @@ public class FM2SQL extends JFrame imple } public Vector[] getListFromTable() { - Vector[] vec = new Vector[4]; + Vector[] vec = new Vector[5]; vec[0] = new Vector(); vec[1] = new Vector(); vec[2] = new Vector(); vec[3] = new Vector(); + vec[4] = new Vector(); int[] rows = tC.table.getSelectedRows(); for (int i = 0; i < rows.length; i++) { @@ -1451,6 +1512,7 @@ public class FM2SQL extends JFrame imple vec[1].add(layoutName); vec[2].add(tC.tableModel.getValueAt(rows[i], 2).toString()); vec[3].add(tC.tableModel.getValueAt(rows[i], 3).toString()); + vec[4].add(tC.tableModel.getValueAt(rows[i], 4).toString()); } return vec;