Package clips.doctor.diagnosis

Source Code of clips.doctor.diagnosis.PanelMkbInput

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

/*
* PanelMkbInput.java
*
* Created on 16.06.2009, 12:23:53
*/

package clips.doctor.diagnosis;

import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import cli_fmw.main.ContentStateListener;
import cli_fmw.main.Stateful;
import cli_fmw.report.panels.model.TextFieldModel;
import cli_fmw.utils.ConfigGui;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.Selector;
import clips.delegate.directory.complex.DirectoryMKB10;
import clips.delegate.directory.complex.DirectoryMKB10Item;
import clips.directory.dialogs.mkb10.DirectoryDialogMKB10;
import java.text.ParseException;
import java.util.ArrayList;

/**
*
* @author vip
*/
public class PanelMkbInput extends javax.swing.JPanel implements Stateful {

    private ArrayList<ContentStateListener> contentStateListeners = new ArrayList<ContentStateListener>();
    private DirectoryMKB10 dir;
    private DirectoryMKB10Item selectedItem;
    private String inputedCode;
    private TextFieldModel modelCode;


    /** Creates new form PanelMkbInput */
    public PanelMkbInput() {
        initComponents();
        if (!ConfigGui.isLoaded()) {
            return;
        }
        try {
            this.dir = DirectoryLocator.getDirectory(DirectoryMKB10.class);
            modelCode = new TextFieldModel(tfCode) {

                @Override
                protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
                    if (!text.isEmpty() && inputedCode.equals(text)) {
                        return;
                    }

                    inputedCode = text;
                    if (!text.isEmpty()){
                        selectedItem = dir.getItemByCode(text.toUpperCase());
                        if (selectedItem == null){
                            throw new ParseException("Справочник МКБ пуст", 0);
                        }
                    }else{
                        selectedItem = dir.getNullItem();
                    }
                    contentStateChanged();
                    fireContentStateEvent();
                }

                @Override
                protected String getModelTextChecked() throws ClipsException {
                    return inputedCode;
                }



                @Override
                public void contentStateChanged() {
                    updateCombo();
                    super.contentStateChanged();
                }

                @Override
                public void setErrorState(Exception ex) {

                   
                    super.setErrorState(ex);
                    if (ex != null){
                        selectedItem = null;
                        updateCombo();
                    }
                }

                private void updateCombo() {
                    inputedCode = selectedItem == null ? "" : selectedItem.getDiseaseCode();
                    tfTitle.setText(selectedItem == null ? "" : selectedItem.getTitle());
                    tfTitle.setToolTipText(selectedItem == null ? "" : selectedItem.getTitle());
                    tfTitle.setCaretPosition(0);
                }



            };
            modelCode.contentStateChanged();
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

    public DirectoryMKB10Item getSelectedItem() {
        return selectedItem;
    }

    public void setSelectedItem(DirectoryMKB10Item selectedItem) {
        this.selectedItem = selectedItem;
        modelCode.contentStateChanged();
        fireContentStateEvent();
        //tfCode.setText(selectedItem.getDiseaseCode());
        //tfCode.setCaretPosition(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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tfCode = new javax.swing.JTextField();
        tfTitle = new javax.swing.JTextField();
        btMkb = new javax.swing.JButton();

        tfCode.setText("MkbCode");

        tfTitle.setEditable(false);
        tfTitle.setText("МКБ Title");

        btMkb.setText("...");
        btMkb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMkbActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(tfCode, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btMkb))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(tfCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(btMkb)
                .addComponent(tfTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btMkb, tfCode, tfTitle});

    }// </editor-fold>//GEN-END:initComponents

    private void btMkbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMkbActionPerformed
        try {
            DirectoryDialogMKB10 ddd = new DirectoryDialogMKB10(false, selectedItem);
            ddd.setAlwaysOnTop(true);
            ddd.setVisible(true);
            if (ddd.getDlgResult() == DirectoryDialogMKB10.DLG_OK) {
                Selector<DirectoryMKB10Item> ii = ddd.getSelectedItems();
                if (ii.size() > 0) {
                    selectedItem = ii.get(0);
                } else {
                    selectedItem = null;
                }
                modelCode.contentStateChanged();
                fireContentStateEvent();
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
}//GEN-LAST:event_btMkbActionPerformed


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

    @Override
    public void addContentStateListener(ContentStateListener listener) {
        if (listener == null) {
            throw new IllegalArgumentException();
        }
        if(contentStateListeners.indexOf(listener) != -1) {
            return;
        }
        contentStateListeners.add(listener);

    }

    @Override
    public void removeContentStateListener(ContentStateListener listener) {
        if(listener == null) {
            throw new IllegalArgumentException();
        }
        contentStateListeners.remove(listener);
    }

    /**
     * Function notifyes all contentSateListeners about state changed event
     */
    protected void fireContentStateEvent() {
        /*tfCode.setText(selectedItem.getDiseaseCode());
        tfCode.setCaretPosition(0);
        tfTitle.setText(selectedItem.getTitle());
        tfTitle.setCaretPosition(0);*/
        for (int i = 0; i < contentStateListeners.size(); i++) {
            contentStateListeners.get(i).contentStateChanged();
        }
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        tfCode.setEditable(enabled);
        btMkb.setEnabled(enabled);
    }
}
TOP

Related Classes of clips.doctor.diagnosis.PanelMkbInput

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.