/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddDvdForm.java
 *
 * Created on 2009.11.26., 18:15:46
 */
package gui;

import connectors.TableGenerator;
import connectors.VisibleException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JTextField;
import mobirentdesktop.entities.*;
import peaconnector.RemoteException;

/**
 *
 * @author Budai Attila
 */
public class AddDvdForm extends javax.swing.JFrame {

    /** Creates new form AddDvdForm */
    public static boolean modify = false;
    private DVD old;

    public AddDvdForm() {
        initComponents();
    }

    /** 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() {

        title1 = new javax.swing.JTextField();
        releaseDate = new javax.swing.JTextField();
        category = new javax.swing.JTextField();
        rentalPrice = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        felirat = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        starring = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("DVD hozzáadása / módosítása");

        title1.setName("Cím"); // NOI18N

        releaseDate.setName("Megjelenés Dátuma"); // NOI18N

        category.setName("Kategória"); // NOI18N

        rentalPrice.setName("Ár"); // NOI18N

        jLabel1.setText("Cím");

        jLabel2.setText("Kategória");

        jLabel3.setText("Kiadás dátuma");

        jLabel4.setText("Ár");

        okButton.setText("Ok");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Mégse");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        felirat.setText("Dvd hozzáadása");

        jLabel6.setText("Főszereplő(k)");

        starring.setName("Főszereplő(k)"); // 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()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(cancelButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(69, 69, 69)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(category, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
                            .addComponent(releaseDate, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
                            .addComponent(rentalPrice, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
                            .addComponent(starring, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
                            .addComponent(title1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
                            .addComponent(felirat)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(255, 255, 255)
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(felirat)
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(title1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(category, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(releaseDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rentalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(starring, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(okButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public AddDvdForm update(DVD dvd) {

        this.old = dvd;
        try {
            WindowFieldSetter.setFields(this, old);
        } catch (Exception e) {
        }
        //this.addButton.setText("Módosit");
        return this;
    }

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        if (title1.getText().equals("") || category.getText().equals("") ||
                releaseDate.getText().equals("") || rentalPrice.getText().equals("")) {
            return;
        } else {
            DVD dvd = new DVD(title1.getText(), category.getText(),
                    Integer.valueOf(rentalPrice.getText()), releaseDate.getText(), starring.getText(), "");
            try {
                if (modify) {
                    Connector.getINSTANCE().getDfs().modifyDvd(dvd);
                } else {
                    Connector.getINSTANCE().getDfs().addDvd(dvd);
                }
                Lists.getInstance().setList(TableGenerator.buildToThis(Lists.getInstance().getTable(), Connector.getINSTANCE().getDfs().getDvdList()));
                this.setVisible(false);
                Lists.getInstance().setGlassed(false);
            } catch (Exception ex) {
                new ExceptionHandlerDialog(this, true, ex.getMessage());
            }
        }
    }//GEN-LAST:event_okButtonActionPerformed

    public JTextField getTitle1() {
        return title1;
    }

    public void setFelirat(String felirat) {
        this.felirat.setText(felirat);
    }

    public JTextField getCategory() {
        return category;
    }

    public JTextField getStarring() {
        return starring;
    }

    public JTextField getRentalPrice() {
        return rentalPrice;
    }

    public JTextField getReleaseDate() {
        return releaseDate;
    }

    public void setReleaseDate(JTextField releaseDate) {
        this.releaseDate = releaseDate;
    }

    public void setRentalPrice(JTextField rentalPrice) {
        this.rentalPrice = rentalPrice;
    }

    public void setStarring(JTextField starring) {
        this.starring = starring;
    }

    public void setCategory(JTextField category) {
        this.category = category;
    }

    public void setTitle1(JTextField title1) {
        this.title1 = title1;
    }

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        Lists.getInstance().setGlassed(false);
    }//GEN-LAST:event_cancelButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JTextField category;
    private javax.swing.JLabel felirat;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JButton okButton;
    private javax.swing.JTextField releaseDate;
    private javax.swing.JTextField rentalPrice;
    private javax.swing.JTextField starring;
    private javax.swing.JTextField title1;
    // End of variables declaration//GEN-END:variables
}
