Package clips.doctor.contraindication

Source Code of clips.doctor.contraindication.PanelContraindication

/*
* PanelContradiction.java
*
* Created on 3 Март 2008 г., 18:47
*/

package clips.doctor.contraindication;

import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.directory.filtered.DirectoryMatter;
import clips.delegate.directory.filtered.DirectoryMatterItem;
import clips.delegate.doctor.contraindication.ContraindicationLocal;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.PageContainer;
import cli_fmw.utils.Selector;
import cli_fmw.main.PageException;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.Printable;
import cli_fmw.report.CombinedReportCreator;
import cli_fmw.report.panels.model.FilteredComboBoxModel;
import cli_fmw.report.panels.model.delegate.DirectoryComboBoxModel;
import cli_fmw.report.panels.model.delegate.DirectorySimpleFilteredComboBoxModel;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.table_config_states.StateSaver;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
*Панель отображения непереносимости
* @author  lacoste
*/
public class PanelContraindication extends PageGeneric implements Persistentable, Printable {
  
    private ContraindicationLocal contraindicationLocal;
    private boolean canBeEdit;
   
  /** Creates new form PanelContradiction
   * @param container
   * @param cl
   * @throws ClipsException
   */
    public PanelContraindication(PageContainer container, ContraindicationLocal cl) throws ClipsException {
        super(container);
        initComponents();      
        this.canBeEdit = cl.getSerrenLocal().canReadMedicalData();
        this.contraindicationLocal = cl;

        chooserDate.setDate(contraindicationLocal.getDate());

        //подготовка комбобокса
        DirectoryMatter directory = DirectoryLocator.getDirectory(DirectoryMatter.class, false);
    FilteredComboBoxModel  model = new FilteredComboBoxModel(cbMatter, new FilteredComboBoxModel.MaskChecker(), false) {

      @Override
      public Object addItem(String txt) {
        throw new UnsupportedOperationException("Not supported yet.");
      }
    };
    model.setContainModel(new DirectoryComboBoxModel<ContraindicationLocal, DirectoryMatterItem>(cbMatter, directory, cl) {

      @Override
      public DirectoryMatterItem getSelectedDirectoryItem() throws ClipsException {
        return getObject().getMatter();
      }

      @Override
      public void setSelectedDirectoryItem(DirectoryMatterItem item) throws ClipsException {
        getObject().setMatter(item);
      }
    });

    setEnableComponents();
    StateSaver.attachTo(this);
    }

    public void setEnableComponents() {
        chooserDate.setEnabled(false);
        cbMatter.setEnabled(canBeEdit);
    }
   
    private boolean isFieldsOk() throws ClipsException {       
    return contraindicationLocal.getMatter() != null && contraindicationLocal.getMatter().getID() != 0;
    }
   
    /** 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() {

        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        chooserDate = new org.infotechservice.ICalendar.components.ICDateChooser();
        cbMatter = new javax.swing.JComboBox();

        setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 8, 8));
        setLayout(new java.awt.BorderLayout());

        jPanel3.setLayout(new java.awt.BorderLayout());

        jPanel4.setLayout(new java.awt.BorderLayout(4, 4));

        jPanel1.setLayout(new java.awt.GridLayout(0, 1, 5, 5));

        jLabel1.setText("Дата регистрации:");
        jPanel1.add(jLabel1);

        jLabel2.setText("Непереносимое вещество:");
        jPanel1.add(jLabel2);

        jPanel4.add(jPanel1, java.awt.BorderLayout.WEST);

        jPanel2.setLayout(new java.awt.GridLayout(0, 1, 5, 5));

        jPanel5.setLayout(new java.awt.BorderLayout());

        chooserDate.setEnabled(false);
        jPanel5.add(chooserDate, java.awt.BorderLayout.LINE_START);

        jPanel2.add(jPanel5);

        cbMatter.setEditable(true);
        jPanel2.add(cbMatter);

        jPanel4.add(jPanel2, java.awt.BorderLayout.CENTER);

        jPanel3.add(jPanel4, java.awt.BorderLayout.NORTH);

        add(jPanel3, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    public boolean canBeClosed() {
        return !isDirty();
    }

    public void beforeClose() {       
    }

    @Override
    public String getPageTitle() {
        return "Непереносимость";
    }

    public String getPageIcon() {
        return null;
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbMatter;
    private org.infotechservice.ICalendar.components.ICDateChooser chooserDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    // End of variables declaration//GEN-END:variables

    @Override
    public boolean isDirty() {
        return contraindicationLocal == null? false : contraindicationLocal.isDirty();
    }

    @Override
    public void save() throws ClipsException {
        if (isFieldsOk()) {
            contraindicationLocal.save1();
        } else {
            throw new ClipsException("Не заполнены необходимые поля");
        }
    }

    @Override
    public void restore() {
        if (isDirty()) {
            if (contraindicationLocal.isNewlyCreated()){
                try {
                    getContainer().removePage(this, true);
                } catch (PageException ex) {
                    MessageBox.showException(ex);
                }
            }else{
        contraindicationLocal.restore();
            }
        }       
    }

    @Override
    public DelegateLine2 getDelegate() {
        return contraindicationLocal;
    }

    @Override
    public boolean readyForPrint() {
        return !isDirty();
    }

    @Override
    public void print() {
        try {
            if (readyForPrint()) {
                CombinedReportCreator parCreator = PrintCreators.createCombinedReportHeader(getClass());
                contraindicationLocal.print(parCreator);
                parCreator.finish();
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

}
TOP

Related Classes of clips.doctor.contraindication.PanelContraindication

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.