/*
 * ValuesDialog.java
 *
 * iReport  --  Visual designer for generating JasperReports Documents
 *  Copyright (C) 2002-2003  Giulio Toffoli gt@businesslogic.it
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Giulio Toffoli
 *  Via T.Aspetti, 233
 *  35100 Padova ITALY
 *  gt@businesslogic.it
 *
 * Created on 7 maggio 2003, 23.43
 */

package it.businesslogic.ireport.gui;

import it.businesslogic.ireport.*;

import javax.swing.table.*;
import javax.swing.*;
import javax.swing.event.*;
import it.businesslogic.ireport.*;
import it.businesslogic.ireport.util.*;

import java.util.*;
/**
 *
 * @author  Administrator
 */
public class ValuesDialog extends javax.swing.JDialog {
    
    /** Creates new form ValuesDialog */
    public ValuesDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setSize(420, 250);
        //DefaultTableColumnModel dtcm = (DefaultTableColumnModel)jTableParameters.getColumnModel();
        //DefaultTableCellRenderer tcr = (DefaultTableCellRenderer)dtcm.getColumn(0).getHeaderRenderer();
        
        //new DefaultTableCellRenderer();
        //tcr.setFont(jTableParameters.getFont());
        //tcr.setBackground(this.getBackground());
        //tcr.setBorder( new javax.swing.border.BevelBorder( javax.swing.border.BevelBorder.RAISED));
        //dtcm.getColumn(0).setHeaderRenderer(tcr);
        
               
        
        DefaultListSelectionModel dlsm =  (DefaultListSelectionModel)this.jTableParameters.getSelectionModel();
        dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e)  {
                jTableParametersListSelectionValueChanged(e);
            }
        });
        
        dlsm =  (DefaultListSelectionModel)this.jTableVariables.getSelectionModel();
        dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e)  {
                jTableVariablesListSelectionValueChanged(e);
            }
        });
        
        dlsm =  (DefaultListSelectionModel)this.jTableFields.getSelectionModel();
        dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e)  {
                jTableFieldsListSelectionValueChanged(e);
            }
        });
        
        // Open in center...
        it.businesslogic.ireport.util.Misc.centerFrame(this);
    }
    
    
    public void jTableParametersListSelectionValueChanged(javax.swing.event.ListSelectionEvent e)
    {
         if (this.jTableParameters.getSelectedRowCount() > 0) {
            this.jButtonModifyParameter.setEnabled(true);
            this.jButtonDeleteParameter.setEnabled(true);
        }
        else {
            this.jButtonModifyParameter.setEnabled(false);
            this.jButtonDeleteParameter.setEnabled(false);
        }
    }
    
    public void jTableVariablesListSelectionValueChanged(javax.swing.event.ListSelectionEvent e)
    {
         if (this.jTableVariables.getSelectedRowCount() > 0) {
            this.jButtonModifyVariable.setEnabled(true);
            this.jButtonDeleteVariable.setEnabled(true);
        }
        else {
            this.jButtonModifyVariable.setEnabled(false);
            this.jButtonDeleteVariable.setEnabled(false);
        }
    }
    
    public void jTableFieldsListSelectionValueChanged(javax.swing.event.ListSelectionEvent e)
    {
         if (this.jTableFields.getSelectedRowCount() > 0) {
            this.jButtonModifyField.setEnabled(true);
            this.jButtonDeleteField.setEnabled(true);
        }
        else {
            this.jButtonModifyField.setEnabled(false);
            this.jButtonDeleteField.setEnabled(false);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents()//GEN-BEGIN:initComponents
    {
       jTabbedPane = new javax.swing.JTabbedPane();
       jPanelFields = new javax.swing.JPanel();
       jScrollPane3 = new javax.swing.JScrollPane();
       jTableFields = new it.businesslogic.ireport.gui.JDragTable();
       jPanelButtons2 = new javax.swing.JPanel();
       jButtonNewField = new javax.swing.JButton();
       jButtonModifyField = new javax.swing.JButton();
       jButtonDeleteField = new javax.swing.JButton();
       jPanelVariables = new javax.swing.JPanel();
       jScrollPane2 = new javax.swing.JScrollPane();
       jTableVariables = new it.businesslogic.ireport.gui.JDragTable();
       jPanelButtons1 = new javax.swing.JPanel();
       jButtonNewVariable = new javax.swing.JButton();
       jButtonModifyVariable = new javax.swing.JButton();
       jButtonDeleteVariable = new javax.swing.JButton();
       jPanelParameters = new javax.swing.JPanel();
       jScrollPane1 = new javax.swing.JScrollPane();
       jTableParameters = new it.businesslogic.ireport.gui.JDragTable();
       jPanelButtons = new javax.swing.JPanel();
       jButtonNewParameter = new javax.swing.JButton();
       jButtonModifyParameter = new javax.swing.JButton();
       jButtonDeleteParameter = new javax.swing.JButton();
       
       FormListener formListener = new FormListener();
       
       setTitle("Values");
       addWindowListener(formListener);
       
       jTabbedPane.setFont(new java.awt.Font("Dialog", 0, 11));
       jTabbedPane.setName("");
       jPanelFields.setLayout(new java.awt.BorderLayout());
       
       jScrollPane3.setBackground(new java.awt.Color(255, 255, 255));
       jScrollPane3.setFont(new java.awt.Font("Dialog", 0, 11));
       jTableFields.setModel(new javax.swing.table.DefaultTableModel(
       new Object [][]
       {
          
       },
       new String []
       {
          "Field name", "Class type"
       }
       )
       {
          boolean[] canEdit = new boolean []
          {
             false, false
          };
          
          public boolean isCellEditable(int rowIndex, int columnIndex)
          {
             return canEdit [columnIndex];
          }
       });
       jTableFields.addMouseListener(formListener);
       
       jScrollPane3.setViewportView(jTableFields);
       
       jPanelFields.add(jScrollPane3, java.awt.BorderLayout.CENTER);
       
       jPanelButtons2.setLayout(null);
       
       jPanelButtons2.setMinimumSize(new java.awt.Dimension(100, 10));
       jPanelButtons2.setPreferredSize(new java.awt.Dimension(100, 10));
       jButtonNewField.setFont(new java.awt.Font("Dialog", 0, 11));
       jButtonNewField.setText("New");
       jButtonNewField.addActionListener(formListener);
       
       jPanelButtons2.add(jButtonNewField);
       jButtonNewField.setBounds(4, 5, 92, 22);
       
       jButtonModifyField.setFont(new java.awt.Font("Dialog", 0, 11));
       jButtonModifyField.setText("Modify");
       jButtonModifyField.setEnabled(false);
       jButtonModifyField.addActionListener(formListener);
       
       jPanelButtons2.add(jButtonModifyField);
       jButtonModifyField.setBounds(4, 30, 92, 22);
       
       jButtonDeleteField.setFont(new java.awt.Font("Dialog", 0, 11));
       jButtonDeleteField.setText("Delete");
       jButtonDeleteField.setEnabled(false);
       jButtonDeleteField.addActionListener(formListener);
       
       jPanelButtons2.add(jButtonDeleteField);
       jButtonDeleteField.setBounds(4, 56, 92, 22);
       
       jPanelFields.add(jPanelButtons2, java.awt.BorderLayout.EAST);
       
       jTabbedPane.addTab("Fields", jPanelFields);
       
       jPanelVariables.setLayout(new java.awt.BorderLayout());
       
       jScrollPane2.setBackground(new java.awt.Color(255, 255, 255));
       jScrollPane2.setFont(new java.awt.Font("Dialog", 0, 11));
       jTableVariables.setModel(new javax.swing.table.DefaultTableModel(
       new Object [][]
       {
          
       },
       new String []
       {
          "Variable name", "Builtin"
       }
       )
       {
          boolean[] canEdit = new boolean []
          {
             false, false
          };
          
          public boolean isCellEditable(int rowIndex, int columnIndex)
          {
             return canEdit [columnIndex];
          }
       });
       jTableVariables.addMouseListener(formListener);
       
       jScrollPane2.setViewportView(jTableVariables);
       
       jPanelVariables.add(jScrollPane2, java.awt.BorderLayout.CENTER);
       
       jPanelButtons1.setLayout(null);
       
       jPanelButtons1.setMinimumSize(new java.awt.Dimension(100, 10));
       jPanelButtons1.setPreferredSize(new java.awt.Dimension(100, 10));
       jButtonNewVariable.setFont(new java.awt.Font("Dialog", 0, 11));
       jButtonNewVariable.setText("New");
       jButtonNewVariable.addActionListener(formListener);
       
       jPanelButtons1.add(jButtonNewVariable);
       jButtonNewVariable.setBounds(4, 5, 92, 22);
       
       jButtonModifyVariable.setFont(new java.awt.Font("Dialog", 0, 11));
       jButtonModifyVariable.setText("Modify");
       jButtonModifyVariable.setEnabled(false);
       jButtonModifyVariable.addActionListener(formListener);
       
       jPanelButtons1.add(jButtonModifyVariable);
       jButtonModifyVariable.setBounds(4, 30, 92, 22);
       
       jButtonDeleteVariable.setFont(new java.awt.Font("Dialog", 0, 11));
       jButtonDeleteVariable.setText("Delete");
       jButtonDeleteVariable.setEnabled(false);
       jButtonDeleteVariable.addActionListener(formListener);
       
       jPanelButtons1.add(jButtonDeleteVariable);
       jButtonDeleteVariable.setBounds(4, 56, 92, 22);
       
       jPanelVariables.add(jPanelButtons1, java.awt.BorderLayout.EAST);
       
       jTabbedPane.addTab("Variables", jPanelVariables);
       
       jPanelParameters.setLayout(new java.awt.BorderLayout(2, 2));
       
       jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
       jScrollPane1.setFont(new java.awt.Font("Dialog", 0, 11));
       jTableParameters.setModel(new javax.swing.table.DefaultTableModel(
       new Object [][]
       {
          
       },
       new String []
       {
          "Parameter name", "Class type", "Is for prompting"
       }
       )
       {
          boolean[] canEdit = new boolean []
          {
             false, false, false
          };
          
          public boolean isCellEditable(int rowIndex, int columnIndex)
          {
             return canEdit [columnIndex];
          }
       });
       jTableParameters.addMouseListener(formListener);
       
       jScrollPane1.setViewportView(jTableParameters);
       
       jPanelParameters.add(jScrollPane1, java.awt.BorderLayout.CENTER);
       
       jPanelButtons.setLayout(null);
       
       jPanelButtons.setMinimumSize(new java.awt.Dimension(100, 10));
       jPanelButtons.setPreferredSize(new java.awt.Dimension(100, 10));
       jButtonNewParameter.setFont(new java.awt.Font("Dialog", 0, 11));
       jButtonNewParameter.setText("New");
       jButtonNewParameter.addActionListener(formListener);
       
       jPanelButtons.add(jButtonNewParameter);
       jButtonNewParameter.setBounds(4, 5, 92, 22);
       
       jButtonModifyParameter.setFont(new java.awt.Font("Dialog", 0, 11));
       jButtonModifyParameter.setText("Modify");
       jButtonModifyParameter.setEnabled(false);
       jButtonModifyParameter.addActionListener(formListener);
       
       jPanelButtons.add(jButtonModifyParameter);
       jButtonModifyParameter.setBounds(4, 30, 92, 22);
       
       jButtonDeleteParameter.setFont(new java.awt.Font("Dialog", 0, 11));
       jButtonDeleteParameter.setText("Delete");
       jButtonDeleteParameter.setEnabled(false);
       jButtonDeleteParameter.addActionListener(formListener);
       
       jPanelButtons.add(jButtonDeleteParameter);
       jButtonDeleteParameter.setBounds(4, 56, 92, 22);
       
       jPanelParameters.add(jPanelButtons, java.awt.BorderLayout.EAST);
       
       jTabbedPane.addTab("Parameters", jPanelParameters);
       
       getContentPane().add(jTabbedPane, java.awt.BorderLayout.CENTER);
       
       pack();
    }
    
    // Code for dispatching events from components to event handlers.
    
    private class FormListener implements java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.WindowListener
    {
       public void actionPerformed(java.awt.event.ActionEvent evt)
       {
          if (evt.getSource() == jButtonNewField)
          {
             ValuesDialog.this.jButtonNewFieldActionPerformed(evt);
          }
          else if (evt.getSource() == jButtonModifyField)
          {
             ValuesDialog.this.jButtonModifyFieldActionPerformed(evt);
          }
          else if (evt.getSource() == jButtonDeleteField)
          {
             ValuesDialog.this.jButtonDeleteFieldActionPerformed(evt);
          }
          else if (evt.getSource() == jButtonNewVariable)
          {
             ValuesDialog.this.jButtonNewVariableActionPerformed(evt);
          }
          else if (evt.getSource() == jButtonModifyVariable)
          {
             ValuesDialog.this.jButtonModifyVariableActionPerformed(evt);
          }
          else if (evt.getSource() == jButtonDeleteVariable)
          {
             ValuesDialog.this.jButtonDeleteVariableActionPerformed(evt);
          }
          else if (evt.getSource() == jButtonNewParameter)
          {
             ValuesDialog.this.jButtonNewParameterActionPerformed(evt);
          }
          else if (evt.getSource() == jButtonModifyParameter)
          {
             ValuesDialog.this.jButtonModifyParameterActionPerformed(evt);
          }
          else if (evt.getSource() == jButtonDeleteParameter)
          {
             ValuesDialog.this.jButtonDeleteParameterActionPerformed(evt);
          }
       }
       
       public void mouseClicked(java.awt.event.MouseEvent evt)
       {
          if (evt.getSource() == jTableFields)
          {
             ValuesDialog.this.jTableFieldsMouseClicked(evt);
          }
          else if (evt.getSource() == jTableVariables)
          {
             ValuesDialog.this.jTableVariablesMouseClicked(evt);
          }
          else if (evt.getSource() == jTableParameters)
          {
             ValuesDialog.this.jTableParametersMouseClicked(evt);
          }
       }
       
       public void mouseEntered(java.awt.event.MouseEvent evt)
       {
       }
       
       public void mouseExited(java.awt.event.MouseEvent evt)
       {
       }
       
       public void mousePressed(java.awt.event.MouseEvent evt)
       {
       }
       
       public void mouseReleased(java.awt.event.MouseEvent evt)
       {
       }
       
       public void windowActivated(java.awt.event.WindowEvent evt)
       {
       }
       
       public void windowClosed(java.awt.event.WindowEvent evt)
       {
       }
       
       public void windowClosing(java.awt.event.WindowEvent evt)
       {
          if (evt.getSource() == ValuesDialog.this)
          {
             ValuesDialog.this.closeDialog(evt);
          }
       }
       
       public void windowDeactivated(java.awt.event.WindowEvent evt)
       {
       }
       
       public void windowDeiconified(java.awt.event.WindowEvent evt)
       {
       }
       
       public void windowIconified(java.awt.event.WindowEvent evt)
       {
       }
       
       public void windowOpened(java.awt.event.WindowEvent evt)
       {
       }
    }//GEN-END:initComponents

    private void jTableParametersMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableParametersMouseClicked
        if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1 &&  jTableParameters.getSelectedRow() >=0 )
        {
            jButtonModifyParameterActionPerformed(new java.awt.event.ActionEvent( jButtonModifyParameter,0, ""));
        }
    }//GEN-LAST:event_jTableParametersMouseClicked

    private void jTableVariablesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableVariablesMouseClicked
       if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1 &&  jTableVariables.getSelectedRow() >=0 )
        {
            jButtonModifyVariableActionPerformed(new java.awt.event.ActionEvent( jButtonModifyVariable,0, ""));
        }
    }//GEN-LAST:event_jTableVariablesMouseClicked

    private void jTableFieldsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableFieldsMouseClicked
        if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1 &&  jTableFields.getSelectedRow() >=0 )
        {
            jButtonModifyFieldActionPerformed(new java.awt.event.ActionEvent( jButtonModifyField,0, ""));
        }
    }//GEN-LAST:event_jTableFieldsMouseClicked

    private void jButtonDeleteFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteFieldActionPerformed
        jTableFields.getSelectedRows();
        int[]  rows= jTableFields.getSelectedRows();
        for (int i=rows.length-1; i>=0; --i)
        {
            this.getJReportFrame().getReport().removeField( (JRField) jTableFields.getValueAt( rows[i], 0) );
            //this.jTableParameters.removeRowSelectionInterval( rows[i],rows[i]);
        }
        updateFields();
    }//GEN-LAST:event_jButtonDeleteFieldActionPerformed

    private void jButtonModifyFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyFieldActionPerformed
         JRField field = (JRField)jTableFields.getValueAt( jTableFields.getSelectedRow(), 0);
        java.awt.Frame parent = Misc.frameFromComponent(this);     
        JRFieldDialog jrpd = new JRFieldDialog(parent, true);
        jrpd.setField( field );
        jrpd.show();
        
        if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
        {
            field.setName( jrpd.getField().getName() );
            field.setClassType( jrpd.getField().getClassType() );
  
            field.setDescription( jrpd.getField().getDescription() );
            
            this.updateFields();
        }        
    }//GEN-LAST:event_jButtonModifyFieldActionPerformed

    private void jButtonNewFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewFieldActionPerformed
        java.awt.Frame parent = Misc.frameFromComponent(this);
        JRFieldDialog jrpd = new JRFieldDialog( parent, true);
        jrpd.show();
        
        if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
        {
            JRField field = jrpd.getField();
            this.getJReportFrame().getReport().addField( field );
            this.updateFields();
        }
    }//GEN-LAST:event_jButtonNewFieldActionPerformed

    private void jButtonDeleteVariableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteVariableActionPerformed
        jTableVariables.getSelectedRows();
        int[]  rows= jTableVariables.getSelectedRows();
        for (int i=rows.length-1; i>=0; --i)
        {
            if (  !((JRVariable)jTableVariables.getValueAt( rows[i], 0)).isBuiltin())
            {
                this.getJReportFrame().getReport().removeVariable( (JRVariable) jTableVariables.getValueAt( rows[i], 0) );
            }
            //this.jTableParameters.removeRowSelectionInterval( rows[i],rows[i]);
        }
        updateVariables();
    }//GEN-LAST:event_jButtonDeleteVariableActionPerformed

    private void jButtonModifyVariableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyVariableActionPerformed
        JRVariable variable = (JRVariable)jTableVariables.getValueAt( jTableVariables.getSelectedRow(), 0);
        
        if (variable.isBuiltin())
        {
             javax.swing.JOptionPane.showMessageDialog(this,"You can't modify or delete builtin variables!","Invalid operation!",javax.swing.JOptionPane.WARNING_MESSAGE );
                return;
        }
        java.awt.Frame parent = Misc.frameFromComponent(this);
        JRVariableDialog jrpd = new JRVariableDialog(getJReportFrame().getReport(),  parent, true);
        jrpd.setVariable( variable );
        jrpd.show();
        
        if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
        {
            variable.setName( jrpd.getVariable().getName() );
            variable.setClassType( jrpd.getVariable().getClassType() );
            variable.setCalculation( jrpd.getVariable().getCalculation() );
            variable.setResetType( jrpd.getVariable().getResetType() );
            variable.setResetGroup( jrpd.getVariable().getResetGroup() );
            variable.setExpression( jrpd.getVariable().getExpression() );
            variable.setInitialValueExpression( jrpd.getVariable().getInitialValueExpression() );
            
            this.updateVariables();
        }        
    }//GEN-LAST:event_jButtonModifyVariableActionPerformed

    private void jButtonNewVariableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewVariableActionPerformed
        
        java.awt.Frame parent = Misc.frameFromComponent(this);
        JRVariableDialog jrpd = new JRVariableDialog(this.getJReportFrame().getReport(), parent, true);
        jrpd.show();
        
        if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
        {
            JRVariable variable = jrpd.getVariable();
            this.getJReportFrame().getReport().addVariable( variable );
            this.updateVariables();
        }
    }//GEN-LAST:event_jButtonNewVariableActionPerformed

    private void jButtonDeleteParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteParameterActionPerformed
        
        jTableParameters.getSelectedRows();
        int[]  rows= jTableParameters.getSelectedRows();
        for (int i=rows.length-1; i>=0; --i)
        {
            this.getJReportFrame().getReport().removeParameter( (JRParameter) jTableParameters.getValueAt( rows[i], 0) );
            //this.jTableParameters.removeRowSelectionInterval( rows[i],rows[i]);
        }
        updateParameters();
        
    }//GEN-LAST:event_jButtonDeleteParameterActionPerformed

    private void jButtonModifyParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyParameterActionPerformed
         
        JRParameter parameter = (JRParameter)jTableParameters.getValueAt( jTableParameters.getSelectedRow(), 0);
        java.awt.Frame parent = Misc.frameFromComponent(this);
        JRParameterDialog jrpd = new JRParameterDialog(parent, true);
        jrpd.setParameter( parameter );
        jrpd.show();
        
        if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
        {
            parameter.setName( jrpd.getParameter().getName() );
            parameter.setClassType( jrpd.getParameter().getClassType() );
            parameter.setDescription( jrpd.getParameter().getDescription() );
            parameter.setDefaultValueExpression( jrpd.getParameter().getDefaultValueExpression() );
            this.updateParameters();
        }
    }//GEN-LAST:event_jButtonModifyParameterActionPerformed

    private void jButtonNewParameterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewParameterActionPerformed
        // create a new parameter....
        java.awt.Frame parent = Misc.frameFromComponent(this);
        JRParameterDialog jrpd = new JRParameterDialog(parent, true);
        jrpd.show();
        
        if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
        {
            JRParameter parameter = jrpd.getParameter();
            this.getJReportFrame().getReport().addParameter( parameter );
            this.updateParameters();
        }
        
    }//GEN-LAST:event_jButtonNewParameterActionPerformed
    
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
    }//GEN-LAST:event_closeDialog
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new ValuesDialog(new javax.swing.JFrame(), true).show();
    }
    
    /** Getter for property jReportFrame.
     * @return Value of property jReportFrame.
     *
     */
    public it.businesslogic.ireport.gui.JReportFrame getJReportFrame() {
        return jReportFrame;
    }
    
    /** Setter for property jReportFrame.
     * @param jReportFrame New value of property jReportFrame.
     *
     */
    public void setJReportFrame(it.businesslogic.ireport.gui.JReportFrame jReportFrame) {
        this.jReportFrame = jReportFrame;
        
        // Update all...
        if (jReportFrame == null) 
        {
            setVisible(false);
            return;
        }
        
        if (isVisible())
        {
            this.setTitle(jReportFrame.getReport().getName()+" values...");
            updateParameters();
            updateFields();
            updateVariables();
        }
    }
    
    public void updateParameters() {
        
        DefaultTableModel dtm = (DefaultTableModel)jTableParameters.getModel();
        dtm.setRowCount(0);
    
        Enumeration enum = jReportFrame.getReport().getParameters().elements();
        while (enum.hasMoreElements())
        {
            it.businesslogic.ireport.JRParameter parameter = (it.businesslogic.ireport.JRParameter)enum.nextElement();
            Vector row = new Vector();
            row.addElement( parameter);
            row.addElement( parameter.getClassType());
            row.addElement( parameter.isIsForPrompting()+"");
            
            dtm.addRow(row);           
        }    
    }
    public void updateFields() {
    
        DefaultTableModel dtm = (DefaultTableModel)jTableFields.getModel();
        dtm.setRowCount(0);
    
        Enumeration enum = jReportFrame.getReport().getFields().elements();
        while (enum.hasMoreElements())
        {
            it.businesslogic.ireport.JRField field = (it.businesslogic.ireport.JRField)enum.nextElement();
            Vector row = new Vector();
            row.addElement( field );
            row.addElement( field.getClassType()  );
            
            dtm.addRow(row);           
        }    
    
    
    }
    public void updateVariables() {
        DefaultTableModel dtm = (DefaultTableModel)jTableVariables.getModel();
        dtm.setRowCount(0);
    
        Enumeration enum = jReportFrame.getReport().getVariables().elements();
        while (enum.hasMoreElements())
        {
            it.businesslogic.ireport.JRVariable variable = (it.businesslogic.ireport.JRVariable)enum.nextElement();
            Vector row = new Vector();
            row.addElement( variable);
            row.addElement( (variable.isBuiltin() ? "yes" : "no"));
            
            dtm.addRow(row);           
        }    
    }
    
       
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JButton jButtonDeleteField;
    protected javax.swing.JButton jButtonDeleteParameter;
    protected javax.swing.JButton jButtonDeleteVariable;
    protected javax.swing.JButton jButtonModifyField;
    protected javax.swing.JButton jButtonModifyParameter;
    protected javax.swing.JButton jButtonModifyVariable;
    protected javax.swing.JButton jButtonNewField;
    protected javax.swing.JButton jButtonNewParameter;
    protected javax.swing.JButton jButtonNewVariable;
    protected javax.swing.JPanel jPanelButtons;
    protected javax.swing.JPanel jPanelButtons1;
    protected javax.swing.JPanel jPanelButtons2;
    protected javax.swing.JPanel jPanelFields;
    protected javax.swing.JPanel jPanelParameters;
    protected javax.swing.JPanel jPanelVariables;
    protected javax.swing.JScrollPane jScrollPane1;
    protected javax.swing.JScrollPane jScrollPane2;
    protected javax.swing.JScrollPane jScrollPane3;
    protected javax.swing.JTabbedPane jTabbedPane;
    protected it.businesslogic.ireport.gui.JDragTable jTableFields;
    protected it.businesslogic.ireport.gui.JDragTable jTableParameters;
    protected it.businesslogic.ireport.gui.JDragTable jTableVariables;
    // End of variables declaration//GEN-END:variables

    private JReportFrame jReportFrame;    

    public void setVisible(boolean visible)
    {
        if (visible == isVisible()) return;
        super.setVisible(visible);
        if (visible == true) 
        {
            this.setJReportFrame(jReportFrame);
        }
    }
    
    public void modifyParameter(it.businesslogic.ireport.JRParameter p)
    {
        // 1. Switch to parameters panel.
        this.jTabbedPane.setSelectedComponent( jPanelParameters );
        // 2. Fine the parameter and select it
        DefaultTableModel dtm = (DefaultTableModel)jTableParameters.getModel();
        for (int i=0; i<dtm.getRowCount(); ++i)
        {
            if (dtm.getValueAt(i, 0) == p)
            {
                jTableParameters.setRowSelectionInterval(i,i);
                this.jButtonModifyParameterActionPerformed(new java.awt.event.ActionEvent(jButtonModifyParameter,0,jButtonModifyParameter.getName()));
                return;
            }
        }
    }
    
    
    public void gotoTab(String tab)
    {
        if (tab.equals("Parameters"))
        {
            this.jTabbedPane.setSelectedIndex(2);
        }
        else if (tab.equals("Fields"))
        {
            this.jTabbedPane.setSelectedIndex(0);
        }
        else if (tab.equals("Variables"))
        {
            this.jTabbedPane.setSelectedIndex(1);
        }
    }
}
