001: /*
002: * Created on 26/01/2007
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2007 Igor Regis da Silva Simões
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: */
023: package br.com.gfp.ofc.actions;
024:
025: import java.awt.event.ActionEvent;
026: import java.awt.event.ActionListener;
027:
028: import javax.swing.JFileChooser;
029: import javax.swing.JFrame;
030: import javax.swing.JOptionPane;
031:
032: import br.com.gfp.dao.GFPController;
033: import br.com.gfp.internationalization.ActionsMessages;
034: import br.com.gfp.ofc.parser.MapeamentoToContaException;
035: import br.com.gfp.ofc.parser.OFC2TransactionConversor;
036: import br.com.gfp.ofc.parser.OFCImportException;
037: import br.com.gfp.ofc.tools.ImportUtils;
038: import br.com.gfp.util.SimpleLog;
039: import br.com.gfp.windows.ConfirmImportedTransactionsWindow;
040: import br.com.gfpshare.util.MyFileFilter;
041:
042: public class ImportOFCTransactionAction implements ActionListener {
043: private static ImportOFCTransactionAction action;
044: private JFileChooser chooser = null;
045:
046: public ImportOFCTransactionAction() {
047: chooser = new JFileChooser();
048: chooser.setDialogTitle(ActionsMessages.getMessages().getString(
049: "tituloAbrirOFCDialog"));
050: chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
051: chooser.setFileFilter(new MyFileFilter("ofc", ActionsMessages
052: .getMessages().getString("ofcFile")));
053: }
054:
055: public void actionPerformed(ActionEvent e) {
056: new Thread() {
057: @Override
058: public void run() {
059: chooser.updateUI();
060: if (chooser.showOpenDialog((JFrame) GFPController
061: .getGFPController().getContexto().get(
062: GFPController.FRAME_PRINCIPAL)) == JFileChooser.APPROVE_OPTION) {
063: try {
064: OFC2TransactionConversor conversor = new OFC2TransactionConversor(
065: chooser.getSelectedFile()
066: .getAbsolutePath());
067: // ConversorOFC2Lancamento conversor = new ConversorOFC2Lancamento("/home/igor/Desktop/4353008.ofc");
068: ImportUtils.conciliate(conversor
069: .getLancamentos());
070: } catch (MapeamentoToContaException e) {
071: ((SimpleLog) GFPController.getGFPController()
072: .getContexto().get(GFPController.LOG))
073: .log("Error when mapping the imported transactions to an account!");
074: ((SimpleLog) GFPController.getGFPController()
075: .getContexto().get(GFPController.LOG))
076: .log(e.getLocalizedMessage());
077: ((SimpleLog) GFPController.getGFPController()
078: .getContexto().get(GFPController.LOG))
079: .log(e);
080: JOptionPane
081: .showMessageDialog(
082: (JFrame) GFPController
083: .getGFPController()
084: .getContexto()
085: .get(
086: GFPController.FRAME_PRINCIPAL),
087: ActionsMessages
088: .getMessages()
089: .getString(
090: "ErroMapeamentoConta"));
091: } catch (OFCImportException e) {
092: ((SimpleLog) GFPController.getGFPController()
093: .getContexto().get(GFPController.LOG))
094: .log("Error when importing transactions from OFC file!");
095: ((SimpleLog) GFPController.getGFPController()
096: .getContexto().get(GFPController.LOG))
097: .log(e.getLocalizedMessage());
098: ((SimpleLog) GFPController.getGFPController()
099: .getContexto().get(GFPController.LOG))
100: .log(e);
101: JOptionPane
102: .showMessageDialog(
103: (JFrame) GFPController
104: .getGFPController()
105: .getContexto()
106: .get(
107: GFPController.FRAME_PRINCIPAL),
108: ActionsMessages
109: .getMessages()
110: .getString(
111: "ErroImportacaoOFC"));
112: }
113: GFPController.getGFPController().create(
114: ConfirmImportedTransactionsWindow.class);
115: }
116: }
117:
118: }.start();
119: }
120:
121: /**
122: * @return Retorna uma instancia desta action
123: */
124: public static ImportOFCTransactionAction getAction() {
125: return action;
126: }
127:
128: /**
129: *
130: */
131: public static void initializeAction() {
132: if (action == null)
133: action = new ImportOFCTransactionAction();
134: }
135: }
|