001: /*
002: * AssetsWindow.java Created on 28 de Março de 2004, 01:30
003: */
004:
005: package br.com.gfp.windows;
006:
007: import java.awt.BorderLayout;
008: import java.awt.Dimension;
009: import java.awt.GridBagConstraints;
010: import java.awt.GridBagLayout;
011: import java.awt.Insets;
012: import java.awt.event.ActionEvent;
013: import java.awt.event.ActionListener;
014: import java.awt.event.ItemEvent;
015: import java.awt.event.ItemListener;
016: import java.sql.SQLException;
017: import java.text.NumberFormat;
018: import java.util.HashMap;
019:
020: import javax.swing.JButton;
021: import javax.swing.JCheckBox;
022: import javax.swing.JFrame;
023: import javax.swing.JLabel;
024: import javax.swing.JOptionPane;
025: import javax.swing.JPanel;
026: import javax.swing.SpinnerNumberModel;
027: import javax.swing.WindowConstants;
028: import javax.swing.event.ChangeEvent;
029: import javax.swing.event.ChangeListener;
030: import javax.swing.event.ListSelectionEvent;
031: import javax.swing.event.ListSelectionListener;
032:
033: import br.com.gfp.actions.AbrirTelaParaInsercaoAction;
034: import br.com.gfp.dao.AssetsDAO;
035: import br.com.gfp.dao.GFPController;
036: import br.com.gfp.data.Assets;
037: import br.com.gfp.data.Contact;
038: import br.com.gfp.internationalization.ErrosDeDadosMessages;
039: import br.com.gfp.internationalization.TelaBemMessages;
040: import br.com.gfp.reports.ReportFactory;
041: import br.com.gfp.util.SimpleLog;
042: import br.com.gfp.windows.componentes.GFPHeaderRenderer;
043: import br.com.gfp.windows.componentes.GFPTableCellRenderer;
044: import br.com.gfpshare.beans.DBComboBox;
045: import br.com.gfpshare.beans.GeneralEventHandler;
046: import br.com.gfpshare.beans.ZCalendarTextField;
047: import br.com.gfpshare.beans.ZLabel;
048: import br.com.gfpshare.beans.ZMoneyTextField;
049: import br.com.gfpshare.beans.ZSpinner;
050: import br.com.gfpshare.beans.ZTextField;
051: import br.com.gfpshare.beans.aplicativos.IconeFactory;
052: import br.com.gfpshare.beans.aplicativos.PainelTelaBasica;
053: import br.com.gfpshare.beans.table.DBTable;
054: import br.com.gfpshare.db.DAOCreationException;
055: import br.com.gfpshare.db.DAOListener;
056:
057: /**
058: * @author Igor Regis da Silva Simões
059: */
060: public class AssetsWindow extends GFPInternalFrame<Assets> {
061:
062: private JFrame owner = null;
063:
064: private Assets assets = new Assets();
065:
066: private static final NumberFormat CURRENCY_INSTANCE_FORMATER = NumberFormat
067: .getCurrencyInstance();
068:
069: private ZCalendarTextField ictfDataCompra;
070:
071: private ZCalendarTextField ictfDataVenda;
072:
073: private JCheckBox jcbDataVenda;
074:
075: private DBComboBox jcbLocalCompra;
076:
077: private ZLabel jlDataCompra;
078:
079: private ZLabel jlDepreciacao;
080:
081: private ZLabel jlLocalCompra;
082:
083: private ZLabel jlNome;
084:
085: private ZLabel jlValorAtual;
086:
087: private ZLabel jlValorCompra;
088:
089: private ZLabel jlValorVenda;
090:
091: private ZLabel jlvValorAtual;
092:
093: private DBTable jtBens;
094:
095: private ZTextField jtfNome;
096:
097: private ZMoneyTextField mtfValorCompra;
098:
099: private ZMoneyTextField mtfValorVenda;
100:
101: private ZSpinner jsDepreciacao;
102:
103: private PainelTelaBasica telaPrincipal;
104:
105: private JPanel southPanel;
106:
107: private JLabel jlSomaDosBensLabel;
108:
109: private JLabel jlSomaDosBens;
110:
111: /**
112: * Creates new form TransactionWindow
113: *
114: * @param owner O Frame propietário desta janela
115: */
116: public AssetsWindow(JFrame owner) {
117: controller = new AssetsDAO();
118: this .owner = owner;
119: initComponents();
120: setSize(720, 450);
121: }
122:
123: public AssetsWindow(JFrame owner, DAOListener<Assets> listener) {
124: this (owner);
125: setListener(listener);
126: }
127:
128: /**
129: * 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
130: * regenerated by the Form Editor.
131: */
132: private void initComponents() {
133: setClosable(true);
134: setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
135: setIconifiable(true);
136: setMaximizable(true);
137: setResizable(true);
138: setTitle(TelaBemMessages.getMessages().getString("bens")); //$NON-NLS-1$
139: setFrameIcon(IconeFactory.getIconeFactory().getImageIcon(
140: IconeFactory.BENS_PEQUENA));
141:
142: GridBagConstraints gridBagConstraints;
143: telaPrincipal = new PainelTelaBasica();
144:
145: jtBens = new DBTable(new Assets(), new GFPHeaderRenderer());
146: jtBens.hideColumn("Id"); //$NON-NLS-1$
147:
148: jtBens.getColumn(jtBens.getColumnName(1)).setWidth(60);
149: jtBens.getColumn(jtBens.getColumnName(1)).setMinWidth(30);
150:
151: jtBens.getColumn(jtBens.getColumnName(8)).setCellRenderer(
152: new GFPTableCellRenderer(
153: GFPTableCellRenderer.PORCENTAGEM, -1));
154: jtBens.getColumn(jtBens.getColumnName(9)).setCellRenderer(
155: new GFPTableCellRenderer(GFPTableCellRenderer.ENTIDADE,
156: -1));
157:
158: telaPrincipal.setJtDados(jtBens);
159: telaPrincipal.addPrintButtonListener(new PrintListener());
160:
161: jsDepreciacao = new ZSpinner();
162: jlNome = new ZLabel();
163: jtfNome = new ZTextField();
164: jlDepreciacao = new ZLabel();
165: jlValorAtual = new ZLabel();
166: jlvValorAtual = new ZLabel();
167: jlDataCompra = new ZLabel();
168: ictfDataCompra = new ZCalendarTextField();
169: jlValorCompra = new ZLabel();
170: mtfValorCompra = new ZMoneyTextField(owner);
171: jlLocalCompra = new ZLabel();
172: ictfDataVenda = new ZCalendarTextField();
173: mtfValorVenda = new ZMoneyTextField(owner);
174: jlValorVenda = new ZLabel();
175: jcbDataVenda = new JCheckBox();
176: jcbLocalCompra = new DBComboBox(new Contact());
177: southPanel = new JPanel();
178: jlSomaDosBensLabel = new JLabel();
179: jlSomaDosBens = new JLabel();
180:
181: jtBens
182: .getSelectionModel()
183: .addListSelectionListener(
184: (ListSelectionListener) GeneralEventHandler
185: .makeProxy(
186: this ,
187: "loadFromTable", ListSelectionListener.class, "valueChanged")); //$NON-NLS-1$ //$NON-NLS-2$
188:
189: jlNome.setLabelFor(jtfNome);
190: jlNome.setText(TelaBemMessages.getMessages().getString("nome")); //$NON-NLS-1$
191: jlNome.setDisplayedMnemonic(TelaBemMessages.getMessages()
192: .getString("NomeMnemonic").charAt(0));
193: jlNome.setRequiredField(jtfNome);
194: jlNome.setValidationNotNull(true);
195: gridBagConstraints = new GridBagConstraints();
196: gridBagConstraints.gridx = 0;
197: gridBagConstraints.gridy = 0;
198: gridBagConstraints.anchor = GridBagConstraints.WEST;
199: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
200: telaPrincipal.addComponent(jlNome, gridBagConstraints,
201: PainelTelaBasica.DATA_COMPONENTS_AREA);
202:
203: jtfNome.setMinimumSize(new Dimension(100, 19));
204: jtfNome.setPreferredSize(new Dimension(100, 19));
205: jtfNome.setToolTipText(TelaBemMessages.getMessages().getString(
206: "NomeToolTip"));
207: gridBagConstraints = new GridBagConstraints();
208: gridBagConstraints.gridx = 1;
209: gridBagConstraints.gridy = 0;
210: gridBagConstraints.gridwidth = 5;
211: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
212: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
213: telaPrincipal.addComponent(jtfNome, gridBagConstraints,
214: PainelTelaBasica.DATA_COMPONENTS_AREA);
215:
216: jlDepreciacao.setText(TelaBemMessages.getMessages().getString(
217: "indiceDepreciacao")); //$NON-NLS-1$
218: jlDepreciacao.setDisplayedMnemonic(TelaBemMessages
219: .getMessages().getString("indiceDepreciacaoMnemonic")
220: .charAt(0));
221: jlDepreciacao.setLabelFor(jsDepreciacao);
222: gridBagConstraints = new GridBagConstraints();
223: gridBagConstraints.gridx = 0;
224: gridBagConstraints.gridy = 1;
225: gridBagConstraints.gridwidth = 2;
226: gridBagConstraints.anchor = GridBagConstraints.WEST;
227: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
228: telaPrincipal.addComponent(jlDepreciacao, gridBagConstraints,
229: PainelTelaBasica.DATA_COMPONENTS_AREA);
230:
231: jsDepreciacao.setModel(new SpinnerNumberModel(0d, -99d, 99d,
232: 0.01d));
233: jsDepreciacao.setMinimumSize(new Dimension(50, 20));
234: jsDepreciacao.setPreferredSize(new Dimension(50, 20));
235: jsDepreciacao.setToolTipText(TelaBemMessages.getMessages()
236: .getString("DepreciacaoToolTip"));
237: jsDepreciacao
238: .addChangeListener((ChangeListener) GeneralEventHandler
239: .makeProxy(
240: this ,
241: "depreciacaoStateChanged", ChangeListener.class, "stateChanged")); //$NON-NLS-1$ //$NON-NLS-2$
242: gridBagConstraints = new GridBagConstraints();
243: gridBagConstraints.gridx = 1;
244: gridBagConstraints.gridy = 1;
245: gridBagConstraints.anchor = GridBagConstraints.EAST;
246: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
247: telaPrincipal.addComponent(jsDepreciacao, gridBagConstraints,
248: PainelTelaBasica.DATA_COMPONENTS_AREA);
249:
250: jlValorAtual.setText(TelaBemMessages.getMessages().getString(
251: "valorAtual")); //$NON-NLS-1$
252: jlValorAtual.setDisplayedMnemonic(TelaBemMessages.getMessages()
253: .getString("ValorAtualMnemonic").charAt(0));
254: gridBagConstraints = new GridBagConstraints();
255: gridBagConstraints.gridx = 4;
256: gridBagConstraints.gridy = 1;
257: gridBagConstraints.anchor = GridBagConstraints.WEST;
258: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
259: telaPrincipal.addComponent(jlValorAtual, gridBagConstraints,
260: PainelTelaBasica.DATA_COMPONENTS_AREA);
261:
262: jlvValorAtual.setText(NumberFormat.getCurrencyInstance()
263: .getCurrency().getSymbol()); //$NON-NLS-1$
264: gridBagConstraints = new GridBagConstraints();
265: gridBagConstraints.gridx = 5;
266: gridBagConstraints.gridy = 1;
267: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
268: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
269: telaPrincipal.addComponent(jlvValorAtual, gridBagConstraints,
270: PainelTelaBasica.DATA_COMPONENTS_AREA);
271:
272: jlDataCompra.setText(TelaBemMessages.getMessages().getString(
273: "dataCompra")); //$NON-NLS-1$
274: jlDataCompra.setDisplayedMnemonic(TelaBemMessages.getMessages()
275: .getString("DataCompraMnemonic").charAt(0));
276: jlDataCompra.setRequiredField(ictfDataCompra);
277: jlDataCompra.setValidationNotNull(true);
278: gridBagConstraints = new GridBagConstraints();
279: gridBagConstraints.gridx = 0;
280: gridBagConstraints.gridy = 2;
281: gridBagConstraints.anchor = GridBagConstraints.WEST;
282: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
283: telaPrincipal.addComponent(jlDataCompra, gridBagConstraints,
284: PainelTelaBasica.DATA_COMPONENTS_AREA);
285:
286: ictfDataCompra.setMinimumSize(new Dimension(100, 26));
287: ictfDataCompra.setToolTipText(TelaBemMessages.getMessages()
288: .getString("DataCompraToolTip"));
289: gridBagConstraints = new GridBagConstraints();
290: gridBagConstraints.gridx = 1;
291: gridBagConstraints.gridy = 2;
292: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
293: telaPrincipal.addComponent(ictfDataCompra, gridBagConstraints,
294: PainelTelaBasica.DATA_COMPONENTS_AREA);
295:
296: jlValorCompra.setText(TelaBemMessages.getMessages().getString(
297: "valorCompra")); //$NON-NLS-1$
298: jlValorCompra.setDisplayedMnemonic(TelaBemMessages
299: .getMessages().getString("ValorCompraMnemonic").charAt(
300: 0));
301: jlValorCompra.setRequiredField(mtfValorCompra);
302: jlValorCompra
303: .setValidationAction(assets, "validateValorCompra");
304: gridBagConstraints = new GridBagConstraints();
305: gridBagConstraints.gridx = 4;
306: gridBagConstraints.gridy = 2;
307: gridBagConstraints.anchor = GridBagConstraints.WEST;
308: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
309: telaPrincipal.addComponent(jlValorCompra, gridBagConstraints,
310: PainelTelaBasica.DATA_COMPONENTS_AREA);
311:
312: mtfValorCompra.setMinimumSize(new Dimension(100, 20));
313: mtfValorCompra.setPreferredSize(new Dimension(100, 20));
314: mtfValorCompra.setToolTipText(TelaBemMessages.getMessages()
315: .getString("ValorCompraToolTip"));
316: gridBagConstraints = new GridBagConstraints();
317: gridBagConstraints.gridx = 5;
318: gridBagConstraints.gridy = 2;
319: gridBagConstraints.gridwidth = 2;
320: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
321: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
322: telaPrincipal.addComponent(mtfValorCompra, gridBagConstraints,
323: PainelTelaBasica.DATA_COMPONENTS_AREA);
324:
325: jlLocalCompra.setText(TelaBemMessages.getMessages().getString(
326: "localCompra")); //$NON-NLS-1$
327: jlLocalCompra.setDisplayedMnemonic(TelaBemMessages
328: .getMessages().getString("LocalCompraMnemonic").charAt(
329: 0));
330: jlLocalCompra.setRequiredField(jcbLocalCompra);
331: jlLocalCompra.setValidationNotNull(true);
332: gridBagConstraints = new GridBagConstraints();
333: gridBagConstraints.gridx = 0;
334: gridBagConstraints.gridy = 3;
335: gridBagConstraints.gridwidth = 2;
336: gridBagConstraints.anchor = GridBagConstraints.WEST;
337: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
338: telaPrincipal.addComponent(jlLocalCompra, gridBagConstraints,
339: PainelTelaBasica.DATA_COMPONENTS_AREA);
340:
341: ictfDataVenda.setMinimumSize(new Dimension(100, 26));
342: ictfDataVenda.setEnabled(false);
343: ictfDataVenda.setToolTipText(TelaBemMessages.getMessages()
344: .getString("DataVendaToolTip"));
345: gridBagConstraints = new GridBagConstraints();
346: gridBagConstraints.gridx = 1;
347: gridBagConstraints.gridy = 4;
348: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
349: telaPrincipal.addComponent(ictfDataVenda, gridBagConstraints,
350: PainelTelaBasica.DATA_COMPONENTS_AREA);
351:
352: mtfValorVenda.setMinimumSize(new Dimension(100, 20));
353: mtfValorVenda.setPreferredSize(new Dimension(100, 20));
354: mtfValorVenda.setEnabled(false);
355: mtfValorVenda.setToolTipText(TelaBemMessages.getMessages()
356: .getString("ValorVendaToolTip"));
357: gridBagConstraints = new GridBagConstraints();
358: gridBagConstraints.gridx = 5;
359: gridBagConstraints.gridy = 4;
360: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
361: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
362: telaPrincipal.addComponent(mtfValorVenda, gridBagConstraints,
363: PainelTelaBasica.DATA_COMPONENTS_AREA);
364:
365: jlValorVenda.setText(TelaBemMessages.getMessages().getString(
366: "valorVenda")); //$NON-NLS-1$
367: jlValorVenda.setDisplayedMnemonic(TelaBemMessages.getMessages()
368: .getString("ValorVendaMnemonic").charAt(0));
369: gridBagConstraints = new GridBagConstraints();
370: gridBagConstraints.gridx = 4;
371: gridBagConstraints.gridy = 4;
372: gridBagConstraints.anchor = GridBagConstraints.WEST;
373: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
374: telaPrincipal.addComponent(jlValorVenda, gridBagConstraints,
375: PainelTelaBasica.DATA_COMPONENTS_AREA);
376:
377: jcbDataVenda.setText(TelaBemMessages.getMessages().getString(
378: "dataVenda")); //$NON-NLS-1$
379: jcbDataVenda.setMnemonic(TelaBemMessages.getMessages()
380: .getString("DataVendaMnemonic").charAt(0));
381: jcbDataVenda.setToolTipText(TelaBemMessages.getMessages()
382: .getString("DataVendaCBToolTip"));
383: jcbDataVenda
384: .addItemListener((ItemListener) GeneralEventHandler
385: .makeProxy(
386: this ,
387: "dataVendaItemStateChanged", ItemListener.class, "itemStateChanged")); //$NON-NLS-1$ //$NON-NLS-2$
388: gridBagConstraints = new GridBagConstraints();
389: gridBagConstraints.gridx = 0;
390: gridBagConstraints.gridy = 4;
391: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
392: telaPrincipal.addComponent(jcbDataVenda, gridBagConstraints,
393: PainelTelaBasica.DATA_COMPONENTS_AREA);
394:
395: jcbLocalCompra.setInsertNewListener(AbrirTelaParaInsercaoAction
396: .getAction(), ContactsWindow.class.getName());
397: gridBagConstraints = new GridBagConstraints();
398: gridBagConstraints.gridx = 1;
399: gridBagConstraints.gridy = 3;
400: gridBagConstraints.gridwidth = 5;
401: gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
402: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
403: telaPrincipal.addComponent(jcbLocalCompra, gridBagConstraints,
404: PainelTelaBasica.DATA_COMPONENTS_AREA);
405:
406: telaPrincipal
407: .getPainelBotoes()
408: .addActionListener(
409: "salvar", (ActionListener) GeneralEventHandler.makeProxy(this , "salvar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
410: telaPrincipal
411: .getPainelBotoes()
412: .addActionListener(
413: "atualizar", (ActionListener) GeneralEventHandler.makeProxy(this , "atualizar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
414: telaPrincipal
415: .getPainelBotoes()
416: .addActionListener(
417: "novo", (ActionListener) GeneralEventHandler.makeProxy(this , "novo", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
418: telaPrincipal
419: .getPainelBotoes()
420: .addActionListener(
421: "excluir", (ActionListener) GeneralEventHandler.makeProxy(this , "excluir", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
422: telaPrincipal
423: .getPainelBotoes()
424: .addActionListener(
425: "pesquisar", (ActionListener) GeneralEventHandler.makeProxy(this , "pesquisar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
426: telaPrincipal
427: .getPainelBotoes()
428: .addActionListener(
429: "limpar", (ActionListener) GeneralEventHandler.makeProxy(this , "limpar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
430: telaPrincipal
431: .getPainelBotoes()
432: .addActionListener(
433: "filtrar", (ActionListener) GeneralEventHandler.makeProxy(this , "filtrar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
434: getContentPane().add(telaPrincipal, BorderLayout.CENTER);
435:
436: southPanel.setLayout(new GridBagLayout());
437: jlSomaDosBensLabel.setText(TelaBemMessages.getMessages()
438: .getString("SomaValorAtualBens"));
439: gridBagConstraints = new GridBagConstraints();
440: gridBagConstraints.gridx = 0;
441: gridBagConstraints.gridy = 0;
442: gridBagConstraints.weightx = 1.0;
443: gridBagConstraints.anchor = GridBagConstraints.EAST;
444: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
445: southPanel.add(jlSomaDosBensLabel, gridBagConstraints);
446:
447: gridBagConstraints = new GridBagConstraints();
448: gridBagConstraints.gridx = 1;
449: gridBagConstraints.gridy = 0;
450: gridBagConstraints.anchor = GridBagConstraints.EAST;
451: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
452: southPanel.add(jlSomaDosBens, gridBagConstraints);
453:
454: getContentPane().add(southPanel, BorderLayout.SOUTH);
455:
456: pack();
457: limpar(null);
458: }
459:
460: private class PrintListener implements ActionListener {
461: public void actionPerformed(final ActionEvent e) {
462: ((JButton) e.getSource()).setEnabled(false);
463: (new Thread() {
464: {
465: setPriority(Thread.MIN_PRIORITY);
466: setDaemon(true);
467: }
468:
469: @Override
470: public void run() {
471: try {
472: ReportFactory.makeReport("Bens", new HashMap());
473: } catch (Exception e1) {
474: ((SimpleLog) GFPController.getGFPController()
475: .getContexto().get(GFPController.LOG))
476: .log("Erro ao gerar relatorio de Bens!");
477: ((SimpleLog) GFPController.getGFPController()
478: .getContexto().get(GFPController.LOG))
479: .log(e1.getLocalizedMessage());
480: ((SimpleLog) GFPController.getGFPController()
481: .getContexto().get(GFPController.LOG))
482: .log(e1);
483: } finally {
484: ((JButton) e.getSource()).setEnabled(true);
485: }
486: }
487: }).start();
488: }
489: }
490:
491: /**
492: * @param e
493: */
494: public void depreciacaoStateChanged(ChangeEvent e) {
495: if (assets != null) {
496: assets.setIndiceDeAtualizacao(Float
497: .valueOf("" + jsDepreciacao.getValue())); //$NON-NLS-1$
498: if (assets.getValorAtual() != null)
499: jlvValorAtual.setText(NumberFormat
500: .getCurrencyInstance().format(
501: assets.getValorAtual()));
502: }
503: }
504:
505: /**
506: * @param e
507: */
508: public void atualizar(ActionEvent e) {
509: refreshTabelaBens();
510: }
511:
512: /**
513: * @param e
514: */
515: public void pesquisar(ActionEvent e) {
516: if (assets == null)
517: assets = new Assets(jtfNome.getText());
518: loadBem();
519: try {
520: assets = controller.getBy(assets);
521: } catch (SQLException sqle) {
522: assets = null;
523: ((SimpleLog) GFPController.getGFPController().getContexto()
524: .get(GFPController.LOG))
525: .log("Erro ao pesquisar assets!");
526: ((SimpleLog) GFPController.getGFPController().getContexto()
527: .get(GFPController.LOG)).log(sqle
528: .getLocalizedMessage());
529: ((SimpleLog) GFPController.getGFPController().getContexto()
530: .get(GFPController.LOG)).log(sqle);
531: }
532: editarBem();
533: }
534:
535: /**
536: * @param e
537: */
538: public void limpar(ActionEvent e) {
539: telaPrincipal.showRequiredFields();
540: assets = null;
541: ictfDataCompra.setDate(null);
542: ictfDataVenda.setDate(null);
543: jcbDataVenda.setSelected(false);
544: jcbLocalCompra.setSelectedIndex(0);
545: jsDepreciacao.setValue(0.0);
546: telaPrincipal.getTextAreaDescricao().setText(""); //$NON-NLS-1$
547: jtfNome.setText(""); //$NON-NLS-1$
548: mtfValorCompra.setValue(0.00);
549: mtfValorVenda.setValue(0.00);
550: controller.setAdicionandoNovo(false);
551: jlvValorAtual.setText(NumberFormat.getCurrencyInstance()
552: .getCurrency().getSymbol());
553: telaPrincipal.getPainelBotoes().dadosCarregados(false);
554: }
555:
556: /**
557: * @param e
558: */
559: public void excluir(ActionEvent e) {
560: if (assets == null) {
561: JOptionPane.showMessageDialog(this , TelaBemMessages
562: .getMessages().getString("semDadosParaExcluir")); //$NON-NLS-1$
563: return;
564: }
565:
566: loadBem();
567:
568: try {
569: controller.deletar(assets);
570: } catch (SQLException sqle) {
571: ((SimpleLog) GFPController.getGFPController().getContexto()
572: .get(GFPController.LOG))
573: .log("Erro ao excluir assets!");
574: ((SimpleLog) GFPController.getGFPController().getContexto()
575: .get(GFPController.LOG)).log(sqle
576: .getLocalizedMessage());
577: ((SimpleLog) GFPController.getGFPController().getContexto()
578: .get(GFPController.LOG)).log(sqle);
579: }
580: assets = null;
581: refreshTabelaBens();
582: }
583:
584: /**
585: * @param e
586: */
587: public void salvar(ActionEvent e) {
588: if (assets == null) {//Todo Rever Mensagem
589: JOptionPane.showMessageDialog(this , TelaBemMessages
590: .getMessages().getString("semDadosParaSalvar")); //$NON-NLS-1$
591: return;
592: }
593: loadBem();
594: if (controller.isAdicionandoNovo()) {
595: try {
596: controller.adicionarNovo(assets);
597: } catch (SQLException sqle) {
598: JOptionPane.showMessageDialog(this , sqle.getMessage(),
599: ErrosDeDadosMessages.getMessages().getString(
600: "MessageTitle"),
601: JOptionPane.WARNING_MESSAGE);
602: telaPrincipal.getPainelBotoes().setOcorreuErro(true);
603: return;
604: }
605: close();
606: } else {
607: try {
608: controller.atualizar(assets);
609: } catch (SQLException sqle) {
610: JOptionPane.showMessageDialog(this , sqle.getMessage(),
611: ErrosDeDadosMessages.getMessages().getString(
612: "MessageTitle"),
613: JOptionPane.WARNING_MESSAGE);
614: telaPrincipal.getPainelBotoes().setOcorreuErro(true);
615: return;
616: }
617: }
618: assets = null;
619: refreshTabelaBens();
620: }
621:
622: /**
623: * @param e
624: */
625: public void novo(ActionEvent e) {
626: assets = new Assets(jtfNome.getText());
627: controller.setAdicionandoNovo(true);
628: }
629:
630: /**
631: * @param evt
632: */
633: public void dataVendaItemStateChanged(ItemEvent evt) {
634: ictfDataVenda.setEnabled(jcbDataVenda.isSelected());
635: mtfValorVenda.setEnabled(jcbDataVenda.isSelected());
636: }
637:
638: /**
639: * @param e
640: */
641: public void filtrar(ActionEvent e) {
642: assets = new Assets();
643: loadBem();
644:
645: jtBens.setDataType(assets);
646: try {
647: jtBens.filter();
648: } catch (Exception e1) {
649: ((SimpleLog) GFPController.getGFPController().getContexto()
650: .get(GFPController.LOG))
651: .log("Erro ao filtrar tabela de bens!");
652: ((SimpleLog) GFPController.getGFPController().getContexto()
653: .get(GFPController.LOG)).log(e1
654: .getLocalizedMessage());
655: ((SimpleLog) GFPController.getGFPController().getContexto()
656: .get(GFPController.LOG)).log(e1);
657: }
658: }
659:
660: /**
661: *
662: */
663: private void loadBem() {
664: assets.setDataCompra(ictfDataCompra.getDate());
665:
666: if (jcbLocalCompra.getSelectedIndex() > 0)
667: try {
668: assets.setLocalCompra(((Integer) jcbLocalCompra
669: .getDataAt(jcbLocalCompra.getSelectedIndex())
670: .get("Id"))); //$NON-NLS-1$
671: } catch (Exception e) {
672: ((SimpleLog) GFPController.getGFPController()
673: .getContexto().get(GFPController.LOG))
674: .log("Erro ao setar local de compra!");
675: ((SimpleLog) GFPController.getGFPController()
676: .getContexto().get(GFPController.LOG)).log(e
677: .getLocalizedMessage());
678: ((SimpleLog) GFPController.getGFPController()
679: .getContexto().get(GFPController.LOG)).log(e);
680: }
681: assets.setIndiceDeAtualizacao(Float
682: .valueOf("" + jsDepreciacao.getValue())); //$NON-NLS-1$
683: assets.setDescricao(telaPrincipal.getTextAreaDescricao()
684: .getText());
685: assets.setNome(jtfNome.getText());
686: if (!((Double) mtfValorCompra.getValue()).equals(Double
687: .valueOf("0.00")))
688: assets.setValorCompra((Double) mtfValorCompra.getValue());
689: if (mtfValorVenda.getValue() != null
690: && !((Double) mtfValorVenda.getValue()).equals(Double
691: .valueOf("0.00"))) {
692: assets.setValorVenda((Double) mtfValorVenda.getValue());
693: assets.setDataVenda(ictfDataVenda.getDate());
694: }
695: }
696:
697: /**
698: *
699: */
700: private void editarBem() {
701: telaPrincipal.hideRequiredFields();
702: if (assets == null)
703: return;
704: jtfNome.setText(assets.getNome());
705: ictfDataCompra.setDate(assets.getDataCompra());
706: ictfDataVenda.setDate(assets.getDataVenda());
707: mtfValorVenda.setValue(assets.getValorVenda());
708: jcbDataVenda.setSelected(assets.getDataVenda() != null);
709: try {
710: jcbLocalCompra.setSelectedItem(assets.getLocalCompra(),
711: "Id"); //$NON-NLS-1$
712: } catch (SQLException e) {
713: ((SimpleLog) GFPController.getGFPController().getContexto()
714: .get(GFPController.LOG))
715: .log("Erro ao carregar local de compra do assets!");
716: ((SimpleLog) GFPController.getGFPController().getContexto()
717: .get(GFPController.LOG)).log(e
718: .getLocalizedMessage());
719: ((SimpleLog) GFPController.getGFPController().getContexto()
720: .get(GFPController.LOG)).log(e);
721: }
722:
723: if (assets.getIndiceDeAtualizacao() != null)
724: jsDepreciacao.setValue(assets.getIndiceDeAtualizacao());
725: telaPrincipal.getTextAreaDescricao().setText(
726: assets.getDescricao());
727: mtfValorCompra.setValue(assets.getValorCompra());
728: telaPrincipal.getPainelBotoes().dadosCarregados(true);
729: if (assets.getValorAtual() != null)
730: jlvValorAtual.setText(NumberFormat.getCurrencyInstance()
731: .format(assets.getValorAtual()));
732: }
733:
734: /**
735: *
736: */
737: private void refreshTabelaBens() {
738: try {
739: jtBens.loadDados();
740: } catch (Exception e) {
741: ((SimpleLog) GFPController.getGFPController().getContexto()
742: .get(GFPController.LOG))
743: .log("Erro ao atualizar tabela de bens!");
744: ((SimpleLog) GFPController.getGFPController().getContexto()
745: .get(GFPController.LOG)).log(e
746: .getLocalizedMessage());
747: ((SimpleLog) GFPController.getGFPController().getContexto()
748: .get(GFPController.LOG)).log(e);
749: }
750: calcularSomaDespesas();
751: }
752:
753: private void calcularSomaDespesas() {
754: try {
755: jlSomaDosBens.setText(CURRENCY_INSTANCE_FORMATER
756: .format(((AssetsDAO) controller).somaValorAtual()));
757: } catch (SQLException e) {
758: ((SimpleLog) GFPController.getGFPController().getContexto()
759: .get(GFPController.LOG))
760: .log("Erro ao calcular soma dos valores dos bens!");
761: ((SimpleLog) GFPController.getGFPController().getContexto()
762: .get(GFPController.LOG)).log(e
763: .getLocalizedMessage());
764: ((SimpleLog) GFPController.getGFPController().getContexto()
765: .get(GFPController.LOG)).log(e);
766: }
767: }
768:
769: /**
770: * @param e
771: */
772: public void loadFromTable(ListSelectionEvent e) {
773: if (AssetsWindow.this .isVisible()) {
774: try {
775: assets = (Assets) jtBens.getPersistentObject(jtBens
776: .getSelectedRow());
777: } catch (SQLException sqle) {
778: ((SimpleLog) GFPController.getGFPController()
779: .getContexto().get(GFPController.LOG))
780: .log("Erro ao carregar assets da tabela de bens!");
781: ((SimpleLog) GFPController.getGFPController()
782: .getContexto().get(GFPController.LOG)).log(sqle
783: .getLocalizedMessage());
784: ((SimpleLog) GFPController.getGFPController()
785: .getContexto().get(GFPController.LOG))
786: .log(sqle);
787: }
788: editarBem();
789: }
790: }
791:
792: @Override
793: public void setVisible(boolean aFlag) {
794: super .setVisible(aFlag);
795: try {
796: if (jcbLocalCompra != null)
797: jcbLocalCompra.loadDados();
798: } catch (DAOCreationException e) {
799: ((SimpleLog) GFPController.getGFPController().getContexto()
800: .get(GFPController.LOG))
801: .log("Erro ao carregar dados em combo da tela assets!");
802: ((SimpleLog) GFPController.getGFPController().getContexto()
803: .get(GFPController.LOG)).log(e
804: .getLocalizedMessage());
805: ((SimpleLog) GFPController.getGFPController().getContexto()
806: .get(GFPController.LOG)).log(e);
807: } catch (SQLException e) {
808: ((SimpleLog) GFPController.getGFPController().getContexto()
809: .get(GFPController.LOG))
810: .log("Erro ao carregar dados em combo da tela de conta assets!");
811: ((SimpleLog) GFPController.getGFPController().getContexto()
812: .get(GFPController.LOG)).log(e
813: .getLocalizedMessage());
814: ((SimpleLog) GFPController.getGFPController().getContexto()
815: .get(GFPController.LOG)).log(e);
816: }
817: }
818: }
|