001: /*
002: * Created on 21/10/2005
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2005 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.db.migration;
024:
025: import java.awt.BorderLayout;
026: import java.awt.Frame;
027: import java.awt.GridBagConstraints;
028: import java.awt.GridBagLayout;
029: import java.sql.SQLException;
030: import java.util.ArrayList;
031: import java.util.HashMap;
032: import java.util.Map;
033:
034: import javax.swing.JLabel;
035: import javax.swing.JPanel;
036: import javax.swing.JScrollPane;
037: import javax.swing.JSpinner;
038: import javax.swing.JTextArea;
039:
040: import br.com.gfp.dao.CreditCardDAO;
041: import br.com.gfp.dao.GFPController;
042: import br.com.gfp.data.CreditCard;
043: import br.com.gfp.internationalization.DBWizard7Messages;
044: import br.com.gfp.util.SimpleLog;
045: import br.com.gfpshare.db.DAO;
046:
047: /**
048: *
049: * @author Igor Regis da Silva Simoes
050: * @since 21/10/2005
051: */
052: public class MigrarDB7 extends MigradorDBWizard {
053: /**
054: * Relaciona os spinners da tela de dados com os cart�es carregados
055: */
056: private Map<CreditCard, JSpinner> map;
057:
058: /**
059: * Cart�es a serem migrados
060: */
061: private ArrayList<CreditCard> cartoes = null;
062:
063: /**
064: * @param owner
065: */
066: public MigrarDB7(Frame owner) {
067: super (owner);
068: }
069:
070: /**
071: * @see br.com.gfp.db.migration.MigradorDBWizard#adicionarPaineis()
072: */
073: @Override
074: protected void adicionarPaineis() {
075: adicionarPainelExplicativo();
076: adicionarPainelDados();
077: }
078:
079: /**
080: * @see br.com.gfp.db.migration.MigradorDBWizard#migrar()
081: */
082: @Override
083: protected void migrar() {
084: setSize(450, 300);
085: setResizable(false);
086: setVisible(true);
087: }
088:
089: /**
090: * @see br.com.gfp.db.migration.MigradorDBWizard#precisaDeWizard()
091: */
092: @Override
093: protected boolean precisaDeWizard() {
094: super .precisaDeWizard();
095: CreditCardDAO controller = new CreditCardDAO();
096: try {
097: return controller.getAllBy(new CreditCard()).size() > 0;
098: } catch (SQLException e) {
099: ((SimpleLog) GFPController.getGFPController().getContexto()
100: .get(GFPController.LOG))
101: .log("Erro ao carregar cartoes de credito!");
102: ((SimpleLog) GFPController.getGFPController().getContexto()
103: .get(GFPController.LOG)).log(e
104: .getLocalizedMessage());
105: ((SimpleLog) GFPController.getGFPController().getContexto()
106: .get(GFPController.LOG)).log(e);
107: return false;
108: }
109: }
110:
111: /**
112: * Adiciona o segundo painel do wizard
113: */
114: private void adicionarPainelExplicativo() {
115: JTextArea jtaTitulo = null;
116: JTextArea jtaIntro = null;
117:
118: JPanel painel = new JPanel();
119: painel.setLayout(new GridBagLayout());
120:
121: jtaTitulo = new JTextArea();
122: jtaTitulo.setText(DBWizard7Messages.getMessages().getString(
123: "changes"));
124: jtaTitulo.setFont(new java.awt.Font("Times New Roman",
125: java.awt.Font.BOLD | java.awt.Font.ITALIC, 18));
126: jtaTitulo.setEditable(false);
127: jtaTitulo.setOpaque(false);
128: GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
129: gridBagConstraints1.gridx = 0;
130: gridBagConstraints1.gridy = 0;
131: gridBagConstraints1.insets = new java.awt.Insets(10, 0, 20, 0);
132: gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH;
133: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
134: painel.add(jtaTitulo, gridBagConstraints1);
135:
136: jtaIntro = new JTextArea();
137: jtaIntro.setText(DBWizard7Messages.getMessages().getString(
138: "changesDesc"));
139: jtaIntro.setEditable(false);
140: jtaIntro.setLineWrap(true);
141: jtaIntro.setWrapStyleWord(true);
142: jtaIntro.setOpaque(false);
143: GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
144: gridBagConstraints2.gridx = 0;
145: gridBagConstraints2.gridy = 1;
146: gridBagConstraints2.weightx = 1;
147: gridBagConstraints2.weighty = 1;
148: gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST;
149: gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH;
150: painel.add(new JScrollPane(jtaIntro), gridBagConstraints2);
151:
152: addPage(painel);
153: }
154:
155: /**
156: * Adiciona o painel que vai capturar os dados do usuario
157: */
158: private void adicionarPainelDados() {
159: JPanel painel = new JPanel();
160: painel.setLayout(new BorderLayout());
161:
162: JTextArea jtaTitulo = new JTextArea();
163: jtaTitulo.setText(DBWizard7Messages.getMessages().getString(
164: "selectDays"));
165: jtaTitulo.setEditable(false);
166: jtaTitulo.setOpaque(false);
167: painel.add(jtaTitulo, BorderLayout.NORTH);
168:
169: DAO<CreditCard> controller = new CreditCardDAO();
170: try {
171: cartoes = controller.getAllBy(new CreditCard());
172: } catch (SQLException e) {
173: ((SimpleLog) GFPController.getGFPController().getContexto()
174: .get(GFPController.LOG))
175: .log("Erro ao carregar cartoes de credito!");
176: ((SimpleLog) GFPController.getGFPController().getContexto()
177: .get(GFPController.LOG)).log(e
178: .getLocalizedMessage());
179: ((SimpleLog) GFPController.getGFPController().getContexto()
180: .get(GFPController.LOG)).log(e);
181: }
182:
183: JPanel painelCentro = new JPanel();
184: painelCentro.setLayout(new GridBagLayout());
185: int i = 0;
186: for (CreditCard cartao : cartoes) {
187: JLabel jlCartao = new JLabel(cartao.getDescricao());
188: GridBagConstraints gridBagConstraints = new GridBagConstraints();
189: gridBagConstraints.gridx = 0;
190: gridBagConstraints.gridy = i + 1;
191: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
192: painelCentro.add(jlCartao, gridBagConstraints);
193:
194: JSpinner jsCartao = new JSpinner();
195: jsCartao.setValue(new Integer(40));
196: GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
197: gridBagConstraints2.gridx = 1;
198: gridBagConstraints2.gridy = i++;
199: gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
200: painelCentro.add(jsCartao, gridBagConstraints2);
201:
202: if (map == null)
203: map = new HashMap<CreditCard, JSpinner>();
204: map.put(cartao, jsCartao);
205: }
206:
207: painel.add(new JScrollPane(painelCentro), BorderLayout.CENTER);
208:
209: addPage(painel);
210: }
211:
212: /**
213: * Executa o passo da passagem da tela <code>passo</code> para a <code>passo + 1</code>
214: * @param passo Passo a ser executado
215: */
216: @Override
217: public void executeStep(int passo) {
218: if (passo == 3) {
219: for (CreditCard cartao : cartoes) {
220: cartao.setDiasParaPagamento((Integer) map.get(cartao)
221: .getValue());
222: DAO<CreditCard> controller = new CreditCardDAO();
223: try {
224: controller.atualizar(cartao);
225: } catch (SQLException e) {
226: ((SimpleLog) GFPController.getGFPController()
227: .getContexto().get(GFPController.LOG))
228: .log("Erro ao migrar cart�o: " + cartao);
229: ((SimpleLog) GFPController.getGFPController()
230: .getContexto().get(GFPController.LOG))
231: .log(e.getLocalizedMessage());
232: ((SimpleLog) GFPController.getGFPController()
233: .getContexto().get(GFPController.LOG))
234: .log(e);
235: }
236: }
237: }
238: }
239: }
|