### Eclipse Workspace Patch 1.0 #P jverein diff --git src/de/jost_net/JVerein/gui/action/FormularfelderExportAction.java src/de/jost_net/JVerein/gui/action/FormularfelderExportAction.java new file mode 100644 index 0000000..a75e900 --- /dev/null +++ src/de/jost_net/JVerein/gui/action/FormularfelderExportAction.java @@ -0,0 +1,89 @@ +/********************************************************************** + * JVerein - Mitgliederverwaltung und einfache Buchhaltung für Vereine + * Copyright (c) by Heiner Jostkleigrewe + * Copyright (c) 2014 by Thomas Hooge + * Main Project: heiner@jverein.dem http://www.jverein.de/ + * Module Author: thomas@hoogi.de, http://www.hoogi.de/ + * + * This file is part of JVerein. + * + * JVerein 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 3 of the License, or + * (at your option) any later version. + * + * JVerein is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **********************************************************************/ +package de.jost_net.JVerein.gui.action; + +import java.util.ArrayList; + +import de.jost_net.JVerein.Einstellungen; +import de.jost_net.JVerein.gui.dialogs.ExportDialog; +import de.jost_net.JVerein.gui.view.DokumentationUtil; +import de.jost_net.JVerein.rmi.Formular; +import de.jost_net.JVerein.rmi.Formularfeld; +import de.willuhn.datasource.rmi.DBIterator; +import de.willuhn.datasource.rmi.DBService; +import de.willuhn.jameica.gui.Action; +import de.willuhn.jameica.gui.GUI; +import de.willuhn.jameica.system.OperationCanceledException; +import de.willuhn.logging.Logger; +import de.willuhn.util.ApplicationException; + +public class FormularfelderExportAction implements Action +{ + + @Override + public void handleAction(Object context) throws ApplicationException + { + Formular f = null; + + if (context != null && (context instanceof Formular)) + { + f = (Formular) context; + } + else + { + throw new ApplicationException("Kein Formular ausgewählt"); + } + + try + { + DBService service = Einstellungen.getDBService(); + DBIterator formularfelder = service.createList(Formularfeld.class); + formularfelder.addFilter("formular = ?", new Object[] { f.getID() }); + ArrayList fflist = new ArrayList(); + while (formularfelder.hasNext()) + { + Formularfeld ff = (Formularfeld) formularfelder.next(); + fflist.add(ff); + } + + ExportDialog d = new ExportDialog((Object[]) fflist.toArray(), + Formularfeld.class, DokumentationUtil.FORMULARE); + d.open(); + } + catch (OperationCanceledException oce) + { + Logger.info(oce.getMessage()); + return; + } + catch (ApplicationException ae) + { + throw ae; + } + catch (Exception e) + { + Logger.error("Fehler", e); + GUI.getStatusBar().setErrorText("Fehler beim Exportieren der Formularfelder"); + } + } +} diff --git src/de/jost_net/JVerein/gui/action/FormularfelderImportAction.java src/de/jost_net/JVerein/gui/action/FormularfelderImportAction.java new file mode 100644 index 0000000..a99201a --- /dev/null +++ src/de/jost_net/JVerein/gui/action/FormularfelderImportAction.java @@ -0,0 +1,104 @@ +/********************************************************************** + * JVerein - Mitgliederverwaltung und einfache Buchhaltung für Vereine + * Copyright (c) by Heiner Jostkleigrewe + * Copyright (c) 2014 by Thomas Hooge + * Main Project: heiner@jverein.dem http://www.jverein.de/ + * Module Author: thomas@hoogi.de, http://www.hoogi.de/ + * + * This file is part of JVerein. + * + * JVerein 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 3 of the License, or + * (at your option) any later version. + * + * JVerein is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **********************************************************************/ +package de.jost_net.JVerein.gui.action; + +import java.rmi.RemoteException; + +import de.willuhn.datasource.GenericObject; +import de.willuhn.jameica.gui.dialogs.AbstractDialog; +import de.willuhn.jameica.gui.dialogs.YesNoDialog; +import de.willuhn.jameica.gui.Action; +import de.willuhn.jameica.gui.GUI; +import de.willuhn.jameica.system.OperationCanceledException; +import de.willuhn.logging.Logger; +import de.willuhn.util.ApplicationException; +import de.jost_net.JVerein.gui.control.FormularfeldControl; +import de.jost_net.JVerein.gui.dialogs.ImportDialog; +import de.jost_net.JVerein.gui.view.DokumentationUtil; +import de.jost_net.JVerein.rmi.Formularfeld; + +public class FormularfelderImportAction implements Action +{ + FormularfeldControl control; + + public FormularfelderImportAction(FormularfeldControl control) + { + this.control = control; + } + + @Override + public void handleAction(Object context) throws ApplicationException + { + + // Nachfrage, da alle Daten gelöscht werden! + YesNoDialog ynd = new YesNoDialog(AbstractDialog.POSITION_CENTER); + ynd.setText("Achtung! Alle momentan vorhanden Formularfelder für\n" + + "dieses Formular werden gelöscht.\n" + + "Dieser Vorgang kann nicht rückgängig gemacht werden.\n\n" + + "Wirklich fortfahren?"); + ynd.setTitle("Import: Formularfelder"); + Boolean choice; + try + { + choice = (Boolean) ynd.open(); + if (!choice.booleanValue()) + return; + } + catch (Exception e) + { + Logger.error("Fehler", e); + } + + try + { + ImportDialog d = new ImportDialog((GenericObject) context, Formularfeld.class, true, + DokumentationUtil.FORMULARE); + d.open(); + } + catch (OperationCanceledException oce) + { + Logger.info(oce.getMessage()); + return; + } + catch (ApplicationException ae) + { + throw ae; + } + catch (Exception e) + { + Logger.error("error while importing form fields", e); + GUI.getStatusBar().setErrorText("Fehler beim Importieren von Formularfeldern"); + } + + try { + control.refreshTable(); + } + catch (RemoteException re) + { + Logger.error("Fehler: ", re); + throw new ApplicationException("Fehler anzeigen der Formularfelder", re); + } + + } +} diff --git src/de/jost_net/JVerein/gui/view/FormularfelderListeView.java src/de/jost_net/JVerein/gui/view/FormularfelderListeView.java index 2709a5c..47f2f3f 100644 --- src/de/jost_net/JVerein/gui/view/FormularfelderListeView.java +++ src/de/jost_net/JVerein/gui/view/FormularfelderListeView.java @@ -19,6 +19,8 @@ import de.jost_net.JVerein.gui.action.DokumentationAction; import de.jost_net.JVerein.gui.action.FormularAnzeigeAction; import de.jost_net.JVerein.gui.action.FormularfeldAction; +import de.jost_net.JVerein.gui.action.FormularfelderExportAction; +import de.jost_net.JVerein.gui.action.FormularfelderImportAction; import de.jost_net.JVerein.gui.control.FormularfeldControl; import de.jost_net.JVerein.rmi.Formular; import de.willuhn.jameica.gui.AbstractView; @@ -45,6 +47,10 @@ ButtonArea buttons = new ButtonArea(); buttons.addButton("Hilfe", new DokumentationAction(), DokumentationUtil.FORMULARE, false, "help-browser.png"); + buttons.addButton("Export", new FormularfelderExportAction(), + getCurrentObject(), false, "document-save.png"); + buttons.addButton("Import", new FormularfelderImportAction(control), + getCurrentObject(), false, "import_obj.gif"); buttons.addButton("anzeigen", new FormularAnzeigeAction(), getCurrentObject(), false, "edit.png"); buttons.addButton("neu", new FormularfeldAction(), getCurrentObject(), diff --git src/de/jost_net/JVerein/io/FormularfelderExport.java src/de/jost_net/JVerein/io/FormularfelderExport.java new file mode 100644 index 0000000..62f2570 --- /dev/null +++ src/de/jost_net/JVerein/io/FormularfelderExport.java @@ -0,0 +1,78 @@ +/********************************************************************** + * JVerein - Mitgliederverwaltung und einfache Buchhaltung für Vereine + * Copyright (c) by Heiner Jostkleigrewe + * Copyright (c) 2014 by Thomas Hooge + * Main Project: heiner@jverein.dem http://www.jverein.de/ + * Module Author: thomas@hoogi.de, http://www.hoogi.de/ + * + * This file is part of JVerein. + * + * JVerein 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 3 of the License, or + * (at your option) any later version. + * + * JVerein is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **********************************************************************/ +package de.jost_net.JVerein.io; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.rmi.RemoteException; + +import com.itextpdf.text.DocumentException; + +import de.jost_net.JVerein.rmi.Formularfeld; +import de.willuhn.logging.Logger; +import de.willuhn.util.ApplicationException; +import de.willuhn.util.ProgressMonitor; + +public abstract class FormularfelderExport implements Exporter +{ + + @Override + public abstract String getName(); + + @Override + public abstract IOFormat[] getIOFormats(Class objectType); + + protected File file; + + @Override + public void doExport(Object[] objects, IOFormat format, File file, + ProgressMonitor monitor) throws ApplicationException, DocumentException, + IOException + { + this.file = file; + Logger.debug(String.format("Formularfelder Export")); + open(); + for (Object ob : objects) + { + add((Formularfeld) ob); + } + close(); + } + + @Override + public String getDateiname() + { + return "formularfelder"; + } + + protected abstract void add(Formularfeld ff) throws RemoteException; + + protected abstract void open() throws DocumentException, + FileNotFoundException; + + protected abstract void close() throws IOException, DocumentException, + ApplicationException; + +} diff --git src/de/jost_net/JVerein/io/FormularfelderExportCSV.java src/de/jost_net/JVerein/io/FormularfelderExportCSV.java new file mode 100644 index 0000000..e3e6737 --- /dev/null +++ src/de/jost_net/JVerein/io/FormularfelderExportCSV.java @@ -0,0 +1,127 @@ +/********************************************************************** + * JVerein - Mitgliederverwaltung und einfache Buchhaltung für Vereine + * Copyright (c) by Heiner Jostkleigrewe + * Copyright (c) 2014 by Thomas Hooge + * Main Project: heiner@jverein.dem http://www.jverein.de/ + * Module Author: thomas@hoogi.de, http://www.hoogi.de/ + * + * This file is part of JVerein. + * + * JVerein 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 3 of the License, or + * (at your option) any later version. + * + * JVerein is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **********************************************************************/ +package de.jost_net.JVerein.io; + +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.supercsv.io.CsvMapWriter; +import org.supercsv.io.ICsvMapWriter; +import org.supercsv.prefs.CsvPreference; + +import com.itextpdf.text.DocumentException; + +import de.jost_net.JVerein.rmi.Formularfeld; + +public class FormularfelderExportCSV extends FormularfelderExport +{ + + private ICsvMapWriter writer; + private String[] header; + private ArrayList formularfelder; + + @Override + public String getName() + { + return "Formularfelder CSV-Export"; + } + + @Override + public IOFormat[] getIOFormats(Class objectType) + { + if (objectType != Formularfeld.class) + { + return null; + } + IOFormat f = new IOFormat() + { + + @Override + public String getName() + { + return FormularfelderExportCSV.this.getName(); + } + + /** + * @see de.willuhn.jameica.hbci.io.IOFormat#getFileExtensions() + */ + @Override + public String[] getFileExtensions() + { + return new String[] { "*.csv" }; + } + }; + return new IOFormat[] { f }; + } + + @Override + public String getDateiname() + { + return "formularfelder"; + } + + @Override + protected void add(Formularfeld ff) + { + formularfelder.add(ff); + } + + @Override + protected void open() throws DocumentException + { + formularfelder = new ArrayList(); + try + { + writer = new CsvMapWriter(new FileWriter(file), CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE); + header = new String[] { "Name", "Seite", "X", "Y", "Font", "Fontsize", "Fontstyle" }; + writer.writeHeader(header); + } + catch (IOException e) + { + throw new DocumentException(e); + } + } + + @Override + protected void close() throws IOException, DocumentException + { + Map ffmap = new HashMap(); + for (Formularfeld ff : formularfelder) + { + ffmap.put("Name", ff.getName()); + ffmap.put("Seite", ff.getSeite()); + ffmap.put("X", ff.getX()); + ffmap.put("Y", ff.getY()); + ffmap.put("Font", ff.getFont()); + ffmap.put("Fontsize", ff.getFontsize()); + ffmap.put("Fontstyle", ff.getFontstyle()); + writer.write(ffmap, header); + } + writer.close(); + } + +} diff --git src/de/jost_net/JVerein/io/FormularfelderImportCSV.java src/de/jost_net/JVerein/io/FormularfelderImportCSV.java new file mode 100644 index 0000000..4ca8431 --- /dev/null +++ src/de/jost_net/JVerein/io/FormularfelderImportCSV.java @@ -0,0 +1,245 @@ +/********************************************************************** + * JVerein - Mitgliederverwaltung und einfache Buchhaltung für Vereine + * Copyright (c) by Heiner Jostkleigrewe + * Copyright (c) 2014 by Thomas Hooge + * Main Project: heiner@jverein.dem http://www.jverein.de/ + * Module Author: thomas@hoogi.de, http://www.hoogi.de/ + * + * This file is part of JVerein. + * + * JVerein 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 3 of the License, or + * (at your option) any later version. + * + * JVerein is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **********************************************************************/ +package de.jost_net.JVerein.io; + +import java.io.File; +import java.rmi.RemoteException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.MessageFormat; +import java.util.Properties; + +import de.jost_net.JVerein.Einstellungen; +import de.jost_net.JVerein.rmi.Formular; +import de.jost_net.JVerein.rmi.Formularfeld; +import de.willuhn.datasource.rmi.DBIterator; +import de.willuhn.logging.Logger; +import de.willuhn.util.ApplicationException; +import de.willuhn.util.ProgressMonitor; + +/* + * Importieren von Objekten zu Mitgliedern + * + * TODO + * - Die Liste mit den Objekttypen muß zuvor vorhanden sein! + * - Optionale Felder + * gruppe + * extnr + */ +public class FormularfelderImportCSV implements Importer +{ + + /** + * Alle vorhandenen Formularfelder für ein bestimmtes Formular löschen + */ + private void deleteExistingData(Formular f) { + try + { + DBIterator list = Einstellungen.getDBService().createList(Formularfeld.class); + list.addFilter("formular = ?", f.getID()); + while (list.hasNext()) + { + Formularfeld ff = (Formularfeld) list.next(); + ff.delete(); + } + } + catch (RemoteException e) + { + Logger.error("Fehler", e); + } + catch (ApplicationException ae) + { + Logger.error("Fehler", ae); + } + } + + @Override + public void doImport(Object context, IOFormat format, File file, + String encoding, ProgressMonitor monitor) + { + + // Datenbank bereinigen + Formular f = (Formular) context; + try { + Logger.info("Importiere Formularfelder für Formular " + f.getBezeichnung()); + } catch (RemoteException re) { + // pass + } + deleteExistingData(f); + + ResultSet results; + try + { + + Properties props = new java.util.Properties(); + props.put("separator", ";"); + props.put("suppressHeaders", "false"); + props.put("charset", encoding); + String path = file.getParent(); + String fil = file.getName(); + int pos = fil.lastIndexOf('.'); + props.put("fileExtension", fil.substring(pos)); + + Class.forName("org.relique.jdbc.csv.CsvDriver"); + Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + path, props); + Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); + results = stmt.executeQuery("SELECT * FROM " + fil.substring(0, pos)); + + int anz = 0; + while (results.next()) + { + anz++; + monitor.setStatus(anz); + + try + { + Formularfeld ff = (Formularfeld) Einstellungen.getDBService().createObject(Formularfeld.class, null); + ff.setFormular(f); + try + { + ff.setName(results.getString("name")); + } + catch (SQLException e) + { + throw new ApplicationException("Spalte 'name' fehlt!"); + } + + try + { + ff.setX(results.getDouble("x")); + } + catch (SQLException e) + { + throw new ApplicationException("Spalte 'x' fehlt!"); + } + + try + { + ff.setY(results.getDouble("y")); + } + catch (SQLException e) + { + throw new ApplicationException("Spalte 'y' fehlt!"); + } + + try + { + ff.setSeite(results.getInt("seite")); + } + catch (SQLException e) + { + ff.setFontsize(1); + } + + try + { + ff.setFont(results.getString("font")); + } + catch (SQLException e) + { + throw new ApplicationException("Spalte 'font' fehlt!"); + } + + try + { + ff.setFontsize(results.getInt("fontsize")); + } + catch (SQLException e) + { + ff.setFontsize(10); + } + + try + { + ff.setFontstyle(results.getInt("fontstyle")); + } + catch (SQLException e) + { + ff.setFontstyle(0); + } + + ff.store(); + } + catch (Exception e) + { + throw new ApplicationException(e.getMessage()); + } + } + results.close(); + stmt.close(); + conn.close(); + } + catch (Exception e) + { + monitor.log(" nicht importiert: " + e.getMessage()); + Logger.error("Fehler", e); + } + finally + { + // + } + } + + @Override + public String getName() + { + return "CSV-Formularfeldimport"; + } + + public boolean hasFileDialog() + { + return true; + } + + @Override + public IOFormat[] getIOFormats(Class objectType) + { + if (objectType != Formularfeld.class) + { + return null; + } + IOFormat f = new IOFormat() + { + + @Override + public String getName() + { + return FormularfelderImportCSV.this.getName(); + } + + /** + * @see de.willuhn.jameica.hbci.io.IOFormat#getFileExtensions() + */ + @Override + public String[] getFileExtensions() + { + return new String[] { "*.csv" }; + } + }; + return new IOFormat[] { f }; + } +}