Source Code Cross Referenced for ContactsWindow.java in  » ERP-CRM-Financial » Personal-Finance-Manager » br » com » gfp » windows » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Personal Finance Manager » br.com.gfp.windows 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ContactsWindow.java Created on 28 de Março de 2004, 17:54
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.Insets;
011:        import java.awt.event.ActionEvent;
012:        import java.awt.event.ActionListener;
013:        import java.awt.event.ItemEvent;
014:        import java.awt.event.ItemListener;
015:        import java.sql.SQLException;
016:        import java.text.ParseException;
017:        import java.util.HashMap;
018:
019:        import javax.swing.DefaultComboBoxModel;
020:        import javax.swing.JButton;
021:        import javax.swing.JComboBox;
022:        import javax.swing.JFormattedTextField;
023:        import javax.swing.JFrame;
024:        import javax.swing.JOptionPane;
025:        import javax.swing.JTextField;
026:        import javax.swing.WindowConstants;
027:        import javax.swing.event.ListSelectionEvent;
028:        import javax.swing.event.ListSelectionListener;
029:        import javax.swing.text.DefaultFormatterFactory;
030:        import javax.swing.text.MaskFormatter;
031:
032:        import br.com.gfp.dao.ContactDAO;
033:        import br.com.gfp.dao.GFPController;
034:        import br.com.gfp.data.Contact;
035:        import br.com.gfp.internationalization.ErrosDeDadosMessages;
036:        import br.com.gfp.internationalization.TelaEntidadeMessages;
037:        import br.com.gfp.reports.ReportFactory;
038:        import br.com.gfp.util.SimpleLog;
039:        import br.com.gfp.windows.componentes.GFPHeaderRenderer;
040:        import br.com.gfp.windows.componentes.GFPTableCellRenderer;
041:        import br.com.gfpshare.beans.GeneralEventHandler;
042:        import br.com.gfpshare.beans.ZLabel;
043:        import br.com.gfpshare.beans.ZTextField;
044:        import br.com.gfpshare.beans.aplicativos.IconeFactory;
045:        import br.com.gfpshare.beans.aplicativos.PainelTelaBasica;
046:        import br.com.gfpshare.beans.table.DBTable;
047:        import br.com.gfpshare.db.DAOListener;
048:        import br.com.gfpshare.util.CNPJ;
049:        import br.com.gfpshare.util.CPF;
050:
051:        /**
052:         * @author Igor Regis da Silva Simões
053:         */
054:        public class ContactsWindow extends GFPInternalFrame<Contact> {
055:
056:            private Contact contact = null;
057:
058:            private JComboBox jcbIdentificacao;
059:
060:            private JFormattedTextField jftfIdentificacao;
061:
062:            private JFormattedTextField jftfTelefone;
063:
064:            private JTextField jtfContato;
065:
066:            private ZTextField jtfEmail;
067:
068:            private ZTextField jtfEndereco;
069:
070:            private ZTextField jtfNome;
071:
072:            private ZLabel jlContato;
073:
074:            private ZLabel jlEmail;
075:
076:            private ZLabel jlEndereco;
077:
078:            private ZLabel jlNome;
079:
080:            private ZLabel jlTelefone;
081:
082:            private DBTable jtEntidades;
083:
084:            private PainelTelaBasica telaPrincipal;
085:
086:            /**
087:             * Creates new form TransactionWindow
088:             * 
089:             * @param owner O Frame propietário desta janela
090:             */
091:            public ContactsWindow(JFrame owner) {
092:                controller = new ContactDAO();
093:                entidadeInit();
094:                initComponents();
095:                setSize(720, 450);
096:            }
097:
098:            /**
099:             * Cria nova tela com listener para saber o que ocorre nela
100:             * @param owner
101:             * @param listener
102:             */
103:            public ContactsWindow(JFrame owner, DAOListener<Contact> listener) {
104:                this (owner);
105:                setListener(listener);
106:            }
107:
108:            /**
109:             * 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
110:             * regenerated by the Form Editor.
111:             */
112:            private void initComponents() {
113:                setClosable(true);
114:                setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
115:                setIconifiable(true);
116:                setMaximizable(true);
117:                setResizable(true);
118:                setTitle(TelaEntidadeMessages.getMessages().getString(
119:                        "Entidades")); //$NON-NLS-1$
120:                setFrameIcon(IconeFactory.getIconeFactory().getImageIcon(
121:                        IconeFactory.ENTIDADE_PEQUENA));
122:
123:                telaPrincipal = new PainelTelaBasica();
124:
125:                GridBagConstraints gridBagConstraints;
126:
127:                jtEntidades = new DBTable(new Contact(),
128:                        new GFPHeaderRenderer());
129:                jtEntidades.hideColumn("Id"); //$NON-NLS-1$
130:                jtEntidades.hideColumn("EhDeSistema"); //$NON-NLS-1$
131:                jtEntidades.getColumn(jtEntidades.getColumnName(7))
132:                        .setCellRenderer(
133:                                new GFPTableCellRenderer(
134:                                        GFPTableCellRenderer.CPF, -1));
135:                jtEntidades
136:                        .getSelectionModel()
137:                        .addListSelectionListener(
138:                                (ListSelectionListener) GeneralEventHandler
139:                                        .makeProxy(
140:                                                this ,
141:                                                "loadFromTable", ListSelectionListener.class, "valueChanged")); //$NON-NLS-1$ //$NON-NLS-2$
142:
143:                telaPrincipal.setJtDados(jtEntidades);
144:                telaPrincipal.addPrintButtonListener(new PrintListener());
145:
146:                jlNome = new ZLabel();
147:                jtfNome = new ZTextField();
148:                jlTelefone = new ZLabel();
149:                jftfTelefone = new JFormattedTextField();
150:                jlEndereco = new ZLabel();
151:                jtfEndereco = new ZTextField();
152:                jlContato = new ZLabel();
153:                jtfContato = new ZTextField();
154:                jlEmail = new ZLabel();
155:                jtfEmail = new ZTextField();
156:                jcbIdentificacao = new JComboBox();
157:                jftfIdentificacao = new JFormattedTextField();
158:
159:                jlNome.setText(TelaEntidadeMessages.getMessages().getString(
160:                        "Nome")); //$NON-NLS-1$
161:                jlNome.setDisplayedMnemonic(TelaEntidadeMessages.getMessages()
162:                        .getString("NomeMnemonic").charAt(0));
163:                jlNome.setRequiredField(jtfNome);
164:                jlNome.setValidationNotNull(true);
165:                gridBagConstraints = new GridBagConstraints();
166:                gridBagConstraints.gridx = 0;
167:                gridBagConstraints.gridy = 0;
168:                gridBagConstraints.anchor = GridBagConstraints.WEST;
169:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
170:                telaPrincipal.addComponent(jlNome, gridBagConstraints,
171:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
172:
173:                jtfNome.setMinimumSize(new Dimension(100, 20));
174:                jtfNome.setPreferredSize(new Dimension(100, 20));
175:                jtfNome.setToolTipText(TelaEntidadeMessages.getMessages()
176:                        .getString("NomeToolTip"));
177:                gridBagConstraints = new GridBagConstraints();
178:                gridBagConstraints.gridx = 1;
179:                gridBagConstraints.gridy = 0;
180:                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
181:                gridBagConstraints.anchor = GridBagConstraints.WEST;
182:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
183:                telaPrincipal.addComponent(jtfNome, gridBagConstraints,
184:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
185:
186:                jlTelefone.setText(TelaEntidadeMessages.getMessages()
187:                        .getString("Telefone")); //$NON-NLS-1$
188:                jlTelefone.setDisplayedMnemonic(TelaEntidadeMessages
189:                        .getMessages().getString("TelefoneMnemonic").charAt(0));
190:                jlTelefone.setLabelFor(jftfTelefone);
191:                gridBagConstraints = new GridBagConstraints();
192:                gridBagConstraints.gridx = 2;
193:                gridBagConstraints.gridy = 0;
194:                gridBagConstraints.anchor = GridBagConstraints.WEST;
195:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
196:                telaPrincipal.addComponent(jlTelefone, gridBagConstraints,
197:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
198:
199:                try {
200:                    jftfTelefone
201:                            .setFormatterFactory(new DefaultFormatterFactory(
202:                                    new MaskFormatter(TelaEntidadeMessages
203:                                            .getMessages().getString(
204:                                                    "MascaraTelefone")))); //$NON-NLS-1$
205:                } catch (ParseException e) {
206:                    ((SimpleLog) GFPController.getGFPController().getContexto()
207:                            .get(GFPController.LOG))
208:                            .log("Erro ao aplicar mascara de telefone!");
209:                    ((SimpleLog) GFPController.getGFPController().getContexto()
210:                            .get(GFPController.LOG)).log(e
211:                            .getLocalizedMessage());
212:                    ((SimpleLog) GFPController.getGFPController().getContexto()
213:                            .get(GFPController.LOG)).log(e);
214:                }
215:                jftfTelefone.setMinimumSize(new Dimension(100, 20));
216:                jftfTelefone.setPreferredSize(new Dimension(100, 20));
217:                jftfTelefone.setToolTipText(TelaEntidadeMessages.getMessages()
218:                        .getString("TelefoneToolTip"));
219:                gridBagConstraints = new GridBagConstraints();
220:                gridBagConstraints.gridx = 3;
221:                gridBagConstraints.gridy = 0;
222:                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
223:                gridBagConstraints.anchor = GridBagConstraints.WEST;
224:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
225:                telaPrincipal.addComponent(jftfTelefone, gridBagConstraints,
226:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
227:
228:                jlEndereco.setText(TelaEntidadeMessages.getMessages()
229:                        .getString("Endereco")); //$NON-NLS-1$
230:                jlEndereco.setDisplayedMnemonic(TelaEntidadeMessages
231:                        .getMessages().getString("EnderecoMnemonic").charAt(0));
232:                jlEndereco.setLabelFor(jtfEndereco);
233:                gridBagConstraints = new GridBagConstraints();
234:                gridBagConstraints.gridx = 0;
235:                gridBagConstraints.gridy = 1;
236:                gridBagConstraints.anchor = GridBagConstraints.WEST;
237:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
238:                telaPrincipal.addComponent(jlEndereco, gridBagConstraints,
239:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
240:
241:                jtfEndereco.setToolTipText(TelaEntidadeMessages.getMessages()
242:                        .getString("EnderecoToolTip"));
243:                gridBagConstraints = new GridBagConstraints();
244:                gridBagConstraints.gridx = 1;
245:                gridBagConstraints.gridy = 1;
246:                gridBagConstraints.gridwidth = 3;
247:                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
248:                gridBagConstraints.anchor = GridBagConstraints.WEST;
249:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
250:                telaPrincipal.addComponent(jtfEndereco, gridBagConstraints,
251:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
252:
253:                jlContato.setText(TelaEntidadeMessages.getMessages().getString(
254:                        "Contato")); //$NON-NLS-1$
255:                jlContato.setDisplayedMnemonic(TelaEntidadeMessages
256:                        .getMessages().getString("ContatoMnemonic").charAt(0));
257:                jlContato.setLabelFor(jtfContato);
258:                gridBagConstraints = new GridBagConstraints();
259:                gridBagConstraints.gridx = 0;
260:                gridBagConstraints.gridy = 2;
261:                gridBagConstraints.anchor = GridBagConstraints.WEST;
262:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
263:                telaPrincipal.addComponent(jlContato, gridBagConstraints,
264:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
265:
266:                jtfContato.setToolTipText(TelaEntidadeMessages.getMessages()
267:                        .getString("ContatoToolTip"));
268:                gridBagConstraints = new GridBagConstraints();
269:                gridBagConstraints.gridx = 1;
270:                gridBagConstraints.gridy = 2;
271:                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
272:                gridBagConstraints.anchor = GridBagConstraints.WEST;
273:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
274:                telaPrincipal.addComponent(jtfContato, gridBagConstraints,
275:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
276:
277:                jlEmail.setText(TelaEntidadeMessages.getMessages().getString(
278:                        "Email")); //$NON-NLS-1$
279:                jlEmail.setDisplayedMnemonic(TelaEntidadeMessages.getMessages()
280:                        .getString("EmailMnemonic").charAt(0));
281:                jlEmail.setLabelFor(jtfEmail);
282:                gridBagConstraints = new GridBagConstraints();
283:                gridBagConstraints.gridx = 2;
284:                gridBagConstraints.gridy = 2;
285:                gridBagConstraints.anchor = GridBagConstraints.WEST;
286:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
287:                telaPrincipal.addComponent(jlEmail, gridBagConstraints,
288:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
289:
290:                jtfEmail.setToolTipText(TelaEntidadeMessages.getMessages()
291:                        .getString("EmailToolTip"));
292:                gridBagConstraints = new GridBagConstraints();
293:                gridBagConstraints.gridx = 3;
294:                gridBagConstraints.gridy = 2;
295:                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
296:                gridBagConstraints.anchor = GridBagConstraints.WEST;
297:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
298:                telaPrincipal.addComponent(jtfEmail, gridBagConstraints,
299:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
300:
301:                jcbIdentificacao
302:                        .setModel(new DefaultComboBoxModel(
303:                                new String[] {
304:                                        "", TelaEntidadeMessages.getMessages().getString("CPF"), TelaEntidadeMessages.getMessages().getString("CNPJ") })); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
305:                jcbIdentificacao.setMinimumSize(new Dimension(100, 25));
306:                jcbIdentificacao.setPreferredSize(new Dimension(100, 25));
307:                jcbIdentificacao
308:                        .addItemListener((ItemListener) GeneralEventHandler
309:                                .makeProxy(
310:                                        this ,
311:                                        "identificacaoItemStateChanged", ItemListener.class, "itemStateChanged")); //$NON-NLS-1$ //$NON-NLS-2$
312:                jcbIdentificacao.setToolTipText(TelaEntidadeMessages
313:                        .getMessages().getString("TipoIdentificacaoToolTip"));
314:
315:                gridBagConstraints = new GridBagConstraints();
316:                gridBagConstraints.gridx = 0;
317:                gridBagConstraints.gridy = 3;
318:                gridBagConstraints.gridwidth = 2;
319:                gridBagConstraints.anchor = GridBagConstraints.WEST;
320:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
321:                telaPrincipal.addComponent(jcbIdentificacao,
322:                        gridBagConstraints,
323:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
324:
325:                jftfIdentificacao.setToolTipText(TelaEntidadeMessages
326:                        .getMessages().getString("IdentificacaoToolTip"));
327:                gridBagConstraints = new GridBagConstraints();
328:                gridBagConstraints.gridx = 2;
329:                gridBagConstraints.gridy = 3;
330:                gridBagConstraints.gridwidth = 2;
331:                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
332:                gridBagConstraints.insets = new Insets(5, 5, 5, 5);
333:                telaPrincipal.addComponent(jftfIdentificacao,
334:                        gridBagConstraints,
335:                        PainelTelaBasica.DATA_COMPONENTS_AREA);
336:
337:                telaPrincipal
338:                        .getPainelBotoes()
339:                        .addActionListener(
340:                                "salvar", (ActionListener) GeneralEventHandler.makeProxy(this , "salvar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
341:                telaPrincipal
342:                        .getPainelBotoes()
343:                        .addActionListener(
344:                                "atualizar", (ActionListener) GeneralEventHandler.makeProxy(this , "atualizar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
345:                telaPrincipal
346:                        .getPainelBotoes()
347:                        .addActionListener(
348:                                "novo", (ActionListener) GeneralEventHandler.makeProxy(this , "novo", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
349:                telaPrincipal
350:                        .getPainelBotoes()
351:                        .addActionListener(
352:                                "excluir", (ActionListener) GeneralEventHandler.makeProxy(this , "excluir", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
353:                telaPrincipal
354:                        .getPainelBotoes()
355:                        .addActionListener(
356:                                "pesquisar", (ActionListener) GeneralEventHandler.makeProxy(this , "pesquisar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
357:                telaPrincipal
358:                        .getPainelBotoes()
359:                        .addActionListener(
360:                                "limpar", (ActionListener) GeneralEventHandler.makeProxy(this , "limpar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
361:                telaPrincipal
362:                        .getPainelBotoes()
363:                        .addActionListener(
364:                                "filtrar", (ActionListener) GeneralEventHandler.makeProxy(this , "filtrar", ActionListener.class, "actionPerformed")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
365:                getContentPane().add(telaPrincipal, BorderLayout.CENTER);
366:
367:                pack();
368:            }
369:
370:            private class PrintListener implements  ActionListener {
371:                public void actionPerformed(final ActionEvent e) {
372:                    ((JButton) e.getSource()).setEnabled(false);
373:                    (new Thread() {
374:                        {
375:                            setPriority(Thread.MIN_PRIORITY);
376:                            setDaemon(true);
377:                        }
378:
379:                        @Override
380:                        public void run() {
381:                            try {
382:                                ReportFactory.makeReport("Entidades",
383:                                        new HashMap());
384:                            } catch (Exception e1) {
385:                                ((SimpleLog) GFPController.getGFPController()
386:                                        .getContexto().get(GFPController.LOG))
387:                                        .log("Erro ao gerar relatorio de entidades!");
388:                                ((SimpleLog) GFPController.getGFPController()
389:                                        .getContexto().get(GFPController.LOG))
390:                                        .log(e1.getLocalizedMessage());
391:                                ((SimpleLog) GFPController.getGFPController()
392:                                        .getContexto().get(GFPController.LOG))
393:                                        .log(e1);
394:                            } finally {
395:                                ((JButton) e.getSource()).setEnabled(true);
396:                            }
397:                        }
398:                    }).start();
399:                }
400:            }
401:
402:            /**
403:             * @param e
404:             */
405:            public void atualizar(ActionEvent e) {
406:                refreshTabelaEntidades();
407:            }
408:
409:            /**
410:             * @param e
411:             */
412:            public void pesquisar(ActionEvent e) {
413:                if (contact == null)
414:                    entidadeInit();
415:                loadEntidade();
416:                try {
417:                    contact = controller.getBy(contact);
418:                } catch (SQLException sqle) {
419:                    ((SimpleLog) GFPController.getGFPController().getContexto()
420:                            .get(GFPController.LOG))
421:                            .log("Erro ao pesquisar entidade: " + contact);
422:                    ((SimpleLog) GFPController.getGFPController().getContexto()
423:                            .get(GFPController.LOG)).log(sqle
424:                            .getLocalizedMessage());
425:                    ((SimpleLog) GFPController.getGFPController().getContexto()
426:                            .get(GFPController.LOG)).log(sqle);
427:                    contact = null;
428:                }
429:                editarEntidade();
430:            }
431:
432:            /**
433:             * @param e
434:             */
435:            public void excluir(ActionEvent e) {
436:                if (contact == null) {//Todo Rever Mensagem
437:                    JOptionPane.showMessageDialog(this , TelaEntidadeMessages
438:                            .getMessages().getString("SemDadosParaExcluir")); //$NON-NLS-1$
439:                    return;
440:                }
441:
442:                loadEntidade();
443:
444:                try {
445:                    controller.deletar(contact);
446:                } catch (SQLException sqle) {
447:                    ((SimpleLog) GFPController.getGFPController().getContexto()
448:                            .get(GFPController.LOG))
449:                            .log("Erro ao excluir entidade: " + contact);
450:                    ((SimpleLog) GFPController.getGFPController().getContexto()
451:                            .get(GFPController.LOG)).log(sqle
452:                            .getLocalizedMessage());
453:                    ((SimpleLog) GFPController.getGFPController().getContexto()
454:                            .get(GFPController.LOG)).log(sqle);
455:                }
456:                contact = null;
457:                refreshTabelaEntidades();
458:            }
459:
460:            /**
461:             * @param e
462:             */
463:            public void salvar(ActionEvent e) {
464:                if (contact == null) {
465:                    JOptionPane.showMessageDialog(this , TelaEntidadeMessages
466:                            .getMessages().getString("SemDadosParaSalvar")); //$NON-NLS-1$
467:                    return;
468:                }
469:                loadEntidade();
470:                if (controller.isAdicionandoNovo()) {
471:                    try {
472:                        controller.adicionarNovo(contact);
473:                    } catch (SQLException sqle) {
474:                        JOptionPane.showMessageDialog(this , sqle.getMessage(),
475:                                ErrosDeDadosMessages.getMessages().getString(
476:                                        "MessageTitle"),
477:                                JOptionPane.WARNING_MESSAGE);
478:                        telaPrincipal.getPainelBotoes().setOcorreuErro(true);
479:                        return;
480:                    }
481:                    close();
482:                } else {
483:                    try {
484:                        controller.atualizar(contact);
485:                    } catch (SQLException sqle) {
486:                        JOptionPane.showMessageDialog(this , sqle.getMessage(),
487:                                ErrosDeDadosMessages.getMessages().getString(
488:                                        "MessageTitle"),
489:                                JOptionPane.WARNING_MESSAGE);
490:                        telaPrincipal.getPainelBotoes().setOcorreuErro(true);
491:                        return;
492:                    }
493:                }
494:                contact = null;
495:                refreshTabelaEntidades();
496:            }
497:
498:            /**
499:             * @param e
500:             */
501:            public void limpar(ActionEvent e) {
502:                telaPrincipal.showRequiredFields();
503:                contact = null;
504:                jcbIdentificacao.setSelectedIndex(0);
505:                jftfIdentificacao.setText(""); //$NON-NLS-1$
506:                jftfTelefone.setText(""); //$NON-NLS-1$
507:                telaPrincipal.getTextAreaDescricao().setText(""); //$NON-NLS-1$
508:                jtfContato.setText(""); //$NON-NLS-1$
509:                jtfEmail.setText(""); //$NON-NLS-1$
510:                jtfEndereco.setText(""); //$NON-NLS-1$
511:                jtfNome.setText(""); //$NON-NLS-1$
512:                controller.setAdicionandoNovo(false);
513:                telaPrincipal.getPainelBotoes().dadosCarregados(false);
514:            }
515:
516:            /**
517:             * @param e
518:             */
519:            public void novo(ActionEvent e) {
520:                entidadeInit();
521:                controller.setAdicionandoNovo(true);
522:            }
523:
524:            /**
525:             * @param evt
526:             */
527:            public void identificacaoItemStateChanged(ItemEvent evt) {
528:                if (jcbIdentificacao.getSelectedItem().toString().toUpperCase()
529:                        .indexOf(
530:                                TelaEntidadeMessages.getMessages().getString(
531:                                        "CPF")) != -1) //$NON-NLS-1$
532:                {
533:                    try {
534:                        MaskFormatter cpf = new MaskFormatter(
535:                                TelaEntidadeMessages.getMessages().getString(
536:                                        "MascaraCPF")); //$NON-NLS-1$
537:                        cpf.setValueContainsLiteralCharacters(false);
538:                        jftfIdentificacao
539:                                .setFormatterFactory(new DefaultFormatterFactory(
540:                                        cpf));
541:                    } catch (ParseException e) {
542:                        ((SimpleLog) GFPController.getGFPController()
543:                                .getContexto().get(GFPController.LOG))
544:                                .log("Erro ao aplicar mascara de CPF!");
545:                        ((SimpleLog) GFPController.getGFPController()
546:                                .getContexto().get(GFPController.LOG)).log(e
547:                                .getLocalizedMessage());
548:                        ((SimpleLog) GFPController.getGFPController()
549:                                .getContexto().get(GFPController.LOG)).log(e);
550:                    }
551:                } else if (jcbIdentificacao.getSelectedItem().toString()
552:                        .toUpperCase().indexOf(
553:                                TelaEntidadeMessages.getMessages().getString(
554:                                        "CNPJ")) != -1) //$NON-NLS-1$
555:                {
556:                    try {
557:                        MaskFormatter cnpj = new MaskFormatter(
558:                                TelaEntidadeMessages.getMessages().getString(
559:                                        "MascaraCNPJ")); //$NON-NLS-1$
560:                        cnpj.setValueContainsLiteralCharacters(false);
561:                        jftfIdentificacao
562:                                .setFormatterFactory(new DefaultFormatterFactory(
563:                                        cnpj));
564:                    } catch (ParseException e) {
565:                        ((SimpleLog) GFPController.getGFPController()
566:                                .getContexto().get(GFPController.LOG))
567:                                .log("Erro ao aplicar mascara do CNPJ!");
568:                        ((SimpleLog) GFPController.getGFPController()
569:                                .getContexto().get(GFPController.LOG)).log(e
570:                                .getLocalizedMessage());
571:                        ((SimpleLog) GFPController.getGFPController()
572:                                .getContexto().get(GFPController.LOG)).log(e);
573:                    }
574:                } else {
575:                    jftfIdentificacao
576:                            .setFormatterFactory(new DefaultFormatterFactory(
577:                                    null));
578:                }
579:                jftfIdentificacao.setText(""); //$NON-NLS-1$
580:            }
581:
582:            /**
583:             * @param e
584:             */
585:            public void filtrar(ActionEvent e) {
586:                entidadeInit();
587:                loadEntidade();
588:
589:                jtEntidades.setDataType(contact);
590:                try {
591:                    jtEntidades.filter();
592:                } catch (Exception e1) {
593:                    ((SimpleLog) GFPController.getGFPController().getContexto()
594:                            .get(GFPController.LOG))
595:                            .log("Erro ao filtrar tabela de entidades: "
596:                                    + contact);
597:                    ((SimpleLog) GFPController.getGFPController().getContexto()
598:                            .get(GFPController.LOG)).log(e1
599:                            .getLocalizedMessage());
600:                    ((SimpleLog) GFPController.getGFPController().getContexto()
601:                            .get(GFPController.LOG)).log(e1);
602:                }
603:            }
604:
605:            /**
606:             *
607:             */
608:            private void entidadeInit() {
609:                contact = new Contact();
610:            }
611:
612:            /**
613:             *
614:             */
615:            private void loadEntidade() {
616:                contact.setNome(jtfNome.getText());
617:
618:                try {
619:                    jftfIdentificacao.commitEdit();
620:                } catch (ParseException pe) {
621:                    pe.printStackTrace();
622:                }
623:
624:                if (jftfIdentificacao.getValue() != null)
625:                    contact.setCod_Identificacao(jftfIdentificacao.getValue()
626:                            .toString());
627:                contact.setTelefone(jftfTelefone.getText());
628:                contact.setDescricao(telaPrincipal.getTextAreaDescricao()
629:                        .getText());
630:                contact.setContato(jtfContato.getText());
631:                contact.setEmail(jtfEmail.getText());
632:                contact.setEndereco(jtfEndereco.getText());
633:            }
634:
635:            /**
636:             *
637:             */
638:            private void editarEntidade() {
639:                telaPrincipal.hideRequiredFields();
640:                if (contact == null)
641:                    return;
642:                jtfNome.setText(contact.getNome());
643:                if (contact.getCod_Identificacao() != null) {
644:                    if (new CNPJ(contact.getCod_Identificacao()).isValido()) {
645:                        jcbIdentificacao.setSelectedItem(TelaEntidadeMessages
646:                                .getMessages().getString("CNPJ")); //$NON-NLS-1$
647:                    } else if (new CPF(contact.getCod_Identificacao())
648:                            .isValido()) {
649:                        jcbIdentificacao.setSelectedItem(TelaEntidadeMessages
650:                                .getMessages().getString("CPF")); //$NON-NLS-1$
651:                    }
652:                } else {
653:                    jcbIdentificacao.setSelectedIndex(0);
654:                }
655:                jftfIdentificacao.setText(contact.getCod_Identificacao());
656:                jftfTelefone.setText(contact.getTelefone());
657:                telaPrincipal.getTextAreaDescricao().setText(
658:                        contact.getDescricao());
659:                jtfContato.setText(contact.getContato());
660:                jtfEmail.setText(contact.getEmail());
661:                jtfEndereco.setText(contact.getEndereco());
662:                telaPrincipal.getPainelBotoes().dadosCarregados(true);
663:            }
664:
665:            /**
666:             *
667:             */
668:            private void refreshTabelaEntidades() {
669:                try {
670:                    jtEntidades.loadDados();
671:                } catch (Exception e) {
672:                    ((SimpleLog) GFPController.getGFPController().getContexto()
673:                            .get(GFPController.LOG))
674:                            .log("Erro ao atualizar tabela de entidades!");
675:                    ((SimpleLog) GFPController.getGFPController().getContexto()
676:                            .get(GFPController.LOG)).log(e
677:                            .getLocalizedMessage());
678:                    ((SimpleLog) GFPController.getGFPController().getContexto()
679:                            .get(GFPController.LOG)).log(e);
680:                }
681:
682:            }
683:
684:            /**
685:             * @param e
686:             */
687:            public void loadFromTable(ListSelectionEvent e) {
688:                if (ContactsWindow.this .isVisible()) {
689:                    try {
690:                        entidadeInit();
691:                        contact.setDados(jtEntidades.getDataAt(jtEntidades
692:                                .getSelectedRow()));
693:                    } catch (SQLException sqle) {
694:                        ((SimpleLog) GFPController.getGFPController()
695:                                .getContexto().get(GFPController.LOG))
696:                                .log("Erro ao carregar entidade da tabela!");
697:                        ((SimpleLog) GFPController.getGFPController()
698:                                .getContexto().get(GFPController.LOG)).log(sqle
699:                                .getLocalizedMessage());
700:                        ((SimpleLog) GFPController.getGFPController()
701:                                .getContexto().get(GFPController.LOG))
702:                                .log(sqle);
703:                    }
704:                    editarEntidade();
705:                }
706:
707:            }
708:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.