Package clips.kek.inability

Source Code of clips.kek.inability.DlgInabilityEdit

/*
* DlgInabilityEdit.java
*
* Created on 14 Июль 2008 г., 12:32
*/

package clips.kek.inability;

import clips.delegate.kek.InabilityData;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.NumberTextField;
import cli_fmw.main.ClipsException;
import cli_fmw.main.audit.AuditManager;
import cli_fmw.utils.table_config_states.StateSaver;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import org.infotechservice.ICalendar.DateEvent;
import org.infotechservice.ICalendar.DateListener;

/**
*
* @author  lacoste
*/
public class DlgInabilityEdit extends ModalDialog {
    private InabilityData inability;
    private NumberTextField levelInNTF;
    private NumberTextField levelOutNTF;
   
    /** Creates new form DlgInabilityEdit
     * @param parent
     * @param inabilityy
     * @throws ClipsException
     */
    public DlgInabilityEdit(java.awt.Frame parent, InabilityData inabilityy, AuditManager am) throws ClipsException {
        super(parent, "", am);
        initComponents();
        this.inability = inabilityy;
        if (inability.getDate() == null) {
            jPanel2.setVisible(false);
        }
       
        levelInNTF = new NumberTextField(1);
        levelOutNTF = new NumberTextField(1);
        levelInNTF.setText(Integer.toString(inability.getLevelIn()));
        levelOutNTF.setText(Integer.toString(inability.getLevelOut()));       
       
        dateIn.addDateListener(new DateListener() {

            @Override
            public void dateChanged(DateEvent evt) {
                try {
                    if (dateIn.getDate() == null) {
                        btOk.setEnabled(false);
                    }
                    else {
                        btOk.setEnabled(true);
                    }
                    inability.setDate(dateIn.getDate());
                } catch(ClipsException ex) {
                    MessageBox.showException(ex);
                }
            }
        });
       
        dateOut.addDateListener(new DateListener() {

            @Override
            public void dateChanged(DateEvent evt) {
                try {
                    inability.setDateAnswer(dateOut.getDate());
                } catch(ClipsException ex) {
                    MessageBox.showException(ex);
                }
            }
        });
       
        levelInNTF.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent arg0) {
                setField(arg0.getDocument());
            }

            @Override
            public void removeUpdate(DocumentEvent arg0) {
                setField(arg0.getDocument());
            }

            @Override
            public void changedUpdate(DocumentEvent arg0) {
            }

            private void setField(Document doc) {
                try {
                    String levelIn = doc.getText(0, doc.getLength());
                    if (!levelIn.equals("")) {
                        try {
                            inability.setLevelIn(Integer.parseInt(levelIn));
                        } catch (NumberFormatException ex) {                           
                           
                        }
                    } else {
                        inability.setLevelIn(0);
                    }
                } catch (ClipsException ex) {
                    MessageBox.showException(ex);
                } catch (BadLocationException ex) {
                    MessageBox.showException(ex);
                }
            }
        });
       
        levelOutNTF.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent arg0) {
                setField(arg0.getDocument());
            }

            @Override
            public void removeUpdate(DocumentEvent arg0) {
                setField(arg0.getDocument());
            }

            @Override
            public void changedUpdate(DocumentEvent arg0) {
            }

            private void setField(Document doc) {
                try {
                    String levelOut = doc.getText(0, doc.getLength());
                    if (!levelOut.equals("")) {
                        try {
                            inability.setLevelOut(Integer.parseInt(levelOut));
                        } catch (NumberFormatException ex) {                           
                           
                        }
                    } else {
                        inability.setLevelOut(0);
                    }
                } catch (ClipsException ex) {
                    MessageBox.showException(ex);
                } catch (BadLocationException ex) {
                    MessageBox.showException(ex);
                }
            }
        });
       
        setScreenFields();
    StateSaver.attachTo(this);
    }

    private void setScreenFields() throws ClipsException {       
        jPanel1.add(levelInNTF);
        jPanel2.add(levelOutNTF);
        dateIn.setDate(inability.getDate());
        dateOut.setDate(inability.getDateAnswer());
       
        boolean b = !inability.isClosed();
       
        dateIn.setEnabled(b);
        dateOut.setEnabled(b);
        levelInNTF.setEditable(b);
        levelOutNTF.setEditable(b);
        taDesc.setEditable(b);
    }
   
    /** 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.
     */
  
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        dateIn = new org.infotechservice.ICalendar.components.ICDateChooser();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        dateOut = new org.infotechservice.ICalendar.components.ICDateChooser();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taDesc = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        btOk = new javax.swing.JButton();
        btCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Направление на МСЭК"));
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel1.setText("Дата: ");
        jPanel1.add(jLabel1);

        dateIn.setPreferredSize(new java.awt.Dimension(140, 27));
        jPanel1.add(dateIn);

        jLabel2.setText("        Группа: ");
        jPanel1.add(jLabel2);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Решение МСЭК"));
        jPanel2.setPreferredSize(jPanel1.getPreferredSize());
        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel3.setText("Дата: ");
        jPanel2.add(jLabel3);

        dateOut.setPreferredSize(dateIn.getPreferredSize());
        jPanel2.add(dateOut);

        jLabel4.setText("        Группа: ");
        jPanel2.add(jLabel4);

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Примечание"));

        taDesc.setColumns(20);
        taDesc.setLineWrap(true);
        taDesc.setRows(5);
        jScrollPane1.setViewportView(taDesc);

        btOk.setText("ОК");
        btOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btOkActionPerformed(evt);
            }
        });

        btCancel.setText("Отмена");
        btCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(477, Short.MAX_VALUE)
                .addComponent(btOk)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btCancel)
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOk});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCancel)
                    .addComponent(btOk)))
        );

        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.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 623, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 623, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 623, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-657)/2, (screenSize.height-425)/2, 657, 425);
    }// </editor-fold>//GEN-END:initComponents

private void btOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOkActionPerformed
    setDlgResult(ModalDialog.DLG_OK);
    dispose();
}//GEN-LAST:event_btOkActionPerformed

private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
    setDlgResult(ModalDialog.DLG_CANCEL);
    dispose();
}//GEN-LAST:event_btCancelActionPerformed
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancel;
    private javax.swing.JButton btOk;
    private org.infotechservice.ICalendar.components.ICDateChooser dateIn;
    private org.infotechservice.ICalendar.components.ICDateChooser dateOut;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea taDesc;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of clips.kek.inability.DlgInabilityEdit

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.