001: /*
002: * Created on 07/02/2007 Swing Components - visit http://sf.net/projects/gfd Copyright (C) 2004 Igor Regis da Silva
003: * Simões This program is free software; you can redistribute it and/or modify it under the terms of the GNU General
004: * Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any
005: * later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
006: * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
007: * more details. You should have received a copy of the GNU General Public License along with this program; if not,
008: * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
009: */
010: package br.com.gfp.ofc.windows;
011:
012: import java.awt.Frame;
013: import java.awt.GridBagConstraints;
014: import java.awt.GridBagLayout;
015: import java.awt.event.ActionEvent;
016: import java.awt.event.ActionListener;
017: import java.sql.SQLException;
018:
019: import javax.swing.JButton;
020: import javax.swing.JDialog;
021: import javax.swing.JLabel;
022: import javax.swing.JPanel;
023:
024: import br.com.gfp.dao.GFPController;
025: import br.com.gfp.data.AccountSaving;
026: import br.com.gfp.data.AccountType;
027: import br.com.gfp.data.CheckingAccount;
028: import br.com.gfp.data.CreditCard;
029: import br.com.gfp.internationalization.ReportsMessages;
030: import br.com.gfp.util.SimpleLog;
031: import br.com.gfp.windows.componentes.GFPComboBoxRenderer;
032: import br.com.gfpshare.beans.DBComboBox;
033:
034: /**
035: * This dialog lets user to select the Account that will receive
036: * the imported/parsed transactions
037: * @author Igor Regis da Silva Simões
038: * @since 04/08/2005 14:04:05
039: */
040: public class SelectAccountDialog extends JDialog {
041: private DBComboBox dbAccountType = new DBComboBox(new AccountType());
042:
043: private DBComboBox dbAccount = new DBComboBox();
044:
045: private JPanel jContentPane = new JPanel();
046:
047: private JButton jbOk = new JButton();
048:
049: private JLabel jlSelectAccount = new JLabel();
050:
051: private JLabel jlAccount = new JLabel();
052:
053: private final String mappingString;
054:
055: /**
056: * This is the default constructor
057: */
058: public SelectAccountDialog(String mapping) {
059: super ((Frame) GFPController.getGFPController().getContexto()
060: .get(GFPController.FRAME_PRINCIPAL), true);
061: this .mappingString = mapping;
062: setDefaultCloseOperation(DISPOSE_ON_CLOSE);
063: initialize();
064: setLocationRelativeTo(getOwner());
065: pack();
066: }
067:
068: /**
069: * This method initialize this
070: * @return void
071: */
072: private void initialize() {
073: this .setTitle(ReportsMessages.getMessages().getString(
074: "DialogTitle"));
075: this .setSize(415, 170);
076:
077: jContentPane.setLayout(new GridBagLayout());
078:
079: jlSelectAccount.setText("Selecione a conta a vincular com: "
080: + mappingString);
081: GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
082: gridBagConstraints1.gridx = 0;
083: gridBagConstraints1.gridy = 0;
084: gridBagConstraints1.gridwidth = 3;
085: gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
086: gridBagConstraints1.insets = new java.awt.Insets(5, 5, 5, 5);
087: jContentPane.add(jlSelectAccount, gridBagConstraints1);
088:
089: GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
090: jlAccount.setText(ReportsMessages.getMessages().getString(
091: "AccountNameLabel"));
092: gridBagConstraints5 = new GridBagConstraints();
093: gridBagConstraints5.gridx = 0;
094: gridBagConstraints5.gridy = 1;
095: gridBagConstraints5.fill = java.awt.GridBagConstraints.BOTH;
096: gridBagConstraints5.insets = new java.awt.Insets(5, 5, 5, 5);
097: gridBagConstraints5.anchor = java.awt.GridBagConstraints.WEST;
098: jContentPane.add(jlAccount, gridBagConstraints5);
099:
100: dbAccountType.addActionListener(new ActionListener() {
101: /**
102: * Este método é chamado sempre que o tipo de conta que está sendo consultada é alterado
103: * @param e Evento que gerou a alteração
104: */
105: public void actionPerformed(ActionEvent e) {
106: if (e.getSource() == dbAccountType) {
107: if (dbAccountType.getSelectedItem() == null) {
108: dbAccount.setDataType(null);
109: } else if (((AccountType) dbAccountType
110: .getSelectedItem()).getNome().toString()
111: .equalsIgnoreCase("contaCorrente")) {
112: dbAccount.setDataType(new CheckingAccount());
113: } else if (((AccountType) dbAccountType
114: .getSelectedItem()).getNome().toString()
115: .equalsIgnoreCase("aplicacao")) {
116: dbAccount.setDataType(new AccountSaving());
117: } else if (((AccountType) dbAccountType
118: .getSelectedItem()).getNome().toString()
119: .equalsIgnoreCase("cartaoCredito")) {
120: dbAccount.setDataType(new CreditCard());
121: }
122:
123: try {
124: dbAccount.setSelectedIndex(0);
125: } catch (IllegalArgumentException iae) {
126: ((SimpleLog) GFPController.getGFPController()
127: .getContexto().get(GFPController.LOG))
128: .log("Erro ao limpar campo conta!");
129: ((SimpleLog) GFPController.getGFPController()
130: .getContexto().get(GFPController.LOG))
131: .log(iae.getLocalizedMessage());
132: ((SimpleLog) GFPController.getGFPController()
133: .getContexto().get(GFPController.LOG))
134: .log(iae);
135: }
136: }
137: setTitle(null);
138: }
139: });
140: dbAccountType.setRenderer(new GFPComboBoxRenderer(
141: GFPComboBoxRenderer.TIPO_DE_CONTA, -1));
142: gridBagConstraints5 = new GridBagConstraints();
143: gridBagConstraints5.gridx = 1;
144: gridBagConstraints5.gridy = 1;
145: gridBagConstraints5.fill = java.awt.GridBagConstraints.BOTH;
146: gridBagConstraints5.insets = new java.awt.Insets(5, 5, 5, 5);
147: gridBagConstraints5.anchor = java.awt.GridBagConstraints.WEST;
148: jContentPane.add(dbAccountType, gridBagConstraints5);
149:
150: gridBagConstraints5 = new GridBagConstraints();
151: gridBagConstraints5.gridx = 2;
152: gridBagConstraints5.gridy = 1;
153: gridBagConstraints5.fill = java.awt.GridBagConstraints.BOTH;
154: gridBagConstraints5.insets = new java.awt.Insets(5, 5, 5, 5);
155: gridBagConstraints5.anchor = java.awt.GridBagConstraints.WEST;
156: jContentPane.add(dbAccount, gridBagConstraints5);
157:
158: jbOk.setPreferredSize(new java.awt.Dimension(80, 26));
159: jbOk.setText(ReportsMessages.getMessages().getString("Ok"));
160: jbOk.addActionListener(new ActionListener() {
161: public void actionPerformed(java.awt.event.ActionEvent e) {
162: SelectAccountDialog.this .dispose();
163: }
164: });
165: GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
166: gridBagConstraints6.gridx = 0;
167: gridBagConstraints6.gridy = 2;
168: gridBagConstraints6.gridwidth = 3;
169: gridBagConstraints6.fill = java.awt.GridBagConstraints.VERTICAL;
170: gridBagConstraints6.anchor = java.awt.GridBagConstraints.CENTER;
171: gridBagConstraints1.insets = new java.awt.Insets(5, 5, 10, 5);
172: jContentPane.add(jbOk, gridBagConstraints6);
173:
174: this .setContentPane(jContentPane);
175: }
176:
177: /**
178: * Retorna o tipo de conta selecionada pelo ususário
179: * @return
180: */
181: public String getTipoConta() {
182: try {
183: if (dbAccountType.getDataAt(dbAccountType
184: .getSelectedIndex()) != null)
185: return dbAccountType.getDataAt(
186: dbAccountType.getSelectedIndex()).get("Id")
187: .toString();
188: } catch (SQLException e) {
189: ((SimpleLog) GFPController.getGFPController().getContexto()
190: .get(GFPController.LOG))
191: .log("Erro ao reter tipo de conta selecionado!");
192: ((SimpleLog) GFPController.getGFPController().getContexto()
193: .get(GFPController.LOG)).log(e
194: .getLocalizedMessage());
195: ((SimpleLog) GFPController.getGFPController().getContexto()
196: .get(GFPController.LOG)).log(e);
197: }
198: return null;
199: }
200:
201: /**
202: * Retorna a conta selecionada pelo ususário
203: * @return
204: */
205: public Integer getConta() {
206: try {
207: if (dbAccount.getDataAt(dbAccount.getSelectedIndex()) != null)
208: return (Integer) dbAccount.getDataAt(
209: dbAccount.getSelectedIndex()).get("Id");
210: } catch (SQLException e) {
211: ((SimpleLog) GFPController.getGFPController().getContexto()
212: .get(GFPController.LOG))
213: .log("Erro ao reter Account selecionada!");
214: ((SimpleLog) GFPController.getGFPController().getContexto()
215: .get(GFPController.LOG)).log(e
216: .getLocalizedMessage());
217: ((SimpleLog) GFPController.getGFPController().getContexto()
218: .get(GFPController.LOG)).log(e);
219: }
220: return null;
221: }
222: } // @jve:decl-index=0:visual-constraint="10,10"
|