0001: /*
0002: * TransactionWindow.java Created on 1 de Janeiro de 2004, 02:26
0003: */
0004:
0005: package br.com.gfp.windows;
0006:
0007: import java.awt.BorderLayout;
0008: import java.awt.Dimension;
0009: import java.awt.GridBagConstraints;
0010: import java.awt.GridBagLayout;
0011: import java.awt.Insets;
0012: import java.awt.event.ActionEvent;
0013: import java.awt.event.ActionListener;
0014: import java.awt.event.FocusAdapter;
0015: import java.awt.event.FocusEvent;
0016: import java.awt.event.ItemEvent;
0017: import java.awt.event.ItemListener;
0018: import java.sql.SQLException;
0019: import java.util.Calendar;
0020: import java.util.Date;
0021: import java.util.Map;
0022:
0023: import javax.swing.DefaultComboBoxModel;
0024: import javax.swing.JButton;
0025: import javax.swing.JCheckBox;
0026: import javax.swing.JFrame;
0027: import javax.swing.JInternalFrame;
0028: import javax.swing.JOptionPane;
0029: import javax.swing.JPanel;
0030: import javax.swing.JSpinner;
0031: import javax.swing.SpinnerNumberModel;
0032: import javax.swing.border.BevelBorder;
0033: import javax.swing.event.InternalFrameEvent;
0034: import javax.swing.event.InternalFrameListener;
0035: import javax.swing.event.ListSelectionEvent;
0036: import javax.swing.event.ListSelectionListener;
0037:
0038: import br.com.gfp.actions.AbrirTelaParaInsercaoAction;
0039: import br.com.gfp.dao.AccountTypeDAO;
0040: import br.com.gfp.dao.GFPController;
0041: import br.com.gfp.dao.TransactionDAO;
0042: import br.com.gfp.dao.TransactionTypeDAO;
0043: import br.com.gfp.data.AccountSaving;
0044: import br.com.gfp.data.AccountType;
0045: import br.com.gfp.data.Assets;
0046: import br.com.gfp.data.BasicGFPDataObject;
0047: import br.com.gfp.data.CheckingAccount;
0048: import br.com.gfp.data.Contact;
0049: import br.com.gfp.data.CreditCard;
0050: import br.com.gfp.data.Transaction;
0051: import br.com.gfp.data.TransactionType;
0052: import br.com.gfp.internationalization.ErrosDeDadosMessages;
0053: import br.com.gfp.internationalization.TelaLancamentosMessages;
0054: import br.com.gfp.reports.ReportFactory;
0055: import br.com.gfp.util.SimpleLog;
0056: import br.com.gfp.windows.componentes.GFPComboBoxRenderer;
0057: import br.com.gfp.windows.componentes.GFPHeaderRenderer;
0058: import br.com.gfp.windows.componentes.GFPTableCellRenderer;
0059: import br.com.gfpshare.beans.DBComboBox;
0060: import br.com.gfpshare.beans.GeneralEventHandler;
0061: import br.com.gfpshare.beans.MessageView;
0062: import br.com.gfpshare.beans.ZCalendarTextField;
0063: import br.com.gfpshare.beans.ZComboBox;
0064: import br.com.gfpshare.beans.ZLabel;
0065: import br.com.gfpshare.beans.ZMoneyLabel;
0066: import br.com.gfpshare.beans.ZMoneyTextField;
0067: import br.com.gfpshare.beans.aplicativos.IconeFactory;
0068: import br.com.gfpshare.beans.aplicativos.PainelTelaBasica;
0069: import br.com.gfpshare.beans.table.DBTable;
0070: import br.com.gfpshare.db.PersistentObject;
0071: import br.com.gfpshare.db.SQLCondition;
0072: import br.com.gfpshare.db.SQLCondition.Condicao;
0073:
0074: /**
0075: * Tela de lançamentos das ocorrências financeiras
0076: *
0077: * @author Igor Regis da Slva Simões
0078: * @created 18/01/2004
0079: */
0080: public class TransactionWindow extends GFPInternalFrame<Transaction> {
0081: private JFrame owner = null;
0082:
0083: /**
0084: * Objeto usado para realizar as operações de manutenção dos lançamentos
0085: */
0086: protected Transaction transaction = null;
0087:
0088: /**
0089: * Campo do dia do lançamento
0090: */
0091: protected ZCalendarTextField ictfDia;
0092:
0093: /**
0094: * Campo que seleciona a data em que se deseja ver o saldo de uma conta
0095: */
0096: protected ZCalendarTextField ictfSaldoEm;
0097:
0098: protected ZCalendarTextField ictfLancamentosDe;
0099:
0100: protected ZCalendarTextField ictfLancamentosAte;
0101:
0102: protected JCheckBox jcbCompra_Venda;
0103:
0104: protected DBComboBox jcbConta;
0105:
0106: protected DBComboBox jcbEntidade;
0107:
0108: protected JCheckBox jcbPago_Recebido;
0109:
0110: protected DBComboBox jcbProduto;
0111:
0112: protected JCheckBox jcbRepetirLancamentoCada;
0113:
0114: protected DBComboBox jcbTipo;
0115:
0116: protected DBComboBox jcbTipoConta;
0117:
0118: protected ZComboBox jcbTipoIntervalorRepeticao;
0119:
0120: protected JCheckBox jcbFiltrarPorData;
0121:
0122: protected JCheckBox jcbOcultarPrevisoes;
0123:
0124: protected JCheckBox jcbIncluirSubTipos;
0125:
0126: protected ZLabel jlConta;
0127:
0128: protected ZLabel jlDia;
0129:
0130: protected ZLabel jlSaldoAtual;
0131:
0132: protected ZLabel jlSaldoEm;
0133:
0134: protected ZLabel jlTipo;
0135:
0136: protected ZLabel jlValor;
0137:
0138: protected ZLabel jlTotalLancadoFiltrado;
0139:
0140: protected ZLabel jlValorTotalLancadoFiltrado;
0141:
0142: protected ZMoneyLabel jlValorSaldoAtual;
0143:
0144: protected ZMoneyLabel jlValorSaldoEm;
0145:
0146: protected ZLabel jlVezesACada;
0147:
0148: protected JPanel jpCabecalho;
0149:
0150: protected JPanel jpSaldoAtual;
0151:
0152: protected JPanel jpSaldoEm;
0153:
0154: protected JPanel jpSaldos;
0155:
0156: /**
0157: * Intervalo de repetião dos lançamentos
0158: */
0159: protected JSpinner jsIntervalorRepeticao;
0160:
0161: /**
0162: * Vezes que o lançamento deverá ser repetido
0163: */
0164: protected JSpinner jsVezes;
0165:
0166: protected DBTable<Transaction> jtLancamentos;
0167:
0168: protected ZMoneyTextField mtfValor;
0169:
0170: protected PainelTelaBasica telaPrincipal;
0171:
0172: protected DBComboBox jcbTipoContaTransferencia;
0173:
0174: protected DBComboBox jcbContaTransferencia;
0175:
0176: private TransactionTypeDAO transactionTypeDAO = new TransactionTypeDAO();;
0177:
0178: /**
0179: * Indica o primeiro valor digitado pelo usuário (0 igual e nada sigitado ainda)
0180: */
0181: private double firstValue = 0;
0182:
0183: private TransactionTypeDAO transactionTypeDAO2 = new TransactionTypeDAO();
0184:
0185: private double valoresFiltradosNaTabela;
0186:
0187: /**
0188: * Creates new form TransactionWindow
0189: *
0190: * @param owner O Frame propietário desta janela
0191: */
0192: public TransactionWindow(JFrame owner) {
0193: controller = new TransactionDAO<Transaction>();
0194: this .owner = owner;
0195: lancamentoInit();
0196: initComponents();
0197: setTitle(TelaLancamentosMessages.getMessages().getString(
0198: "lancamentos"));
0199: setSize(700, 490);
0200: //refreshTabelaLancamentos();
0201: }
0202:
0203: /**
0204: * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always
0205: * regenerated by the Form Editor.
0206: */
0207: private void initComponents() {
0208: GridBagConstraints gridBagConstraints;
0209: telaPrincipal = new PainelTelaBasica();
0210:
0211: setClosable(true);
0212: setIconifiable(true);
0213: setMaximizable(true);
0214: setResizable(true);
0215: setFrameIcon(IconeFactory.getIconeFactory().getImageIcon(
0216: IconeFactory.LANCAMENTOS_PEQUENA));
0217:
0218: addInternalFrameListener((InternalFrameListener) GeneralEventHandler
0219: .makeProxy(this , "telaLancamentosFechada",
0220: InternalFrameListener.class,
0221: "internalFrameClosed"));
0222:
0223: initTable();
0224: telaPrincipal.addPrintButtonListener(new PrintListener());
0225:
0226: jlDia = new ZLabel();
0227: jlValor = new ZLabel();
0228: jlTipo = new ZLabel();
0229: mtfValor = new ZMoneyTextField(owner);
0230: jcbRepetirLancamentoCada = new JCheckBox();
0231: jsIntervalorRepeticao = new JSpinner();
0232: jcbTipoIntervalorRepeticao = new ZComboBox();
0233: ictfDia = new ZCalendarTextField();
0234: ictfLancamentosDe = new ZCalendarTextField();
0235: ictfLancamentosAte = new ZCalendarTextField();
0236: jcbPago_Recebido = new JCheckBox();
0237: jcbCompra_Venda = new JCheckBox();
0238: jsVezes = new JSpinner();
0239: jlVezesACada = new ZLabel();
0240: jcbProduto = new DBComboBox(new Assets());
0241: jcbEntidade = new DBComboBox(new Contact());
0242: jcbTipo = new DBComboBox(new TransactionType());
0243: jpCabecalho = new JPanel();
0244: jlConta = new ZLabel();
0245: jcbTipoConta = new DBComboBox(new AccountType());
0246: jcbConta = new DBComboBox();
0247: jpSaldos = new JPanel();
0248: jpSaldoEm = new JPanel();
0249: jlSaldoEm = new ZLabel();
0250: jlValorSaldoEm = new ZMoneyLabel();
0251: jlValorTotalLancadoFiltrado = new ZMoneyLabel();
0252: jlTotalLancadoFiltrado = new ZLabel();
0253: ictfSaldoEm = new ZCalendarTextField();
0254: jpSaldoAtual = new JPanel();
0255: jlSaldoAtual = new ZLabel();
0256: jlValorSaldoAtual = new ZMoneyLabel();
0257: jcbFiltrarPorData = new JCheckBox();
0258: jcbOcultarPrevisoes = new JCheckBox();
0259: jcbIncluirSubTipos = new JCheckBox();
0260: jcbTipoContaTransferencia = new DBComboBox(new AccountType());
0261: jcbContaTransferencia = new DBComboBox();
0262:
0263: jcbIncluirSubTipos.setText(TelaLancamentosMessages
0264: .getMessages().getString("incluirSubTipos"));
0265: jcbIncluirSubTipos.setToolTipText(TelaLancamentosMessages
0266: .getMessages().getString("incluirSubTiposToolTip"));
0267: jcbIncluirSubTipos.setMnemonic(TelaLancamentosMessages
0268: .getMessages().getString("incluirSubTiposMnemonic")
0269: .charAt(0));
0270: gridBagConstraints = new GridBagConstraints();
0271: gridBagConstraints.gridx = 2;
0272: gridBagConstraints.gridy = 0;
0273: gridBagConstraints.weightx = 1;
0274: gridBagConstraints.anchor = GridBagConstraints.WEST;
0275: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0276: telaPrincipal.addComponent(jcbIncluirSubTipos,
0277: gridBagConstraints, PainelTelaBasica.TABLE_HEADER_AREA);
0278:
0279: jcbOcultarPrevisoes.setText(TelaLancamentosMessages
0280: .getMessages().getString("ocultarPrevisoes"));
0281: jcbOcultarPrevisoes.setToolTipText(TelaLancamentosMessages
0282: .getMessages().getString("ocultarPrevisoesToolTip"));
0283: jcbOcultarPrevisoes.setMnemonic(TelaLancamentosMessages
0284: .getMessages().getString("ocultarPrevisoesMnemonic")
0285: .charAt(0));
0286: gridBagConstraints = new GridBagConstraints();
0287: gridBagConstraints.gridx = 1;
0288: gridBagConstraints.gridy = 0;
0289: gridBagConstraints.anchor = GridBagConstraints.WEST;
0290: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0291: telaPrincipal.addComponent(jcbOcultarPrevisoes,
0292: gridBagConstraints, PainelTelaBasica.TABLE_HEADER_AREA);
0293:
0294: jlDia.setText(TelaLancamentosMessages.getMessages().getString(
0295: "dia"));
0296: jlDia.setPreferredSize(new Dimension(150, 26));
0297: jlDia.setRequiredField(ictfDia);
0298: jlDia.setValidationNotNull(true);
0299: jlDia.setDisplayedMnemonic(TelaLancamentosMessages
0300: .getMessages().getString("DiaMnemonic").charAt(0));
0301: gridBagConstraints = new GridBagConstraints();
0302: gridBagConstraints.gridx = 0;
0303: gridBagConstraints.gridy = 0;
0304: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0305: telaPrincipal.addComponent(jlDia, gridBagConstraints,
0306: PainelTelaBasica.DATA_COMPONENTS_AREA);
0307:
0308: jlValor.setText(TelaLancamentosMessages.getMessages()
0309: .getString("valor"));
0310: jlValor.setDisplayedMnemonic(TelaLancamentosMessages
0311: .getMessages().getString("ValorMnemonic").charAt(0));
0312: jlValor.setRequiredField(mtfValor);
0313: jlValor.setValidationAction(transaction, "validateValor");
0314: jlValor.setPreferredSize(new Dimension(150, 26));
0315: gridBagConstraints = new GridBagConstraints();
0316: gridBagConstraints.gridx = 4;
0317: gridBagConstraints.gridy = 0;
0318: gridBagConstraints.anchor = GridBagConstraints.WEST;
0319: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0320: telaPrincipal.addComponent(jlValor, gridBagConstraints,
0321: PainelTelaBasica.DATA_COMPONENTS_AREA);
0322:
0323: jlTipo.setText(TelaLancamentosMessages.getMessages().getString(
0324: "tipo"));
0325: jlTipo.setDisplayedMnemonic(TelaLancamentosMessages
0326: .getMessages().getString("TipoMnemonic").charAt(0));
0327: jlTipo.setRequiredField(jcbTipo);
0328: jlTipo.setValidationNotNull(true);
0329: jlTipo.setPreferredSize(new Dimension(150, 26));
0330: gridBagConstraints = new GridBagConstraints();
0331: gridBagConstraints.gridx = 0;
0332: gridBagConstraints.gridy = 1;
0333: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0334: telaPrincipal.addComponent(jlTipo, gridBagConstraints,
0335: PainelTelaBasica.DATA_COMPONENTS_AREA);
0336:
0337: mtfValor.setMinimumSize(new Dimension(100, 20));
0338: mtfValor.setPreferredSize(new Dimension(100, 20));
0339: mtfValor.setToolTipText(TelaLancamentosMessages.getMessages()
0340: .getString("ValorToolTip"));
0341: mtfValor.addFocusListener(new FocusAdapter() {
0342: @Override
0343: public void focusLost(FocusEvent e) {
0344: valorEditado(e);
0345: }
0346: });
0347: gridBagConstraints = new GridBagConstraints();
0348: gridBagConstraints.gridx = 5;
0349: gridBagConstraints.gridy = 0;
0350: gridBagConstraints.gridwidth = 3;
0351: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
0352: gridBagConstraints.anchor = GridBagConstraints.WEST;
0353: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0354: telaPrincipal.addComponent(mtfValor, gridBagConstraints,
0355: PainelTelaBasica.DATA_COMPONENTS_AREA);
0356:
0357: jcbRepetirLancamentoCada.setText(TelaLancamentosMessages
0358: .getMessages().getString("repetir"));
0359: jcbRepetirLancamentoCada.setMnemonic(TelaLancamentosMessages
0360: .getMessages().getString("RepetirMnemonic").charAt(0));
0361: jcbRepetirLancamentoCada.setToolTipText(TelaLancamentosMessages
0362: .getMessages().getString("RepetirToolTip"));
0363: jcbRepetirLancamentoCada
0364: .addItemListener((ItemListener) GeneralEventHandler
0365: .makeProxy(
0366: this ,
0367: "repetirLancamentoCadaItemStateChanged",
0368: ItemListener.class, "itemStateChanged"));
0369:
0370: gridBagConstraints = new GridBagConstraints();
0371: gridBagConstraints.gridx = 0;
0372: gridBagConstraints.gridy = 2;
0373: gridBagConstraints.gridwidth = 2;
0374: gridBagConstraints.anchor = GridBagConstraints.WEST;
0375: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0376: telaPrincipal.addComponent(jcbRepetirLancamentoCada,
0377: gridBagConstraints,
0378: PainelTelaBasica.DATA_COMPONENTS_AREA);
0379:
0380: jsIntervalorRepeticao.setModel(new SpinnerNumberModel(0, 0, 99,
0381: 1));
0382: jsIntervalorRepeticao.setMinimumSize(new Dimension(37, 20));
0383: jsIntervalorRepeticao.setEnabled(false);
0384: jsIntervalorRepeticao.setToolTipText(TelaLancamentosMessages
0385: .getMessages().getString("IntervaloToolTip"));
0386: gridBagConstraints = new GridBagConstraints();
0387: gridBagConstraints.gridx = 6;
0388: gridBagConstraints.gridy = 2;
0389: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
0390: gridBagConstraints.anchor = GridBagConstraints.WEST;
0391: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0392: telaPrincipal.addComponent(jsIntervalorRepeticao,
0393: gridBagConstraints,
0394: PainelTelaBasica.DATA_COMPONENTS_AREA);
0395:
0396: jcbTipoIntervalorRepeticao
0397: .setModel(new DefaultComboBoxModel(
0398: new String[] {
0399: "", TelaLancamentosMessages.getMessages().getString("dias"), TelaLancamentosMessages.getMessages().getString("semenas"), TelaLancamentosMessages.getMessages().getString("meses"), TelaLancamentosMessages.getMessages().getString("anos") })); //$NON-NLS-4$ //$NON-NLS-5$
0400: jcbTipoIntervalorRepeticao
0401: .setMinimumSize(new Dimension(100, 25));
0402: jcbTipoIntervalorRepeticao.setEnabled(false);
0403: jcbTipoIntervalorRepeticao
0404: .setToolTipText(TelaLancamentosMessages.getMessages()
0405: .getString("TipoIntervaloToolTip"));
0406: gridBagConstraints = new GridBagConstraints();
0407: gridBagConstraints.gridx = 7;
0408: gridBagConstraints.gridy = 2;
0409: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0410: telaPrincipal.addComponent(jcbTipoIntervalorRepeticao,
0411: gridBagConstraints,
0412: PainelTelaBasica.DATA_COMPONENTS_AREA);
0413:
0414: ictfDia.setMinimumSize(new Dimension(100, 26));
0415: ictfDia.setToolTipText(TelaLancamentosMessages.getMessages()
0416: .getString("DiaToolTip"));
0417: gridBagConstraints = new GridBagConstraints();
0418: gridBagConstraints.gridx = 1;
0419: gridBagConstraints.gridy = 0;
0420: gridBagConstraints.gridwidth = 3;
0421: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
0422: gridBagConstraints.anchor = GridBagConstraints.WEST;
0423: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0424: telaPrincipal.addComponent(ictfDia, gridBagConstraints,
0425: PainelTelaBasica.DATA_COMPONENTS_AREA);
0426:
0427: jcbPago_Recebido.setText(TelaLancamentosMessages.getMessages()
0428: .getString("pagoRecebidoDe"));
0429: jcbPago_Recebido.setMnemonic(TelaLancamentosMessages
0430: .getMessages().getString("PagoRecebidoDeMnemonic")
0431: .charAt(0));
0432: jcbPago_Recebido.setToolTipText(TelaLancamentosMessages
0433: .getMessages().getString("PagoRecebidoDeToolTip"));
0434: jcbPago_Recebido
0435: .addItemListener((ItemListener) GeneralEventHandler
0436: .makeProxy(this ,
0437: "pago_RecebidoItemStateChanged",
0438: ItemListener.class, "itemStateChanged"));
0439:
0440: gridBagConstraints = new GridBagConstraints();
0441: gridBagConstraints.gridx = 0;
0442: gridBagConstraints.gridy = 3;
0443: gridBagConstraints.gridwidth = 4;
0444: gridBagConstraints.anchor = GridBagConstraints.WEST;
0445: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0446: telaPrincipal.addComponent(jcbPago_Recebido,
0447: gridBagConstraints,
0448: PainelTelaBasica.DATA_COMPONENTS_AREA);
0449:
0450: jsVezes.setMinimumSize(new Dimension(40, 20));
0451: jsVezes.setPreferredSize(new Dimension(40, 20));
0452: jsVezes.setEnabled(false);
0453: jsVezes.setToolTipText(TelaLancamentosMessages.getMessages()
0454: .getString("VezesToolTip"));
0455: gridBagConstraints = new GridBagConstraints();
0456: gridBagConstraints.gridx = 2;
0457: gridBagConstraints.gridy = 2;
0458: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
0459: gridBagConstraints.anchor = GridBagConstraints.WEST;
0460: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0461: telaPrincipal.addComponent(jsVezes, gridBagConstraints,
0462: PainelTelaBasica.DATA_COMPONENTS_AREA);
0463:
0464: jlVezesACada.setText(TelaLancamentosMessages.getMessages()
0465: .getString("46"));
0466: jlVezesACada.setDisplayedMnemonic(TelaLancamentosMessages
0467: .getMessages().getString("VezesACadaMnemonic")
0468: .charAt(0));
0469: jlVezesACada.setLabelFor(jsIntervalorRepeticao);
0470: jlVezesACada.setEnabled(false);
0471: gridBagConstraints = new GridBagConstraints();
0472: gridBagConstraints.gridx = 3;
0473: gridBagConstraints.gridy = 2;
0474: gridBagConstraints.gridwidth = 3;
0475: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
0476: gridBagConstraints.anchor = GridBagConstraints.WEST;
0477: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0478: telaPrincipal.addComponent(jlVezesACada, gridBagConstraints,
0479: PainelTelaBasica.DATA_COMPONENTS_AREA);
0480:
0481: jcbCompra_Venda.setText(TelaLancamentosMessages.getMessages()
0482: .getString("compraVendaDe"));
0483: jcbCompra_Venda.setMnemonic(TelaLancamentosMessages
0484: .getMessages().getString("CompraVendaDeMnemonic")
0485: .charAt(0));
0486: jcbCompra_Venda.setToolTipText(TelaLancamentosMessages
0487: .getMessages().getString("CompraVendaDeToolTip"));
0488: jcbCompra_Venda
0489: .addItemListener((ItemListener) GeneralEventHandler
0490: .makeProxy(this ,
0491: "compra_VendaItemStateChanged",
0492: ItemListener.class, "itemStateChanged"));
0493: gridBagConstraints = new GridBagConstraints();
0494: gridBagConstraints.gridx = 0;
0495: gridBagConstraints.gridy = 4;
0496: gridBagConstraints.gridwidth = 4;
0497: gridBagConstraints.anchor = GridBagConstraints.WEST;
0498: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0499: telaPrincipal.addComponent(jcbCompra_Venda, gridBagConstraints,
0500: PainelTelaBasica.DATA_COMPONENTS_AREA);
0501:
0502: jcbTipoContaTransferencia
0503: .setToolTipText(TelaLancamentosMessages.getMessages()
0504: .getString("TipoContaTransferenciaToolTip"));
0505: jcbTipoContaTransferencia.setVisible(false);
0506: jcbTipoContaTransferencia.setRenderer(new GFPComboBoxRenderer(
0507: GFPComboBoxRenderer.TIPO_DE_CONTA, -1));
0508: jcbTipoContaTransferencia
0509: .addActionListener((ActionListener) GeneralEventHandler
0510: .makeProxy(this ,
0511: "tipoContaTransferenciaAlterado",
0512: ActionListener.class, "actionPerformed"));
0513: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
0514: telaPrincipal.addComponent(jcbTipoContaTransferencia,
0515: gridBagConstraints,
0516: PainelTelaBasica.DATA_COMPONENTS_AREA);
0517:
0518: jcbProduto.setEnabled(false);
0519: jcbProduto.setToolTipText(TelaLancamentosMessages.getMessages()
0520: .getString("ProdutoToolTip"));
0521: jcbProduto.setInsertNewListener(AbrirTelaParaInsercaoAction
0522: .getAction(), AssetsWindow.class.getName());
0523: gridBagConstraints = new GridBagConstraints();
0524: gridBagConstraints.gridx = 4;
0525: gridBagConstraints.gridy = 4;
0526: gridBagConstraints.gridwidth = 4;
0527: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
0528: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0529: telaPrincipal.addComponent(jcbProduto, gridBagConstraints,
0530: PainelTelaBasica.DATA_COMPONENTS_AREA);
0531:
0532: jcbContaTransferencia.setToolTipText(TelaLancamentosMessages
0533: .getMessages().getString("ContaTransferenciaToolTip"));
0534: jcbContaTransferencia.setVisible(false);
0535: jcbContaTransferencia.setMinimumSize(new Dimension(100, 25));
0536: jcbContaTransferencia.setPreferredSize(new Dimension(120, 25));
0537: jcbContaTransferencia.setInsertNewListener(
0538: AbrirTelaParaInsercaoAction.getAction(), null);
0539: telaPrincipal.addComponent(jcbContaTransferencia,
0540: gridBagConstraints,
0541: PainelTelaBasica.DATA_COMPONENTS_AREA);
0542:
0543: jcbEntidade.setEnabled(false);
0544: jcbEntidade.setToolTipText(TelaLancamentosMessages
0545: .getMessages().getString("EntidadeToolTip"));
0546: jcbEntidade.setInsertNewListener(AbrirTelaParaInsercaoAction
0547: .getAction(), ContactsWindow.class.getName());
0548: gridBagConstraints = new GridBagConstraints();
0549: gridBagConstraints.gridx = 4;
0550: gridBagConstraints.gridy = 3;
0551: gridBagConstraints.gridwidth = 4;
0552: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
0553: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0554: telaPrincipal.addComponent(jcbEntidade, gridBagConstraints,
0555: PainelTelaBasica.DATA_COMPONENTS_AREA);
0556:
0557: jcbTipo.addItemListener((ItemListener) GeneralEventHandler
0558: .makeProxy(this , "tipoLancamentoItemStateChanged",
0559: ItemListener.class, "itemStateChanged"));
0560: jcbTipo.setInsertNewListener(AbrirTelaParaInsercaoAction
0561: .getAction(), TypeOfTransactionWindow.class.getName());
0562: gridBagConstraints = new GridBagConstraints();
0563: gridBagConstraints.gridx = 1;
0564: gridBagConstraints.gridy = 1;
0565: gridBagConstraints.gridwidth = 7;
0566: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
0567: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0568: telaPrincipal.addComponent(jcbTipo, gridBagConstraints,
0569: PainelTelaBasica.DATA_COMPONENTS_AREA);
0570:
0571: telaPrincipal.getPainelBotoes().addActionListener(
0572: "salvar",
0573: (ActionListener) GeneralEventHandler.makeProxy(this ,
0574: "salvar", ActionListener.class,
0575: "actionPerformed"));
0576: telaPrincipal.getPainelBotoes().addActionListener(
0577: "atualizar",
0578: (ActionListener) GeneralEventHandler.makeProxy(this ,
0579: "atualizar", ActionListener.class,
0580: "actionPerformed"));
0581: telaPrincipal.getPainelBotoes().addActionListener(
0582: "novo",
0583: (ActionListener) GeneralEventHandler
0584: .makeProxy(this , "novo", ActionListener.class,
0585: "actionPerformed"));
0586: telaPrincipal.getPainelBotoes().addActionListener(
0587: "excluir",
0588: (ActionListener) GeneralEventHandler.makeProxy(this ,
0589: "excluir", ActionListener.class,
0590: "actionPerformed"));
0591: telaPrincipal.getPainelBotoes().addActionListener(
0592: "pesquisar",
0593: (ActionListener) GeneralEventHandler.makeProxy(this ,
0594: "pesquisar", ActionListener.class,
0595: "actionPerformed"));
0596: telaPrincipal.getPainelBotoes().addActionListener(
0597: "limpar",
0598: (ActionListener) GeneralEventHandler.makeProxy(this ,
0599: "limpar", ActionListener.class,
0600: "actionPerformed"));
0601: telaPrincipal.getPainelBotoes().addActionListener(
0602: "filtrar",
0603: (ActionListener) GeneralEventHandler.makeProxy(this ,
0604: "filtrar", ActionListener.class,
0605: "actionPerformed"));
0606: getContentPane().add(telaPrincipal, BorderLayout.CENTER);
0607:
0608: jlConta.setText(TelaLancamentosMessages.getMessages()
0609: .getString("conta"));
0610: jlConta.setDisplayedMnemonic(TelaLancamentosMessages
0611: .getMessages().getString("ContaMnemonic").charAt(0));
0612: jlConta.setRequiredField(jcbConta);
0613: jlConta.setLabelFor(jcbTipoConta);
0614: jlConta.setValidationNotNull(true);
0615: jlConta.highlight(true);
0616: jpCabecalho.add(jlConta);
0617:
0618: jcbTipoConta.setRenderer(new GFPComboBoxRenderer(
0619: GFPComboBoxRenderer.TIPO_DE_CONTA, -1));
0620: jcbTipoConta.setMinimumSize(new Dimension(120, 25));
0621: jcbTipoConta.setPreferredSize(new Dimension(140, 25));
0622: jcbTipoConta.setToolTipText(TelaLancamentosMessages
0623: .getMessages().getString("TipoContaToolTip"));
0624: jcbTipoConta
0625: .addActionListener((ActionListener) GeneralEventHandler
0626: .makeProxy(this , "tipoContaAlterado",
0627: ActionListener.class, "actionPerformed"));
0628:
0629: jpCabecalho.add(jcbTipoConta);
0630:
0631: jcbConta.setMinimumSize(new Dimension(150, 25));
0632: jcbConta.setPreferredSize(new Dimension(250, 25));
0633: jcbConta.setToolTipText(TelaLancamentosMessages.getMessages()
0634: .getString("ContaToolTip"));
0635: jcbConta.addActionListener((ActionListener) GeneralEventHandler
0636: .makeProxy(this , "tipoContaAlterado",
0637: ActionListener.class, "actionPerformed"));
0638: jcbConta.setInsertNewListener(AbrirTelaParaInsercaoAction
0639: .getAction(), null);
0640: jpCabecalho.add(jcbConta);
0641:
0642: jcbFiltrarPorData.setText(TelaLancamentosMessages.getMessages()
0643: .getString("periodo"));
0644: jcbFiltrarPorData.setMnemonic(TelaLancamentosMessages
0645: .getMessages().getString("PeriodoMnemonic").charAt(0));
0646: jcbFiltrarPorData.setSelected(true);
0647: jcbFiltrarPorData
0648: .addActionListener((ActionListener) GeneralEventHandler
0649: .makeProxy(this , "ativarFiltroPorData",
0650: ActionListener.class, "actionPerformed"));
0651: jpCabecalho.add(jcbFiltrarPorData);
0652:
0653: ictfLancamentosDe.setMinimumSize(new Dimension(100, 26));
0654: ictfLancamentosDe.setToolTipText(TelaLancamentosMessages
0655: .getMessages().getString("LancamentosDeToolTip"));
0656: jpCabecalho.add(ictfLancamentosDe);
0657:
0658: ictfLancamentosAte.setMinimumSize(new Dimension(100, 26));
0659: ictfLancamentosAte.setToolTipText(TelaLancamentosMessages
0660: .getMessages().getString("LancamentosAteToolTip"));
0661: jpCabecalho.add(ictfLancamentosAte);
0662:
0663: getContentPane().add(jpCabecalho, BorderLayout.NORTH);
0664:
0665: jpSaldos.setLayout(new GridBagLayout());
0666:
0667: jpSaldoEm.setLayout(new GridBagLayout());
0668:
0669: jpSaldoEm.setBorder(new BevelBorder(BevelBorder.LOWERED));
0670:
0671: jlTotalLancadoFiltrado.setText(TelaLancamentosMessages
0672: .getMessages().getString("somaLancamentosFiltrados"));
0673: gridBagConstraints = new GridBagConstraints();
0674: gridBagConstraints.gridx = 0;
0675: gridBagConstraints.gridy = 0;
0676: gridBagConstraints.insets = new Insets(0, 10, 0, 0);
0677: jpSaldoEm.add(jlTotalLancadoFiltrado, gridBagConstraints);
0678:
0679: jlValorTotalLancadoFiltrado.setText(TelaLancamentosMessages
0680: .getMessages().getString("0.00"));
0681: gridBagConstraints = new GridBagConstraints();
0682: gridBagConstraints.gridx = 1;
0683: gridBagConstraints.gridy = 0;
0684: jpSaldoEm.add(jlValorTotalLancadoFiltrado, gridBagConstraints);
0685:
0686: JPanel separador = new JPanel();
0687: separador.setMinimumSize(new Dimension(3, 30));
0688: separador.setPreferredSize(new Dimension(3, 30));
0689: separador.setMaximumSize(new Dimension(3, 30));
0690: separador.setBorder(new BevelBorder(BevelBorder.RAISED));
0691: gridBagConstraints = new GridBagConstraints();
0692: gridBagConstraints.gridx = 2;
0693: gridBagConstraints.gridy = 0;
0694: gridBagConstraints.weighty = 1.0;
0695: gridBagConstraints.insets = new Insets(0, 10, 0, 5);
0696: jpSaldoEm.add(separador, gridBagConstraints);
0697:
0698: jlSaldoEm.setText(TelaLancamentosMessages.getMessages()
0699: .getString("saldoEm"));
0700: jlSaldoEm.setDisplayedMnemonic(TelaLancamentosMessages
0701: .getMessages().getString("SaldoEmMnemonic").charAt(0));
0702: jlSaldoEm.setLabelFor(ictfSaldoEm);
0703: gridBagConstraints = new GridBagConstraints();
0704: gridBagConstraints.gridx = 3;
0705: gridBagConstraints.gridy = 0;
0706: gridBagConstraints.insets = new Insets(0, 10, 0, 5);
0707: jpSaldoEm.add(jlSaldoEm, gridBagConstraints);
0708:
0709: ictfSaldoEm.setToolTipText(TelaLancamentosMessages
0710: .getMessages().getString("SaldoEmToolTip"));
0711: gridBagConstraints = new GridBagConstraints();
0712: gridBagConstraints.gridx = 4;
0713: gridBagConstraints.gridy = 0;
0714: jpSaldoEm.add(ictfSaldoEm, gridBagConstraints);
0715: ictfSaldoEm
0716: .addActionListener((ActionListener) GeneralEventHandler
0717: .makeProxy(this , "calculaSaldoEm",
0718: ActionListener.class, "actionPerformed"));
0719:
0720: jlValorSaldoEm.setText("0.00");
0721: gridBagConstraints = new GridBagConstraints();
0722: gridBagConstraints.gridx = 5;
0723: gridBagConstraints.gridy = 0;
0724: gridBagConstraints.anchor = GridBagConstraints.WEST;
0725: gridBagConstraints.weightx = 1.0;
0726: gridBagConstraints.insets = new Insets(0, 5, 0, 0);
0727: jpSaldoEm.add(jlValorSaldoEm, gridBagConstraints);
0728:
0729: gridBagConstraints = new GridBagConstraints();
0730: gridBagConstraints.gridx = 0;
0731: gridBagConstraints.fill = GridBagConstraints.BOTH;
0732: gridBagConstraints.weightx = 1.0;
0733: jpSaldos.add(jpSaldoEm, gridBagConstraints);
0734:
0735: jpSaldoAtual.setLayout(new GridBagLayout());
0736:
0737: jpSaldoAtual.setBorder(new BevelBorder(BevelBorder.LOWERED));
0738: jlSaldoAtual.setText(TelaLancamentosMessages.getMessages()
0739: .getString("saldoNoFimdoMes"));
0740: gridBagConstraints = new GridBagConstraints();
0741: gridBagConstraints.ipadx = 5;
0742: gridBagConstraints.anchor = GridBagConstraints.EAST;
0743: gridBagConstraints.weightx = 1.0;
0744: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0745: jpSaldoAtual.add(jlSaldoAtual, gridBagConstraints);
0746:
0747: jlValorSaldoAtual.setText("R$ 0,00");
0748: gridBagConstraints = new GridBagConstraints();
0749: gridBagConstraints.ipadx = 10;
0750: gridBagConstraints.anchor = GridBagConstraints.EAST;
0751: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
0752: jpSaldoAtual.add(jlValorSaldoAtual, gridBagConstraints);
0753:
0754: gridBagConstraints = new GridBagConstraints();
0755: gridBagConstraints.gridx = 1;
0756: gridBagConstraints.gridy = 0;
0757: gridBagConstraints.fill = GridBagConstraints.BOTH;
0758: gridBagConstraints.anchor = GridBagConstraints.EAST;
0759: gridBagConstraints.weightx = 1.0;
0760: jpSaldos.add(jpSaldoAtual, gridBagConstraints);
0761:
0762: getContentPane().add(jpSaldos, BorderLayout.SOUTH);
0763:
0764: pack();
0765: limpar(null);
0766: }
0767:
0768: /**
0769: *
0770: */
0771: protected void initTable() {
0772: createTable();
0773: jtLancamentos.hideColumn("Id");
0774: jtLancamentos.hideColumn("TipoConta");
0775: jtLancamentos.hideColumn("IntervaloRepeticao");
0776: jtLancamentos.hideColumn("TipoIntervaloRepeticao");
0777: jtLancamentos.hideColumn("EhDeSistema");
0778: jtLancamentos.hideColumn("EhPrevisao");
0779: jtLancamentos.hideColumn("Transferencia");
0780: jtLancamentos.hideColumn("TipoContaTransf");
0781: jtLancamentos.hideColumn("ContaTransf");
0782:
0783: jtLancamentos.getColumn("Dia").setMinWidth(90);
0784: jtLancamentos.getColumn("Dia").setMaxWidth(100);
0785: jtLancamentos.getColumn("Valor").setMinWidth(100);
0786: jtLancamentos.getColumn("Valor").setMaxWidth(100);
0787: jtLancamentos.getColumn("Conta").setMinWidth(100);
0788: jtLancamentos.getColumn("Tipo").setMinWidth(85);
0789: jtLancamentos.getColumn("Produto").setMinWidth(70);
0790: jtLancamentos.getColumn("EntidadeEnvolvida").setMinWidth(70);
0791: jtLancamentos.getColumn("Descricao").setMinWidth(65);
0792:
0793: jtLancamentos.getColumn("Dia")
0794: .setCellRenderer(
0795: new GFPTableCellRenderer(
0796: GFPTableCellRenderer.DATA, -1));
0797: jtLancamentos.getColumn("Valor").setCellRenderer(
0798: new GFPTableCellRenderer(GFPTableCellRenderer.DINHEIRO,
0799: -1));
0800: jtLancamentos.getColumn("Tipo").setCellRenderer(
0801: new GFPTableCellRenderer(
0802: GFPTableCellRenderer.TIPO_LANCAMENTO, -1));
0803: jtLancamentos.getColumn("Conta").setCellRenderer(
0804: new GFPTableCellRenderer(
0805: GFPTableCellRenderer.APLICACAO, -1));
0806: jtLancamentos.getColumn("Produto").setCellRenderer(
0807: new GFPTableCellRenderer(GFPTableCellRenderer.BEM, -1));
0808: jtLancamentos.getColumn("EntidadeEnvolvida").setCellRenderer(
0809: new GFPTableCellRenderer(GFPTableCellRenderer.ENTIDADE,
0810: -1));
0811: jtLancamentos
0812: .getColumn("TipoIntervaloRepeticao")
0813: .setCellRenderer(
0814: new GFPTableCellRenderer(
0815: GFPTableCellRenderer.TIPO_REPETICAO, -1));
0816:
0817: jtLancamentos.getSelectionModel().addListSelectionListener(
0818: (ListSelectionListener) GeneralEventHandler.makeProxy(
0819: this , "loadFromTable",
0820: ListSelectionListener.class, "valueChanged"));
0821:
0822: telaPrincipal.setJtDados(jtLancamentos);
0823: telaPrincipal.getPdtPaginador().setColocarFocoNaTabela(false);
0824: }
0825:
0826: /**
0827: *
0828: */
0829: protected void createTable() {
0830: //Passamos um lançamento que não existem para que não seja carregado dado algum no DBTable
0831: jtLancamentos = new DBTable<Transaction>(new Transaction(-5),
0832: new GFPHeaderRenderer());
0833: }
0834:
0835: private class PrintListener implements ActionListener {
0836: public void actionPerformed(final ActionEvent e) {
0837: ((JButton) e.getSource()).setEnabled(false);
0838: (new Thread() {
0839: {
0840: setPriority(Thread.MIN_PRIORITY);
0841: setDaemon(true);
0842: }
0843:
0844: @Override
0845: public void run() {
0846: try {
0847: lancamentoInit();
0848: loadLancamento();
0849: Map<String, Object> map = transaction
0850: .getAsMap();
0851:
0852: //Seta o mes cuje o movimento será listado
0853: Calendar inicioMes = Calendar.getInstance();
0854: Calendar fimMes = Calendar.getInstance();
0855:
0856: if (jcbFiltrarPorData.isSelected()) {
0857: if (ictfLancamentosDe.getDate() != null) {
0858: inicioMes.setTime(ictfLancamentosDe
0859: .getDate());
0860: } else {
0861: inicioMes.setTime(new Date());
0862: inicioMes.set(Calendar.DAY_OF_MONTH, 1);
0863: }
0864:
0865: if (ictfLancamentosAte.getDate() != null) {
0866: fimMes.setTime(ictfLancamentosAte
0867: .getDate());
0868: } else {
0869: fimMes.setTime(new Date());
0870: fimMes.add(Calendar.MONTH, 1);
0871: fimMes.set(Calendar.DAY_OF_MONTH, 0);
0872: }
0873:
0874: map.put("DiaComeco", new java.sql.Date(
0875: inicioMes.getTime().getTime()));
0876: map.put("DiaFim", new java.sql.Date(fimMes
0877: .getTime().getTime()));
0878: }
0879:
0880: map.remove("Dia");
0881:
0882: if (jcbOcultarPrevisoes.isSelected())
0883: map.put("EhPrevisao", Boolean.FALSE);
0884: else
0885: map.remove("EhPrevisao");
0886:
0887: if (jcbIncluirSubTipos.isSelected()) {
0888: map
0889: .put(
0890: "IncluirSubtipos",
0891: "(select ST2.* from (select distinct t3.\"Id\" from (select * from \"TipoLancamento\" where \"SuperTipo\" = "
0892: + transaction
0893: .getTipo()
0894: + " or \"Id\" = "
0895: + transaction
0896: .getTipo()
0897: + ") t1 "
0898: + "join \"TipoLancamento\" t2 on t2.\"SuperTipo\" = t1.\"Id\" or t1.\"Id\" = t2.\"Id\" "
0899: + "join \"TipoLancamento\" t3 on t3.\"SuperTipo\" = t2.\"Id\" or t2.\"Id\" = t3.\"Id\") ST1 join \"Lancamento\" ST2 on ST2.\"Tipo\" = ST1.\"Id\") ");
0900: map.remove("Tipo");
0901: } else {
0902: map
0903: .put("IncluirSubtipos",
0904: "\"Lancamento\"");
0905: }
0906:
0907: map.remove("EhDeSistema");
0908: ReportFactory.makeReport("TodosLancamentos",
0909: map);
0910: } catch (Exception e1) {
0911: ((SimpleLog) GFPController.getGFPController()
0912: .getContexto().get(GFPController.LOG))
0913: .log("Erro ao gerar relatorio de lancamentos!");
0914: ((SimpleLog) GFPController.getGFPController()
0915: .getContexto().get(GFPController.LOG))
0916: .log(e1.getLocalizedMessage());
0917: ((SimpleLog) GFPController.getGFPController()
0918: .getContexto().get(GFPController.LOG))
0919: .log(e1);
0920: } finally {
0921: ((JButton) e.getSource()).setEnabled(true);
0922: }
0923: }
0924: }).start();
0925: }
0926: }
0927:
0928: /**
0929: * Pega o valor que foi editado para o mtfValor quando o mesmo perde o foco
0930: * @param evt
0931: */
0932: public void valorEditado(FocusEvent evt) {
0933: if (mtfValor.getValue() != null) {
0934: firstValue = Double.parseDouble(mtfValor.getValue()
0935: .toString());
0936: }
0937: }
0938:
0939: /**
0940: * Chamado sempre que o tipo do lançamento é alterado
0941: * @param evt
0942: */
0943: public void tipoLancamentoItemStateChanged(ItemEvent evt) {
0944: try {
0945: TransactionType transactionType = (TransactionType) jcbTipo
0946: .getSelectedItem();
0947: if (transactionType == null)
0948: return;
0949: if (transactionTypeDAO.isTransferencia(transactionType)) {
0950: jcbTipoContaTransferencia.setVisible(true);
0951: jcbContaTransferencia.setVisible(true);
0952: jcbCompra_Venda.setVisible(false);
0953: jcbProduto.setVisible(false);
0954: } else {
0955: jcbCompra_Venda.setVisible(true);
0956: jcbProduto.setVisible(true);
0957: jcbTipoContaTransferencia.setVisible(false);
0958: jcbContaTransferencia.setVisible(false);
0959: }
0960:
0961: if (transactionTypeDAO.isDespesa(transactionType)) {
0962: if (mtfValor.getValue() != null
0963: && !(mtfValor.getValue() instanceof Float)) {
0964: double campo = (Double) mtfValor.getValue();
0965: if (campo > 0)
0966: campo *= -1;
0967: mtfValor.setValue(campo);
0968: }
0969: } else if (transactionTypeDAO.isReceita(transactionType)) {
0970: if (mtfValor.getValue() != null
0971: && !(mtfValor.getValue() instanceof Float)) {
0972: double campo = (Double) mtfValor.getValue();
0973: if (campo < 0)
0974: campo *= -1;
0975: mtfValor.setValue(campo);
0976: }
0977: } else {
0978: mtfValor.setValue(firstValue);
0979: }
0980:
0981: } catch (SQLException e) {
0982: // TODO Tratar Exceção
0983: e.printStackTrace();
0984: }
0985: }
0986:
0987: /**
0988: * @param e
0989: */
0990: public void ativarFiltroPorData(ActionEvent e) {
0991: ictfLancamentosAte.setEnabled(jcbFiltrarPorData.isSelected());
0992: ictfLancamentosAte.setDate(null);
0993: ictfLancamentosDe.setEnabled(jcbFiltrarPorData.isSelected());
0994: ictfLancamentosDe.setDate(null);
0995: }
0996:
0997: /**
0998: * Este método é chamado sempre que o tipo de conta que está sendo consultada é alterado
0999: * @param e Evento que gerou a alteração
1000: */
1001: public void tipoContaAlterado(ActionEvent e) {
1002: if (e.getSource() == jcbTipoConta) {
1003: try {
1004: jcbConta.setSelectedItem(null);
1005: } catch (IllegalArgumentException iae) {
1006: ((SimpleLog) GFPController.getGFPController()
1007: .getContexto().get(GFPController.LOG))
1008: .log("Erro ao limpar campo conta!");
1009: ((SimpleLog) GFPController.getGFPController()
1010: .getContexto().get(GFPController.LOG)).log(iae
1011: .getLocalizedMessage());
1012: ((SimpleLog) GFPController.getGFPController()
1013: .getContexto().get(GFPController.LOG)).log(iae);
1014: }
1015:
1016: if (jcbTipoConta.getSelectedItem() == null) {
1017: jcbConta.setDataType(null);
1018: } else if (((AccountType) jcbTipoConta.getSelectedItem())
1019: .getNome().toString().equalsIgnoreCase(
1020: "contaCorrente")) {
1021: jcbConta.setDataType(new CheckingAccount());
1022: jcbConta
1023: .setInsertNewCommand(CheckingAccountWindow.class
1024: .getName());
1025: } else if (((AccountType) jcbTipoConta.getSelectedItem())
1026: .getNome().toString().equalsIgnoreCase("aplicacao")) {
1027: jcbConta.setDataType(new AccountSaving());
1028: jcbConta.setInsertNewCommand(SavingsWindow.class
1029: .getName());
1030: } else if (((AccountType) jcbTipoConta.getSelectedItem())
1031: .getNome().toString().equalsIgnoreCase(
1032: "cartaoCredito")) {
1033: jcbConta.setDataType(new CreditCard());
1034: jcbConta.setInsertNewCommand(CreditCardWindow.class
1035: .getName());
1036: }
1037: }
1038: setTitle(null);
1039: }
1040:
1041: /**
1042: * Este método é chamado sempre que o tipo de conta que está sendo consultada é alterado
1043: * @param e Evento que gerou a alteração
1044: */
1045: public void tipoContaTransferenciaAlterado(ActionEvent e) {
1046: if (e.getSource() == jcbTipoContaTransferencia) {
1047: try {
1048: jcbContaTransferencia.setSelectedItem(null);
1049: } catch (IllegalArgumentException iae) {
1050: iae.printStackTrace();
1051: ((SimpleLog) GFPController.getGFPController()
1052: .getContexto().get(GFPController.LOG))
1053: .log("Erro ao limpar campo conta!");
1054: ((SimpleLog) GFPController.getGFPController()
1055: .getContexto().get(GFPController.LOG)).log(iae
1056: .getLocalizedMessage());
1057: ((SimpleLog) GFPController.getGFPController()
1058: .getContexto().get(GFPController.LOG)).log(iae);
1059: }
1060:
1061: if (jcbTipoContaTransferencia.getSelectedItem() == null) {
1062: jcbContaTransferencia.setDataType(null);
1063: } else if (((AccountType) jcbTipoContaTransferencia
1064: .getSelectedItem()).getNome().toString()
1065: .equalsIgnoreCase("contaCorrente")) {
1066: jcbContaTransferencia
1067: .setDataType(new CheckingAccount());
1068: jcbContaTransferencia
1069: .setInsertNewCommand(CheckingAccountWindow.class
1070: .getName());
1071: } else if (((AccountType) jcbTipoContaTransferencia
1072: .getSelectedItem()).getNome().toString()
1073: .equalsIgnoreCase("aplicacao")) {
1074: jcbContaTransferencia.setDataType(new AccountSaving());
1075: jcbContaTransferencia
1076: .setInsertNewCommand(SavingsWindow.class
1077: .getName());
1078: } else if (((AccountType) jcbTipoContaTransferencia
1079: .getSelectedItem()).getNome().toString()
1080: .equalsIgnoreCase("cartaoCredito")) {
1081: jcbContaTransferencia.setDataType(new CreditCard());
1082: jcbContaTransferencia
1083: .setInsertNewCommand(CreditCardWindow.class
1084: .getName());
1085: }
1086: }
1087: }
1088:
1089: /**
1090: * @param e
1091: */
1092: public void atualizar(ActionEvent e) {
1093: refreshTabelaLancamentos();
1094: }
1095:
1096: /**
1097: * @param e
1098: */
1099: public void pesquisar(ActionEvent e) {
1100: if (transaction == null)
1101: lancamentoInit();
1102: loadLancamento();
1103: try {
1104: transaction = controller.getBy(transaction);
1105: } catch (SQLException sqle) {
1106: ((SimpleLog) GFPController.getGFPController().getContexto()
1107: .get(GFPController.LOG))
1108: .log("Erro ao pesquisar por lancamento: "
1109: + transaction);
1110: ((SimpleLog) GFPController.getGFPController().getContexto()
1111: .get(GFPController.LOG)).log(sqle
1112: .getLocalizedMessage());
1113: ((SimpleLog) GFPController.getGFPController().getContexto()
1114: .get(GFPController.LOG)).log(sqle);
1115: transaction = null;
1116: }
1117: editarLancamento();
1118: }
1119:
1120: /**
1121: * @param e
1122: */
1123: public void excluir(ActionEvent e) {
1124: if (transaction == null) {//Todo Rever Mensagem
1125: JOptionPane.showMessageDialog(this , TelaLancamentosMessages
1126: .getMessages().getString("semDadosPraExcluir"));
1127: return;
1128: }
1129:
1130: loadLancamento();
1131:
1132: try {
1133: if (transactionTypeDAO
1134: .isTransferencia((TransactionType) jcbTipo
1135: .getSelectedItem())) {
1136: if (transaction.getTipoContaTransf() != null) {
1137: Transaction temp = getFiltro();
1138: temp.setTransferencia(transaction
1139: .getTransferencia());
1140: temp.setTipoConta(transaction.getTipoContaTransf());
1141: temp.setConta(transaction.getContaTransf());
1142: temp.setTipo(transaction.getTipo());
1143: temp.setDia(transaction.getDia());
1144: controller.deletar(temp);
1145: }
1146: }
1147: controller.deletar(transaction);
1148: } catch (SQLException sqle) {
1149: ((SimpleLog) GFPController.getGFPController().getContexto()
1150: .get(GFPController.LOG))
1151: .log("Erro ao excluir lancamento: " + transaction);
1152: ((SimpleLog) GFPController.getGFPController().getContexto()
1153: .get(GFPController.LOG)).log(sqle
1154: .getLocalizedMessage());
1155: ((SimpleLog) GFPController.getGFPController().getContexto()
1156: .get(GFPController.LOG)).log(sqle);
1157: }
1158: transaction = null;
1159: refreshTabelaLancamentos();
1160: }
1161:
1162: /**
1163: * @param e
1164: */
1165: public void salvar(ActionEvent e) {
1166: if (transaction == null) {//Todo Rever Mensagem
1167: JOptionPane.showMessageDialog(this , TelaLancamentosMessages
1168: .getMessages().getString("semDadosPraSalvar"));
1169: return;
1170: }
1171: loadLancamento();
1172:
1173: if (controller.isAdicionandoNovo()) {
1174: if (transaction.getVezesPraRealizar() > 2) {
1175: final Transaction tTemp = new Transaction();
1176: tTemp.setDados(transaction.getAsMap());
1177: tTemp.setIntervaloRepeticao(transaction
1178: .getIntervaloRepeticao());
1179: tTemp.setTipoIntervaloRepeticao(transaction
1180: .getTipoIntervaloRepeticao());
1181: tTemp.setVezesPraRealizar(transaction
1182: .getVezesPraRealizar());
1183: new Thread("AddingMultipleTransactions") {
1184: @Override
1185: public void run() {
1186: addNewTransaction(tTemp);
1187: }
1188: }.start();
1189: } else
1190: addNewTransaction(transaction);
1191: } else {
1192: try {
1193: if (transactionTypeDAO
1194: .isTransferencia((TransactionType) jcbTipo
1195: .getPersistentObject(jcbTipo
1196: .getSelectedIndex()))) {
1197: Transaction temp = getFiltro();
1198: temp.setTransferencia(transaction
1199: .getTransferencia());
1200: temp.setTipoConta(transaction.getTipoContaTransf());
1201: temp.setConta(transaction.getContaTransf());
1202: temp.setTipoContaTransf(transaction.getTipoConta());
1203: temp.setContaTransf(transaction.getConta());
1204: temp = controller.getBy(temp);
1205:
1206: Transaction peer = new Transaction(temp.getAsMap());
1207: peer.setId(temp.getId());
1208: peer.setValor(new Double(transaction.getValor()
1209: .doubleValue()
1210: * -1));
1211: peer.setDia(transaction.getDia());
1212: peer.setEhPrevisao(false);
1213: controller.atualizar(peer);
1214: }
1215: controller.atualizar(transaction);
1216: } catch (SQLException sqle) {
1217: JOptionPane.showMessageDialog(this , sqle.getMessage(),
1218: ErrosDeDadosMessages.getMessages().getString(
1219: "MessageTitle"),
1220: JOptionPane.WARNING_MESSAGE);
1221: telaPrincipal.getPainelBotoes().setOcorreuErro(true);
1222: return;
1223: }
1224: }
1225:
1226: transaction = null;
1227: refreshTabelaLancamentos();
1228: }
1229:
1230: /**
1231: * Add a new Transaction to the data base
1232: */
1233: private void addNewTransaction(final Transaction transaction) {
1234: try {
1235: if (transactionTypeDAO
1236: .isTransferencia((TransactionType) jcbTipo
1237: .getPersistentObject(jcbTipo
1238: .getSelectedIndex()))) {
1239: transaction.setTransferencia(new Double(System
1240: .currentTimeMillis() / 1000d));
1241: Transaction peer = getFiltro();
1242: peer.setDados(transaction.getAsMap());
1243: peer.setTipoConta(transaction.getTipoContaTransf());
1244: peer.setConta(transaction.getContaTransf());
1245: peer.setTipoContaTransf(transaction.getTipoConta());
1246: peer.setContaTransf(transaction.getConta());
1247: peer.setValor(new Double(transaction.getValor()
1248: .doubleValue()
1249: * -1));
1250: transaction.validateTransfer(null);
1251: peer.validateTransfer(null);
1252: controller.adicionarNovo(peer);
1253: }
1254: controller.adicionarNovo(transaction);
1255: } catch (SQLException sqle) {
1256: MessageView message = (MessageView) GFPController
1257: .getGFPController().getContexto().get(
1258: GFPController.RODAPE_MESSAGER);
1259: message.showMessage(ErrosDeDadosMessages.getMessages()
1260: .getString("MessageTitle"), sqle.getMessage(),
1261: false);
1262: telaPrincipal.getPainelBotoes().setOcorreuErro(true);
1263: return;
1264: }
1265: }
1266:
1267: /**
1268: * @param e
1269: */
1270: public void novo(ActionEvent e) {
1271: lancamentoInit();
1272: controller.setAdicionandoNovo(true);
1273: }
1274:
1275: /**
1276: * @param evt
1277: */
1278: public void compra_VendaItemStateChanged(ItemEvent evt) {
1279: jcbProduto.setEnabled(jcbCompra_Venda.isSelected());
1280: if (jcbCompra_Venda.isSelected())
1281: jcbProduto.requestFocus();
1282: }
1283:
1284: /**
1285: * @param evt
1286: */
1287: public void pago_RecebidoItemStateChanged(ItemEvent evt) {
1288: jcbEntidade.setEnabled(jcbPago_Recebido.isSelected());
1289: if (jcbPago_Recebido.isSelected())
1290: jcbEntidade.requestFocus();
1291: }
1292:
1293: /**
1294: * @param e
1295: */
1296: public void telaLancamentosFechada(InternalFrameEvent e) {
1297: GFPController.getGFPController().removeTela(this );
1298: }
1299:
1300: /**
1301: * @param e
1302: */
1303: public void limpar(ActionEvent e) {
1304: telaPrincipal.showRequiredFields();
1305: ictfDia.setDate(null);
1306: telaPrincipal.getTextAreaDescricao().setText("");
1307: jcbRepetirLancamentoCada.setSelected(false);
1308: jcbTipo.setSelectedIndex(0);
1309: jcbTipoIntervalorRepeticao.setSelectedIndex(0);
1310: jsIntervalorRepeticao.setValue(new Integer(0));
1311: mtfValor.setValue(new Double(0.00));
1312: jcbCompra_Venda.setSelected(false);
1313: jcbProduto.setSelectedIndex(0);
1314: jcbPago_Recebido.setSelected(false);
1315: jcbEntidade.setSelectedIndex(0);
1316: transaction = null;
1317: controller.setAdicionandoNovo(false);
1318: jcbTipo.setEnabled(true);
1319: jcbTipoContaTransferencia.setSelectedIndex(0);
1320: jcbTipoContaTransferencia.setEnabled(true);
1321: jcbContaTransferencia.setEnabled(true);
1322: jcbCompra_Venda.setVisible(true);
1323: jcbProduto.setVisible(true);
1324: jcbTipoContaTransferencia.setVisible(false);
1325: jcbContaTransferencia.setVisible(false);
1326: firstValue = 0;
1327: telaPrincipal.getPainelBotoes().dadosCarregados(false);
1328: }
1329:
1330: /**
1331: * @param e
1332: */
1333: public void repetirLancamentoCadaItemStateChanged(ItemEvent e) {
1334: jlVezesACada.setEnabled(jcbRepetirLancamentoCada.isSelected());
1335: jsVezes.setEnabled(jcbRepetirLancamentoCada.isSelected());
1336: jsIntervalorRepeticao.setEnabled(jcbRepetirLancamentoCada
1337: .isSelected());
1338: jcbTipoIntervalorRepeticao.setEnabled(jcbRepetirLancamentoCada
1339: .isSelected());
1340: }
1341:
1342: /**
1343: *
1344: */
1345: protected void lancamentoInit() {
1346: transaction = new Transaction();
1347: }
1348:
1349: /**
1350: *
1351: */
1352: protected void loadLancamento() {
1353: transaction.setDescricao(telaPrincipal.getTextAreaDescricao()
1354: .getText());
1355: transaction.setDia(ictfDia.getDate());
1356: transaction.setEhPrevisao(Boolean.FALSE);
1357:
1358: if (jcbPago_Recebido.isSelected())
1359: if (jcbEntidade.getSelectedIndex() > 0)
1360: try {
1361: transaction
1362: .setEntidadeEnvolvida(((Contact) jcbEntidade
1363: .getPersistentObject(jcbEntidade
1364: .getSelectedIndex()))
1365: .getId());
1366: } catch (Exception e) {
1367: ((SimpleLog) GFPController.getGFPController()
1368: .getContexto().get(GFPController.LOG))
1369: .log("Erro ao setar entidade para lancamento!");
1370: ((SimpleLog) GFPController.getGFPController()
1371: .getContexto().get(GFPController.LOG))
1372: .log(e.getLocalizedMessage());
1373: ((SimpleLog) GFPController.getGFPController()
1374: .getContexto().get(GFPController.LOG))
1375: .log(e);
1376: }
1377:
1378: transaction
1379: .setIntervaloRepeticao((Integer) jsIntervalorRepeticao
1380: .getValue());
1381: transaction.setTipoIntervaloRepeticao(new Integer(
1382: jcbTipoIntervalorRepeticao.getSelectedIndex()));
1383:
1384: if (jcbCompra_Venda.isSelected())
1385: if (jcbProduto.getSelectedIndex() > 0)
1386: try {
1387: transaction.setProduto(((Assets) jcbProduto
1388: .getPersistentObject(jcbProduto
1389: .getSelectedIndex())).getId());
1390: } catch (Exception e) {
1391: ((SimpleLog) GFPController.getGFPController()
1392: .getContexto().get(GFPController.LOG))
1393: .log("Erro ao setar produto para lancamento!");
1394: ((SimpleLog) GFPController.getGFPController()
1395: .getContexto().get(GFPController.LOG))
1396: .log(e.getLocalizedMessage());
1397: ((SimpleLog) GFPController.getGFPController()
1398: .getContexto().get(GFPController.LOG))
1399: .log(e);
1400: }
1401:
1402: boolean despesa = false;
1403: if (jcbTipo.getSelectedIndex() > 0)
1404: try {
1405: transaction
1406: .setTipo(((TransactionType) jcbTipo
1407: .getPersistentObject(jcbTipo
1408: .getSelectedIndex())).getId());
1409: despesa = transactionTypeDAO2
1410: .isDespesa((TransactionType) jcbTipo
1411: .getPersistentObject(jcbTipo
1412: .getSelectedIndex()));
1413: } catch (Exception e) {
1414: ((SimpleLog) GFPController.getGFPController()
1415: .getContexto().get(GFPController.LOG))
1416: .log("Erro ao setar tipo de lancamento!");
1417: ((SimpleLog) GFPController.getGFPController()
1418: .getContexto().get(GFPController.LOG)).log(e
1419: .getLocalizedMessage());
1420: ((SimpleLog) GFPController.getGFPController()
1421: .getContexto().get(GFPController.LOG)).log(e);
1422: }
1423: /*
1424: * if (jcbTransferencia.getSelectedIndex() > 0)
1425: * try {
1426: * lancamento.setLancamentoTransferencia(((Integer)((DataBaseComboBoxModel)jcbTransferencia.getModel()).getDataAt(jcbTransferencia.getSelectedIndex()).get("id")).intValue());
1427: * }
1428: * catch(Exception sqle) { }
1429: */
1430: if (jcbTipoConta.getSelectedIndex() > 0) {
1431: try {
1432: transaction
1433: .setTipoConta(""
1434: + ((AccountType) jcbTipoConta
1435: .getSelectedItem()).getId());
1436: } catch (Exception e) {
1437: ((SimpleLog) GFPController.getGFPController()
1438: .getContexto().get(GFPController.LOG))
1439: .log("Erro ao setar tipo da conta do lancamento!");
1440: ((SimpleLog) GFPController.getGFPController()
1441: .getContexto().get(GFPController.LOG)).log(e
1442: .getLocalizedMessage());
1443: ((SimpleLog) GFPController.getGFPController()
1444: .getContexto().get(GFPController.LOG)).log(e);
1445: }
1446:
1447: if (jcbConta.getSelectedIndex() > 0) {
1448: try {
1449: transaction.setConta((Integer) jcbConta.getDataAt(
1450: jcbConta.getSelectedIndex()).get("Id"));
1451: } catch (Exception e) {
1452: ((SimpleLog) GFPController.getGFPController()
1453: .getContexto().get(GFPController.LOG))
1454: .log("Erro ao setar conta para o lancamento!");
1455: ((SimpleLog) GFPController.getGFPController()
1456: .getContexto().get(GFPController.LOG))
1457: .log(e.getLocalizedMessage());
1458: ((SimpleLog) GFPController.getGFPController()
1459: .getContexto().get(GFPController.LOG))
1460: .log(e);
1461: }
1462: }
1463: }
1464:
1465: if (mtfValor.getValue() != null
1466: && !(mtfValor.getValue() instanceof Float)
1467: && !((Double) mtfValor.getValue()).equals(Double
1468: .valueOf("0.00"))) {
1469: if ((Double) mtfValor.getValue() > 0 && despesa)
1470: transaction.setValor(-1 * (Double) mtfValor.getValue());
1471: else
1472: transaction.setValor((Double) mtfValor.getValue());
1473: }
1474:
1475: if (jcbRepetirLancamentoCada.isSelected())
1476: transaction.setVezesPraRealizar(((Integer) jsVezes
1477: .getValue()).intValue());
1478:
1479: try {
1480: if (transactionTypeDAO
1481: .isTransferencia((TransactionType) jcbTipo
1482: .getSelectedItem())) {
1483: if (jcbContaTransferencia.getSelectedItem() != null)
1484: transaction
1485: .setContaTransf(((BasicGFPDataObject) jcbContaTransferencia
1486: .getSelectedItem()).getId());
1487: if (jcbTipoContaTransferencia.getSelectedItem() != null)
1488: transaction
1489: .setTipoContaTransf(((AccountType) jcbTipoContaTransferencia
1490: .getSelectedItem()).getId()
1491: .toString());
1492: }
1493: } catch (SQLException e) {
1494: ((SimpleLog) GFPController.getGFPController().getContexto()
1495: .get(GFPController.LOG))
1496: .log("Erro ao setar conta para transferencia!");
1497: ((SimpleLog) GFPController.getGFPController().getContexto()
1498: .get(GFPController.LOG)).log(e
1499: .getLocalizedMessage());
1500: ((SimpleLog) GFPController.getGFPController().getContexto()
1501: .get(GFPController.LOG)).log(e);
1502: }
1503:
1504: //Indicamos se é pra incluir subtipos
1505: transaction.setIncluirSubtipos(jcbIncluirSubTipos.isSelected());
1506: }
1507:
1508: /**
1509: *
1510: */
1511: private void editarLancamento() {
1512: telaPrincipal.hideRequiredFields();
1513: if (transaction == null)
1514: return;
1515: telaPrincipal.getTextAreaDescricao().setText(
1516: transaction.getDescricao());
1517: ictfDia.setDate(transaction.getDia());
1518:
1519: if (transaction.getEntidadeEnvolvida() != null) {
1520: jcbPago_Recebido.setSelected(true);
1521: try {
1522: jcbEntidade.setSelectedItem(transaction
1523: .getEntidadeEnvolvida(), "Id");
1524: } catch (SQLException e) {
1525: ((SimpleLog) GFPController.getGFPController()
1526: .getContexto().get(GFPController.LOG))
1527: .log("Erro ao carregar entidade do lancamento: "
1528: + transaction);
1529: ((SimpleLog) GFPController.getGFPController()
1530: .getContexto().get(GFPController.LOG)).log(e
1531: .getLocalizedMessage());
1532: ((SimpleLog) GFPController.getGFPController()
1533: .getContexto().get(GFPController.LOG)).log(e);
1534: }
1535: } else {
1536: jcbEntidade.setSelectedIndex(0);
1537: jcbPago_Recebido.setSelected(false);
1538: }
1539:
1540: if (transaction.getIntervaloRepeticao() != null)
1541: jsIntervalorRepeticao.setValue(transaction
1542: .getIntervaloRepeticao());
1543: if (transaction.getTipoIntervaloRepeticao() != null)
1544: jcbTipoIntervalorRepeticao.setSelectedIndex(transaction
1545: .getTipoIntervaloRepeticao().intValue());
1546:
1547: if (transaction.getProduto() != null) {
1548: jcbCompra_Venda.setSelected(true);
1549: try {
1550: jcbProduto.setSelectedItem(transaction.getProduto(),
1551: "Id");
1552: } catch (SQLException e) {
1553: ((SimpleLog) GFPController.getGFPController()
1554: .getContexto().get(GFPController.LOG))
1555: .log("Erro ao carregar produto do lancamento: "
1556: + transaction);
1557: ((SimpleLog) GFPController.getGFPController()
1558: .getContexto().get(GFPController.LOG)).log(e
1559: .getLocalizedMessage());
1560: ((SimpleLog) GFPController.getGFPController()
1561: .getContexto().get(GFPController.LOG)).log(e);
1562: }
1563: } else {
1564: jcbProduto.setSelectedIndex(0);
1565: jcbCompra_Venda.setSelected(false);
1566: }
1567:
1568: try {
1569: jcbTipo.setSelectedItem(transaction.getTipo(), "Id");
1570: } catch (SQLException e) {
1571: ((SimpleLog) GFPController.getGFPController().getContexto()
1572: .get(GFPController.LOG))
1573: .log("Erro ao carregar tipo do lancamento: "
1574: + transaction);
1575: ((SimpleLog) GFPController.getGFPController().getContexto()
1576: .get(GFPController.LOG)).log(e
1577: .getLocalizedMessage());
1578: ((SimpleLog) GFPController.getGFPController().getContexto()
1579: .get(GFPController.LOG)).log(e);
1580: }
1581: /*
1582: * try { ((DataBaseComboBoxModel)jcbTransferencia.getModel()).setSelectedItem(new Integer(lancamento.getEntidade()), Lancamento.ID); }
1583: * catch(SQLException sqle) { }
1584: */
1585: try {
1586: jcbTipoConta.setSelectedItem(new AccountTypeDAO()
1587: .getBy(new AccountType(Integer.valueOf(transaction
1588: .getTipoConta()))));
1589: } catch (SQLException e) {
1590: ((SimpleLog) GFPController.getGFPController().getContexto()
1591: .get(GFPController.LOG))
1592: .log("Erro ao carregar tipo de conta para o lancamento: "
1593: + transaction);
1594: ((SimpleLog) GFPController.getGFPController().getContexto()
1595: .get(GFPController.LOG)).log(e
1596: .getLocalizedMessage());
1597: ((SimpleLog) GFPController.getGFPController().getContexto()
1598: .get(GFPController.LOG)).log(e);
1599: }
1600:
1601: try {
1602: jcbConta.setSelectedItem(transaction.getConta(), "Id");
1603: } catch (SQLException e) {
1604: ((SimpleLog) GFPController.getGFPController().getContexto()
1605: .get(GFPController.LOG))
1606: .log("Erro ao carregar conta para o lancamento: "
1607: + transaction);
1608: ((SimpleLog) GFPController.getGFPController().getContexto()
1609: .get(GFPController.LOG)).log(e
1610: .getLocalizedMessage());
1611: ((SimpleLog) GFPController.getGFPController().getContexto()
1612: .get(GFPController.LOG)).log(e);
1613: }
1614:
1615: mtfValor.setValue(transaction.getValor());
1616:
1617: try {
1618: if (transactionTypeDAO
1619: .isTransferencia((TransactionType) jcbTipo
1620: .getSelectedItem())) {
1621: jcbTipo.setEnabled(false);
1622: jcbTipoContaTransferencia.setEnabled(false);
1623: jcbContaTransferencia.setEnabled(false);
1624: jcbTipoContaTransferencia.setSelectedItem(transaction
1625: .getTipoContaTransf(), "Id");
1626: jcbContaTransferencia.setSelectedItem(transaction
1627: .getContaTransf(), "Id");
1628: } else {
1629: jcbTipo.setEnabled(true);
1630: jcbTipoContaTransferencia.setEnabled(true);
1631: jcbContaTransferencia.setEnabled(true);
1632: jcbTipoContaTransferencia.setSelectedIndex(0);
1633: }
1634: } catch (SQLException e) {
1635: // TODO Auto-generated catch block
1636: e.printStackTrace();
1637: }
1638:
1639: telaPrincipal.getPainelBotoes().dadosCarregados(true);
1640: }
1641:
1642: /**
1643: *
1644: */
1645: private void refreshTabelaLancamentos() {
1646: try {
1647: Transaction filtro = getFiltro();
1648:
1649: //Seta o tipo da conta a ter o movimento listado
1650: if (jcbTipoConta.getSelectedItem() != null)
1651: filtro
1652: .setTipoConta(""
1653: + ((AccountType) jcbTipoConta
1654: .getSelectedItem()).getId());
1655:
1656: //Seta a conta a ter o movimento listado
1657: if (jcbConta.getSelectedIndex() >= 1) {
1658: filtro.setConta((Integer) jcbConta.getDataAt(
1659: jcbConta.getSelectedIndex()).get("Id"));
1660: jtLancamentos.hideColumn("Conta");
1661: } else
1662: jtLancamentos.showColumn("Conta", 120);
1663:
1664: if (jcbFiltrarPorData.isSelected()) {
1665: //Seta o mes cuje o movimento será listado
1666: Calendar inicioMes = Calendar.getInstance();
1667: Calendar fimMes = Calendar.getInstance();
1668:
1669: if (ictfLancamentosDe.getDate() != null) {
1670: inicioMes.setTime(ictfLancamentosDe.getDate());
1671: } else {
1672: inicioMes.setTime(new Date());
1673: inicioMes.set(Calendar.DAY_OF_MONTH, 1);
1674: }
1675:
1676: if (ictfLancamentosAte.getDate() != null) {
1677: fimMes.setTime(ictfLancamentosAte.getDate());
1678: } else {
1679: fimMes.set(Calendar.MONTH, inicioMes
1680: .get(Calendar.MONTH));
1681: fimMes.add(Calendar.MONTH, 1);
1682: fimMes.set(Calendar.DAY_OF_MONTH, 0);
1683: }
1684: filtro
1685: .addCondicaoExtra(new SQLCondition<java.sql.Date>(
1686: "Dia", new java.sql.Date(inicioMes
1687: .getTime().getTime()),
1688: new java.sql.Date(fimMes.getTime()
1689: .getTime()), Condicao.BETWEEN));
1690: }
1691:
1692: if (jcbOcultarPrevisoes.isSelected()) {
1693: filtro.setEhPrevisao(Boolean.FALSE);
1694: }
1695:
1696: //Informamos se é pra incluir os subtipos
1697: filtro.setIncluirSubtipos(jcbIncluirSubTipos.isSelected());
1698:
1699: //Aplica o filtro
1700: jtLancamentos.setDataType(filtro);
1701:
1702: //Realiaza a filtragem
1703: jtLancamentos.filter();
1704: valoresFiltradosNaTabela = ((TransactionDAO<Transaction>) controller)
1705: .getTotalNoPeriodo(filtro);
1706: jlValorTotalLancadoFiltrado.setText(""
1707: + valoresFiltradosNaTabela);
1708:
1709: //Calcula do saldo atual da conta(s) e exibe no campo "Saldo no Fim do Mes"
1710: Transaction filtro2 = getFiltro();
1711: filtro2.setTipoConta(filtro.getTipoConta()); //Tipo da conta que queremos o saldo
1712: filtro2.setConta(filtro.getConta()); //Account que queremos o saldo
1713: if (jcbOcultarPrevisoes.isSelected()) {
1714: filtro2.setEhPrevisao(Boolean.FALSE);
1715: }
1716:
1717: Calendar fimMes = Calendar.getInstance(); //Iniciamos o calendar com o mes atual
1718: if (jcbFiltrarPorData.isSelected()) //Se for para filtrar por uma data especifica
1719: {
1720: if (ictfLancamentosAte.getDate() != null) //E a data fim estiver especificada (caso de não ser o mes atual)
1721: fimMes.setTime(ictfLancamentosAte.getDate()); //Calculamos o saldo para o fim do mês que está sendo consultado
1722: else
1723: fimMes.setTime(new Date());
1724: }
1725: fimMes.add(Calendar.MONTH, 1); //Vamos para o mes seguinte
1726: fimMes.set(Calendar.DAY_OF_MONTH, 0); //Voltamos para o ultimo dia do mes anterior
1727:
1728: filtro2.addCondicaoExtra(new SQLCondition<java.sql.Date>(
1729: "Dia",
1730: new java.sql.Date(fimMes.getTime().getTime()),
1731: Condicao.MENOR_IGUAL));
1732: filtro2.setIncluirSubtipos(jcbIncluirSubTipos.isSelected());
1733:
1734: jlValorSaldoAtual.setText(""
1735: + ((TransactionDAO<Transaction>) controller)
1736: .getTotalNoPeriodo(filtro2));
1737:
1738: } catch (Exception e) {
1739: ((SimpleLog) GFPController.getGFPController().getContexto()
1740: .get(GFPController.LOG))
1741: .log("Erro ao atualizar tabela de lancamentos!");
1742: ((SimpleLog) GFPController.getGFPController().getContexto()
1743: .get(GFPController.LOG)).log(e
1744: .getLocalizedMessage());
1745: ((SimpleLog) GFPController.getGFPController().getContexto()
1746: .get(GFPController.LOG)).log(e);
1747: }
1748: }
1749:
1750: /**
1751: * @param e
1752: */
1753: public void filtrar(ActionEvent e) {
1754: lancamentoInit();
1755: loadLancamento();
1756:
1757: //Indicamos se é ou não para ocultar as previsões
1758: if (jcbOcultarPrevisoes.isSelected()) {
1759: transaction.setEhPrevisao(Boolean.FALSE);
1760: } else {
1761: transaction.setEhPrevisao(null);
1762: }
1763:
1764: //Seta a conta a ter o movimento listado
1765: if (jcbConta.getSelectedIndex() > 0) {
1766: jtLancamentos.hideColumn("Conta");
1767: } else
1768: jtLancamentos.showColumn("Conta", 120);
1769:
1770: if (jcbFiltrarPorData.isSelected()) {
1771: //Seta o mes cuje o movimento será listado
1772: Calendar inicioMes = Calendar.getInstance();
1773: Calendar fimMes = Calendar.getInstance();
1774:
1775: if (ictfLancamentosDe.getDate() != null) {
1776: inicioMes.setTime(ictfLancamentosDe.getDate());
1777: } else {
1778: inicioMes.setTime(new Date());
1779: inicioMes.set(Calendar.DAY_OF_MONTH, 1);
1780: }
1781:
1782: if (ictfLancamentosAte.getDate() != null) {
1783: fimMes.setTime(ictfLancamentosAte.getDate());
1784: } else {
1785: fimMes.setTime(new Date());
1786: fimMes.add(Calendar.MONTH, 1);
1787: fimMes.set(Calendar.DAY_OF_MONTH, 0);
1788: }
1789: transaction
1790: .addCondicaoExtra(new SQLCondition<java.sql.Date>(
1791: "Dia", new java.sql.Date(inicioMes
1792: .getTime().getTime()),
1793: new java.sql.Date(fimMes.getTime()
1794: .getTime()), Condicao.BETWEEN));
1795: }
1796:
1797: jtLancamentos.setDataType(transaction);
1798: try {
1799: jtLancamentos.filter();
1800: } catch (Exception e2) {
1801: ((SimpleLog) GFPController.getGFPController().getContexto()
1802: .get(GFPController.LOG))
1803: .log("Erro ao filtar tabela de lancamentos: "
1804: + transaction);
1805: ((SimpleLog) GFPController.getGFPController().getContexto()
1806: .get(GFPController.LOG)).log(e2
1807: .getLocalizedMessage());
1808: ((SimpleLog) GFPController.getGFPController().getContexto()
1809: .get(GFPController.LOG)).log(e2);
1810: }
1811: try {
1812: valoresFiltradosNaTabela = ((TransactionDAO<Transaction>) controller)
1813: .getTotalNoPeriodo(transaction);
1814: jlValorTotalLancadoFiltrado.setText(""
1815: + valoresFiltradosNaTabela);
1816: } catch (SQLException e1) {
1817: ((SimpleLog) GFPController.getGFPController().getContexto()
1818: .get(GFPController.LOG))
1819: .log("Erro ao calcular valor total filtrado!");
1820: ((SimpleLog) GFPController.getGFPController().getContexto()
1821: .get(GFPController.LOG)).log(e1
1822: .getLocalizedMessage());
1823: ((SimpleLog) GFPController.getGFPController().getContexto()
1824: .get(GFPController.LOG)).log(e1);
1825: }
1826: transaction = null;
1827: }
1828:
1829: /**
1830: * Preenche o campo de saldo em:... com o saldo para a data selecionada
1831: * @param e
1832: */
1833: public void calculaSaldoEm(ActionEvent e) {
1834: Transaction filtro = getFiltro();
1835:
1836: //Seta o tipo da conta a ter o movimento listado
1837: if (jcbTipoConta.getSelectedItem() != null) {
1838: filtro.setTipoConta(""
1839: + ((AccountType) jcbTipoConta.getSelectedItem())
1840: .getId());
1841: }
1842:
1843: //Seta a conta a ter o movimento listado
1844: if (jcbConta.getSelectedIndex() >= 1) {
1845: try {
1846: filtro.setConta((Integer) jcbConta.getDataAt(
1847: jcbConta.getSelectedIndex()).get("Id"));
1848: } catch (SQLException ex) {
1849: ((SimpleLog) GFPController.getGFPController()
1850: .getContexto().get(GFPController.LOG))
1851: .log("Erro ao atribuir conta para filtro de lancamento!");
1852: ((SimpleLog) GFPController.getGFPController()
1853: .getContexto().get(GFPController.LOG)).log(ex
1854: .getLocalizedMessage());
1855: ((SimpleLog) GFPController.getGFPController()
1856: .getContexto().get(GFPController.LOG)).log(ex);
1857: }
1858: }
1859:
1860: //Seta o mes cuje o movimento será listado
1861: Calendar fimMes = Calendar.getInstance();
1862:
1863: fimMes.setTime(ictfSaldoEm.getDate());
1864:
1865: //Calcula do saldo atual da conta(s)
1866: filtro.addCondicaoExtra(new SQLCondition<java.sql.Date>("Dia",
1867: new java.sql.Date(fimMes.getTime().getTime()),
1868: Condicao.MENOR_IGUAL));
1869:
1870: if (jcbOcultarPrevisoes.isSelected()) {
1871: filtro.setEhPrevisao(Boolean.FALSE);
1872: }
1873: filtro.setIncluirSubtipos(jcbIncluirSubTipos.isSelected());
1874:
1875: try {
1876: jlValorSaldoEm.setText(""
1877: + ((TransactionDAO<Transaction>) controller)
1878: .getTotalNoPeriodo(filtro));
1879: } catch (SQLException ex) {
1880: ((SimpleLog) GFPController.getGFPController().getContexto()
1881: .get(GFPController.LOG))
1882: .log("Erro ao calcular saldo em: " + fimMes);
1883: ((SimpleLog) GFPController.getGFPController().getContexto()
1884: .get(GFPController.LOG)).log(ex
1885: .getLocalizedMessage());
1886: ((SimpleLog) GFPController.getGFPController().getContexto()
1887: .get(GFPController.LOG)).log(ex);
1888: }
1889: }
1890:
1891: /**
1892: * @param e
1893: */
1894: public void loadFromTable(ListSelectionEvent e) {
1895: if (TransactionWindow.this .isVisible()) {
1896: if (jtLancamentos.getSelectedRowCount() == 1) {
1897: try {
1898: transaction = jtLancamentos
1899: .getPersistentObject(jtLancamentos
1900: .getSelectedRow());
1901: editarLancamento();
1902: } catch (SQLException sqle) {
1903: ((SimpleLog) GFPController.getGFPController()
1904: .getContexto().get(GFPController.LOG))
1905: .log("Erro ao carregar lancamento da tabela!");
1906: ((SimpleLog) GFPController.getGFPController()
1907: .getContexto().get(GFPController.LOG))
1908: .log(sqle.getLocalizedMessage());
1909: ((SimpleLog) GFPController.getGFPController()
1910: .getContexto().get(GFPController.LOG))
1911: .log(sqle);
1912: }
1913: jlValorTotalLancadoFiltrado.setText(""
1914: + valoresFiltradosNaTabela);
1915: } else if (jtLancamentos.getSelectedRowCount() > 1) {
1916: limpar(null);
1917: int[] linhas = jtLancamentos.getSelectedRows();
1918: double valor = 0;
1919: for (int i : linhas)
1920: try {
1921: valor += jtLancamentos.getPersistentObject(i)
1922: .getValor();
1923: } catch (SQLException sqle) {
1924: ((SimpleLog) GFPController.getGFPController()
1925: .getContexto().get(GFPController.LOG))
1926: .log("Erro ao somar valores de várias linhas da tabela");
1927: ((SimpleLog) GFPController.getGFPController()
1928: .getContexto().get(GFPController.LOG))
1929: .log(sqle.getLocalizedMessage());
1930: ((SimpleLog) GFPController.getGFPController()
1931: .getContexto().get(GFPController.LOG))
1932: .log(sqle);
1933: }
1934: jlValorTotalLancadoFiltrado.setText("" + valor);
1935: }
1936: }
1937: }
1938:
1939: /**
1940: * @see JInternalFrame#setTitle(java.lang.String)
1941: */
1942: @Override
1943: public void setTitle(String title) {
1944: title = TelaLancamentosMessages.getMessages().getString(
1945: "lancamentos")
1946: + " - "
1947: + (jcbTipoConta.getSelectedItem() == null ? ""
1948: : TelaLancamentosMessages.getMessages()
1949: .getString(
1950: ((AccountType) jcbTipoConta
1951: .getSelectedItem())
1952: .getNome()))
1953: + " - "
1954: + (jcbConta.getSelectedItem() != null ? ((PersistentObject) jcbConta
1955: .getSelectedItem())
1956: .getAsString(PersistentObject.CURTO)
1957: : "");
1958: super .setTitle(title);
1959: }
1960:
1961: /**
1962: * Cria um lancamento para ser usado como filtro
1963: * @return
1964: */
1965: protected Transaction getFiltro() {
1966: return new Transaction();
1967: }
1968: }
|