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

/*
 * BancoDetalhe.java
 *
 * Created on 02/05/2009, 05:09:24
 */
package br.com.syndic.frame;

import br.com.syndic.controller.InquilinoLookupController;
import br.com.syndic.vo.CondominioVO;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.util.Collection;
import org.openswing.swing.client.DeleteButton;
import org.openswing.swing.client.EditButton;
import org.openswing.swing.client.SaveButton;
import org.openswing.swing.form.client.Form;
import org.openswing.swing.form.client.FormController;
import org.openswing.swing.lookup.client.LookupController;
import org.openswing.swing.lookup.client.LookupListener;
import org.openswing.swing.mdi.client.InternalFrame;
import org.openswing.swing.message.receive.java.ValueObject;

/**
 *
 * @author Albert Eije
 */
public class InquilinoDetalhe extends InternalFrame implements ActionListener {

    private Connection conn = null;
    private CondominioVO condominio;

    public InquilinoDetalhe(Connection conn, FormController dataController) {
        try {
            this.conn = conn;

            initComponents();

            LookupController lookupController = new InquilinoLookupController(conn);
            codLookupControl1.setLookupController(lookupController);

            lookupController.addLookupListener(new LookupListener() {

                public void beforeLookupAction(ValueObject parentVO) {
                }

                public void codeChanged(ValueObject parentVO, Collection parentChangedAttributes) {
                    condominio = (CondominioVO) codLookupControl1.getLookupController().getLookupVO();
                }

                public void codeValidated(boolean validated) {
                }

                public void forceValidate() {
                }
            });

            form1.setFormController(dataController);

            setSize(590, 440);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Form getForm1() {
        return form1;
    }

    public SaveButton getSaveButton() {
        return saveButton1;
    }

    public DeleteButton getDeleteButton() {
        return deleteButton1;
    }

    public EditButton getEditButton() {
        return editButton1;
    }

    /** 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() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        insertButton1 = new org.openswing.swing.client.InsertButton();
        editButton1 = new org.openswing.swing.client.EditButton();
        copyButton1 = new org.openswing.swing.client.CopyButton();
        deleteButton1 = new org.openswing.swing.client.DeleteButton();
        reloadButton1 = new org.openswing.swing.client.ReloadButton();
        saveButton1 = new org.openswing.swing.client.SaveButton();
        form1 = new org.openswing.swing.form.client.Form();
        textControl1 = new org.openswing.swing.client.TextControl();
        textControl2 = new org.openswing.swing.client.TextControl();
        labelControl1 = new org.openswing.swing.client.LabelControl();
        labelControl2 = new org.openswing.swing.client.LabelControl();
        labelControl3 = new org.openswing.swing.client.LabelControl();
        codLookupControl1 = new org.openswing.swing.client.CodLookupControl();
        textControl3 = new org.openswing.swing.client.TextControl();
        labelControl4 = new org.openswing.swing.client.LabelControl();
        labelControl5 = new org.openswing.swing.client.LabelControl();
        labelControl6 = new org.openswing.swing.client.LabelControl();
        labelControl7 = new org.openswing.swing.client.LabelControl();
        textControl4 = new org.openswing.swing.client.TextControl();
        textControl5 = new org.openswing.swing.client.TextControl();
        numericControl1 = new org.openswing.swing.client.NumericControl();
        currencyControl1 = new org.openswing.swing.client.CurrencyControl();
        labelControl8 = new org.openswing.swing.client.LabelControl();
        labelControl9 = new org.openswing.swing.client.LabelControl();
        labelControl10 = new org.openswing.swing.client.LabelControl();
        labelControl11 = new org.openswing.swing.client.LabelControl();
        textControl6 = new org.openswing.swing.client.TextControl();
        formattedTextControl1 = new org.openswing.swing.client.FormattedTextControl();
        formattedTextControl2 = new org.openswing.swing.client.FormattedTextControl();
        formattedTextControl3 = new org.openswing.swing.client.FormattedTextControl();

        setTitle("Cadastro de Bancos (Inserindo/Alterando)");
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
        jPanel1.add(insertButton1);
        jPanel1.add(editButton1);
        jPanel1.add(copyButton1);
        jPanel1.add(deleteButton1);
        jPanel1.add(reloadButton1);

        saveButton1.setEnabled(false);
        saveButton1.addActionListener(this);
        jPanel1.add(saveButton1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(jPanel1, gridBagConstraints);

        form1.setVOClassName("br.com.syndic.vo.InquilinoVO");
        form1.setCopyButton(copyButton1);
        form1.setDeleteButton(deleteButton1);
        form1.setEditButton(editButton1);
        form1.setInsertButton(insertButton1);
        form1.setReloadButton(reloadButton1);
        form1.setSaveButton(saveButton1);
        form1.setLayout(new java.awt.GridBagLayout());

        textControl1.setAttributeName("bloco");
        textControl1.setCanCopy(false);
        textControl1.setEnabled(false);
        textControl1.setLinkLabel(labelControl3);
        textControl1.setUpperCase(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
        form1.add(textControl1, gridBagConstraints);

        textControl2.setAttributeName("apto");
        textControl2.setCanCopy(false);
        textControl2.setEnabled(false);
        textControl2.setLinkLabel(labelControl2);
        textControl2.setRequired(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(textControl2, gridBagConstraints);

        labelControl1.setLabel("Condomínio:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(labelControl1, gridBagConstraints);
        labelControl1.getAccessibleContext().setAccessibleName("Código Inquilino:");

        labelControl2.setLabel("Apartamento:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(labelControl2, gridBagConstraints);

        labelControl3.setLabel("Bloco:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
        form1.add(labelControl3, gridBagConstraints);

        codLookupControl1.setAllowOnlyNumbers(true);
        codLookupControl1.setAttributeName("codCondominio");
        codLookupControl1.setAutoCompletitionWaitTime(2L);
        codLookupControl1.setEnabled(false);
        codLookupControl1.setMaxCharacters(10);
        codLookupControl1.setRequired(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
        form1.add(codLookupControl1, gridBagConstraints);

        textControl3.setAttributeName("nomeCondominio");
        textControl3.setEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 10);
        form1.add(textControl3, gridBagConstraints);

        labelControl4.setLabel("Quadra:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        form1.add(labelControl4, gridBagConstraints);

        labelControl5.setLabel("Cod. Inquilino");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        form1.add(labelControl5, gridBagConstraints);

        labelControl6.setLabel("Fração Ideal:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        form1.add(labelControl6, gridBagConstraints);

        labelControl7.setLabel("Cota Normal:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
        form1.add(labelControl7, gridBagConstraints);

        textControl4.setAttributeName("quadra");
        textControl4.setEnabled(false);
        textControl4.setLinkLabel(labelControl4);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(textControl4, gridBagConstraints);

        textControl5.setAttributeName("codInquilino");
        textControl5.setEnabled(false);
        textControl5.setEnabledOnEdit(false);
        textControl5.setEnabledOnInsert(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(textControl5, gridBagConstraints);

        numericControl1.setAttributeName("fracaoIdeal");
        numericControl1.setDecimals(8);
        numericControl1.setEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(numericControl1, gridBagConstraints);

        currencyControl1.setAttributeName("cotaNormal");
        currencyControl1.setCurrencySymbol("R$");
        currencyControl1.setDecimals(2);
        currencyControl1.setEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(currencyControl1, gridBagConstraints);

        labelControl8.setLabel("Nome Inquilino:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(labelControl8, gridBagConstraints);

        labelControl9.setLabel("CPF:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(labelControl9, gridBagConstraints);

        labelControl10.setLabel("Celular:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(labelControl10, gridBagConstraints);

        labelControl11.setLabel("Fone:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(labelControl11, gridBagConstraints);

        textControl6.setAttributeName("nomeInquilino");
        textControl6.setCanCopy(false);
        textControl6.setEnabled(false);
        textControl6.setUpperCase(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(textControl6, gridBagConstraints);

        formattedTextControl1.setAttributeName(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(formattedTextControl1, gridBagConstraints);

        formattedTextControl2.setAttributeName(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(formattedTextControl2, gridBagConstraints);

        formattedTextControl3.setAttributeName(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
        form1.add(formattedTextControl3, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(form1, gridBagConstraints);

        pack();
    }

    // Code for dispatching events from components to event handlers.

    public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (evt.getSource() == saveButton1) {
            InquilinoDetalhe.this.saveButton1ActionPerformed(evt);
        }
    }// </editor-fold>//GEN-END:initComponents

    private void saveButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButton1ActionPerformed
        if (!textControl1.getText().equals("")) {
            textControl5.setText(codLookupControl1.getValue().toString() + textControl2.getText() + textControl1.getText());
        } else {
            textControl5.setText(codLookupControl1.getValue().toString() + textControl2.getText() + "UNI");
        }
        double fracaoIdeal = Double.parseDouble(numericControl1.getText());
        if (fracaoIdeal > 0.0) {
            System.out.println(condominio.getRateioCondominio() * fracaoIdeal);
        }
    }//GEN-LAST:event_saveButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.openswing.swing.client.CodLookupControl codLookupControl1;
    private org.openswing.swing.client.CopyButton copyButton1;
    private org.openswing.swing.client.CurrencyControl currencyControl1;
    private org.openswing.swing.client.DeleteButton deleteButton1;
    private org.openswing.swing.client.EditButton editButton1;
    private org.openswing.swing.form.client.Form form1;
    private org.openswing.swing.client.FormattedTextControl formattedTextControl1;
    private org.openswing.swing.client.FormattedTextControl formattedTextControl2;
    private org.openswing.swing.client.FormattedTextControl formattedTextControl3;
    private org.openswing.swing.client.InsertButton insertButton1;
    private javax.swing.JPanel jPanel1;
    private org.openswing.swing.client.LabelControl labelControl1;
    private org.openswing.swing.client.LabelControl labelControl10;
    private org.openswing.swing.client.LabelControl labelControl11;
    private org.openswing.swing.client.LabelControl labelControl2;
    private org.openswing.swing.client.LabelControl labelControl3;
    private org.openswing.swing.client.LabelControl labelControl4;
    private org.openswing.swing.client.LabelControl labelControl5;
    private org.openswing.swing.client.LabelControl labelControl6;
    private org.openswing.swing.client.LabelControl labelControl7;
    private org.openswing.swing.client.LabelControl labelControl8;
    private org.openswing.swing.client.LabelControl labelControl9;
    private org.openswing.swing.client.NumericControl numericControl1;
    private org.openswing.swing.client.ReloadButton reloadButton1;
    private org.openswing.swing.client.SaveButton saveButton1;
    private org.openswing.swing.client.TextControl textControl1;
    private org.openswing.swing.client.TextControl textControl2;
    private org.openswing.swing.client.TextControl textControl3;
    private org.openswing.swing.client.TextControl textControl4;
    private org.openswing.swing.client.TextControl textControl5;
    private org.openswing.swing.client.TextControl textControl6;
    // End of variables declaration//GEN-END:variables
}
