001: /*
002: * Created on 13/10/2004
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: package br.com.gfp.actions;
023:
024: import java.awt.event.ActionEvent;
025: import java.awt.event.ActionListener;
026: import java.io.IOException;
027: import java.sql.SQLException;
028:
029: import br.com.gfp.dao.GFPController;
030: import br.com.gfp.db.DBInicializador;
031: import br.com.gfp.internationalization.ActionsMessages;
032: import br.com.gfp.util.SimpleLog;
033: import br.com.gfp.util.ThreadUtil;
034: import br.com.gfp.windows.GFPPrincipal;
035: import br.com.gfp.windows.TransactionWindow;
036: import br.com.gfpshare.beans.MessageView;
037: import br.com.gfpshare.controllers.ArquivoDeDadosAbertoContoller;
038:
039: /**
040: * @author Igor Regis da Silva Simoes
041: */
042: public class NovoDBAction implements ActionListener {
043: private static NovoDBAction action = null;
044:
045: /**
046: *
047: */
048: private NovoDBAction() {
049: super ();
050: }
051:
052: /**
053: * @return Retorna uma instancia desta action
054: */
055: public static NovoDBAction getAction() {
056: return action;
057: }
058:
059: /**
060: *
061: */
062: public static void initializeAction() {
063: if (action == null)
064: action = new NovoDBAction();
065: }
066:
067: /**
068: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
069: */
070: public void actionPerformed(ActionEvent e) {
071: FecharDBAction.getAction().actionPerformed(e);
072: if (ArquivoDeDadosAbertoContoller.getInstance(null) != null
073: && ArquivoDeDadosAbertoContoller.getInstance(null)
074: .isArquivoAberto())
075: return;
076:
077: ThreadUtil.waitFor("FecharDB");
078: try {
079: DBInicializador.inicializarBancoDeDados();
080: } catch (IOException e1) {
081: ((SimpleLog) GFPController.getGFPController().getContexto()
082: .get(GFPController.LOG)).log(e1
083: .getLocalizedMessage());
084: ((SimpleLog) GFPController.getGFPController().getContexto()
085: .get(GFPController.LOG)).log(e1);
086: } catch (SQLException e1) {
087: if (e1.getErrorCode() != -21) {
088: ((SimpleLog) GFPController.getGFPController()
089: .getContexto().get(GFPController.LOG)).log(e1
090: .getErrorCode()
091: + " " + e1.getLocalizedMessage());
092: ((SimpleLog) GFPController.getGFPController()
093: .getContexto().get(GFPController.LOG)).log(e1);
094: }
095: }
096:
097: try {
098: DBInicializador.inicializarDBDosPlugins();
099: } catch (Exception e1) {
100: SimpleLog log = (SimpleLog) GFPController
101: .getGFPController().getContexto().get(
102: GFPController.LOG);
103: log.log("Erro ao inicializar plugins DB: "
104: + e1.getLocalizedMessage());
105: log.log(e1);
106: }
107:
108: ArquivoDeDadosAbertoContoller.getInstance(null)
109: .setArquivoAberto();
110: ((GFPPrincipal) GFPController.getGFPController().getContexto()
111: .get(GFPController.FRAME_PRINCIPAL))
112: .buildMenusAndButtons(true);
113:
114: MessageView messages = (MessageView) GFPController
115: .getGFPController().getContexto().get(
116: GFPController.RODAPE_MESSAGER);
117: messages = messages.showMessage(ActionsMessages.getMessages()
118: .getString("ArquivoCriadoTitulo"), ActionsMessages
119: .getMessages().getString("ArquivoCriadoMessage"), true);
120: messages.finishUse();
121:
122: GFPController.getGFPController().create(
123: TransactionWindow.class, true);
124: }
125: }
|