/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* AltaAula.java
*
* Created on 07/06/2010, 11:51:12
*/
package calendar.vista;
import calendar.dao.Dao;
import calendar.domino.Aulas;
import calendar.domino.Edificios;
import calendar.util.CompareValidator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.JOptionPane;
/**
*
* @author gaby
*/
public class AltaAula extends javax.swing.JDialog {
List listaEdificios;
/** Creates new form AltaAula */
public AltaAula(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
inicio();
}
private void inicio(){
Dao dao = new Dao(new Edificios());
listaEdificios = dao.getAll();
for (Iterator<Edificios> it = listaEdificios.iterator(); it.hasNext();) {
jComboBoxEdificio.addItem(it.next());
}
}
/** 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() {
jTextFieldDescripcion = new javax.swing.JTextField();
jTextFieldEstado = new javax.swing.JTextField();
jTextFieldBancosDisp = new javax.swing.JTextField();
jButtonCancelar = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jButtonAceptar = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jTextFieldNombre = new javax.swing.JTextField();
jPanel1 = new javax.swing.JPanel();
jLabelCabeceraAltaAula = new javax.swing.JLabel();
jComboBoxEdificio = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(calendar.vista.CalendarApp.class).getContext().getResourceMap(AltaAula.class);
setTitle(resourceMap.getString("Form.title")); // NOI18N
setName("Form"); // NOI18N
jTextFieldDescripcion.setName("jTextFieldDescripcion"); // NOI18N
jTextFieldEstado.setName("jTextFieldEstado"); // NOI18N
jTextFieldBancosDisp.setName("jTextFieldBancosDisp"); // NOI18N
jButtonCancelar.setText(resourceMap.getString("jButtonCancelar.text")); // NOI18N
jButtonCancelar.setName("jButtonCancelar"); // NOI18N
jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCancelarActionPerformed(evt);
}
});
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jButtonAceptar.setText(resourceMap.getString("jButtonAceptar.text")); // NOI18N
jButtonAceptar.setName("jButtonAceptar"); // NOI18N
jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonAceptarActionPerformed(evt);
}
});
jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
jLabel2.setName("jLabel2"); // NOI18N
jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
jLabel3.setName("jLabel3"); // NOI18N
jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
jLabel4.setName("jLabel4"); // NOI18N
jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
jLabel5.setName("jLabel5"); // NOI18N
jTextFieldNombre.setName("jTextFieldNombre"); // NOI18N
jTextFieldNombre.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextFieldNombreActionPerformed(evt);
}
});
jPanel1.setName("jPanel1"); // NOI18N
jLabelCabeceraAltaAula.setText(resourceMap.getString("jLabelCabeceraAltaAula.text")); // NOI18N
jLabelCabeceraAltaAula.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabelCabeceraAltaAula.setName("jLabelCabeceraAltaAula"); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabelCabeceraAltaAula, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabelCabeceraAltaAula, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(22, 22, 22))
);
jComboBoxEdificio.setName("jComboBoxEdificio"); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jComboBoxEdificio, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextFieldDescripcion)
.addComponent(jTextFieldEstado)
.addComponent(jTextFieldBancosDisp)
.addComponent(jTextFieldNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(163, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButtonAceptar)
.addGap(35, 35, 35)
.addComponent(jButtonCancelar)
.addGap(80, 80, 80))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextFieldBancosDisp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextFieldEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextFieldDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBoxEdificio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonAceptar)
.addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(43, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jTextFieldNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNombreActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextFieldNombreActionPerformed
private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButtonCancelarActionPerformed
private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed
ArrayList lista = new ArrayList();
lista.add(jTextFieldNombre);
lista.add(jTextFieldBancosDisp);
lista.add(jTextFieldEstado);
lista.add(jTextFieldDescripcion);
if ((CompareValidator.isSomeEmpty(lista))&&(CompareValidator.isInteger(jTextFieldBancosDisp))){
Aulas aulas = new Aulas();
aulas.setNombre(jTextFieldNombre.getText());
aulas.setBancosDisponibles(Integer.parseInt((jTextFieldBancosDisp.getText())));
aulas.setEstado(jTextFieldEstado.getText());
aulas.setDescripcion(jTextFieldDescripcion.getText());
aulas.setEdificios((Edificios) jComboBoxEdificio.getSelectedItem());
Dao dao = new Dao(aulas);
dao.insert(aulas);
CompareValidator.restoreAll(lista);
}else{
JOptionPane.showMessageDialog(this,"Compruebe los campos", "Error!!", JOptionPane.ERROR_MESSAGE);
}
}//GEN-LAST:event_jButtonAceptarActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
AltaAula dialog = new AltaAula(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButtonAceptar;
private javax.swing.JButton jButtonCancelar;
private javax.swing.JComboBox jComboBoxEdificio;
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 jLabelCabeceraAltaAula;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextFieldBancosDisp;
private javax.swing.JTextField jTextFieldDescripcion;
private javax.swing.JTextField jTextFieldEstado;
private javax.swing.JTextField jTextFieldNombre;
// End of variables declaration//GEN-END:variables
}