Author: jpepin Date: 2010-07-01 17:51:40 +0200 (Thu, 01 Jul 2010) New Revision: 2959 Url: http://chorem.org/repositories/revision/lima/2959 Log: Ajout export plan BCR. Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/ImportExportForm.jaxx Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/ImportExportForm.jaxx Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java 2010-07-01 14:23:40 UTC (rev 2958) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ImportExportService.java 2010-07-01 15:51:40 UTC (rev 2959) @@ -103,12 +103,13 @@ /** * export accounts chart as CSV. - * - * @param data - * @throws LimaException */ void exportAccountsChartAsCSV(String path) throws LimaException; + /** + * import accounts chart as CSV. + * Return result log + */ String importAccountsChartCSV(String path) throws LimaException; /** @@ -121,9 +122,11 @@ /** * export financialstatement chart as CSV. - * - * @param data - * @throws LimaException */ - void exportFinancialStatementChartAsCSV(byte[] data) throws LimaException; + void exportFinancialStatementChartAsCSV(String path) throws LimaException; + + /** + * export financialstatement chart as CSV. + */ + String importFinancialStatementChartCSV(String path) throws LimaException; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java 2010-07-01 14:23:40 UTC (rev 2958) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ImportExportServiceImpl.java 2010-07-01 15:51:40 UTC (rev 2959) @@ -25,7 +25,6 @@ import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; -import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.TreeMap; @@ -36,7 +35,9 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.AccountImport; import org.chorem.lima.beans.AccountImportImpl; +import org.chorem.lima.beans.FinancialStatementImport; import org.chorem.lima.business.AccountService; +import org.chorem.lima.business.FinancialStatementService; import org.chorem.lima.business.ImportExportService; import org.chorem.lima.business.ImportExportServiceLocal; import org.chorem.lima.business.LimaBusinessException; @@ -45,6 +46,9 @@ import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; import org.chorem.lima.entity.AccountImpl; +import org.chorem.lima.entity.FinancialStatement; +import org.chorem.lima.entity.FinancialStatementDAO; +import org.chorem.lima.entity.FinancialStatementImpl; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; @@ -52,6 +56,8 @@ import org.nuiton.topia.TopiaNotFoundException; import au.com.bytecode.opencsv.CSVReader; import au.com.bytecode.opencsv.CSVWriter; +import au.com.bytecode.opencsv.bean.ColumnPositionMappingStrategy; +import au.com.bytecode.opencsv.bean.CsvToBean; /** * XML and CSV import export service. @@ -74,6 +80,9 @@ @EJB AccountService accountService; + @EJB + FinancialStatementService financialStatementService; + public ImportExportServiceImpl() { LimaConfig config = LimaConfig.getInstance(); try { @@ -231,14 +240,15 @@ CSVReader csvReader = new CSVReader(new FileReader(f), ';'); nextLine = csvReader.readNext(); // Date début période - log.debug(nextLine[0]); if (!nextLine[0].equals("lima.accountschart")){ - throw new LimaBusinessException("The file is not an export csv file type accountschart"); + throw new LimaBusinessException( + "The file is not an export csv file type accountschart"); } AccountDAO accountDAO = LimaCallaoDAOHelper.getAccountDAO(topiaContext); - TreeMap<String, AccountImport> accounts = new TreeMap<String, AccountImport>(); + TreeMap<String, AccountImport> accounts = + new TreeMap<String, AccountImport>(); while ((nextLine = csvReader.readNext()) != null) { String accountNumber = nextLine[0]; @@ -249,7 +259,8 @@ //if exist, skip if (accountDAO.findByAccountNumber(accountNumber) != null){ - result += "FAILED : The account " + accountNumber + " already exists !\n"; + result += "FAILED : The account " + + accountNumber + " already exists !\n"; } else { //create it @@ -265,18 +276,17 @@ } while (accounts.size() > 0){ - - log.debug(accounts.size()); - for (Iterator<AccountImport> itr = accounts.values().iterator(); itr.hasNext();){ + for (Iterator<AccountImport> itr =accounts.values().iterator(); itr.hasNext();){ AccountImport accountImport = itr.next(); String masterAccountNumber = accountImport.getMasterAccount(); String generalLedgerNumber = accountImport.getGeneralLedger(); - Account masterAccount = accountDAO.findByAccountNumber(masterAccountNumber); - Account generalLedger = accountDAO.findByAccountNumber(generalLedgerNumber); + Account masterAccount = + accountDAO.findByAccountNumber(masterAccountNumber); + Account generalLedger = + accountDAO.findByAccountNumber(generalLedgerNumber); - if ((masterAccountNumber.equals("") && generalLedgerNumber.equals("")) || masterAccount != null || generalLedger != null){ - log.debug("create it"); - log.debug(accountImport.getAccountNumber()); + if ((masterAccountNumber.equals("") && generalLedgerNumber.equals("")) + || masterAccount != null || generalLedger != null){ //create it Account account = new AccountImpl(); account.setAccountNumber(accountImport.getAccountNumber()); @@ -291,11 +301,15 @@ else { accountService.createAccount(masterAccount, account); } - result += "SUCCESS : The account " + accountImport.getAccountNumber() + " is created ! \n"; + result += "SUCCESS : The account " + + accountImport.getAccountNumber() + " is created ! \n"; itr.remove(); } - else if (!accounts.containsKey(masterAccountNumber) && !accounts.containsKey(generalLedgerNumber) ){ - result += "FAILED : The account " + accountImport.getAccountNumber() + " have masterAccount : " + masterAccountNumber + "which not exist \n"; + else if (!accounts.containsKey(masterAccountNumber) + && !accounts.containsKey(generalLedgerNumber) ){ + result += "FAILED : The account " + + accountImport.getAccountNumber() + " have masterAccount : " + + masterAccountNumber + "which not exist \n"; itr.remove(); } } @@ -316,16 +330,168 @@ @Override public void exportEntryBookChartAsCSV(byte[] data) throws LimaException { - // TODO Auto-generated method stub - } @Override - public void exportFinancialStatementChartAsCSV(byte[] data) - throws LimaException { - // TODO Auto-generated method stub - + public void exportFinancialStatementChartAsCSV(String path) throws LimaException { + File f = new File(path); + TopiaContext topiaContext = null; + + try { + topiaContext = beginTransaction(); + CSVWriter csvWriter = new CSVWriter(new FileWriter(f), ';'); + String[] nextLine = new String[9]; + // Récupère tous les comptes + FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); + List<FinancialStatement> listFinancialStatements = financialStatementDAO.findAll(); + nextLine[0] = "lima.financialstatementschart"; + csvWriter.writeNext(nextLine); + // Pour tous les comptes + for (FinancialStatement financialStatement : listFinancialStatements) { + nextLine[0] = financialStatement.getLabel(); + nextLine[1] = new Boolean(financialStatement.getHeader()).toString(); + nextLine[2] = financialStatement.getAccounts(); + nextLine[3] = financialStatement.getDebitAccounts(); + nextLine[4] = financialStatement.getCreditAccounts(); + nextLine[5] = financialStatement.getProvisionDeprecationAccounts(); + nextLine[6] = new Boolean(financialStatement.getSubAmount()).toString(); + nextLine[7] = new Boolean(financialStatement.getHeaderAmount()).toString(); + FinancialStatement masterFinancialStatement = financialStatement.getMasterFinancialStatement(); + String masterFinancialStatementString = ""; + if (masterFinancialStatement != null){ + masterFinancialStatementString = masterFinancialStatement.getLabel(); + } + nextLine[8] = masterFinancialStatementString; + // Ajoute la ligne au fichier + csvWriter.writeNext(nextLine); + } + // Write cache in file + csvWriter.flush(); + csvWriter.close(); + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + catch (IOException eeeIO) { + log.debug("Can't create new CSV Writer with file"+f+eeeIO); + } + finally { + doFinally(topiaContext, log); + } } + + @Override + public String importFinancialStatementChartCSV(String path) throws LimaException { + File f = new File(path); + String result = ""; + + TopiaContext topiaContext = null; + try { + topiaContext = beginTransaction(); + /* + String[] nextLine = new String[1]; + CSVReader csvReader = new CSVReader(new FileReader(f), ';'); + + nextLine = csvReader.readNext(); // Date début période + if (!nextLine[0].equals("lima.financialstatementschart")){ + throw new LimaBusinessException( + "The file is not an export csv file type financialstatementschart"); + } + + FinancialStatementDAO financialStatementDAO = LimaCallaoDAOHelper.getFinancialStatementDAO(topiaContext); + + TreeMap<String, AccountImport> accounts = + new TreeMap<String, AccountImport>(); + + ColumnPositionMappingStrategy strat = + new ColumnPositionMappingStrategy(); + strat.setType(FinancialStatementImport.class); + String[] columns = new String[] {"label", "header", "accounts", + "debitAccounts", "creditAccounts","provisionDeprecationAccounts", + "subAmount", "headerAmount", "masterFinancialStatement"}; + strat.setColumnMapping(columns); + + CsvToBean csv = new CsvToBean(); + List list = csv.parse(strat, csvReader); + + while ((nextLine = csvReader.readNext()) != null) { + String accountNumber = nextLine[0]; + String label = nextLine[1]; + String thirdParty = nextLine[2]; + String masterAccountNumber = nextLine[3]; + String generalLedgerNumber = nextLine[4]; + + //if exist, skip + if (financialStatementDAO.findByLabel(accountNumber) != null){ + result += "FAILED : The account " + + accountNumber + " already exists !\n"; + } + else { + //create it + AccountImport account = new AccountImportImpl(); + account.setAccountNumber(accountNumber); + account.setLabel(label); + account.setThirdParty(thirdParty); + account.setMasterAccount(masterAccountNumber); + account.setGeneralLedger(generalLedgerNumber); + // put it in hashset + accounts.put(accountNumber, account); + } + } + + while (accounts.size() > 0){ + for (Iterator<AccountImport> itr =accounts.values().iterator(); itr.hasNext();){ + AccountImport accountImport = itr.next(); + String masterAccountNumber = accountImport.getMasterAccount(); + String generalLedgerNumber = accountImport.getGeneralLedger(); + //Account masterAccount = + accountDAO.findByAccountNumber(masterAccountNumber); + Account generalLedger = + accountDAO.findByAccountNumber(generalLedgerNumber); + + if ((masterAccountNumber.equals("") && generalLedgerNumber.equals("")) + || masterAccount != null || generalLedger != null){ + //create it + Account account = new AccountImpl(); + account.setAccountNumber(accountImport.getAccountNumber()); + account.setLabel(accountImport.getLabel()); + account.setThirdParty(accountImport.getThirdParty()); + account.setMasterAccount(masterAccount); + account.setGeneralLedger(generalLedger); + + if (generalLedger != null){ + accountService.createSubLedger(generalLedger, account); + } + else { + accountService.createAccount(masterAccount, account); + } + result += "SUCCESS : The account " + + accountImport.getAccountNumber() + " is created ! \n"; + itr.remove(); + } + else if (!accounts.containsKey(masterAccountNumber) + && !accounts.containsKey(generalLedgerNumber) ){ + result += "FAILED : The account " + + accountImport.getAccountNumber() + " have masterAccount : " + + masterAccountNumber + "which not exist \n"; + itr.remove(); + } + } + + } + */ + } + catch (TopiaException eeeTE){ + doCatch(topiaContext, eeeTE, log); + } + //catch (IOException eeeIO) { + // log.debug("Can't create new CSV Reader with file"+f+eeeIO); + //} + finally { + doFinally(topiaContext, log); + } + return result; + } protected TopiaContext beginTransaction() throws TopiaException { // basic check done, make check in database Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/ImportExportForm.jaxx (from rev 2958, trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/ImportExportForm.jaxx) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/ImportExportForm.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/ImportExportForm.jaxx 2010-07-01 15:51:40 UTC (rev 2959) @@ -0,0 +1,50 @@ +<!-- ##% 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. + ##% --> + +<JDialog modal="true"> + + <jaxx.runtime.swing.JAXXButtonGroup id="radioButtons" javaBean='new JAXXButtonGroup()'/> + <Boolean id="addState" javaBean='true'/> + + <script> + <![CDATA[ + protected void performCancel() { + getRadioButtons().setSelectedValue(null); + dispose(); + } + ]]> + </script> + + <Table> + <row> + <cell> + <JRadioButton text='lima.importexport.export' value='export' buttonGroup="{getRadioButtons()}" + selected='true'/> + </cell> + <cell> + <JRadioButton text='lima.importexport.import' value='import' buttonGroup="{getRadioButtons()}" + selected='true'/> + </cell> + <cell fill="none"> + <JButton text="lima.common.ok" onActionPerformed="dispose()"/> + </cell> + <cell fill="none"> + <JButton text="lima.common.cancel" onActionPerformed="performCancel()"/> + </cell> + </row> + </Table> +</JDialog> \ No newline at end of file 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-01 14:23:40 UTC (rev 2958) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-07-01 15:51:40 UTC (rev 2959) @@ -31,6 +31,7 @@ import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountImpl; import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.ImportExportForm; import org.chorem.lima.ui.account.AccountForm; import org.chorem.lima.ui.account.AccountView; import org.chorem.lima.ui.account.SubLedgerForm; @@ -259,7 +260,6 @@ importExportForm.setVisible(true); Object value = importExportForm.getRadioButtons().getSelectedValue(); - log.debug(value); // if action confirmed if (value != null){ String mode = (String) value; @@ -272,19 +272,7 @@ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { String filePath = chooser.getSelectedFile().getAbsolutePath(); - log.debug(filePath); - accountService.removeAllAccount(); String message = importExportService.importAccountsChartCSV(filePath); - DialogHelper.showMessageDialog(message); - } - - } - else if (mode.equals("update")){ - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { - String filePath = chooser.getSelectedFile().getAbsolutePath(); - log.debug(filePath); - String message = importExportService.importAccountsChartCSV(filePath); accountsTreeTableModel.refreshTree(); DialogHelper.showMessageDialog(message); } @@ -293,7 +281,6 @@ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { String filePath = chooser.getSelectedFile().getAbsolutePath(); - log.debug(filePath); importExportService.exportAccountsChartAsCSV(filePath); } } @@ -303,9 +290,6 @@ } DialogHelper.showMessageDialog(eee.getMessage()); } - } - } - } Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/ImportExportForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/ImportExportForm.jaxx 2010-07-01 14:23:40 UTC (rev 2958) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/ImportExportForm.jaxx 2010-07-01 15:51:40 UTC (rev 2959) @@ -1,56 +0,0 @@ -<!-- ##% 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. - ##% --> - -<JDialog modal="true"> - - <org.chorem.lima.entity.Account id="account" javaBean='null'/> - <jaxx.runtime.swing.JAXXButtonGroup id="radioButtons" javaBean='new JAXXButtonGroup()'/> - <Boolean id="addState" javaBean='true'/> - - <script> - <![CDATA[ - protected void performCancel() { - getRadioButtons().setSelectedValue(null); - dispose(); - } - ]]> - </script> - - <Table> - <row> - <cell> - <JRadioButton text='lima.importexport.export' value='export' buttonGroup="{getRadioButtons()}" - selected='true'/> - </cell> - <cell> - <JRadioButton text='lima.importexport.import' value='import' buttonGroup="{getRadioButtons()}" - selected='true'/> - </cell> - <cell> - <JRadioButton text='lima.importexport.update' value='update' buttonGroup="{getRadioButtons()}" - selected='true'/> - </cell> - - <cell fill="none"> - <JButton text="lima.common.ok" onActionPerformed="dispose()"/> - </cell> - <cell fill="none"> - <JButton text="lima.common.cancel" onActionPerformed="performCancel()"/> - </cell> - </row> - </Table> -</JDialog> \ No newline at end of file Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java 2010-07-01 14:23:40 UTC (rev 2958) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartTreeTableModel.java 2010-07-01 15:51:40 UTC (rev 2959) @@ -174,8 +174,19 @@ return getChildCount(node) == 0; } + /** - * Add FinancialStatementHeader (path can be null). + * Refresh FinancialStatementChart. + * + */ + public void refreshTree() throws LimaException { + + modelSupport.fireNewRoot(); + } + + + /** + * Add FinancialStatement(path can be null). * * @param path * @param account Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartView.jaxx 2010-07-01 14:23:40 UTC (rev 2958) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartView.jaxx 2010-07-01 15:51:40 UTC (rev 2959) @@ -27,7 +27,7 @@ </script> <row> - <cell fill="both" weightx="1" weighty="1" rows='4'> + <cell fill="both" weightx="1" weighty="1" rows='5'> <JScrollPane> <org.jdesktop.swingx.JXTreeTable id="treeTable" selectionMode="{ListSelectionModel.SINGLE_SELECTION}" @@ -64,4 +64,10 @@ enabled="{isSelectedRow()}"/> </cell> </row> + <row> + <cell fill="horizontal"> + <JButton id="importexportButton" text="lima.common.importexport" + onActionPerformed="getHandler().importexportFinancialStatement()"/> + </cell> + </row> </Table> \ No newline at end of file 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-01 14:23:40 UTC (rev 2958) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2010-07-01 15:51:40 UTC (rev 2959) @@ -19,18 +19,23 @@ package org.chorem.lima.ui.financialstatementchart; import static org.nuiton.i18n.I18n._; +import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.tree.TreePath; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ImportExportService; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.FinancialStatement; import org.chorem.lima.entity.FinancialStatementImpl; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.ImportExportForm; import org.chorem.lima.ui.financialstatementchart.FinancialStatementHeaderForm; import org.chorem.lima.ui.financialstatementchart.FinancialStatementMovementForm; import org.chorem.lima.util.DialogHelper; import org.chorem.lima.util.ErrorHelper; +import org.chorem.lima.util.FileChooseView; import org.jdesktop.swingx.JXTreeTable; /** @@ -48,9 +53,12 @@ private static final Log log = LogFactory.getLog(FinancialStatementChartViewHandler.class); protected FinancialStatementChartView view; + + protected ImportExportService importExportService; protected FinancialStatementChartViewHandler(FinancialStatementChartView view) { this.view = view; + importExportService = LimaServiceFactory.getInstance().getImportExportService(); } /** @@ -202,7 +210,8 @@ */ public void removeFinancialStatement() { JXTreeTable treeTable = view.getTreeTable(); - FinancialStatementChartTreeTableModel treeTableModel = (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); + FinancialStatementChartTreeTableModel treeTableModel = + (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); // Any row selected int selectedRow = view.treeTable.getSelectedRow(); @@ -227,6 +236,50 @@ } } } - }; + } + public void importexportFinancialStatement(){ + + JXTreeTable treeTable = view.getTreeTable(); + FinancialStatementChartTreeTableModel treeTableModel = + (FinancialStatementChartTreeTableModel) treeTable.getTreeTableModel(); + + ImportExportForm importExportForm = new ImportExportForm(view); + importExportForm.setLocationRelativeTo(view); + importExportForm.setVisible(true); + + Object value = importExportForm.getRadioButtons().getSelectedValue(); + // if action confirmed + if (value != null){ + String mode = (String) value; + FileChooseView fileChooseView = new FileChooseView(view); + + JFileChooser chooser = fileChooseView.getChooser(); + + try { + if (mode.equals("import")){ + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { + String filePath = chooser.getSelectedFile().getAbsolutePath(); + String message = importExportService.importFinancialStatementChartCSV(filePath); + treeTableModel.refreshTree(); + DialogHelper.showMessageDialog(message); + } + } + else { + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + if (chooser.showOpenDialog(view) == JFileChooser.APPROVE_OPTION) { + String filePath = chooser.getSelectedFile().getAbsolutePath(); + importExportService.exportFinancialStatementChartAsCSV(filePath); + } + } + } catch (LimaException eee) { + if (log.isErrorEnabled()){ + log.error("Can't "+ mode +" this file", eee); + } + DialogHelper.showMessageDialog(eee.getMessage()); + } + } + } + }