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

/*
 * SPanelFilterRecordType.java
 *
 * Created on 10/06/2010, 01:18:00 PM
 */

package erp.mfin.view;

import erp.data.SDataConstants;
import erp.lib.SLibConstants;
import erp.lib.table.STableConstants;
import erp.lib.table.STableSetting;
import erp.mfin.form.SDialogFilterRecordType;

/**
 *
 * @author Sergio Flores
 */
public class SPanelFilterRecordType extends javax.swing.JPanel {

    private erp.client.SClientInterface miClient;
    private erp.lib.table.STableTab moTableTab;
    private erp.mfin.form.SDialogFilterRecordType moFilterRecordType;

    /** Creates new form SPanelFilterRecordType */
    public SPanelFilterRecordType(erp.client.SClientInterface client, erp.lib.table.STableTab tableTab) {
        miClient = client;
        moTableTab = tableTab;
        initComponents();
        initComponentsExtra();
    }

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

        jtfRecordType = new javax.swing.JTextField();
        jbRecordType = new javax.swing.JButton();

        setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 1, 0));

        jtfRecordType.setEditable(false);
        jtfRecordType.setText("TYPE");
        jtfRecordType.setToolTipText("Tipo de póliza contable");
        jtfRecordType.setFocusable(false);
        jtfRecordType.setPreferredSize(new java.awt.Dimension(30, 20));
        add(jtfRecordType);

        jbRecordType.setIcon(new javax.swing.ImageIcon(getClass().getResource("/erp/img/icon_std_look.gif"))); // NOI18N
        jbRecordType.setToolTipText("Seleccionar tipo de póliza contable");
        jbRecordType.setPreferredSize(new java.awt.Dimension(23, 23));
        jbRecordType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRecordTypeActionPerformed(evt);
            }
        });
        add(jbRecordType);
    }// </editor-fold>//GEN-END:initComponents

    private void jbRecordTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRecordTypeActionPerformed
        actionRecordType();
}//GEN-LAST:event_jbRecordTypeActionPerformed

    private void initComponentsExtra() {
        moFilterRecordType = new SDialogFilterRecordType(miClient);
        jtfRecordType.setText("");
    }

    private void actionRecordType() {
        moFilterRecordType.formReset();
        moFilterRecordType.formRefreshCatalogues();
        moFilterRecordType.setFormVisible(true);

        if (moFilterRecordType.getFormResult() == SLibConstants.FORM_RESULT_OK) {
            Object value = moFilterRecordType.getValue(SDataConstants.FINU_TP_REC);
            String type = value == null ? "" : (String) ((Object[]) value)[0];

            jtfRecordType.setText(type);
            moTableTab.updateSetting(new STableSetting(STableConstants.SETTING_FILTER_FIN_REC_TYPE, type));
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jbRecordType;
    private javax.swing.JTextField jtfRecordType;
    // End of variables declaration//GEN-END:variables

}
