/*
* ConfigDialog.java
*
* Created on 28 de abril de 2010, 11:17 AM
*/
package gafetes;
import gafetes.db.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import java.sql.*;
/**
*
* @author gateway
*/
public class ConfigDialog extends javax.swing.JDialog {
/** Creates new form ConfigDialog */
public ConfigDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
initComponentsWithoutNetbeans();
}
private void initComponentsWithoutNetbeans(){
AdqalConfiguration conf = new AdqalConfiguration();
DataSource ds = conf.getDataSource();
ipTextField.setText(ds.getURL().substring((ds.getURL().indexOf("jdbc:microsoft:sqlserver://") + "jdbc:microsoft:sqlserver://".length()), ds.getURL().indexOf(";") ));
bdTextField.setText(ds.getURL().substring( (ds.getURL().indexOf("databaseName=") + "databaseName=".length()) ));
userNameTextField.setText(ds.getUserName());
passwordTextField.setText(ds.getPassword());
//Cargamos los campos en la tabla Empleados
java.util.Vector v = gafetes.business.SqlHelper.getListaCampos(gafetes.db.GlobalSettings.GetPrefix() + "Empleados");
for(int i=0; i < v.size(); i++)
{
cbCodigoBarra.addItem(v.elementAt(i));
}
//Cargamos las plantillas
DefaultListModel ve = (DefaultListModel)gafetes.business.SqlHelper.getListaTemplates();
lista.setModel(ve);
java.util.Vector configuraciones = gafetes.business.SqlHelper.getConfiguracionGlobal();
for(int i=0; i < configuraciones.size(); i++)
{
if( ( (gafetes.beans.Configuracion)configuraciones.elementAt(i) ).getParametro().equals("CAMPO_CODIGOBARRA") )
{
gafetes.beans.Configuracion config = (gafetes.beans.Configuracion)configuraciones.elementAt(i);
int index = v.indexOf( (String)config.getValor() );
cbCodigoBarra.setSelectedIndex(index);
}else{
cbCodigoBarra.setSelectedIndex(2);
}
//Buscamos cual va a ser la plantilla tama�o carta
if( ( (gafetes.beans.Configuracion)configuraciones.elementAt(i) ).getParametro().equals("LETTER_TEMPLATE") )
{
gafetes.beans.Configuracion config = (gafetes.beans.Configuracion)configuraciones.elementAt(i);
int index = v.indexOf( (String)config.getValor() );
lista.setSelectedIndex(index);
}else{
lista.setSelectedIndex(0);
}
if( ( (gafetes.beans.Configuracion)configuraciones.elementAt(i) ).getParametro().equals("EDITOR_IMAGENES") )
{
gafetes.beans.Configuracion config = (gafetes.beans.Configuracion)configuraciones.elementAt(i);
editorTextField.setText(config.getValor());
}
}
/*
int index = configuraciones.indexOf("CAMPO_CODIGOBARRA");
if (index != -1) {
gafetes.beans.Configuracion config = (gafetes.beans.Configuracion)configuraciones.elementAt(index);
index = v.indexOf( (String)config.getValor() );
cbCodigoBarra.setSelectedIndex(index);
}else{
index = v.indexOf( "CLAVE" );
cbCodigoBarra.setSelectedIndex(index);
}
*/
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
cbCodigoBarra = new javax.swing.JComboBox();
jPanel6 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
ipTextField = new javax.swing.JTextField();
bdTextField = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
userNameTextField = new javax.swing.JTextField();
passwordTextField = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
editorTextField = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
lista = new javax.swing.JList();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
getContentPane().add(jPanel2, java.awt.BorderLayout.EAST);
jButton1.setText("Aceptar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel3.add(jButton1);
jButton2.setText("Cancelar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel3.add(jButton2);
getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
getContentPane().add(jPanel4, java.awt.BorderLayout.WEST);
jPanel5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel1.setText("Campo Codigo de Barras");
jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Los parametros de conexi\u00f3n solo estan disponibles en modo lectura"));
jLabel3.setText("IP Servidor BD");
jLabel4.setText("Nombre de BD");
jLabel6.setText("Password de BD");
jLabel5.setText("Username de BD");
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel6)
.addComponent(jLabel5))
.addGap(39, 39, 39)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(passwordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
.addComponent(bdTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
.addComponent(userNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
.addComponent(ipTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE))
.addGap(51, 51, 51))
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(ipTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(19, 19, 19)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(userNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(bdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(21, 21, 21)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(passwordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(50, Short.MAX_VALUE))
);
jPanel6.getAccessibleContext().setAccessibleName("Los par\u00e1metros de conexi\u00f3n s\u00f3lo estan disponibles en modo lectura");
jLabel2.setText("Ruta al programa editor de imagenes");
jLabel7.setText("Plantilla para impresiones tama\u00f1o carta");
lista.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
lista.setVerifyInputWhenFocusTarget(false);
lista.setVisibleRowCount(4);
jScrollPane1.setViewportView(lista);
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(19, 19, 19))
.addGroup(jPanel5Layout.createSequentialGroup()
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(editorTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 612, Short.MAX_VALUE))
.addGap(19, 19, 19))
.addGroup(jPanel5Layout.createSequentialGroup()
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
.addGap(9, 9, 9)
.addComponent(jLabel1)
.addGap(30, 30, 30)
.addComponent(cbCodigoBarra, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING))
.addContainerGap(294, Short.MAX_VALUE))))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(cbCodigoBarra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(17, 17, 17)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(editorTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(19, 19, 19)
.addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31))
);
getContentPane().add(jPanel5, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
dispose();
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
gafetes.beans.Configuracion config = new gafetes.beans.Configuracion();
config.setParametro("CAMPO_CODIGOBARRA");
config.setValor((String)cbCodigoBarra.getSelectedItem());
gafetes.business.SqlHelper.saveConfig(config);
config.setParametro("EDITOR_IMAGENES");
config.setValor( editorTextField.getText().trim());
gafetes.business.SqlHelper.saveConfig(config);
gafetes.beans.Template temp = (gafetes.beans.Template)lista.getModel().getElementAt(lista.getSelectedIndex());
config.setParametro("LETTER_TEMPLATE");
config.setValor(temp.getId()+"");
gafetes.business.SqlHelper.saveConfig(config);
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ConfigDialog(new javax.swing.JFrame(), true).setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField bdTextField;
private javax.swing.JComboBox cbCodigoBarra;
private javax.swing.JTextField editorTextField;
private javax.swing.JTextField ipTextField;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JList lista;
private javax.swing.JTextField passwordTextField;
private javax.swing.JTextField userNameTextField;
// End of variables declaration//GEN-END:variables
}