Package com.GestDB.sql

Source Code of com.GestDB.sql.ConexionIFrame

/*
* Conexion.java
*
*
* Created on 2004
* Created by Arsenio Molinero
* Copyright (C) 2004, 2005 Arsenio Molinero
*
* GestDB - a Java multi database client
*
* This file is part of GestDB.
*
* GestDB 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 2 of the License, or
* (at your option) any later version.
*
* GestDB 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 GestDB; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.GestDB.sql;

import com.GestDB.general.Trackbug;
import com.GestDB.swing.*;
import com.GestDB.convert.wizarExportarDatos;
import com.GestDB.convert.ImportarDlg;
import com.GestDB.*;
import com.utils.utilidades;
import java.awt.Rectangle;
import java.beans.PropertyVetoException;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
*
* @author  seni
*/
public class ConexionIFrame extends javax.swing.JInternalFrame implements Literales {
   
    /** Creates new form Conexion */
    public ConexionIFrame(final Gestor padre, String key, String titulo, String jdbcDriverClass1, String jdbcDriverURL1, String user1, String password1) {
        super(titulo);
       
        try  {
            initComponents();
            PonLiterales();
            this.key = key;
            this.padre = padre;
            this.setTitle(titulo);
            jdbcDriverClass = jdbcDriverClass1;
            jdbcDriverURL = jdbcDriverURL1;
            user = user1;
            password = password1;

            jTabbedPane1 = new CloseButtonTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);

            jTabbedPane1.addContainerListener(new java.awt.event.ContainerAdapter() {
                public void componentRemoved(java.awt.event.ContainerEvent evt) {
                    CloseButtonTabbedPane ctp2 = (CloseButtonTabbedPane)evt.getSource();
                    padre.saveAll(padre);
                    //System.out.println("Componente borrado: " + ((JButton)evt.getChild()).getText());
                }
            });

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

            Thread thr = new Thread(){
                public void run()
                {
                    try {
                        while(getParent() == null)
                            sleep(500);

                        setMaximum(true);
                    } catch (Exception ex) {
                        Logger.getLogger(ConexionIFrame.class.getName()).log(Level.SEVERE, null, ex);
                        try {
                            while(getParent() == null)
                                sleep(500);

                            setMaximum(true);
                        } catch (Exception ex2) {
                            Logger.getLogger(ConexionIFrame.class.getName()).log(Level.SEVERE, null, ex2);
                        }
                    }

                }
            };

            thr.start();
        } catch(Throwable e)
        {
            Trackbug.fatal(e, "Error: " + e.getMessage());
        }
    }

    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jButton14 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jButton16 = new javax.swing.JButton();
        jButton17 = new javax.swing.JButton();
        jbFavoritos = new javax.swing.JButton();
        jbAddFavoritos = new javax.swing.JButton();
        jbShowQuerys = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setFont(new java.awt.Font("Verdana", 0, 10));
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/db4.gif"))); // NOI18N
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosed(evt);
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jToolBar1.setFloatable(false);
        jToolBar1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jToolBar1.setRollover(true);
        jToolBar1.setBorderPainted(false);

        jButton14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/lupa.gif"))); // NOI18N
        jButton14.setToolTipText("Visualiza el hist�rico de querys lanzadas");
        jButton14.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton14.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton14);

        jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/exportar.gif"))); // NOI18N
        jButton11.setToolTipText("Exporta datos a archivos de texto");
        jButton11.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton11.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton11);

        jButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/importar.gif"))); // NOI18N
        jButton12.setToolTipText("Importa datos desde archivos de texto");
        jButton12.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton12.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton12);

        jButton13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/tablas.gif"))); // NOI18N
        jButton13.setToolTipText("Visualiza la estructura de tablas y la configuraci�n de la conexi�n");
        jButton13.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton13.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton13);

        jButton15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/sql.gif"))); // NOI18N
        jButton15.setToolTipText("Visualiza la estructura de tablas y la configuraci�n de la conexi�n");
        jButton15.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton15.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton15);

        jButton16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/codegen.gif"))); // NOI18N
        jButton16.setToolTipText("Visualiza la estructura de tablas y la configuraci�n de la conexi�n");
        jButton16.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton16.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton16ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton16);

        jButton17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/edit.gif"))); // NOI18N
        jButton17.setToolTipText("Visualiza la estructura de tablas y la configuraci�n de la conexi�n");
        jButton17.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton17.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton17ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton17);

        jbFavoritos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/fav.png"))); // NOI18N
        jbFavoritos.setToolTipText("Permite gestionar los favoritos");
        jbFavoritos.setFocusable(false);
        jbFavoritos.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbFavoritos.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbFavoritos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbFavoritosActionPerformed(evt);
            }
        });
        jToolBar1.add(jbFavoritos);

        jbAddFavoritos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/fav_add.png"))); // NOI18N
        jbAddFavoritos.setToolTipText("Permite gestionar los favoritos");
        jbAddFavoritos.setFocusable(false);
        jbAddFavoritos.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbAddFavoritos.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbAddFavoritos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAddFavoritosActionPerformed(evt);
            }
        });
        jToolBar1.add(jbAddFavoritos);

        jbShowQuerys.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/verquery.gif"))); // NOI18N
        jbShowQuerys.setToolTipText("Visualiza el hist�rico de querys lanzadas");
        jbShowQuerys.setFocusable(false);
        jbShowQuerys.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbShowQuerys.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbShowQuerys.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbShowQuerysActionPerformed(evt);
            }
        });
        jToolBar1.add(jbShowQuerys);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.WEST);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-658)/2, (screenSize.height-518)/2, 658, 518);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton17ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton17ActionPerformed
    {//GEN-HEADEREND:event_jButton17ActionPerformed
        if(Gestor.propiedades.containsKey("sql.editor") && Gestor.propiedades.getProperty("sql.editor").trim().length() > 0)
        {
            if(jTabbedPane1.getSelectedIndex() != -1 && jTabbedPane1.getTitleAt(jTabbedPane1.getSelectedIndex()).trim().equals("SQL"))
            {

                String sEditor = Gestor.propiedades.getProperty("sql.editor").trim();
                File file = new File(Gestor.getRutaBaseTmp() + "edit.sql");
                if(!file.getParentFile().exists())
                    file.getParentFile().mkdirs();
               
                String sArchivoSql = file.getAbsolutePath();
                Runtime r = Runtime.getRuntime();
                Process p = null;
                String comando[] = { sEditor, sArchivoSql };

                // tiene que abrir el editor externo con el contenido del editor de sql activo en ese momento.
                // si tenemos una pesta�a activa del tipo SQL cojemos la sql si no la pasamos vacia
                String ssql = ((SQLPannel)jTabbedPane1.getComponentAt(jTabbedPane1.getSelectedIndex())).getQuery();

                try {
                    // escribimos un archivo con la sql
                   
                    FileOutputStream fout = new FileOutputStream(sArchivoSql);
                    fout.write(ssql.getBytes());
                    fout.flush();
                    fout.close();

                    // lanzamos el editor
                    p = r.exec( comando );
                    p.waitFor(); // esperamos a que lo cierre el usuario

                    // System.out.println( comando[0]+" ha devuelto "+p.exitValue() );

                    // tenemos que cargar el contenido en la pesta�a activa
                    if(jTabbedPane1.getSelectedIndex() != -1 && jTabbedPane1.getTitleAt(jTabbedPane1.getSelectedIndex()).trim().equals("SQL"))
                    {
                        ((SQLPannel)jTabbedPane1.getComponentAt(jTabbedPane1.getSelectedIndex())).setQuery(new String(utilidades.lee_Archivo2(sArchivoSql)));
                    }
                } catch( Exception e ) {
                    Trackbug.error(e, Gestor.GetLiteral("gestor.error_1","Error") + ": " + comando[0] + ", " + e.getMessage() );
                }
            }
            else
            {
                Alerta al = new Alerta(new javax.swing.JDialog(),Gestor.GetLiteral("gestor.alert","Aviso"),true,
                    Gestor.GetLiteral("conexion.error_6","Tiene que tener como pesta\u00F1a activa un editor de SQL"),Alerta.OK);
                al.setVisible(true);
                al = null;
            }
        }
        else
        {
            Alerta al = new Alerta(new javax.swing.JDialog(),Gestor.GetLiteral("gestor.alert","Aviso"),true,
                Gestor.GetLiteral("conexion.error_5","Tiene que indicar en la configuraci\u00F3n un editor externo para poder utilizar esta funcionalidad"),Alerta.OK);
            al.setVisible(true);
            al = null;
        }
       

       
    }//GEN-LAST:event_jButton17ActionPerformed

    private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
        // Visualiza el generador de c�digo
        try {
            if(jdbcDriverURL != null && jdbcDriverURL.length() > 0) {
                com.GestDB.gencode.CodeGenerator gc = new com.GestDB.gencode.CodeGenerator(this, jdbcDriverClass, jdbcDriverURL, user, password);
                jTabbedPane1.add("GenCode   ", gc);
                jTabbedPane1.setSelectedComponent(gc);
            }
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", en gencode. titulo: " + this.getTitle());
        }

    }//GEN-LAST:event_jButton16ActionPerformed

    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
        try {
            // a�ade una pesta�a de SQLPannel al tabbed
            SQLPannel sqlp = new SQLPannel(padre, key, this.getTitle(), jdbcDriverClass, jdbcDriverURL, user, password);
            this.jTabbedPane1.add("SQL   ", sqlp);
            jTabbedPane1.setSelectedComponent(sqlp);
            padre.saveAll(padre);
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", titulo: " + this.getTitle());
        }
           
    }//GEN-LAST:event_jButton15ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        try {
            BuscarYReemplazarPanel br = new BuscarYReemplazarPanel(this.getTitle().substring((Gestor.GetLiteral("gestor.connected_to","Conexi�n con") + ": ").length()), jdbcDriverURL,  jdbcDriverClass, user, password,this);
            jTabbedPane1.add(Gestor.GetLiteral("conexion.button_find","Buscar") + "   ", br);
            jTabbedPane1.setSelectedComponent(br);
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", titulo: " + this.getTitle().substring((Gestor.GetLiteral("gestor.connected_to","Conexi�n con") + ": ").length()));
        }
       
    }//GEN-LAST:event_jButton14ActionPerformed

    private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosed
        // Tengo que guardar las propiedades
       
    }//GEN-LAST:event_formInternalFrameClosed

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        try {
            // Visualiza la estructura de tablas y la configuraci�n de la conexi�n
            if(jdbcDriverURL != null && jdbcDriverURL.length() > 0) {
                EstructuraBDPanel ebd = new EstructuraBDPanel();
                ebd.Iniciar(jdbcDriverURL, jdbcDriverClass, user, password,this);
                jTabbedPane1.add("TBL   ", ebd);
                jTabbedPane1.setSelectedComponent(ebd);
                padre.saveAll(padre);
            }
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", en estructura bbdd. titulo: " + this.getTitle());
        }
       
    }//GEN-LAST:event_jButton13ActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        try {
            // Importa datos desde archivos de texto
            ImportarDlg importar = null;
            try {
                importar = new ImportarDlg(padre.propiedades, new java.awt.Frame(),false, jdbcDriverClass, jdbcDriverURL, user, password,this);
                importar.setBounds((this.padre.DesktopPanel.getWidth()/2)-(importar.getWidth()/2), (this.padre.DesktopPanel.getHeight()/2)-(importar.getHeight()/2), importar.getWidth(), importar.getHeight());
                this.padre.DesktopPanel.add(importar);
                importar.setVisible(true);
    //            jTabbedPane1.add(Gestor.GetLiteral("conexion.button_import","Importar") + "   ",importar);
    //            jTabbedPane1.setSelectedComponent(importar);
            } catch (Exception e) {
                Trackbug.error(e, e.getMessage());
            }
            importar = null;
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", importar. titulo: " + this.getTitle());
        }
       
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        try {
            // Exporta datos a archivos de texto
            wizarExportarDatos ex1 = null;
            try {
                // si tenemos una pesta�a activa del tipo SQL cojemos la sql si no la pasamos vacia
                String ssql = "";
                if(jTabbedPane1.getSelectedIndex() != -1 && jTabbedPane1.getTitleAt(jTabbedPane1.getSelectedIndex()).trim().equals("SQL"))
                {
                    ssql = ((SQLPannel)jTabbedPane1.getComponentAt(jTabbedPane1.getSelectedIndex())).getQuery();
                }

                ex1 = new wizarExportarDatos(padre.propiedades, new java.awt.Frame(), true,
                    jdbcDriverURL, jdbcDriverClass, user, password,ssql);
                ex1.setBounds((this.padre.DesktopPanel.getWidth()/2)-(ex1.getWidth()/2), (this.padre.DesktopPanel.getHeight()/2)-(ex1.getHeight()/2), ex1.getWidth(), ex1.getHeight());
                this.padre.DesktopPanel.add(ex1);
                ex1.setVisible(true);
            } catch (Exception e) {
                Trackbug.error(e, e.getMessage());
            }
            ex1 = null;
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", exportar. titulo: " + this.getTitle());
        }

    }//GEN-LAST:event_jButton11ActionPerformed

    private void jbFavoritosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbFavoritosActionPerformed
        try {
            padre.showFavoritesDialog(this);
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", favioritos. titulo: " + this.getTitle());
        }
           
    }//GEN-LAST:event_jbFavoritosActionPerformed

    private void jbAddFavoritosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddFavoritosActionPerformed
        try{
            // Manejar XML
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder parser = factory.newDocumentBuilder();
            TransformerFactory tranFactory = TransformerFactory.newInstance();
            Transformer aTransformer = tranFactory.newTransformer();
            // aTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "systmId");

            // Cargar el xml de favoritos
            Document doc = Gestor.CargaFavoritos(this.getClass());
            if(doc == null)
            {
                // lo creamos de cero por que no existe
                doc = parser.newDocument();

                Comment comment = doc.createComment("GestDB. File containing the user's favorite querys");
                doc.appendChild(comment);

                Element eFavoritos = doc.createElement("favoritos"); // creamos el elemento root
                doc.appendChild(eFavoritos);
            }

            // le a�adimos el nuevo favorito
            Element eFavorito = doc.createElement("favorito");

            // tenemos que calcular cuantos favoritos tenemos para poder calcular la posici�n del nuevo que es justo al final
            NodeList nodes = doc.getElementsByTagName("favorito");
            eFavorito.setAttribute("posicion",utilidades.AddLeftCadena(String.valueOf(Integer.toHexString(nodes.getLength())), 5, "0"));

            Element eNombre = doc.createElement("nombre");
            eNombre.setTextContent(Gestor.GetLiteral("gestor.literal_1","Favorito nuevo"));
            eFavorito.appendChild(eNombre);

            // sacamos la query del editor activo en estos momentos
            String sQuery = "";
            if(jTabbedPane1.getComponentAt(jTabbedPane1.getSelectedIndex()) instanceof SQLPannel)
            {
                sQuery = ((SQLPannel)jTabbedPane1.getComponentAt(jTabbedPane1.getSelectedIndex())).gEditor.getQuery();
            }

            Element eQuery = doc.createElement("query");
            eQuery.setTextContent(sQuery);
            eFavorito.appendChild(eQuery);

            Element eComentario = doc.createElement("comentario");
            eComentario.setTextContent("");
            eFavorito.appendChild(eComentario);

            // lo a�adimos
            doc.getElementsByTagName("favoritos").item(0).appendChild(eFavorito);

            // Lo guardamos
            Gestor.GuardaFavoritos(this.getClass(), doc, aTransformer);

            padre.jifFav.reloadData();
        }catch(Exception e){
            Trackbug.error(e, e.getMessage());
        }

    }//GEN-LAST:event_jbAddFavoritosActionPerformed

    private void jbShowQuerysActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbShowQuerysActionPerformed
    {//GEN-HEADEREND:event_jbShowQuerysActionPerformed
        try {
            ShowLogQuerys slog = new ShowLogQuerys();
            jTabbedPane1.add(Gestor.GetLiteral("conexion.button_viewquery","Log Querys") + "   ", slog);
            jTabbedPane1.setSelectedComponent(slog);
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", showquerys. titulo: " + this.getTitle());
        }

    }//GEN-LAST:event_jbShowQuerysActionPerformed

    /** Getter for property key.
     * @return Value of property key.
     *
     */
    public java.lang.String getKey() {
        return key;
    }   
   
    /** Setter for property key.
     * @param key New value of property key.
     *
     */
    public void setKey(java.lang.String key) {
        this.key = key;
    }   
   
    public String getXML()
    {
       String Resultado = "";
      
       try {
           // se tiene que recorrer todas las lenguetas e ir cogiendo su xml para retornarlo
           for(int i=0,j=jTabbedPane1.getTabCount();i<j;i++)
           {
               if(jTabbedPane1.getComponentAt(i) instanceof SQLPannel)
               {
                   Resultado += "<panel type=\"SQLPannel\">";
                   Resultado += "<limit status=\"" + ((SQLPannel)jTabbedPane1.getComponentAt(i)).jckLimite.isSelected() + "\" value=\"" +
                           ((SQLPannel)jTabbedPane1.getComponentAt(i)).jtLimite.getText() + "\" />";
                   Resultado += "<multitabs status=\"" + ((SQLPannel)jTabbedPane1.getComponentAt(i)).jckMultitabs.isSelected() + "\" />";
                   Resultado += ((SQLPannel)jTabbedPane1.getComponentAt(i)).gEditor.getEditorTabsXML();
                   Resultado += "</panel>";

               }
               else if(jTabbedPane1.getComponentAt(i) instanceof EstructuraBDPanel)
               {
                   Resultado += "<panel type=\"EstructuraBD\">";
                   Resultado += "</panel>";
               }
               else if(jTabbedPane1.getComponentAt(i) instanceof BuscarYReemplazarPanel)
               {
                   Resultado += "<panel type=\"BuscarYReemplazar\">";
                   Resultado += ((BuscarYReemplazarPanel)jTabbedPane1.getComponentAt(i)).getXML();
                   Resultado += "</panel>";
               }
           }
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", getxml. titulo: " + this.getTitle());
        }
      
       return Resultado;
    }
   
    public void putXML(String xml)
    {
        int pos1 = 0, pos2 = 0;
        String titulo1 = "", query1 = "", tipo = "";
       
        try {
            // se tiene que asegurar que la �ltima conexi�n no estaba en modo clasico, de lo
            // contrario no cargar� nada de la �ltima sesi�n
            if(xml == null || xml.trim().length() < 1 || xml.substring(0,7).equals("<panel ") == false)
                return;

            // se recorre las distintas pesta�as y las va creando
            while(xml.length() > 0)
            {
                // coge el tipo de panel <panel type="SQLPannel">
                pos1 = 13;
                pos2 = xml.indexOf("\"",pos1);
                if(pos2 != -1)
                    tipo = xml.substring(pos1,pos2);
                else
                    break;

                // Recoge toda la parte del tab y se lo pasa a la aplicaci�n
                if(tipo.equals("SQLPannel"))
                {
    //                Resultado += "<limit status=\"" + ((SQLPannel)jTabbedPane1.getComponentAt(i)).jckLimite.isSelected() + "\" value=\"" +
    //                       ((SQLPannel)jTabbedPane1.getComponentAt(i)).jtLimite.getText() + "\" />";
    //               Resultado += "<multitabs status=\"" + ((SQLPannel)jTabbedPane1.getComponentAt(i)).jckMultitabs.isSelected() + "\" />";

                    boolean bMultitabs = true;
                    boolean bLimite = true;
                    int nLimite = 1000;

                    pos1 = xml.indexOf("<limit");
                    if(pos1 != -1)
                    {
                        pos1 = xml.indexOf("\"",pos1);
                        pos2 = xml.indexOf("\"",pos1 + 1);
                        bLimite = Boolean.parseBoolean(xml.substring(pos1 + 1, pos2));
                        pos1 = xml.indexOf("\"",pos2 + 1);
                        pos2 = xml.indexOf("\"",pos1 + 1);
                        try {
                            nLimite = Integer.parseInt(xml.substring(pos1 + 1, pos2));
                        } catch(NumberFormatException ne)
                        {
                            ;
                        }
                    }

                    pos1 = xml.indexOf("<multitabs");
                    if(pos1 != -1)
                    {
                        pos1 = xml.indexOf("\"",pos1);
                        pos2 = xml.indexOf("\"",pos1 + 1);
                        bMultitabs = Boolean.parseBoolean(xml.substring(pos1 + 1, pos2));
                    }

                    // coge el titulo <tab>
                    pos1 = xml.indexOf("<tab>",pos2);
                    if(pos1 == -1)
                        break;
                    pos2 = xml.indexOf("</panel>",pos1);
                    if(pos2 == -1)
                        break;

                    SQLPannel sqlp1 = new SQLPannel(padre, key, this.getTitle(), jdbcDriverClass, jdbcDriverURL, user, password, bLimite, nLimite, bMultitabs);
                    sqlp1.putXML(xml.substring(pos1,pos2));
                    xml = xml.substring(pos2+8);
                    this.jTabbedPane1.add("SQL   ", sqlp1);
                    jTabbedPane1.setSelectedComponent(sqlp1);
                }
                else if(tipo.equals("EstructuraBD"))
                {
                    // como no se posiciona en ning�n sitio en concreto de la estructura simplemente descarta el XML y a�ade la pesta�a
                    pos2 = xml.indexOf("</panel>",pos1);
                    if(pos2 == -1)
                        break;

                    EstructuraBDPanel ebd = new EstructuraBDPanel();
                    ebd.Iniciar(jdbcDriverURL, jdbcDriverClass, user, password,this);
                    jTabbedPane1.add("TBL   ", ebd);
                    jTabbedPane1.setSelectedComponent(ebd);
                    xml = xml.substring(pos2+8);
                }
                else if(tipo.equals("BuscarYReemplazar"))
                {
                    // quita lo que lengthsobra
                    pos1 = xml.indexOf(">",pos2);
                    if(pos1 == -1)
                        break;
                    pos2 = xml.indexOf("</panel>",pos1);
                    if(pos2 == -1)
                        break;

                    BuscarYReemplazarPanel br = new BuscarYReemplazarPanel(this.getTitle().substring((Gestor.GetLiteral("gestor.connected_to","Conexi�n con") + ": ").length()), jdbcDriverURL,  jdbcDriverClass, user, password,this);
                    br.putXML(xml.substring(pos1,pos2));
                    jTabbedPane1.add(Gestor.GetLiteral("conexion.button_find","Buscar") + "   ", br);
                    jTabbedPane1.setSelectedComponent(br);
                    xml = xml.substring(pos2+8);
                }
            }
        } catch(Throwable e)
        {
            Trackbug.fatal(e,"Error: " + e.getMessage() + ", putxml. titulo: " + this.getTitle() + ". xml[" + xml + "]");
        }
    }

    public void PonLiterales()
    {
//         this.jButton14.setText(Gestor.GetLiteral("conexion.button_find","Buscar"));
         this.jButton14.setToolTipText(Gestor.GetLiteral("conexion.button_find_tooltips","Visualiza el hist�rico de querys lanzadas"));
//         this.jButton11.setText(Gestor.GetLiteral("conexion.button_export","Exportar"));
         this.jButton11.setToolTipText(Gestor.GetLiteral("conexion.button_export_tooltips","Exporta datos a archivos de texto"));
//         this.jButton12.setText(Gestor.GetLiteral("conexion.button_import","Importar"));
         this.jButton12.setToolTipText(Gestor.GetLiteral("conexion.button_import_tooltips","Importa datos desde archivos de texto"));
//         this.jButton13.setText(Gestor.GetLiteral("conexiontxt.tables","Tablas"));
         this.jButton13.setToolTipText(Gestor.GetLiteral("conexion.button_tables_tooltips","Visualiza la estructura de tablas y la configuraci�n de la conexi�n"));
//         this.jButton16.setText(Gestor.GetLiteral("conexion.codegen","Gen. src"));
         this.jButton16.setToolTipText(Gestor.GetLiteral("conexion.codegen_tooltips","Genera c�digo fuente en varios lenguajes de programaci�n para consultar tablas"));
//         this.jButton17.setText(Gestor.GetLiteral("conexion.button_edit","Editar"));
         this.jButton17.setToolTipText(Gestor.GetLiteral("conexion.button_edit_tooltips","Edita la sql del editor de sql en un editor externo"));
//         this.jbFavoritos.setText(Gestor.GetLiteral("conexion.button_favorite","Favoritas"));
         this.jbFavoritos.setToolTipText(Gestor.GetLiteral("conexion.button_favorite_tooltips","Permite gestionar las querys favoritas"));
//         this.jbAddFavoritos.setText(Gestor.GetLiteral("conexion.button_add_favorite","Add Fav."));
         this.jbAddFavoritos.setToolTipText(Gestor.GetLiteral("conexion.button_add_favorite_tooltips","A�ade la query actual en el listado de favoritas"));
         this.jbShowQuerys.setToolTipText(Gestor.GetLiteral("conexion.button_viewquery_tooltips","Visualiza el hist�rico de querys lanzadas"));
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton jbAddFavoritos;
    private javax.swing.JButton jbFavoritos;
    private javax.swing.JButton jbShowQuerys;
    // End of variables declaration//GEN-END:variables
   
    private int posQuery = 0;
    public String jdbcDriverClass=null;
    public String jdbcDriverURL=null;
    private String user=null;
    private String password=null;
    private String key = "";
    public Gestor padre = null;
    public com.GestDB.swing.CloseButtonTabbedPane jTabbedPane1 = null;

}
TOP

Related Classes of com.GestDB.sql.ConexionIFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.