Package com.GestDB.sql

Source Code of com.GestDB.sql.ResulsetPannel$ThreadQuerys

/*
* ResulsetPannel.java
*
* Created on 2010
* Created by Arsenio Molinero
* Copyright (C) 2010-2012 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.Gestor;
import com.GestDB.general.Trackbug;
import com.GestDB.swing.Chart;
import com.GestDB.swing.ImprimirThread;
import com.utils.Valor;
import com.utils.utilidades;
import java.awt.Color;
import java.awt.FontMetrics;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JEditorPane;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

/**
*
* @author seni
*/
public class ResulsetPannel extends javax.swing.JPanel {

    /** Creates new form ResulsetPannel */
    public ResulsetPannel(String sQuery, SQLPannel sqlpannel, String jdbcDriverClass1, String jdbcDriverURL1, String user1, String password1,
                          boolean bLimite, int nLimite)
    {
        this.sqlpannel = sqlpannel;
        this.sQuery = sQuery;
        this.jdbcDriverClass = jdbcDriverClass1;
        this.jdbcDriverURL = jdbcDriverURL1;
        this.user = user1;
        this.password = password1;

        initComponents();
        PonLiterales();

        jlQuery.setText(sQuery);
        jlQuery.setToolTipText(sQuery);

        jtmodel.configurar(jdbcDriverClass,jdbcDriverURL,user,password);
        jtmodel.setLimit(bLimite, nLimite);
       
        jtmodel.addCChangeRowNumberListener(new JdbcTModel.ChangeRowNumber()
        {
            public void ChangeValue(int nTotRows)
            {
                if(nTotRows != 0) {
                    tNReg.setText(Gestor.GetLiteral("conexion.reg","Reg") + ": 1");
                    tTotalReg.setText(Gestor.GetLiteral("conexion.total","Total") + ": " + nTotRows);
                }
                else {
                    tNReg.setText(Gestor.GetLiteral("conexion.reg","Reg") + ": 0");
                    tTotalReg.setText(Gestor.GetLiteral("conexion.total","Total") + ": 0");
                }

                boolean bEval = jtmodel.isActualizable() && !jtmodel.isError();
                jbCommit.setVisible(bEval);
                jbDelete.setVisible(bEval);
                jbInfoChanges.setVisible(bEval);
            }

            public void InitChange()
            {
                setResponseMessage(Gestor.GetLiteral("conexion.process_wait","Procesando SQL, espere por favor"),MSGOK,0,0);
            }

            public void EndChange()
            {
                if( jtmodel.isError() ) {
                    tNReg.setText(Gestor.GetLiteral("conexion.reg","Reg") + ": 0");
                    tTotalReg.setText(Gestor.GetLiteral("conexion.total","Total") + ": 0");
                    setResponseMessage(jtmodel.getError(),MSGERR,jtmodel.getMiliseconsQuery(),(new java.util.Date()).getTime() - inicio);
                }
                else
                {
                    setResponseMessage("" + jtmodel.getRowCount() + " " +
                        Gestor.GetLiteral("conexion.reg_found","registros encontrados"),MSGOK,jtmodel.getMiliseconsQuery(),(new java.util.Date()).getTime() - inicio);

                    setColumnSize();
                }
            }
        });

        sorttmodel = new SortTModel(jtableResulset,jtmodel);

        DefaultTableCellRenderer df = new DefaultTableCellRenderer.UIResource(){
            public void setValue(Object value) {
                String cadena = "";
                try {
                    if (value != null && value instanceof byte[])
                    {
                        int longitud = Math.min(((byte[])value).length, 50);
                        cadena = new String((byte[])value, 0, longitud);
                        if(longitud < ((byte[])value).length)
                            cadena += " ...";
                    }
                    else if (value != null && value instanceof java.sql.Clob)
                    {
                        try {
                            cadena = ((java.sql.Clob) value).getSubString(1L, (int) Math.min(1000, ((java.sql.Clob) value).length()));
                            if (cadena.length() < ((java.sql.Clob) value).length()) {
                                cadena += "...";
                            }
                        } catch (SQLException ex) {
                            Logger.getLogger(SQLPannel.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                    else if(value != null && value instanceof java.sql.Blob)
                    {
                        try {
                            cadena = new String(((java.sql.Blob) value).getBytes(1L, (int) Math.min(1000, ((java.sql.Blob) value).length())));
                            if (cadena.length() < ((java.sql.Blob) value).length()) {
                                cadena += "...";
                            }
                        } catch (Exception ex) {
                            Logger.getLogger(SQLPannel.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                    else if(value != null && ( value instanceof java.sql.Date ||
                            value instanceof java.sql.Time || value instanceof java.sql.Timestamp))
                    {
                        Calendar caltmp = Calendar.getInstance();
                        if(value instanceof java.sql.Date)
                            caltmp.setTimeInMillis(((java.sql.Date)value).getTime());
                        else if(value instanceof java.sql.Time)
                            caltmp.setTimeInMillis(((java.sql.Time)value).getTime());
                        else
                            caltmp.setTimeInMillis(((java.sql.Timestamp)value).getTime());
                        cadena = utilidades.GenDateString( caltmp, value instanceof java.sql.Timestamp, value.getClass(), value);
                    }
                    else if (value != null && value instanceof Integer[])
                    {
                        Integer valores[] = (Integer[])value;
                        cadena = "{ ";
                        for(int k = 0; k < valores.length; k++)
                        {
                            cadena += ((k > 0)?", ":"") + valores[k];
                        }
                       
                        cadena += " }";
                    }
                    else if (value != null && value instanceof String[])
                    {
                        String valores[] = (String[])value;
                        cadena = "{ ";
                        for(int k = 0; k < valores.length; k++)
                        {
                            cadena += ((k > 0)?", '":"'") + valores[k] + "'";
                        }
                       
                        cadena += " }";
                    }
                    else if (value != null && value instanceof Object[])
                    {
                        Object valores[] = (Object[])value;
                        cadena = "{ ";
                        for(int k = 0; k < valores.length; k++)
                        {
                            cadena += ((k > 0)?", '":"'") + valores[k] + "'";
                        }
                       
                        cadena += " }";
                    }
                    else if(value != null)
                        cadena = value.toString();
                    else
                        cadena = "{null}";

                    if(bFiltro && cadena != null && cadena.toLowerCase().indexOf(sFiltro) != -1)
                    {
                        this.setForeground(Color.red);
                    }
                    else
                        this.setForeground(Color.black);
                } catch(Exception e)
                {
                    Trackbug.error(e, e.getMessage());
                }
                setText(cadena);
            }
        };

        jtableResulset.setDefaultRenderer(Object.class, df);
        jtableResulset.setDefaultRenderer(String.class, df);
        jtableResulset.setDefaultRenderer(Boolean.class, df);
        jtableResulset.setDefaultRenderer(Short.class, df);
        jtableResulset.setDefaultRenderer(Integer.class, df);
        jtableResulset.setDefaultRenderer(Long.class, df);
        jtableResulset.setDefaultRenderer(Number.class, df);
        jtableResulset.setDefaultRenderer(Double.class, df);
        jtableResulset.setDefaultRenderer(Float.class, df);
        jtableResulset.setDefaultRenderer(BigDecimal.class, df);
        jtableResulset.setDefaultRenderer(java.sql.Date.class, df);
        jtableResulset.setDefaultRenderer(java.sql.Time.class, df);
        jtableResulset.setDefaultRenderer(java.sql.Timestamp.class, df);
        jtableResulset.setDefaultRenderer(java.sql.Clob.class, df);

        jtableResulset.setDefaultEditor(java.sql.Date.class, new com.GestDB.swing.table.CellEditor(sqlpannel.padre));
        jtableResulset.setDefaultEditor(java.sql.Timestamp.class, new com.GestDB.swing.table.CellEditor(sqlpannel.padre));
        jtableResulset.setDefaultEditor(java.sql.Clob.class, new com.GestDB.swing.table.CellEditor(sqlpannel.padre));
//        jtableResulset.setDefaultEditor(Object.class, new com.GestDB.swing.table.CellEditor(padre));

        sorttmodel.addMouseListenerToHeaderInTable(jtableResulset);

        // jtableResulset.getTableHeader().setBackground(new Color(255,153,51));
    }

    private static int MSGOK = 0;
    private static int MSGERR = 1;

    private void setResponseMessage(String msg, int typemsg, long totalQuery, long totalLoad)
    {
        lRespuesta.setText(msg);
        lRespuesta.setToolTipText(msg);
        if(typemsg == MSGOK)
            lRespuesta.setForeground(Color.BLACK);
        else if(typemsg == MSGERR)
            lRespuesta.setForeground(Color.RED);

        jlTimeQuery.setText(utilidades.AddLeftCadena(String.valueOf(totalQuery),6,"0"));
        jlTimegetData.setText(utilidades.AddLeftCadena(String.valueOf(totalLoad),6,"0"));
        jlTimeQuery.setToolTipText(jlTimeQuery.getText() + " " + Gestor.GetLiteral("sqlpannel.milisecons_query","milisegundos query"));
        jlTimegetData.setToolTipText(jlTimegetData.getText() + " " + Gestor.GetLiteral("sqlpannel.total_time","Tiempo total"));
    }


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

        titulo = new javax.swing.JPanel();
        jlQuery = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jtFiltro = new javax.swing.JTextField();
        jbInfoChanges = new javax.swing.JButton();
        jbFiltrar = new javax.swing.JButton();
        jbQuitarFiltro = new javax.swing.JButton();
        jbCommit = new javax.swing.JButton();
        jbDelete = new javax.swing.JButton();
        jbRefresh = new javax.swing.JButton();
        jbAddRow = new javax.swing.JButton();
        jbPrint = new javax.swing.JButton();
        resultados = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtableResulset = new javax.swing.JTable();
        jstaResulset = new javax.swing.JScrollPane();
        jtaResulset = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jlColumnX = new javax.swing.JLabel();
        jcbXColumn = new javax.swing.JComboBox();
        jlColumnY = new javax.swing.JLabel();
        jbVer = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        chart = new Chart(Chart.CHART_2D);
        jckDrawLines = new javax.swing.JCheckBox();
        jckdrawValues = new javax.swing.JCheckBox();
        jScrollPane6 = new javax.swing.JScrollPane();
        jlYColumn = new javax.swing.JList();
        jckDrawTitles = new javax.swing.JCheckBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtableMetadata = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jepInfo = new javax.swing.JEditorPane();
        pie = new javax.swing.JPanel();
        jlTimeQuery = new javax.swing.JLabel();
        jlTimegetData = new javax.swing.JLabel();
        tNReg = new javax.swing.JTextField();
        tTotalReg = new javax.swing.JTextField();
        lRespuesta = new javax.swing.JLabel();
        jbAviso = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        titulo.setPreferredSize(new java.awt.Dimension(425, 55));

        jlQuery.setText("Select * from la tabla");

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/filtro.gif"))); // NOI18N

        jtFiltro.setPreferredSize(new java.awt.Dimension(4, 21));
        jtFiltro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtFiltroKeyReleased(evt);
            }
        });

        jbInfoChanges.setForeground(new java.awt.Color(0, 102, 51));
        jbInfoChanges.setText("?");
        jbInfoChanges.setToolTipText("Informaci�n de como componer SQL que permitan la modificaci�n de celdas.");
        jbInfoChanges.setBorder(null);
        jbInfoChanges.setMaximumSize(new java.awt.Dimension(9, 24));
        jbInfoChanges.setPreferredSize(new java.awt.Dimension(25, 21));
        jbInfoChanges.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbInfoChangesActionPerformed(evt);
            }
        });

        jbFiltrar.setText("...");
        jbFiltrar.setPreferredSize(new java.awt.Dimension(49, 21));
        jbFiltrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbFiltrarActionPerformed(evt);
            }
        });

        jbQuitarFiltro.setText("X");
        jbQuitarFiltro.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jbQuitarFiltro.setPreferredSize(new java.awt.Dimension(49, 21));
        jbQuitarFiltro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbQuitarFiltroActionPerformed(evt);
            }
        });

        jbCommit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/actualizar.gif"))); // NOI18N
        jbCommit.setBorder(null);
        jbCommit.setPreferredSize(new java.awt.Dimension(55, 21));
        jbCommit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCommitActionPerformed(evt);
            }
        });

        jbDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/eliminar.gif"))); // NOI18N
        jbDelete.setBorder(null);
        jbDelete.setPreferredSize(new java.awt.Dimension(55, 21));
        jbDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbDeleteActionPerformed(evt);
            }
        });

        jbRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/refresh.png"))); // NOI18N
        jbRefresh.setBorder(null);
        jbRefresh.setPreferredSize(new java.awt.Dimension(55, 21));
        jbRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRefreshActionPerformed(evt);
            }
        });

        jbAddRow.setForeground(new java.awt.Color(0, 102, 51));
        jbAddRow.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/new.png"))); // NOI18N
        jbAddRow.setToolTipText("Informaci�n de como componer SQL que permitan la modificaci�n de celdas.");
        jbAddRow.setBorder(null);
        jbAddRow.setMaximumSize(new java.awt.Dimension(9, 24));
        jbAddRow.setPreferredSize(new java.awt.Dimension(25, 21));
        jbAddRow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAddRowActionPerformed(evt);
            }
        });

        jbPrint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/print.png"))); // NOI18N
        jbPrint.setBorder(null);
        jbPrint.setPreferredSize(new java.awt.Dimension(55, 21));
        jbPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbPrintActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tituloLayout = new javax.swing.GroupLayout(titulo);
        titulo.setLayout(tituloLayout);
        tituloLayout.setHorizontalGroup(
            tituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jlQuery, javax.swing.GroupLayout.DEFAULT_SIZE, 789, Short.MAX_VALUE)
            .addGroup(tituloLayout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbFiltrar, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbQuitarFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(166, 166, 166)
                .addComponent(jbRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jbCommit, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(jbAddRow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbInfoChanges, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbPrint, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26))
        );
        tituloLayout.setVerticalGroup(
            tituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tituloLayout.createSequentialGroup()
                .addComponent(jlQuery)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(tituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbAddRow, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                        .addComponent(jbInfoChanges, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jtFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbFiltrar, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbQuitarFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jbRefresh, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jbCommit, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jbDelete, javax.swing.GroupLayout.Alignment.TRAILING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jbPrint, 0, 0, Short.MAX_VALUE))
                .addContainerGap())
        );

        add(titulo, java.awt.BorderLayout.NORTH);

        resultados.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                resultadosStateChanged(evt);
            }
        });

        jtableResulset.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jtableResulset.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jtableResulset.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtableResulsetMouseClicked(evt);
            }
        });
        jtableResulset.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtableResulsetKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jtableResulset);

        resultados.addTab("Resulset", new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/resulset.png")), jScrollPane1); // NOI18N

        jtaResulset.setColumns(20);
        jtaResulset.setFont(new java.awt.Font("Courier 10 Pitch", 0, 12));
        jtaResulset.setRows(5);
        jstaResulset.setViewportView(jtaResulset);

        resultados.addTab("Text Format", new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/resulset_txt.png")), jstaResulset); // NOI18N

        jlColumnX.setText("X column:");

        jlColumnY.setText("Y Column:");

        jbVer.setText("Ver");
        jbVer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbVerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout chartLayout = new javax.swing.GroupLayout(chart);
        chart.setLayout(chartLayout);
        chartLayout.setHorizontalGroup(
            chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 757, Short.MAX_VALUE)
        );
        chartLayout.setVerticalGroup(
            chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 182, Short.MAX_VALUE)
        );

        jScrollPane5.setViewportView(chart);

        jckDrawLines.setText("Dibujar l�neas");
        jckDrawLines.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jckDrawLinesActionPerformed(evt);
            }
        });

        jckdrawValues.setText("Dibujar valores");
        jckdrawValues.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jckdrawValuesActionPerformed(evt);
            }
        });

        jScrollPane6.setViewportView(jlYColumn);

        jckDrawTitles.setSelected(true);
        jckDrawTitles.setText("Dibujar encabezados");
        jckDrawTitles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jckDrawTitlesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 760, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jlColumnX)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jcbXColumn, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jlColumnY))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jckDrawLines)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jckdrawValues))
                            .addComponent(jckDrawTitles))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
                        .addGap(12, 12, 12)
                        .addComponent(jbVer)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlColumnX)
                            .addComponent(jcbXColumn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlColumnY)
                            .addComponent(jbVer))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jckDrawLines)
                            .addComponent(jckdrawValues))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jckDrawTitles))
                    .addComponent(jScrollPane6, 0, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)
                .addContainerGap())
        );

        resultados.addTab("Chart", new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/chart_bar.png")), jPanel1); // NOI18N

        jtableMetadata.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jtableMetadata);

        resultados.addTab("Metadata", new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/metadata.png")), jScrollPane2); // NOI18N

        jepInfo.setContentType("text/html");
        jScrollPane3.setViewportView(jepInfo);

        resultados.addTab("Info", new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/info.png")), jScrollPane3); // NOI18N

        add(resultados, java.awt.BorderLayout.CENTER);

        pie.setPreferredSize(new java.awt.Dimension(425, 19));

        jlTimeQuery.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlTimeQuery.setText("000000");
        jlTimeQuery.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jlTimeQuery.setPreferredSize(new java.awt.Dimension(95, 14));

        jlTimegetData.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlTimegetData.setText("000000");
        jlTimegetData.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jlTimegetData.setPreferredSize(new java.awt.Dimension(95, 14));

        tNReg.setEditable(false);
        tNReg.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tNReg.setToolTipText("Registro actual");
        tNReg.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        tNReg.setMaximumSize(new java.awt.Dimension(60, 18));
        tNReg.setMinimumSize(new java.awt.Dimension(50, 18));
        tNReg.setPreferredSize(new java.awt.Dimension(70, 14));

        tTotalReg.setEditable(false);
        tTotalReg.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tTotalReg.setToolTipText("Total registros");
        tTotalReg.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        tTotalReg.setMaximumSize(new java.awt.Dimension(70, 32));
        tTotalReg.setMinimumSize(new java.awt.Dimension(50, 20));
        tTotalReg.setPreferredSize(new java.awt.Dimension(70, 14));

        lRespuesta.setText(" ");
        lRespuesta.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lRespuestaMouseClicked(evt);
            }
        });

        jbAviso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/GestDB/images/ayuda2.gif"))); // NOI18N
        jbAviso.setPreferredSize(new java.awt.Dimension(20, 18));
        jbAviso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAvisoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pieLayout = new javax.swing.GroupLayout(pie);
        pie.setLayout(pieLayout);
        pieLayout.setHorizontalGroup(
            pieLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pieLayout.createSequentialGroup()
                .addComponent(jlTimeQuery, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jlTimegetData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lRespuesta, javax.swing.GroupLayout.PREFERRED_SIZE, 403, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbAviso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tNReg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tTotalReg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        pieLayout.setVerticalGroup(
            pieLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pieLayout.createSequentialGroup()
                .addGroup(pieLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tTotalReg, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(tNReg, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(jlTimeQuery, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(jlTimegetData, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(lRespuesta, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE))
                .addGap(12, 12, 12))
            .addGroup(pieLayout.createSequentialGroup()
                .addComponent(jbAviso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        add(pie, java.awt.BorderLayout.SOUTH);
    }// </editor-fold>//GEN-END:initComponents

    private void jbAvisoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAvisoActionPerformed
        com.GestDB.swing.Alerta al = new com.GestDB.swing.Alerta(new javax.swing.JDialog(),
                Gestor.GetLiteral("gestor.alert","Atenci�n"), true,
                lRespuesta.getText(), com.GestDB.swing.Alerta.OK);
        al.setVisible(true);
}//GEN-LAST:event_jbAvisoActionPerformed

    private void jbCommitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCommitActionPerformed
        if(jtmodel.ActualizarCambios() == false && jtmodel.bError) {
            com.GestDB.swing.Alerta al = new com.GestDB.swing.Alerta(new javax.swing.JDialog(),
                Gestor.GetLiteral("gestor.alert","Atenci�n"), true,
                Gestor.GetLiteral("conexion.error_1","Se han producido errores actualizando las modificaciones en la\nbase de datos. A continuaci�n se indican los registros y el error.") + "\n" + jtmodel.sError, com.GestDB.swing.Alerta.OK);
            al.setVisible(true);
        }
        else
        {
            com.GestDB.swing.Alerta al = new com.GestDB.swing.Alerta(new javax.swing.JDialog(),
                Gestor.GetLiteral("gestor.alert","Atenci�n"), true,
                Gestor.GetLiteral("conexion.alert_1","Se han actualizando las modificaciones en la\nbase de datos."), com.GestDB.swing.Alerta.OK);
            al.setVisible(true);
        }

    }//GEN-LAST:event_jbCommitActionPerformed

    private void jbDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbDeleteActionPerformed
        // tiene que crear un vector con los n�meros de los registros a borrar
        Vector elementos = new Vector();
        int nfilas = this.jtableResulset.getSelectedRowCount();
        if(nfilas > 0)
        {
            int filas[] = jtableResulset.getSelectedRows();
            for(int i = 0; i< nfilas;i++)
                elementos.addElement(String.valueOf(filas[i]+1));

            com.GestDB.swing.Alerta al = new com.GestDB.swing.Alerta(new javax.swing.JDialog(),
                Gestor.GetLiteral("gestor.alert","Atenci�n"), true,
                Gestor.GetLiteral("conexion.alert_2","Se va a proceder a eliminar los registros. �Desea continuar?"), com.GestDB.swing.Alerta.OKCANCEL);
            al.setVisible(true);
            if(al.getReturnStatus() == com.GestDB.swing.Alerta.RET_OK)
            {
                if(sorttmodel.BorrarRegistros(elementos) == false && jtmodel.bError) {
                    al = new com.GestDB.swing.Alerta(new javax.swing.JDialog(),
                        Gestor.GetLiteral("gestor.alert","Atenci�n"), true,
                        Gestor.GetLiteral("conexion.error_2","Se han producido errores eliminando los registros en la\nbase de datos. A continuaci�n se indican los registros y el error.") + "\n" + jtmodel.sError, com.GestDB.swing.Alerta.OK);
                    al.setVisible(true);
                }
                else
                {
                    al = new com.GestDB.swing.Alerta(new javax.swing.JDialog(),
                        Gestor.GetLiteral("gestor.alert","Atenci�n"), true,
                        Gestor.GetLiteral("conexion.alert_3","Se han eliminado los registros de la\nbase de datos correctamente."), com.GestDB.swing.Alerta.OK);
                    al.setVisible(true);
                }
            }
        }

    }//GEN-LAST:event_jbDeleteActionPerformed

    private void jbInfoChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbInfoChangesActionPerformed
        String sMensaje = Gestor.GetLiteral("conexion.help1","Como actualizar de informaci�n en las tablas desde el editor.") + "\n" +
                "-------------------------------------------------------------------\n\n" +
                Gestor.GetLiteral("conexion.help2","Para que la informaci�n presentada en la zona de registros sea") + " \n" +
                Gestor.GetLiteral("conexion.help3","modifcable, tiene que cumplir las siguientes reglas:") + " \n\n" +
                Gestor.GetLiteral("conexion.help4","- No se tiene que utilizar el asterisco para referenciar a los") + "\n  " +
                Gestor.GetLiteral("conexion.help5","campos a no ser que se ponga delante el alias de la tabla, un") + " \n  " +
                Gestor.GetLiteral("conexion.help6","ejemplo incorrectop ser�a 'select * from usuarios'.") + " \n  " +
                Gestor.GetLiteral("conexion.help7","La manera correcta es 'select usuarios.* from usuarios'.") + "\n" +
                Gestor.GetLiteral("conexion.help8","- No se puede utilizar m�s de una tabla en la sentencia.") + "\n" +
                Gestor.GetLiteral("conexion.help9","- No se puede utilizar sentencias joing.") + "\n" +
                Gestor.GetLiteral("conexion.help10","- No se pueden utilizar columnas derivadas, como por ejemplo con") + "\n  " +
                Gestor.GetLiteral("conexion.help11","el max o el sum.") + "\n\n" +
                Gestor.GetLiteral("conexion.help12","Si selecciona una tabla desde la lista desplegable tendr� toda la") + "\n" +
                Gestor.GetLiteral("conexion.help13","seguridad de poder modificar sus registros.") + "\n" +
                Gestor.GetLiteral("conexion.help14","El generador de autoquerys funciona de la siguiente manera:") + "\n" +
                Gestor.GetLiteral("conexion.help15","1) seleccione una tabla de la lista.") + "\n" +
                Gestor.GetLiteral("conexion.help16","2) Si lo desea aplique un filtro pulsando en el bot�n filtro.") + "\n" +
                Gestor.GetLiteral("conexion.help17","3) pulse el bot�n 'Generar'.") + "\n";
        com.GestDB.swing.Alerta al = new com.GestDB.swing.Alerta(new javax.swing.JDialog(),
                Gestor.GetLiteral("conexion.help","Ayuda"), false, sMensaje, com.GestDB.swing.Alerta.OK);
        al.setVisible(true);
}//GEN-LAST:event_jbInfoChangesActionPerformed

    private void jtableResulsetKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtableResulsetKeyReleased
        jtableResulsetMouseClicked(null);
    }//GEN-LAST:event_jtableResulsetKeyReleased

    private void jtableResulsetMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtableResulsetMouseClicked
        if(jtableResulset.getSelectedRow() != -1)
            tNReg.setText(Gestor.GetLiteral("conexion.reg","Reg") + ": " + Integer.toString(jtableResulset.getSelectedRow() + 1));

    }//GEN-LAST:event_jtableResulsetMouseClicked

    private void lRespuestaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lRespuestaMouseClicked
        jbAvisoActionPerformed(null);
    }//GEN-LAST:event_lRespuestaMouseClicked

    private void jbFiltrarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbFiltrarActionPerformed
    {//GEN-HEADEREND:event_jbFiltrarActionPerformed
        sorttmodel.setFilter(jtFiltro.getText().toLowerCase());
    }//GEN-LAST:event_jbFiltrarActionPerformed

    private void jtFiltroKeyReleased(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jtFiltroKeyReleased
    {//GEN-HEADEREND:event_jtFiltroKeyReleased
        sFiltro = jtFiltro.getText().trim().toLowerCase();
        bFiltro = sFiltro.length() > 0;
        jtableResulset.repaint();

    }//GEN-LAST:event_jtFiltroKeyReleased

    private void jbQuitarFiltroActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbQuitarFiltroActionPerformed
    {//GEN-HEADEREND:event_jbQuitarFiltroActionPerformed
        jtFiltro.setText("");
        sFiltro = "";
        bFiltro = false;
        jtableResulset.repaint();
        sorttmodel.setFilter("");
    }//GEN-LAST:event_jbQuitarFiltroActionPerformed

    private void resultadosStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_resultadosStateChanged
    {//GEN-HEADEREND:event_resultadosStateChanged
        if(resultados.getSelectedIndex() == 1 && !bjtaResulsetCharge)
        {
            bjtaResulsetCharge = true;
            jtmodel.getText(jtaResulset);
            jtaResulset.setCaretPosition(0);
        }
        else if(resultados.getSelectedIndex() == 2 && !bChartCharge)
        {
            bChartCharge = true;
            Vector vtemp = new Vector();
            for(int i=0, limite = jtmodel.columnNames.length; i < limite; i++)
            {
                if(jtmodel.columnTypes[i].equals(Short.class) || jtmodel.columnTypes[i].equals(Integer.class) ||
                   jtmodel.columnTypes[i].equals(Number.class) || jtmodel.columnTypes[i].equals(java.math.BigDecimal.class) ||
                   jtmodel.columnTypes[i].equals(Long.class) || jtmodel.columnTypes[i].equals(Double.class||
                   jtmodel.columnTypes[i].equals(java.sql.Date.class) || jtmodel.columnTypes[i].equals(java.sql.Time.class) ||
                   jtmodel.columnTypes[i].equals(java.sql.Timestamp.class))
                {
                    jcbXColumn.addItem(new Valor(i,jtmodel.columnNames[i]));
                    vtemp.addElement(new Valor(i,jtmodel.columnNames[i]));
                }
            }

            jlYColumn.setModel(new DefaultComboBoxModel(vtemp));
        }

    }//GEN-LAST:event_resultadosStateChanged

    private void jbVerActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbVerActionPerformed
    {//GEN-HEADEREND:event_jbVerActionPerformed

        // Tenemos que calcular las columnas que se correspondan con los combos
        int colx = 0;
        int coly[] = null;
        int colz = 0;
        boolean bColyDistintos = false;

        colx = ((Valor)jcbXColumn.getSelectedItem()).id;

        Object valores[] = jlYColumn.getSelectedValues();
        coly = new int[valores.length];
        for(int i = 0; i < valores.length; i++)
        {
            coly[i] = ((Valor)valores[i]).id;

            if(i > 0 && ((esFecha(jtmodel.columnTypes[coly[i - 1]]) && esFecha(jtmodel.columnTypes[coly[i]]) == false) ||
                    (esFecha(jtmodel.columnTypes[coly[i - 1]]) == false && esFecha(jtmodel.columnTypes[coly[i]])) ) )
                    bColyDistintos = true;
        }

        if(bColyDistintos)
        {
            com.GestDB.swing.Alerta al = new com.GestDB.swing.Alerta(new javax.swing.JDialog(),
                    Gestor.GetLiteral("gestor.alert","Atenci�n"), true,
                    Gestor.GetLiteral("ResulsetPannel.columnyIdenticals","Las columnas seleccionadas para la columna Y tienen que ser del tipo numerico o de fecha, pero no de ambas."), com.GestDB.swing.Alerta.OK);
            al.setVisible(true);
        }

        ((Chart)chart).setModel(jtmodel, colx, coly, 0);

    }//GEN-LAST:event_jbVerActionPerformed

    private void jckDrawLinesActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jckDrawLinesActionPerformed
    {//GEN-HEADEREND:event_jckDrawLinesActionPerformed
        ((Chart)chart).setDrawLines(jckDrawLines.isSelected());
    }//GEN-LAST:event_jckDrawLinesActionPerformed

    private void jckdrawValuesActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jckdrawValuesActionPerformed
    {//GEN-HEADEREND:event_jckdrawValuesActionPerformed
        ((Chart)chart).setDrawValues(jckdrawValues.isSelected());
    }//GEN-LAST:event_jckdrawValuesActionPerformed

    private void jckDrawTitlesActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jckDrawTitlesActionPerformed
    {//GEN-HEADEREND:event_jckDrawTitlesActionPerformed
        ((Chart)chart).setDrawTitles(jckDrawTitles.isSelected());
    }//GEN-LAST:event_jckDrawTitlesActionPerformed

    private void jbRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRefreshActionPerformed
        doQuery();
    }//GEN-LAST:event_jbRefreshActionPerformed

    private void jbPrintActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbPrintActionPerformed
    {//GEN-HEADEREND:event_jbPrintActionPerformed
        ImprimirThread it = new ImprimirThread(jtableResulset);
        it.start();

    }//GEN-LAST:event_jbPrintActionPerformed

    private void jbAddRowActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbAddRowActionPerformed
    {//GEN-HEADEREND:event_jbAddRowActionPerformed
        addInternalFrame addif = new addInternalFrame(this, sCatalog, sSchema,
                                                      sTable, jdbcDriverURL,
                                                      user, password);
        sqlpannel.padre.DesktopPanel.add(addif);
        addif.show();
    }//GEN-LAST:event_jbAddRowActionPerformed

    private boolean esFecha(Class clase)
    {
        boolean resultado = false;

        if(clase == java.sql.Date.class || clase == java.sql.Time.class || clase == java.sql.Timestamp.class)
            resultado = true;

        return resultado;
    }

    private void PonLiterales()
    {
         this.jbCommit.setToolTipText(Gestor.GetLiteral("conexion.button_act_tooltips","Actualiza los cambios realizados en las celdas de la tabla(S�lo si el driver JDBC lo permite)."));
         this.jbDelete.setToolTipText(Gestor.GetLiteral("conexion.button_del_tooltips","Elimina el registro seleccionado en la lista de registros(s�lo si el driver JDBC lo permite)."));
         this.tNReg.setToolTipText(Gestor.GetLiteral("conexion.tf_nreg_tooltips","Registro actual"));
         this.tTotalReg.setToolTipText(Gestor.GetLiteral("conexion.tf_totalreg_tooltips","Total registros"));
         this.jbFiltrar.setToolTipText(Gestor.GetLiteral("ResulsetPannel.filter_tooltips","Aplicar filtro al resultado"));
         this.resultados.setTitleAt(0, Gestor.GetLiteral("ResulsetPannel.resulset","Resulset"));
         this.resultados.setTitleAt(1, Gestor.GetLiteral("importardlg.textplain","Texto plano"));
         this.resultados.setTitleAt(2, Gestor.GetLiteral("ResulsetPannel.chart","Gr�fico"));
         this.resultados.setTitleAt(3, Gestor.GetLiteral("ResulsetPannel.metadata","Metadata"));
         this.resultados.setTitleAt(4, Gestor.GetLiteral("ResulsetPannel.info","Info"));
         this.jbInfoChanges.setText(Gestor.GetLiteral("conexion.button_help","?"));
         this.jbInfoChanges.setToolTipText(Gestor.GetLiteral("conexion.button_help_tooltips","Informaci�n de como componer SQL que permitan la modificaci�n de celdas."));
         this.jlColumnX.setText(Gestor.GetLiteral("ResulsetPannel.xcolumn","Columna X"));
         this.jlColumnY.setText(Gestor.GetLiteral("ResulsetPannel.ycolumn","Columna Y"));
         this.jbVer.setText(Gestor.GetLiteral("buscaryreemplazar.view","Ver"));
    }

    private void setColumnSize()
    {
            // ponemos  las columnas  con un ancho m�s agradable
            FontMetrics fm = getGraphics().getFontMetrics(jtableResulset.getFont());
            int ancho26 = fm.bytesWidth("ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes(), 0, 26);
            int ancho10 = fm.bytesWidth("0000000000".getBytes(), 0, 10);
            int anchoFecha = fm.bytesWidth("00-MMM-0000 00:00:00  ".getBytes(), 0, 21);
            int anchoFecha2 = fm.bytesWidth("00-MMM-0000  ".getBytes(), 0, 12);
            int anchoHora = fm.bytesWidth("00:00:00  ".getBytes(), 0, 10);
            int ancho1 = ancho10 / 10;
            int ancho = 0;
            int limiteColumnas = jtableResulset.getTableHeader().getColumnModel().getColumnCount();

            for(int i=0, limite = Math.min(jtmodel.columnWidth.length, limiteColumnas); i < limite; i++)
            {
                if(jtmodel.columnTypes[i].equals(java.sql.Date.class))
                    ancho = anchoFecha2;
                else if(jtmodel.columnTypes[i].equals(java.sql.Time.class))
                    ancho = anchoHora;
                else if(jtmodel.columnTypes[i].equals(java.sql.Timestamp.class))
                    ancho = anchoFecha2;
                else if(jtmodel.columnWidth[i] > 26)
                    ancho = ancho26;
                else if(jtmodel.columnWidth[i] < 1)
                    ancho = ancho26;
                else
                    ancho = jtmodel.columnWidth[i] * ancho1;
                try {
                    jtableResulset.getTableHeader().getColumnModel().getColumn(i).setPreferredWidth(ancho + 10);
                } catch(Exception e)
                {
                    ;
                }
            }
    }

    public void doQuery() {
        jbCommit.setVisible(false);
        jbDelete.setVisible(false);

        ThreadQuerys tq = new ThreadQuerys(this);
        tq.start();
    }

    private class ThreadQuerys extends Thread
    {
        private ResulsetPannel rp = null;

        public ThreadQuerys(ResulsetPannel rp)
        {
            this.rp = rp;
        }

        public void run()
        {
            inicio = (new java.util.Date()).getTime();
            jtmodel.doQuery(sQuery);

            boolean bEval = jtmodel.isActualizable() && !jtmodel.isError();
            jbCommit.setVisible(bEval);
            jbDelete.setVisible(bEval);
            jbInfoChanges.setVisible(bEval);

            if( jtmodel.isError() ) {
//                tNReg.setText(Gestor.GetLiteral("conexion.reg","Reg") + ": 0");
//                tTotalReg.setText(Gestor.GetLiteral("conexion.total","Total") + ": 0");
//                setResponseMessage(jtmodel.getError(),MSGERR,jtmodel.getMiliseconsQuery(),(new java.util.Date()).getTime() - inicio);

                // vamos con el info
                String sHtml = "<html><body><h1>" + Gestor.GetLiteral("ResulsetPannel.info","Info") + "</h1>" +
                        "<p>" + Gestor.GetLiteral("favorites.query","Query") + ": <b>" + sQuery + "</b><p>" +
                        "<p>" + Gestor.GetLiteral("sqlpannel.milisecons_query","milisegundos query") + ": <b>" + jtmodel.getMiliseconsQuery() + "</b><p>" +
                        "<p>" + Gestor.GetLiteral("sqlpannel.total_time","Tiempo total") + ": <b>" + ((new java.util.Date()).getTime() - inicio) + "</b><p>" +
                        "<h1>" + Gestor.GetLiteral("gestor.error_1","Error") + "</h1>" +
                        "<p style='color:red;'>" + jtmodel.getError() + "</p>" +
                        "</body></html>";

                JEditorPane jep = new JEditorPane("text/html", sHtml);
                javax.swing.JScrollPane jscroll = new javax.swing.JScrollPane();
                jscroll.setViewportView(jep);
                sqlpannel.jtabResulserts.add("<E> " + sQuery.substring(0,Math.min(15, sQuery.length())), jscroll); // m�ximo 15 caracteres
                sqlpannel.jtabResulserts.setSelectedComponent(jscroll);

                // quitamos este panel
                sqlpannel.jtabResulserts.remove(rp);
            }
            else
            {

                // ponemos  las columnas  con un ancho m�s agradable
                setColumnSize();

                // rellenamos el metadata
                try {
                    int numberOfColumns = jtmodel.metaData.getColumnCount();
                    Vector vMetadata = new Vector(numberOfColumns);
                    Vector vTemp = null;
                    Vector vNombres = new Vector(11);
                    vNombres.addElement(Gestor.GetLiteral("ResulsetPannel.metadata_label","etiqueta"));
                    vNombres.addElement(Gestor.GetLiteral("estructurabd.name","Nombre"));
                    vNombres.addElement("Catalog");
                    vNombres.addElement("Scheme");
                    vNombres.addElement(Gestor.GetLiteral("buscaryreemplazar.table","tabla"));
                    vNombres.addElement(Gestor.GetLiteral("estructurabd.type","Tipo"));
                    vNombres.addElement(Gestor.GetLiteral("estructurabd.type","Tipo"));
                    vNombres.addElement("Class");
                    vNombres.addElement(Gestor.GetLiteral("ResulsetPannel.metadata_readonly","S�lo lectura"));
                    vNombres.addElement(Gestor.GetLiteral("estructurabd.precision","Precision/Tama�o"));
                    vNombres.addElement(Gestor.GetLiteral("estructurabd.decimal","Decimales"));

                    sCatalog = jtmodel.metaData.getCatalogName(1);
                    sSchema = jtmodel.metaData.getSchemaName(1);
                    sTable = jtmodel.metaData.getTableName(1);
                   
                    // si el nombre de la tabla esta vacio lo sacamnos a las bravas
                    if(sTable.trim().length() == 0)
                    {
                        int posIni = sQuery.toLowerCase().indexOf("from");
                        if(posIni != -1)
                        {
                            String sResult[] = sQuery.substring(posIni + 4).split("[\\s\\,]");
                            if(sResult[0].trim().length() > 0)
                                sTable = sResult[0].trim();
                            else
                                sTable = sResult[1].trim();
                        }
                    }

                    for(int column = 0; column < numberOfColumns; column++)
                    {
                        vTemp = new Vector(11);
                        vTemp.addElement(jtmodel.metaData.getColumnLabel(column+1));
                        vTemp.addElement(jtmodel.metaData.getColumnName(column+1));
                        vTemp.addElement(jtmodel.metaData.getCatalogName(column+1));
                        vTemp.addElement(jtmodel.metaData.getSchemaName(column+1));
                        vTemp.addElement(jtmodel.metaData.getTableName(column+1));
                        vTemp.addElement(jtmodel.metaData.getColumnType(column+1));
                        vTemp.addElement(jtmodel.metaData.getColumnTypeName(column+1));
                        vTemp.addElement(jtmodel.metaData.getColumnClassName(column+1));
                        vTemp.addElement(jtmodel.metaData.isReadOnly(column+1));
                        try {
                            vTemp.addElement(jtmodel.metaData.getPrecision(column+1));
                        } catch(NumberFormatException ne)
                        {
                            // For input string: "4294967295"
                            String error = ne.getMessage();
                            if(error != null && error.indexOf("\"") != -1)
                            {
                                int pos = error.indexOf("\"");
                                int pos2 = error.indexOf("\"",pos + 1);
                                if(pos2 != -1)
                                {
                                    vTemp.addElement(Long.parseLong(error.substring(pos + 1, pos2)));
                                }
                            }
                            Trackbug.error(ne, ne.getMessage() + "nombre columna " + (column + 1) + ": " + jtmodel.metaData.getColumnName(column+1) );
                        }
                        vTemp.addElement(jtmodel.metaData.getScale(column+1));
                        vMetadata.addElement(vTemp);
                    }

                    jtableMetadata.setModel(new DefaultTableModel(vMetadata, vNombres));
                }catch(Exception e)
                {
                    Trackbug.error(e, e.getMessage());
                }

                // vamos con el info
                String sHtml = "<html><body><h1>" + Gestor.GetLiteral("ResulsetPannel.info","Info") + "</h1>" +
                        "<p>" + Gestor.GetLiteral("favorites.query","Query") + ": <b>" + sQuery + "</b><p>" +
                        "<p>" + Gestor.GetLiteral("sqlpannel.total_time","Tiempo total") + ": <b>" + jlTimeQuery.getText() + "</b><p>" +
                        "<p>" + Gestor.GetLiteral("conexion.tf_totalreg_tooltips","Total registros") + ": <b>" + jtmodel.getRowCount() + "</b><p>" +
                        "<p>" + Gestor.GetLiteral("ResulsetPannel.numcolumns","N�mero de columnas") + ": <b>" + jtmodel.getColumnCount() + "</b><p>" +
                        "</body></html>";
                jepInfo.setText(sHtml);
            } // fin del else

        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel chart;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JButton jbAddRow;
    private javax.swing.JButton jbAviso;
    private javax.swing.JButton jbCommit;
    private javax.swing.JButton jbDelete;
    private javax.swing.JButton jbFiltrar;
    private javax.swing.JButton jbInfoChanges;
    private javax.swing.JButton jbPrint;
    private javax.swing.JButton jbQuitarFiltro;
    private javax.swing.JButton jbRefresh;
    private javax.swing.JButton jbVer;
    private javax.swing.JComboBox jcbXColumn;
    private javax.swing.JCheckBox jckDrawLines;
    private javax.swing.JCheckBox jckDrawTitles;
    private javax.swing.JCheckBox jckdrawValues;
    private javax.swing.JEditorPane jepInfo;
    private javax.swing.JLabel jlColumnX;
    private javax.swing.JLabel jlColumnY;
    private javax.swing.JLabel jlQuery;
    private javax.swing.JLabel jlTimeQuery;
    private javax.swing.JLabel jlTimegetData;
    private javax.swing.JList jlYColumn;
    private javax.swing.JScrollPane jstaResulset;
    private javax.swing.JTextField jtFiltro;
    private javax.swing.JTextArea jtaResulset;
    private javax.swing.JTable jtableMetadata;
    private javax.swing.JTable jtableResulset;
    private javax.swing.JLabel lRespuesta;
    private javax.swing.JPanel pie;
    private javax.swing.JTabbedPane resultados;
    private javax.swing.JTextField tNReg;
    private javax.swing.JTextField tTotalReg;
    private javax.swing.JPanel titulo;
    // End of variables declaration//GEN-END:variables

    private String sQuery = "";
    public SQLPannel sqlpannel = null;
    public JdbcTModel jtmodel = new JdbcTModel();
    private SortTModel sorttmodel = null;
    private String jdbcDriverClass=null;
    private String jdbcDriverURL=null;
    private String user=null;
    private String password=null;
    private long inicio = 0;
    private String sFiltro = "";
    private boolean bFiltro = false;
    private boolean bjtaResulsetCharge = false;
    private boolean bChartCharge = false;

    private String sCatalog = null;
    private String sSchema = null;
    private String sTable  = null;
}
TOP

Related Classes of com.GestDB.sql.ResulsetPannel$ThreadQuerys

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.