Author: jpepin Date: 2010-07-29 14:51:43 +0200 (Thu, 29 Jul 2010) New Revision: 2989 Url: http://chorem.org/repositories/revision/lima/2989 Log: Ajout dans l'import/export d'une option de s?\195?\169lection de l'encodage du fichier CSV, d?\195?\169sormais compatible avec Excel. Added: trunk/lima-swing/src/main/java/org/chorem/lima/enums/EncodingEnum.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExportFileChooser.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialStatementService.java trunk/lima-swing/src/main/java/org/chorem/lima/enums/AccountsChartEnum.java trunk/lima-swing/src/main/java/org/chorem/lima/enums/EntryBooksChartEnum.java trunk/lima-swing/src/main/java/org/chorem/lima/enums/FinancialStatementsChartEnum.java trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementImportForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/OpeningViewHandler.java trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialStatementServiceImpl.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -186,7 +186,17 @@ } } + + @Override + public void removeAllFinancialStatement() throws LimaException, + LimaBusinessException { + for (FinancialStatement financialStatement : getChildrenFinancialStatement(null)) { + removeFinancialStatement(financialStatement); + } + } + + @Override public List<FinancialStatement> getAllFinancialStatements() throws LimaException { TopiaContext transaction = null; List<FinancialStatement> financialStatements = null; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialStatementService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialStatementService.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/FinancialStatementService.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -34,7 +34,8 @@ public void createFinancialStatement(FinancialStatement masterFinancialStatement, FinancialStatement financialStatement) throws LimaException, LimaBusinessException; public void updateFinancialStatement(FinancialStatement financialStatement) throws LimaException, LimaBusinessException; public void removeFinancialStatement(FinancialStatement financialStatement) throws LimaException, LimaBusinessException; - + public void removeAllFinancialStatement() throws LimaException, LimaBusinessException; + public List<FinancialStatement> getAllFinancialStatements() throws LimaException; public List<FinancialStatement> getChildrenFinancialStatement(FinancialStatement financialStatement) throws LimaException; public List<FinancialStatement> getAllChildrenFinancialStatement(FinancialStatement financialStatement, List<FinancialStatement> financialStatements) throws LimaException, LimaBusinessException; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/enums/AccountsChartEnum.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/enums/AccountsChartEnum.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/enums/AccountsChartEnum.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -1,3 +1,21 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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. + * + * This program 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + package org.chorem.lima.enums; public enum AccountsChartEnum { Added: trunk/lima-swing/src/main/java/org/chorem/lima/enums/EncodingEnum.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/enums/EncodingEnum.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/enums/EncodingEnum.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -0,0 +1,63 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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. + * + * This program 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.enums; + +public enum EncodingEnum { + + UTF8("UTF-8", "UTF-8 Lima"), ISOLATIN1("ISO-8859-1", "ISO-Latin-1 Excel / Windows"); + + private final String encoding; + private final String description; + + private EncodingEnum(String encoding, String description) { + this.encoding = encoding; + this.description = description; + } + + public String getEncoding() { + return this.encoding; + } + + public String getDescription(){ + return this.description; + } + + public static String[] descriptions(){ + int nbElts = EncodingEnum.values().length; + String[] descriptions = new String[nbElts]; + EncodingEnum[] encodingEnums = EncodingEnum.values(); + for (int i = 0; i < nbElts; i++) { + descriptions[i] = encodingEnums[i].getDescription(); + } + return descriptions; + } + + public static EncodingEnum valueOfDescription(String description){ + EncodingEnum value = null; + + for (EncodingEnum encodingEnum : EncodingEnum.values()) { + if (description.equals(encodingEnum.description)){ + value = encodingEnum; + break; + } + } + return value; + } + +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/enums/EntryBooksChartEnum.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/enums/EntryBooksChartEnum.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/enums/EntryBooksChartEnum.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -1,3 +1,21 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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. + * + * This program 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + package org.chorem.lima.enums; public enum EntryBooksChartEnum { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/enums/FinancialStatementsChartEnum.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/enums/FinancialStatementsChartEnum.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/enums/FinancialStatementsChartEnum.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -1,3 +1,21 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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. + * + * This program 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + package org.chorem.lima.enums; public enum FinancialStatementsChartEnum { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/enums/ImportExportEnum.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -1,3 +1,21 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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. + * + * This program 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + package org.chorem.lima.enums; @@ -6,18 +24,32 @@ * */ public enum ImportExportEnum { - LIMA_ALL_EXPORT(false), LIMA_ALL_IMPORT(true), - LIMA_ACCOUNTCHARTS_EXPORT(false), LIMA_ENTRYBOOKS_EXPORT(false), LIMA_FINANCIALSTATEMENTS_EXPORT(false), - LIMA_ACCOUNTCHARTS_IMPORT(true), LIMA_ENTRYBOOKS_IMPORT(true), LIMA_FINANCIALSTATEMENTS_IMPORT(true), - EBP_ACCOUNTCHARTS_EXPORT(false), EBP_ENTRIES_EXPORT(false), - EBP_ACCOUNTCHARTS_IMPORT(true), EBP_ENTRIES_IMPORT(true); + CSV_ALL_EXPORT(false, true), CSV_ALL_IMPORT(true, true), + CSV_ACCOUNTCHARTS_EXPORT(false, true), CSV_ENTRYBOOKS_EXPORT(false, true), CSV_FINANCIALSTATEMENTS_EXPORT(false, true), + CSV_ACCOUNTCHARTS_IMPORT(true, true), CSV_ENTRYBOOKS_IMPORT(true, true), CSV_FINANCIALSTATEMENTS_IMPORT(true, true), + EBP_ACCOUNTCHARTS_EXPORT(false, false), EBP_ENTRIES_EXPORT(false, false), + EBP_ACCOUNTCHARTS_IMPORT(true, false), EBP_ENTRIES_IMPORT(true, false); private final Boolean importMode; + private final Boolean encodingOption; - private ImportExportEnum(Boolean importMode) { + /** + * import mode : + * true if import, false if export + */ + private ImportExportEnum(Boolean importMode, Boolean encodingOption) { this.importMode = importMode; + this.encodingOption = encodingOption; } + /** + * encoding choice + * true if import or export methode let encoding option + */ + public Boolean getEncodingOption(){ + return this.encodingOption; + } + public Boolean getImportMode() { return this.importMode; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainView.jaxx 2010-07-29 12:51:43 UTC (rev 2989) @@ -85,16 +85,16 @@ <JMenu text="lima.menu.file"> <JMenu text="lima.importexport.lima"> <JMenu text="lima.importexport.import" actionIcon='import-element'> - <JMenuItem text="lima.importexport.all" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.LIMA_ALL_IMPORT)'/> - <JMenuItem text="lima.importexport.accountcharts" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.LIMA_ACCOUNTCHARTS_IMPORT)'/> - <JMenuItem text="lima.importexport.entrybooks" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.LIMA_ENTRYBOOKS_IMPORT)'/> - <JMenuItem text="lima.importexport.financialstatements" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.LIMA_FINANCIALSTATEMENTS_IMPORT)'/> + <JMenuItem text="lima.importexport.all" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ALL_IMPORT)'/> + <JMenuItem text="lima.importexport.accountcharts" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ACCOUNTCHARTS_IMPORT)'/> + <JMenuItem text="lima.importexport.entrybooks" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ENTRYBOOKS_IMPORT)'/> + <JMenuItem text="lima.importexport.financialstatements" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_FINANCIALSTATEMENTS_IMPORT)'/> </JMenu> <JMenu text="lima.importexport.export" actionIcon='export-element'> - <JMenuItem text="lima.importexport.all" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.LIMA_ALL_EXPORT)'/> - <JMenuItem text="lima.importexport.accountcharts" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.LIMA_ACCOUNTCHARTS_EXPORT)'/> - <JMenuItem text="lima.importexport.entrybooks" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.LIMA_ENTRYBOOKS_EXPORT)'/> - <JMenuItem text="lima.importexport.financialstatements" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.LIMA_FINANCIALSTATEMENTS_EXPORT)'/> + <JMenuItem text="lima.importexport.all" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ALL_EXPORT)'/> + <JMenuItem text="lima.importexport.accountcharts" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ACCOUNTCHARTS_EXPORT)'/> + <JMenuItem text="lima.importexport.entrybooks" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_ENTRYBOOKS_EXPORT)'/> + <JMenuItem text="lima.importexport.financialstatements" onActionPerformed='getHandler().showImportExportView(this, ImportExportEnum.CSV_FINANCIALSTATEMENTS_EXPORT)'/> </JMenu> </JMenu> <JMenu text="lima.importexport.ebp"> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -277,7 +277,7 @@ AccountsChartEnum defaultAccountsChartEnum = (AccountsChartEnum) value; ImportExport importExport = ImportExport.getInstance(view); - importExport.importExport(ImportExportEnum.LIMA_ACCOUNTCHARTS_IMPORT, + importExport.importExport(ImportExportEnum.CSV_ACCOUNTCHARTS_IMPORT, defaultAccountsChartEnum.getFilePath(), true); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -30,7 +30,6 @@ import org.chorem.lima.enums.EntryBooksChartEnum; import org.chorem.lima.enums.ImportExportEnum; import org.chorem.lima.service.LimaServiceFactory; -import org.chorem.lima.ui.MainView; import org.chorem.lima.ui.importexport.ImportExport; import org.chorem.lima.util.DialogHelper; import org.jdesktop.swingx.JXTable; @@ -149,30 +148,21 @@ public void importEntryBooks(){ - - try { - if (entryBookService.getAllEntryBooks().size() == 0){ - EntryBookImportForm form = - new EntryBookImportForm(); - form.setLocationRelativeTo(view); - form.setVisible(true); + EntryBookImportForm form = + new EntryBookImportForm(); + form.setLocationRelativeTo(view); + form.setVisible(true); - Object value = form.getRadioButtons().getSelectedValue(); - // if action confirmed - if (value != null){ - EntryBooksChartEnum defaultEntryBooksEnum = - (EntryBooksChartEnum) value; - ImportExport importExport = ImportExport.getInstance(view); - importExport.importExport(ImportExportEnum.LIMA_ENTRYBOOKS_IMPORT, - defaultEntryBooksEnum.getFilePath(), true); - } - } - } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't get default accounts chart", eee); - } - } + Object value = form.getRadioButtons().getSelectedValue(); + // if action confirmed + if (value != null){ + EntryBooksChartEnum defaultEntryBooksEnum = + (EntryBooksChartEnum) value; + ImportExport importExport = ImportExport.getInstance(view); + importExport.importExport(ImportExportEnum.CSV_ENTRYBOOKS_IMPORT, + defaultEntryBooksEnum.getFilePath(), true); + } } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -23,7 +23,6 @@ import javax.swing.tree.TreePath; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.beans.FinancialStatementImport; import org.chorem.lima.business.FinancialStatementServiceMonitorable; import org.chorem.lima.business.ImportServiceMonitorable; import org.chorem.lima.business.LimaBusinessException; @@ -34,7 +33,6 @@ import org.chorem.lima.enums.FinancialStatementsChartEnum; import org.chorem.lima.enums.ImportExportEnum; import org.chorem.lima.service.LimaServiceFactory; -import org.chorem.lima.ui.MainView; import org.chorem.lima.ui.financialstatementchart.FinancialStatementHeaderForm; import org.chorem.lima.ui.financialstatementchart.FinancialStatementMovementForm; import org.chorem.lima.ui.importexport.ImportExport; @@ -277,30 +275,33 @@ } public void importFinancialStatementChart(){ - try { - if (financialStatementService.getAllFinancialStatements().size() == 0){ - FinancialStatementImportForm form = - new FinancialStatementImportForm(); - form.setLocationRelativeTo(view); - form.setVisible(true); + FinancialStatementImportForm form = + new FinancialStatementImportForm(); + form.setLocationRelativeTo(view); + form.setVisible(true); - Object value = form.getRadioButtons().getSelectedValue(); - // if action confirmed - if (value != null){ - FinancialStatementsChartEnum defaultFinancialStatementsEnum = - (FinancialStatementsChartEnum) value; - ImportExport importExport = ImportExport.getInstance(view); - importExport.importExport(ImportExportEnum.LIMA_FINANCIALSTATEMENTS_IMPORT, - defaultFinancialStatementsEnum.getFilePath(), true); + Object value = form.getRadioButtons().getSelectedValue(); + // if action confirmed + if (value != null){ + if (form.getDeleteFinancialStatementChart().isSelected()){ + try { + financialStatementService.removeAllFinancialStatement(); + + } catch (LimaException eee) { + if (log.isDebugEnabled()){ + log.debug("Can't delete financial statement chart", eee); + } } - } - } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't get default accounts chart", eee); - } + } + FinancialStatementsChartEnum defaultFinancialStatementsEnum = + (FinancialStatementsChartEnum) value; + ImportExport importExport = ImportExport.getInstance(view); + importExport.importExport(ImportExportEnum.CSV_FINANCIALSTATEMENTS_IMPORT, + defaultFinancialStatementsEnum.getFilePath(), true); } - } + } + @Override public void notifyMethod(String serviceName, String methodName) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementImportForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementImportForm.jaxx 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementImportForm.jaxx 2010-07-29 12:51:43 UTC (rev 2989) @@ -59,6 +59,11 @@ </cell> </row> <row> + <cell> + <JCheckBox id='deleteFinancialStatementChart' text='lima.financialstatement.delete' selected='false'/> + </cell> + </row> + <row> <cell> <Table> <row> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExport.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -20,8 +20,10 @@ package org.chorem.lima.ui.importexport; import static org.nuiton.i18n.I18n._; +import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Container; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -31,15 +33,17 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.concurrent.ExecutionException; +import javax.swing.JComboBox; import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JPanel; import javax.swing.SwingWorker; -import javax.swing.text.StyledEditorKit.BoldAction; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ExportServiceMonitorable; import org.chorem.lima.business.ImportServiceMonitorable; import org.chorem.lima.business.LimaException; +import org.chorem.lima.enums.EncodingEnum; import org.chorem.lima.enums.ImportExportEnum; import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.ui.account.AccountViewHandler; @@ -54,6 +58,8 @@ private static final Log log = LogFactory.getLog(AccountViewHandler.class); protected static Component viewComponent; + + protected EncodingEnum encodingEnum; protected ImportServiceMonitorable importService; @@ -87,71 +93,69 @@ */ public void importExport(ImportExportEnum importExportMethode, String file, Boolean verbose){ final ImportExportEnum importExportMethodeF = importExportMethode; + encodingEnum = EncodingEnum.UTF8; if (file.equals("")){ - file = chooseFile(importExportMethode.getImportMode()); + file = chooseFile(importExportMethode.getImportMode(), importExportMethode); + log.debug(encodingEnum.getEncoding()); } + final EncodingEnum charset = encodingEnum; final String filePath = file; final Boolean verboseMode = verbose; new SwingWorker<String,Void>() { @Override protected String doInBackground() throws LimaException { - String charset = "UTF-8"; String datas = ""; String result = ""; switch (importExportMethodeF) { - case LIMA_ALL_EXPORT: + case CSV_ALL_EXPORT: datas = exportService.exportAsCSV(); - createFile(filePath, charset, datas); + createFile(filePath, charset.getEncoding(), datas); break; - case LIMA_ACCOUNTCHARTS_EXPORT: + case CSV_ACCOUNTCHARTS_EXPORT: datas = exportService.exportAccountsChartAsCSV(); - createFile(filePath, charset, datas); + createFile(filePath, charset.getEncoding(), datas); break; - case LIMA_ENTRYBOOKS_EXPORT: + case CSV_ENTRYBOOKS_EXPORT: datas = exportService.exportEntryBookChartAsCSV(); - createFile(filePath, charset, datas); + createFile(filePath, charset.getEncoding(), datas); break; - case LIMA_FINANCIALSTATEMENTS_EXPORT: + case CSV_FINANCIALSTATEMENTS_EXPORT: datas = exportService.exportFinancialStatementChartAsCSV(); - createFile(filePath, charset, datas); + createFile(filePath, charset.getEncoding(), datas); break; case EBP_ACCOUNTCHARTS_EXPORT: //For windows ebp - charset = "ISO-8859-1"; datas = exportService.exportAccountsAsEBP(); - createFile(filePath, charset, datas); + createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas); break; case EBP_ENTRIES_EXPORT: //For windows ebp - charset = "ISO-8859-1"; datas = exportService.exportEntriesAsEBP(); - createFile(filePath, charset, datas); + createFile(filePath, EncodingEnum.ISOLATIN1.getEncoding(), datas); break; - case LIMA_ALL_IMPORT: - datas = extractFile(filePath, charset); + case CSV_ALL_IMPORT: + datas = extractFile(filePath, charset.getEncoding()); result = importService.importAllAsCSV(datas); break; - case LIMA_ACCOUNTCHARTS_IMPORT: - datas = extractFile(filePath, charset); + case CSV_ACCOUNTCHARTS_IMPORT: + datas = extractFile(filePath, charset.getEncoding()); result = importService.importAccountsChartAsCSV(datas); break; - case LIMA_ENTRYBOOKS_IMPORT: - datas = extractFile(filePath, charset); + case CSV_ENTRYBOOKS_IMPORT: + datas = extractFile(filePath, charset.getEncoding()); result = importService.importEntryBooksChartAsCSV(datas); break; - case LIMA_FINANCIALSTATEMENTS_IMPORT: - datas = extractFile(filePath, charset); + case CSV_FINANCIALSTATEMENTS_IMPORT: + datas = extractFile(filePath, charset.getEncoding()); result = importService.importFinancialStatementsChartAsCSV(datas); break; case EBP_ACCOUNTCHARTS_IMPORT: //For windows ebp - charset = "ISO-8859-1"; - datas = extractFile(filePath, charset); + datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); result = importService.importAccountsChartFromEbp(datas); break; case EBP_ENTRIES_IMPORT: //For windows ebp - charset = "ISO-8859-1"; - datas = extractFile(filePath, charset); + datas = extractFile(filePath, EncodingEnum.ISOLATIN1.getEncoding()); result = importService.importEntriesFromEbp(datas); break; } @@ -192,25 +196,37 @@ * @param importMode * @return */ - public String chooseFile(Boolean importMode){ + public String chooseFile(Boolean importMode, ImportExportEnum importExportMethode){ String filePath = ""; FileChooseView fileChooseView = new FileChooseView(); JFileChooser chooser = fileChooseView.getChooser(); - + //Encoding option + + JComboBox comboBox = new JComboBox(EncodingEnum.descriptions()); + if (importExportMethode.getEncodingOption()){ + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + panel.add(new JLabel(_("lima.importexport.choiceencoding")), BorderLayout.WEST); + panel.add(comboBox, BorderLayout.CENTER); + ((Container)chooser.getComponent(2)).add(panel, BorderLayout.SOUTH); + } + if (importMode){ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - if (chooser.showOpenDialog(viewComponent) == JFileChooser.APPROVE_OPTION) { - filePath = chooser.getSelectedFile().getAbsolutePath(); - } } else { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - if (chooser.showOpenDialog(viewComponent) == JFileChooser.APPROVE_OPTION) { - filePath = chooser.getSelectedFile().getAbsolutePath(); - filePath = chooser.getSelectedFile().getAbsolutePath(); + } + if (chooser.showOpenDialog(viewComponent) == JFileChooser.APPROVE_OPTION) { + filePath = chooser.getSelectedFile().getAbsolutePath(); + + if (importExportMethode.getEncodingOption()){ + encodingEnum = EncodingEnum.valueOfDescription((String) comboBox.getSelectedItem()); } - } - log.debug(filePath); + log.debug(encodingEnum.getEncoding()); + log.debug(filePath); + } + return filePath; } Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExportFileChooser.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExportFileChooser.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/importexport/ImportExportFileChooser.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -0,0 +1,34 @@ +package org.chorem.lima.ui.importexport; + +import java.awt.BorderLayout; +import java.awt.Component; + +import javax.swing.JPanel; + +public class ImportExportFileChooser extends JPanel { + + private static final long serialVersionUID = 1L; + + public ImportExportFileChooser() { + + setLayout(new BorderLayout()); + // il y a 4 composants dans le JFileChooser, on les retire un par un pour les replacer comme on le souhaite + Component navigationBar = getComponent(0); + remove(0); + // on retire un JPanel qui n'est pas utile + remove(0); + add(navigationBar, BorderLayout.NORTH); + Component panelFiles = getComponent(0); + remove(0); + add(panelFiles, BorderLayout.CENTER); + Component buttons = getComponent(0); + remove(0); + add(buttons, BorderLayout.SOUTH); + + //this.add(panelFileChooser); + //this.add(panelOptions, BorderLayout.SOUTH); + + } + + +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/OpeningViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/OpeningViewHandler.java 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/opening/OpeningViewHandler.java 2010-07-29 12:51:43 UTC (rev 2989) @@ -104,22 +104,22 @@ break; default: - importExport.importExport(ImportExportEnum.LIMA_ACCOUNTCHARTS_IMPORT, + importExport.importExport(ImportExportEnum.CSV_ACCOUNTCHARTS_IMPORT, defaultAccountsChartEnum.getFilePath(), false); break; } //Import financialstatement switch (defaultAccountsChartEnum) { case SHORTENED: - importExport.importExport(ImportExportEnum.LIMA_FINANCIALSTATEMENTS_IMPORT, + importExport.importExport(ImportExportEnum.CSV_FINANCIALSTATEMENTS_IMPORT, FinancialStatementsChartEnum.SHORTENED.getFilePath(), false); break; case DEVELOPED: - importExport.importExport(ImportExportEnum.LIMA_FINANCIALSTATEMENTS_IMPORT, + importExport.importExport(ImportExportEnum.CSV_FINANCIALSTATEMENTS_IMPORT, FinancialStatementsChartEnum.DEVELOPED.getFilePath(), false); break; default: - importExport.importExport(ImportExportEnum.LIMA_FINANCIALSTATEMENTS_IMPORT, + importExport.importExport(ImportExportEnum.CSV_FINANCIALSTATEMENTS_IMPORT, FinancialStatementsChartEnum.BASE.getFilePath(), false); break; } @@ -134,7 +134,7 @@ case 3 : if (ebPanel.getImportEntryBook().isSelected()){ - importExport.importExport(ImportExportEnum.LIMA_ENTRYBOOKS_IMPORT, + importExport.importExport(ImportExportEnum.CSV_ENTRYBOOKS_IMPORT, EntryBooksChartEnum.DEFAULT.getFilePath(), false); } view.getEntrybooksIcon().setBorder(noBorder); Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-en_GB.properties 2010-07-29 12:51:43 UTC (rev 2989) @@ -93,6 +93,7 @@ lima.financialstatement.accounts= lima.financialstatement.creditaccounts= lima.financialstatement.debitaccounts= +lima.financialstatement.delete= lima.financialstatement.formula= lima.financialstatement.header.add= lima.financialstatement.headeramount= @@ -123,6 +124,7 @@ lima.import.journal=Import journal lima.importexport.accountcharts= lima.importexport.all= +lima.importexport.choiceencoding= lima.importexport.ebp= lima.importexport.entries= lima.importexport.entrybooks= Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-07-28 18:53:39 UTC (rev 2988) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing-fr_FR.properties 2010-07-29 12:51:43 UTC (rev 2989) @@ -90,6 +90,7 @@ lima.financialstatement.accounts=Liste de comptes au cr\u00E9dit et au d\u00E9bit lima.financialstatement.creditaccounts=Liste de comptes au cr\u00E9dit lima.financialstatement.debitaccounts=Liste de comptes au d\u00E9bit +lima.financialstatement.delete=Supprimer le plan BCR actuel avant d'importer lima.financialstatement.formula=Formule de compte, ex \: '7'-'6'+'510-520' lima.financialstatement.header.add=Ajouter une cat\u00E9gorie lima.financialstatement.headeramount=Calculer le total en en-tete @@ -115,6 +116,7 @@ lima.import.journal= lima.importexport.accountcharts=Plan des comptes lima.importexport.all=Tout +lima.importexport.choiceencoding=Choisir encodage \: lima.importexport.ebp=Import/Export EBP lima.importexport.entries=\u00C9critures lima.importexport.entrybooks=Journaux