/*
* dlgMdfGrupos.java
*
* Created on 2004
* Created by Arsenio Molinero
* Copyright (C) 2004, 2005 Arsenio Molinero
*
* GestDB - a Java multi database client
*
* This file is part of GestDB.
*
* GestDB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GestDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GestDB; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.GestDB.sql;
import com.GestDB.swing.*;
import com.GestDB.Gestor;
import java.util.*;
import javax.swing.ListModel;
import javax.swing.DefaultComboBoxModel;
/**
*
* @author amolinero
*/
public class dlgMdfGrupos extends javax.swing.JDialog implements Literales {
public boolean bCancelada = true;
private Vector vConexiones = null;
/** Creates new form dlgMdfGrupos */
public dlgMdfGrupos(java.awt.Frame parent, boolean modal, Vector vConexiones, String Nombre, String sConexiones) {
super(parent, modal);
initComponents();
PonLiterales();
// rellena las conexiones
DefaultComboBoxModel mConexiones = new DefaultComboBoxModel();
for(int i=0,j=vConexiones.size();i<j;i++)
mConexiones.addElement(vConexiones.elementAt(i));
DefaultComboBoxModel mSel = new DefaultComboBoxModel();
StringTokenizer st1 = new StringTokenizer(sConexiones,";",false);
String stemp = null;
while(st1.hasMoreTokens())
{
stemp = st1.nextToken();
mSel.addElement(stemp);
// lo quito de la lista de conexiones
mConexiones.removeElement(stemp);
}
lTodos.setModel(mConexiones);
lSeleccionados.setModel(mSel);
if(Nombre != null)
tNombre.setText(Nombre);
this.vConexiones = vConexiones;
bCancelada = true;
}
/** 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
jPanel1 = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
lTodos = new javax.swing.JList();
jScrollPane2 = new javax.swing.JScrollPane();
lSeleccionados = new javax.swing.JList();
jPanel5 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
bSelTodos = new javax.swing.JButton();
bSelUno = new javax.swing.JButton();
bDeselUno = new javax.swing.JButton();
bDeselTodos = new javax.swing.JButton();
jPanel6 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
tNombre = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
bAceptar = new javax.swing.JButton();
bCancelar = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
jPanel1.setLayout(new java.awt.BorderLayout());
jPanel4.setLayout(new java.awt.GridLayout(1, 0));
lTodos.setFont(new java.awt.Font("Verdana", 0, 12));
jScrollPane1.setViewportView(lTodos);
jPanel4.add(jScrollPane1);
lSeleccionados.setFont(new java.awt.Font("Verdana", 0, 12));
jScrollPane2.setViewportView(lSeleccionados);
jPanel4.add(jScrollPane2);
jPanel1.add(jPanel4, java.awt.BorderLayout.CENTER);
jPanel5.setLayout(new java.awt.GridLayout(2, 1));
jPanel7.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 14, 0));
bSelTodos.setText(">>");
bSelTodos.setPreferredSize(new java.awt.Dimension(81, 16));
bSelTodos.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bSelTodosActionPerformed(evt);
}
});
jPanel7.add(bSelTodos);
bSelUno.setText(">");
bSelUno.setPreferredSize(new java.awt.Dimension(81, 16));
bSelUno.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bSelUnoActionPerformed(evt);
}
});
jPanel7.add(bSelUno);
bDeselUno.setText("<");
bDeselUno.setPreferredSize(new java.awt.Dimension(81, 16));
bDeselUno.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bDeselUnoActionPerformed(evt);
}
});
jPanel7.add(bDeselUno);
bDeselTodos.setText("<<");
bDeselTodos.setPreferredSize(new java.awt.Dimension(81, 16));
bDeselTodos.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bDeselTodosActionPerformed(evt);
}
});
jPanel7.add(bDeselTodos);
jPanel5.add(jPanel7);
jPanel6.setLayout(new java.awt.GridLayout(1, 2));
jLabel2.setFont(new java.awt.Font("Verdana", 0, 12));
jLabel2.setText("Conexiones");
jLabel2.setPreferredSize(new java.awt.Dimension(41, 14));
jPanel6.add(jLabel2);
jLabel3.setFont(new java.awt.Font("Verdana", 0, 12));
jLabel3.setText("Conexiones seleccionadas");
jLabel3.setPreferredSize(new java.awt.Dimension(41, 14));
jPanel6.add(jLabel3);
jPanel5.add(jPanel6);
jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
jLabel1.setText("Nombre del grupo:");
jPanel2.add(jLabel1);
tNombre.setFont(new java.awt.Font("Verdana", 0, 12));
tNombre.setPreferredSize(new java.awt.Dimension(200, 20));
jPanel2.add(tNombre);
getContentPane().add(jPanel2, java.awt.BorderLayout.NORTH);
jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
bAceptar.setText("Aceptar");
bAceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bAceptarActionPerformed(evt);
}
});
jPanel3.add(bAceptar);
bCancelar.setText("Cancelar");
bCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bCancelarActionPerformed(evt);
}
});
jPanel3.add(bCancelar);
getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
pack();
}//GEN-END:initComponents
private void bDeselUnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDeselUnoActionPerformed
// Pasa la conexi�n/es seleccionadas a la lista de todas
if(!lSeleccionados.isSelectionEmpty())
{
int indice[] = lSeleccionados.getSelectedIndices();
// copia los elementos
for(int i=0;i<indice.length;i++)
((DefaultComboBoxModel)lTodos.getModel()).addElement(lSeleccionados.getModel().getElementAt(indice[i]));
// borra los elementos
for(int i=indice.length-1;i>=0;i--)
((DefaultComboBoxModel)lSeleccionados.getModel()).removeElementAt(indice[i]);
}
}//GEN-LAST:event_bDeselUnoActionPerformed
private void bSelUnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSelUnoActionPerformed
// Pasa la conexi�n/es seleccionadas a la lista de selecci�n
if(!lTodos.isSelectionEmpty())
{
int indice[] = lTodos.getSelectedIndices();
// copia los elementos
for(int i=0;i<indice.length;i++)
((DefaultComboBoxModel)lSeleccionados.getModel()).addElement(lTodos.getModel().getElementAt(indice[i]));
// borra los elementos
for(int i=indice.length-1;i>=0;i--)
((DefaultComboBoxModel)lTodos.getModel()).removeElementAt(indice[i]);
}
}//GEN-LAST:event_bSelUnoActionPerformed
private void bDeselTodosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDeselTodosActionPerformed
// pone todas las conexiones como deseleccionadas
DefaultComboBoxModel mConexiones = new DefaultComboBoxModel();
for(int i=0,j=vConexiones.size();i<j;i++)
mConexiones.addElement(vConexiones.elementAt(i));
lTodos.setModel(mConexiones);
((DefaultComboBoxModel)lSeleccionados.getModel()).removeAllElements();
}//GEN-LAST:event_bDeselTodosActionPerformed
private void bSelTodosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSelTodosActionPerformed
// pone todas las conexiones como seleccionadas
DefaultComboBoxModel mConexiones = new DefaultComboBoxModel();
for(int i=0,j=vConexiones.size();i<j;i++)
mConexiones.addElement(vConexiones.elementAt(i));
lSeleccionados.setModel(mConexiones);
((DefaultComboBoxModel)lTodos.getModel()).removeAllElements();
}//GEN-LAST:event_bSelTodosActionPerformed
private void bCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelarActionPerformed
bCancelada = true;
setVisible(false);
dispose();
}//GEN-LAST:event_bCancelarActionPerformed
private void bAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAceptarActionPerformed
// comprueba si se ha rellenado el nombre. este es obligatorio
if(tNombre.getText().trim().length() == 0)
{
Alerta al = new Alerta(this, Gestor.GetLiteral("gestor.error_1","Error"), true,
Gestor.GetLiteral("selectconexion.error_4","El nombre es obligatorio"), Alerta.OK);
al.setVisible(true);
al = null;
tNombre.grabFocus();
return;
}
bCancelada = false;
setVisible(false);
dispose();
}//GEN-LAST:event_bAceptarActionPerformed
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new dlgMdfGrupos(new javax.swing.JFrame(), true, new Vector(),"","" ).setVisible(true);
}
public String getNombre()
{
return tNombre.getText();
}
public String getConexiones()
{
// se tiene que recorrer las conexiones seleccionadas y componer un string separado por ";"
String resultado = "";
ListModel lm = lSeleccionados.getModel();
for(int i=0,j=lm.getSize();i<j;i++)
{
if(i!=0)
resultado += ";" + (String)lm.getElementAt(i);
else
resultado += (String)lm.getElementAt(i);
}
return resultado;
}
public void PonLiterales()
{
jLabel2.setText(Gestor.GetLiteral("selectconexion.connections","Conexiones"));
jLabel3.setText(Gestor.GetLiteral("dlgmdfgrupos.selected_connections","Conexiones seleccionadas"));
jLabel1.setText(Gestor.GetLiteral("dlgmdfgrupos.group_name","Nombre del grupo") + ":");
bAceptar.setText(Gestor.GetLiteral("dlgmdfgrupos.accept","Aceptar"));
bCancelar.setText(Gestor.GetLiteral("importardlg.cancel","Cancelar"));
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton bAceptar;
private javax.swing.JButton bCancelar;
private javax.swing.JButton bDeselTodos;
private javax.swing.JButton bDeselUno;
private javax.swing.JButton bSelTodos;
private javax.swing.JButton bSelUno;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
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.JPanel jPanel7;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JList lSeleccionados;
private javax.swing.JList lTodos;
private javax.swing.JTextField tNombre;
// End of variables declaration//GEN-END:variables
}