/*
 * WANDORA
 * Knowledge Extraction, Management, and Publishing Application
 * http://wandora.org
 * 
 * Copyright (C) 2004-2023 Wandora Team
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * 
 * SQLConsole.java
 *
 * Created on 28. joulukuuta 2004, 15:09
 */

package org.wandora.application.tools.sqlconsole;

import org.wandora.utils.Options;

/**
 *
 * @author  olli
 */
public class SQLConsoleFrame extends javax.swing.JFrame {

	private static final long serialVersionUID = 1L;

	//private Kirjava kirjava;
    public Options options = null;
    
    /** Creates new form SQLConsole */
    public SQLConsoleFrame(String[] args) {
        //this.kirjava=kirjava;
        String optionsFileName = "conf/sqlconsole_options.xml";
        options = new Options(optionsFileName);
        initComponents();
        try{
            connect((String)options.get("options.sqlconsole.driver"),
                    (String)options.get("options.sqlconsole.connectstring"),
                    (String)options.get("options.sqlconsole.user"),
                    (String)options.get("options.sqlconsole.password"));
        } catch(Exception e) {
            e.printStackTrace();
        }
        try {
            ((SQLConsolePanel)consolePanel).loadStoredQueries();
        } catch(Exception e){
            e.printStackTrace();
        }
    }
    
    /** 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 regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        consolePanel = new SQLConsolePanel(options);

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        getContentPane().add(consolePanel, java.awt.BorderLayout.CENTER);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-585)/2, (screenSize.height-486)/2, 585, 486);
    }//GEN-END:initComponents
    
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        try{
            ((SQLConsolePanel)consolePanel).saveStoredQueries();
        }catch(java.io.IOException ioe){
            ioe.printStackTrace();
        }
    }//GEN-LAST:event_exitForm
    
    public void connect(String driver,String connectString,String user,String password){
        ((SQLConsolePanel)consolePanel).connect(driver,connectString,user,password);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new SQLConsoleFrame(args).show();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel consolePanel;
    // End of variables declaration//GEN-END:variables
    
}
