001: /*
002: * Created on 17/01/2005
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2004 Igor Regis da Silva Simões
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: */
023: package br.com.gfp.ols.telas;
024:
025: import java.awt.BorderLayout;
026: import java.awt.Dimension;
027: import java.awt.GridBagConstraints;
028: import java.awt.Insets;
029: import java.awt.event.ActionEvent;
030: import java.awt.event.ActionListener;
031: import java.sql.SQLException;
032:
033: import javax.swing.JComboBox;
034: import javax.swing.JInternalFrame;
035: import javax.swing.JOptionPane;
036: import javax.swing.JScrollPane;
037: import javax.swing.event.ListSelectionEvent;
038: import javax.swing.event.ListSelectionListener;
039:
040: import br.com.gfp.dao.GFPController;
041: import br.com.gfp.dao.SupportRequestDAO;
042: import br.com.gfp.internationalization.ErrosDeDadosMessages;
043: import br.com.gfp.internationalization.TableHeaderMessages;
044: import br.com.gfp.internationalization.TelaBancoMessages;
045: import br.com.gfp.ols.componentes.CategoriaComboBoxModel;
046: import br.com.gfp.ols.componentes.GrupoComboBoxModel;
047: import br.com.gfp.ols.componentes.OLSTableCellRenderer;
048: import br.com.gfp.ols.componentes.OnLineSupportMessages;
049: import br.com.gfp.ols.componentes.WebComboBoxModel;
050: import br.com.gfp.ols.dados.SupportRequest;
051: import br.com.gfp.util.SimpleLog;
052: import br.com.gfp.windows.componentes.GFPHeaderRenderer;
053: import br.com.gfpshare.beans.GeneralEventHandler;
054: import br.com.gfpshare.beans.MessageView;
055: import br.com.gfpshare.beans.ZLabel;
056: import br.com.gfpshare.beans.ZTextArea;
057: import br.com.gfpshare.beans.ZTextField;
058: import br.com.gfpshare.beans.aplicativos.PainelTelaBasica;
059: import br.com.gfpshare.beans.table.DBTable;
060:
061: /**
062: * @author f4353008
063: * @since 17/01/2005 11:15:05
064: *
065: * To change the template for this generated type comment go to
066: * Window - Preferences - Java - Code Generation - Code and Comments
067: */
068: public class TelaSupportRequest extends JInternalFrame {
069: private PainelTelaBasica painelTelaBasica = new PainelTelaBasica();
070:
071: private ZLabel jlTituloDoRequest;
072:
073: private ZTextField jtfTituloDoRequest;
074:
075: private ZLabel jlCategoria;
076:
077: private JComboBox jcbCategoria;
078:
079: private ZLabel jlGrupo;
080:
081: private JComboBox jcbGrupo;
082:
083: private DBTable jtRequest;
084:
085: private ZLabel jlComentario;
086:
087: private ZTextArea taComentario;
088:
089: private SupportRequest request = null;
090:
091: private SupportRequestDAO controller = new SupportRequestDAO();
092:
093: /**
094: *
095: */
096: public TelaSupportRequest() {
097: request = new SupportRequest();
098: setVisible(true);
099: setIconifiable(true);
100: setMaximizable(true);
101: setResizable(true);
102: setClosable(true);
103: setContentPane(painelTelaBasica);
104:
105: setTitle(OnLineSupportMessages.getMessages().getString(
106: "SupportRequest")); //$NON-NLS-1$
107: // setFrameIcon(IconeFactory.getIconeFactory().getImageIcon(IconeFactory.BANCO_PEQUENA));
108:
109: GridBagConstraints gridBagConstraints;
110:
111: painelTelaBasica = new PainelTelaBasica();
112:
113: jtRequest = new DBTable(new SupportRequest(),
114: new GFPHeaderRenderer());
115: jtRequest.hideColumn("Id");
116: jtRequest.hideColumn("Tipo");
117: jtRequest.hideColumn("MyRequest");
118: jtRequest.hideColumn("LocalPost");
119:
120: jtRequest.getColumn("AtribuidoPara").setCellRenderer(
121: new OLSTableCellRenderer(-1, -1));
122: jtRequest.getColumn("CommentsCount").setCellRenderer(
123: new OLSTableCellRenderer(-1, -1));
124: jtRequest.getColumn("Id").setCellRenderer(
125: new OLSTableCellRenderer(-1, -1));
126: jtRequest.getColumn("Prioridade").setCellRenderer(
127: new OLSTableCellRenderer(-1, -1));
128: jtRequest.getColumn("Status").setCellRenderer(
129: new OLSTableCellRenderer(-1, -1));
130: jtRequest.getColumn("Texto").setCellRenderer(
131: new OLSTableCellRenderer(-1, -1));
132: jtRequest.getColumn("Titulo").setCellRenderer(
133: new OLSTableCellRenderer(-1, -1));
134: jtRequest.getColumn("Categoria").setCellRenderer(
135: new OLSTableCellRenderer(-1, -1));
136: jtRequest.getColumn("Grupo").setCellRenderer(
137: new OLSTableCellRenderer(-1, -1));
138:
139: jtRequest.getSelectionModel().addListSelectionListener(
140: (ListSelectionListener) GeneralEventHandler.makeProxy(
141: this , "loadFromTable",
142: ListSelectionListener.class, "valueChanged"));
143:
144: painelTelaBasica.setJtDados(jtRequest);
145: painelTelaBasica.setPrintButtonVisible(false);
146: painelTelaBasica.getTextAreaDescricao().setEditable(false);
147:
148: jlTituloDoRequest = new ZLabel((MessageView) GFPController
149: .getGFPController().getContexto().get(
150: GFPController.RODAPE_MESSAGER));
151: jtfTituloDoRequest = new ZTextField();
152: jlGrupo = new ZLabel((MessageView) GFPController
153: .getGFPController().getContexto().get(
154: GFPController.RODAPE_MESSAGER));
155: jcbGrupo = new JComboBox(new GrupoComboBoxModel());
156: jlCategoria = new ZLabel((MessageView) GFPController
157: .getGFPController().getContexto().get(
158: GFPController.RODAPE_MESSAGER));
159: jcbCategoria = new JComboBox(new CategoriaComboBoxModel());
160: jlComentario = new ZLabel((MessageView) GFPController
161: .getGFPController().getContexto().get(
162: GFPController.RODAPE_MESSAGER));
163: taComentario = new ZTextArea();
164:
165: jlTituloDoRequest.setText(TableHeaderMessages.getMessages()
166: .getString("Titulo"));
167: jlTituloDoRequest.setDisplayedMnemonic(TableHeaderMessages
168: .getMessages().getString("TituloMnemonic").charAt(0));
169: jlTituloDoRequest.setRequiredField(jtfTituloDoRequest);
170: jlTituloDoRequest.setValidationNotNull(true);
171: jlTituloDoRequest.setToolTipText(TableHeaderMessages
172: .getMessages().getString("TituloToolTip"));
173: gridBagConstraints = new GridBagConstraints();
174: gridBagConstraints.gridx = 0;
175: gridBagConstraints.gridy = 0;
176: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
177: painelTelaBasica.addComponent(jlTituloDoRequest,
178: gridBagConstraints,
179: PainelTelaBasica.DATA_COMPONENTS_AREA);
180:
181: jtfTituloDoRequest.setMinimumSize(new Dimension(100, 24));
182: jtfTituloDoRequest.setPreferredSize(new Dimension(180, 26));
183: jtfTituloDoRequest.setToolTipText(TableHeaderMessages
184: .getMessages().getString("TituloToolTip"));
185: gridBagConstraints = new GridBagConstraints();
186: gridBagConstraints.gridx = 1;
187: gridBagConstraints.gridy = 0;
188: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
189: painelTelaBasica.addComponent(jtfTituloDoRequest,
190: gridBagConstraints,
191: PainelTelaBasica.DATA_COMPONENTS_AREA);
192:
193: jlCategoria.setText(TableHeaderMessages.getMessages()
194: .getString("Categoria"));
195: jlCategoria
196: .setDisplayedMnemonic(TableHeaderMessages.getMessages()
197: .getString("CategoriaMnemonic").charAt(0));
198: jlCategoria.setRequiredField(jtfTituloDoRequest);
199: jlCategoria.setValidationNotNull(true);
200: jlCategoria.setToolTipText(TableHeaderMessages.getMessages()
201: .getString("CategoriaToolTip"));
202: gridBagConstraints = new GridBagConstraints();
203: gridBagConstraints.gridx = 0;
204: gridBagConstraints.gridy = 1;
205: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
206: painelTelaBasica.addComponent(jlCategoria, gridBagConstraints,
207: PainelTelaBasica.DATA_COMPONENTS_AREA);
208:
209: jcbCategoria.setMinimumSize(new Dimension(100, 24));
210: jcbCategoria.setPreferredSize(new Dimension(180, 26));
211: jcbCategoria.setToolTipText(TableHeaderMessages.getMessages()
212: .getString("CategoriaToolTip"));
213: gridBagConstraints = new GridBagConstraints();
214: gridBagConstraints.gridx = 1;
215: gridBagConstraints.gridy = 1;
216: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
217: painelTelaBasica.addComponent(jcbCategoria, gridBagConstraints,
218: PainelTelaBasica.DATA_COMPONENTS_AREA);
219:
220: jlGrupo.setText(TableHeaderMessages.getMessages().getString(
221: "Grupo"));
222: jlGrupo.setDisplayedMnemonic(TableHeaderMessages.getMessages()
223: .getString("GrupoMnemonic").charAt(0));
224: jlGrupo.setRequiredField(jtfTituloDoRequest);
225: jlGrupo.setValidationNotNull(true);
226: jlGrupo.setToolTipText(TableHeaderMessages.getMessages()
227: .getString("GrupoToolTip"));
228: gridBagConstraints = new GridBagConstraints();
229: gridBagConstraints.gridx = 0;
230: gridBagConstraints.gridy = 2;
231: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
232: painelTelaBasica.addComponent(jlGrupo, gridBagConstraints,
233: PainelTelaBasica.DATA_COMPONENTS_AREA);
234:
235: jcbGrupo.setMinimumSize(new Dimension(100, 24));
236: jcbGrupo.setPreferredSize(new Dimension(180, 26));
237: jcbGrupo.setToolTipText(TableHeaderMessages.getMessages()
238: .getString("GrupoToolTip"));
239: gridBagConstraints = new GridBagConstraints();
240: gridBagConstraints.gridx = 1;
241: gridBagConstraints.gridy = 2;
242: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
243: painelTelaBasica.addComponent(jcbGrupo, gridBagConstraints,
244: PainelTelaBasica.DATA_COMPONENTS_AREA);
245:
246: jlComentario.setText(OnLineSupportMessages.getMessages()
247: .getString("NovoComentario"));
248: jlComentario.setDisplayedMnemonic(OnLineSupportMessages
249: .getMessages().getString("NovoComentarioMnemonic")
250: .charAt(0));
251: jlComentario.setRequiredField(taComentario);
252: jlComentario.setToolTipText(OnLineSupportMessages.getMessages()
253: .getString("NovoComentarioToolTip"));
254: gridBagConstraints = new GridBagConstraints();
255: gridBagConstraints.gridx = 0;
256: gridBagConstraints.gridy = 3;
257: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
258: painelTelaBasica.addComponent(jlComentario, gridBagConstraints,
259: PainelTelaBasica.DATA_COMPONENTS_AREA);
260:
261: JScrollPane scroll = new JScrollPane(taComentario);
262: scroll.setPreferredSize(new Dimension(150, 60));
263: scroll.setMinimumSize(new Dimension(150, 60));
264: scroll.setMinimumSize(new Dimension(250, 60));
265: taComentario.setToolTipText(OnLineSupportMessages.getMessages()
266: .getString("NovoComentarioToolTip"));
267: gridBagConstraints = new GridBagConstraints();
268: gridBagConstraints.gridx = 1;
269: gridBagConstraints.gridy = 3;
270: gridBagConstraints.weightx = 1;
271: gridBagConstraints.fill = GridBagConstraints.BOTH;
272: gridBagConstraints.insets = new Insets(5, 5, 5, 5);
273: painelTelaBasica.addComponent(scroll, gridBagConstraints,
274: PainelTelaBasica.DATA_COMPONENTS_AREA);
275:
276: painelTelaBasica.getPainelBotoes().addActionListener(
277: "salvar",
278: (ActionListener) GeneralEventHandler.makeProxy(this ,
279: "salvar", ActionListener.class,
280: "actionPerformed"));
281: painelTelaBasica.getPainelBotoes().addActionListener(
282: "atualizar",
283: (ActionListener) GeneralEventHandler.makeProxy(this ,
284: "atualizar", ActionListener.class,
285: "actionPerformed"));
286: painelTelaBasica.getPainelBotoes().addActionListener(
287: "novo",
288: (ActionListener) GeneralEventHandler
289: .makeProxy(this , "novo", ActionListener.class,
290: "actionPerformed"));
291: painelTelaBasica.getPainelBotoes().addActionListener(
292: "excluir",
293: (ActionListener) GeneralEventHandler.makeProxy(this ,
294: "excluir", ActionListener.class,
295: "actionPerformed"));
296: painelTelaBasica.getPainelBotoes().addActionListener(
297: "pesquisar",
298: (ActionListener) GeneralEventHandler.makeProxy(this ,
299: "pesquisar", ActionListener.class,
300: "actionPerformed"));
301: painelTelaBasica.getPainelBotoes().addActionListener(
302: "limpar",
303: (ActionListener) GeneralEventHandler.makeProxy(this ,
304: "limpar", ActionListener.class,
305: "actionPerformed"));
306: painelTelaBasica.getPainelBotoes().addActionListener(
307: "filtrar",
308: (ActionListener) GeneralEventHandler.makeProxy(this ,
309: "filtrar", ActionListener.class,
310: "actionPerformed"));
311:
312: getContentPane().add(painelTelaBasica, BorderLayout.CENTER);
313:
314: }
315:
316: public void salvar(ActionEvent e) {
317: if (request == null) {
318: JOptionPane.showMessageDialog(this , TelaBancoMessages
319: .getMessages().getString("semDadosParaSalvar"));
320: return;
321: }
322: loadRequest();
323: if (controller.isAdicionandoNovo()) {
324: final SupportRequest supportRequest = new SupportRequest();
325: supportRequest.setDados(request.getAsMap());
326: supportRequest.setNovoTexto(request.getNovoTexto());
327: new Thread("AdicionandoSupportRequest") {
328: @Override
329: public void run() {
330: try {
331: controller.adicionarNovo(supportRequest);
332: } catch (SQLException sqle) {
333: JOptionPane.showMessageDialog(
334: TelaSupportRequest.this , sqle
335: .getMessage(),
336: ErrosDeDadosMessages.getMessages()
337: .getString("MessageTitle"),
338: JOptionPane.WARNING_MESSAGE);
339: painelTelaBasica.getPainelBotoes()
340: .setOcorreuErro(true);
341: return;
342: }
343: }
344: }.start();
345: } else {
346: final SupportRequest supportRequest = new SupportRequest();
347: supportRequest.setDados(request.getAsMap());
348: supportRequest.setNovoTexto("\n" + "Post by "
349: + System.getProperty("user.name") + "\n"
350: + request.getNovoTexto());
351: new Thread("AtualizandoSupportRequest") {
352: @Override
353: public void run() {
354: try {
355: controller.atualizar(supportRequest);
356: } catch (SQLException sqle) {
357: JOptionPane.showMessageDialog(
358: TelaSupportRequest.this , sqle
359: .getMessage(),
360: ErrosDeDadosMessages.getMessages()
361: .getString("MessageTitle"),
362: JOptionPane.WARNING_MESSAGE);
363: painelTelaBasica.getPainelBotoes()
364: .setOcorreuErro(true);
365: return;
366: }
367: }
368: }.start();
369: }
370: request = null;
371: refreshTabelaRequests();
372: }
373:
374: /**
375: * @param e
376: */
377: public void pesquisar(ActionEvent e) {
378: if (request == null)
379: request = new SupportRequest(jtfTituloDoRequest.getText());
380:
381: loadRequest();
382: try {
383: request = controller.getBy(request);
384: } catch (SQLException sqle) {
385: ((SimpleLog) GFPController.getGFPController().getContexto()
386: .get(GFPController.LOG))
387: .log("Erro ao pesquisar mapeamentoVisaVale: "
388: + request);
389: ((SimpleLog) GFPController.getGFPController().getContexto()
390: .get(GFPController.LOG)).log(sqle
391: .getLocalizedMessage());
392: ((SimpleLog) GFPController.getGFPController().getContexto()
393: .get(GFPController.LOG)).log(sqle);
394: request = null;
395: }
396: editarRequest();
397: }
398:
399: /**
400: * @param e
401: */
402: public void excluir(ActionEvent e) {
403: if (request == null) {
404: JOptionPane.showMessageDialog(this , TelaBancoMessages
405: .getMessages().getString("semDadosParaExcluir")); //$NON-NLS-1$
406: return;
407: }
408:
409: loadRequest();
410:
411: try {
412: controller.deletar(request);
413: } catch (SQLException sqle) {
414: ((SimpleLog) GFPController.getGFPController().getContexto()
415: .get(GFPController.LOG))
416: .log("Erro ao deletar mapeamentoVisaVale: "
417: + request);
418: ((SimpleLog) GFPController.getGFPController().getContexto()
419: .get(GFPController.LOG)).log(sqle
420: .getLocalizedMessage());
421: ((SimpleLog) GFPController.getGFPController().getContexto()
422: .get(GFPController.LOG)).log(sqle);
423: }
424: request = null;
425: refreshTabelaRequests();
426: }
427:
428: /**
429: * @param e
430: */
431: public void novo(ActionEvent e) {
432: request = new SupportRequest(jtfTituloDoRequest.getText());
433: controller.setAdicionandoNovo(true);
434: }
435:
436: /**
437: * @param e
438: */
439: public void atualizar(ActionEvent e) {
440: refreshTabelaRequests();
441: }
442:
443: /**
444: * @param e
445: */
446: public void limpar(ActionEvent e) {
447: painelTelaBasica.showRequiredFields();
448: request = null;
449: painelTelaBasica.getTextAreaDescricao().setText(""); //$NON-NLS-1$
450: jtfTituloDoRequest.setText(""); //$NON-NLS-1$
451: jcbGrupo.setSelectedItem(null);
452: jcbCategoria.setSelectedItem(null);
453: taComentario.setText("");
454: painelTelaBasica.getPainelBotoes().dadosCarregados(false);
455: controller.setAdicionandoNovo(false);
456: jtfTituloDoRequest.setEnabled(true);
457: jcbCategoria.setEnabled(true);
458: jcbGrupo.setEnabled(true);
459: }
460:
461: /**
462: * @param e
463: */
464: public void filtrar(ActionEvent e) {
465: request = new SupportRequest();
466: loadRequest();
467:
468: jtRequest.setDataType(request);
469: try {
470: jtRequest.filter();
471: } catch (Exception e1) {
472: ((SimpleLog) GFPController.getGFPController().getContexto()
473: .get(GFPController.LOG))
474: .log("Erro na filtragem da tabela de mapeamentoVisaVales!");
475: ((SimpleLog) GFPController.getGFPController().getContexto()
476: .get(GFPController.LOG)).log(e1
477: .getLocalizedMessage());
478: ((SimpleLog) GFPController.getGFPController().getContexto()
479: .get(GFPController.LOG)).log(e1);
480: }
481: }
482:
483: /**
484: *
485: */
486: private void loadRequest() {
487: request.setTitulo(jtfTituloDoRequest.getText());
488: request.setCategoria(((WebComboBoxModel) jcbCategoria
489: .getModel()).getSelectedId());
490: request.setGrupo(((WebComboBoxModel) jcbGrupo.getModel())
491: .getSelectedId());
492: request.setNovoTexto(taComentario.getText());
493: }
494:
495: /**
496: *
497: */
498: private void editarRequest() {
499: painelTelaBasica.hideRequiredFields();
500: if (request == null)
501: return;
502:
503: jtfTituloDoRequest.setText(request.getTitulo());
504: jtfTituloDoRequest.setEnabled(false);
505: jcbCategoria.setSelectedItem(request.getCategoria());
506: jcbCategoria.setEnabled(false);
507: jcbGrupo.setSelectedItem(request.getGrupo());
508: jcbGrupo.setEnabled(false);
509: painelTelaBasica.getTextAreaDescricao().setText(
510: request.getTexto());
511: painelTelaBasica.getPainelBotoes().dadosCarregados(true);
512:
513: }
514:
515: /**
516: *
517: */
518: private void refreshTabelaRequests() {
519: try {
520: jtRequest.loadDados();
521: } catch (Exception e) {
522: ((SimpleLog) GFPController.getGFPController().getContexto()
523: .get(GFPController.LOG))
524: .log("Erro na atualizacao da tabela de mapeamentoVisaVales!");
525: ((SimpleLog) GFPController.getGFPController().getContexto()
526: .get(GFPController.LOG)).log(e
527: .getLocalizedMessage());
528: ((SimpleLog) GFPController.getGFPController().getContexto()
529: .get(GFPController.LOG)).log(e);
530: }
531: }
532:
533: /**
534: * @param e
535: */
536: public void loadFromTable(ListSelectionEvent e) {
537: if (this .isVisible()) {
538: try {
539: request = (SupportRequest) jtRequest
540: .getPersistentObject(jtRequest.getSelectedRow());
541: } catch (SQLException sqle) {
542: ((SimpleLog) GFPController.getGFPController()
543: .getContexto().get(GFPController.LOG))
544: .log("Erro ao carregar Mapeamentos VisaVale!");
545: ((SimpleLog) GFPController.getGFPController()
546: .getContexto().get(GFPController.LOG)).log(sqle
547: .getLocalizedMessage());
548: ((SimpleLog) GFPController.getGFPController()
549: .getContexto().get(GFPController.LOG))
550: .log(sqle);
551: }
552: editarRequest();
553: }
554: }
555: }
|