Package clips.directory.editors.vidalMkb10

Source Code of clips.directory.editors.vidalMkb10.PanelMkb10VidalEdit

/*
* PanelVidalGroupEdit.java
*
* Created on 26 �?юнь 2008 г., 17:18
*/

package clips.directory.editors.vidalMkb10;

import cli_fmw.delegate.directory.DirectoryItem;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.directory.complex.DirectoryMKB10;
import clips.delegate.directory.complex.DirectoryMKB10Item;
import clips.delegate.directory.complex.DirectoryVidal;
import clips.delegate.directory.complex.DirectoryVidalItem;
import cli_fmw.delegate.DelegateLine2;
import clips.directory.DialogDirectoryVidal;
import clips.directory.editors.matter.PanelMatter;
import clips.directory.editors.matter.VidalChangeListener;
import clips.directory.editors.vidalAtc.TableModelVidal;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.Printable;
import cli_fmw.report.panels.model.EnterKeyListener;
import cli_fmw.report.panels.model.FilteredComboBoxModel;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.Selector;
import cli_fmw.utils.SelectorEditableExceptional;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import beans.directory.mkb10.entity.Mkb10Details;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

/**
* редактор групп услуг и услуг
* @author  lacoste
*/
public class PanelMkb10VidalEdit extends PageGeneric implements Printable, ListSelectionListener {
    private DirectoryMKB10Item selectedMKB10item;
    private DirectoryVidal directoryVidal;
    private ArrayList<DirectoryVidalItem> vidalItems;
    private boolean selectVidalMode; //Режим только выбора препарата
    private PanelMatter panelMatter;
    private DirectoryVidalItem selectedVidal;
    private DirectoryMKB10 directoryMKB10;
    private boolean canBeEdit;

   
    public PanelMkb10VidalEdit(PageContainer container) throws ClipsException{
        this(container, false);
    }
   
    /** Creates new form PanelVidalGroupEdit */
    public PanelMkb10VidalEdit(PageContainer container, boolean selectVidalMode) throws ClipsException {
        super(container);
        initComponents();
        this.selectVidalMode = selectVidalMode;

        directoryMKB10 = (DirectoryMKB10) DirectoryLocator.getDirectory(DirectoryMKB10.class, false);

        //права
        canBeEdit = directoryMKB10.canEdit();

        panelMatter = new PanelMatter(selectVidalMode);
        jSplitPane2.setRightComponent(panelMatter);
        jPanel2.setVisible(!selectVidalMode);
        panelMKBItem.setVisible(!selectVidalMode);
        jPanel7.setVisible(!selectVidalMode);
        updateTree();
        tblVidals1.getSelectionModel().addListSelectionListener(this);
       
        directoryVidal = (DirectoryVidal) DirectoryLocator.getDirectory(DirectoryVidal.class, false);
       
        DocumentListener docListener = new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                setEnabledComponents();
            }
            @Override
            public void removeUpdate(DocumentEvent e) {
                setEnabledComponents();
            }
            @Override
            public void changedUpdate(DocumentEvent e) {
                setEnabledComponents();
            }
        };
       
        tfTitle.getDocument().addDocumentListener(docListener);
        tfShortTitle.getDocument().addDocumentListener(docListener);
        tfCode.getDocument().addDocumentListener(docListener);
        updateTableVidal(selectedMKB10item);
        setEnabledComponents();
    resizeColumn();

        DefaultComboBoxModel model = new DefaultComboBoxModel(directoryMKB10.toArray(false, true));
        model.insertElementAt("", 0);
        model.setSelectedItem("");
        FilteredComboBoxModel filteredModel = new FilteredComboBoxModel(cbSearch, new FilteredComboBoxModel.MaskChecker(), false) {

            @Override
            public Object addItem(String txt) {
                //throw new UnsupportedOperationException("Not supported yet.");
                return null;
            }
        };
        filteredModel.setContainModel(model);
        filteredModel.addEnterListener(new EnterKeyListener() {

            @Override
            public void onEnterPressed(KeyEvent e) {
                if (cbSearch.getSelectedItem() instanceof DirectoryItem){
                    try {
                        onSearchFieldChanged(((DirectoryItem)cbSearch.getSelectedItem()).getTitle());
                    } catch (ClipsException ex) {
                        MessageBox.showException(ex);
                    }
                }
            }
        });

    StateSaver.attachTo(this);
    }
   
    private void updateTableVidal(DirectoryMKB10Item mkb10Item){
        vidalItems = new ArrayList<DirectoryVidalItem>();
        try {
            if (mkb10Item != null && mkb10Item.getID() != 0) {
                SelectorEditableExceptional<DirectoryVidalItem> s = directoryVidal.getFilteredItems(mkb10Item);
                for (int i=0;i<s.size();i++){
                    vidalItems.add(s.get(i));
                }
            }
            TableModelVidal model = new TableModelVidal(vidalItems);
            tblVidals1.setModel(model);
        } catch (Exception ex) {
            MessageBox.showException(ex);
        }
       
    }

   
    public void setEnabledComponents() {
        int[] sel = tblVidals1.getSelectedRowsSorted();
        if (selectedMKB10item != null && selectedMKB10item.getID() == 0) {
            btAddMKB10.setEnabled(false);
        } else {
            btAddMKB10.setEnabled(canBeEdit);
        }
        if (selectedMKB10item != null && selectedMKB10item.getID() != 0) {
            if (!selectedMKB10item.getTitle().equals(tfTitle.getText())
                    || !selectedMKB10item.getDiseaseCode().equals(tfCode.getText())
                    || !selectedMKB10item.getShortTitle().equals(tfShortTitle.getText())) {
                btSetTitleCode.setEnabled(canBeEdit);
            } else {
                btSetTitleCode.setEnabled(false);
            }
            tfTitle.setEditable(canBeEdit);
            tfShortTitle.setEditable(canBeEdit);
            tfCode.setEditable(canBeEdit);
            chbNotify.setEnabled(canBeEdit);
            chbInfectious.setEnabled(canBeEdit);
            btAddVidal1.setEnabled(canBeEdit);
            btDeleteVidal1.setEnabled(canBeEdit && sel.length >0);
            btDeleteMKB10.setEnabled(canBeEdit);
        } else {
            btSetTitleCode.setEnabled(false);
            tfTitle.setEditable(false);
            tfShortTitle.setEditable(false);
            tfCode.setEditable(false);
            chbNotify.setEnabled(false);
            chbInfectious.setEnabled(false);
            btAddVidal1.setEnabled(false);
            btDeleteVidal1.setEnabled(false);
            btDeleteMKB10.setEnabled(false);
        }
    }


    private void updateTree() throws ClipsException{
        TreeModelVidalMkb10 model = new TreeModelVidalMkb10(directoryMKB10);
        treeMkb10.setRootVisible(true);
        treeMkb10.setModel(model);
        treeMkb10.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
//        expandTree();
    }

    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelVidal.COL_ID,      1);
    state.setPreferredWidth(TableModelVidal.COL_TITLE,    8);
    state.setPreferredWidth(TableModelVidal.COL_DIRTY,    1);
      StateSaver.setDefaultState(this, tblVidals1, state);
    }
   
    private void updateRightPanel() throws ClipsException {
        if (selectedMKB10item != null && selectedMKB10item.getID() != 0) {
            tfTitle.setText(selectedMKB10item.getTitle());
            tfTitle.setCaretPosition(0);
            tfShortTitle.setText(selectedMKB10item.getShortTitle());
            tfShortTitle.setCaretPosition(0);
            tfCode.setText(selectedMKB10item.getDiseaseCode());
            chbNotify.setSelected(selectedMKB10item.getMustNotify());
            chbInfectious.setSelected(selectedMKB10item.isInfectious());
        } else {
            tfTitle.setText("");
            tfShortTitle.setText("");
            tfCode.setText("");
            chbNotify.setSelected(false);
            chbInfectious.setSelected(false);
        }
        updateTableVidal(selectedMKB10item);
    }
   
    private void deleteMKB10Item(DirectoryMKB10Item mkb10item) throws ClipsException {
        ClipsException hasException = null;

        SelectorEditableExceptional<DirectoryMKB10Item> iie = mkb10item.getItems();       
        for (int i = iie.size() - 1; i > -1; i--) {
            DirectoryMKB10Item item = iie.get(i);
            try {
                deleteMKB10Item(item);
            } catch (ClipsException ex) {
                hasException = ex;
            }
        }
        DirectoryMKB10Item parent = mkb10item.getParent();

        if (parent == null) {
            iie = directoryMKB10.getItems();
        }
        else {
            iie = parent.getItems();
        }
        if (hasException == null) {
            iie.remove(mkb10item);
        } else {
            throw hasException;
        }

    }

    public DirectoryVidalItem getVidalItem() {
        int k = tblVidals1.getSelectedRowSorted();
        if (k < 0) {
            return null;
        } else {
            return vidalItems.get(k);
        }
    }
   
   
    /** 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() {

        pnlNewNode = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        tfName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbSearch = new javax.swing.JComboBox();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        treeMkb10 = new javax.swing.JTree();
        jPanel2 = new javax.swing.JPanel();
        btDeleteMKB10 = new javax.swing.JButton();
        btAddMKB10 = new javax.swing.JButton();
        rightPanel = new javax.swing.JPanel();
        panelMKBItem = new javax.swing.JPanel();
        panelTitle = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        labTitle = new javax.swing.JLabel();
        labShortTitle = new javax.swing.JLabel();
        labCode = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        tfTitle = new javax.swing.JTextField();
        tfShortTitle = new javax.swing.JTextField();
        tfCode = new javax.swing.JTextField();
        btSetTitleCode = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        chbInfectious = new javax.swing.JCheckBox();
        chbNotify = new javax.swing.JCheckBox();
        jPanel3 = new javax.swing.JPanel();
        jSplitPane2 = new javax.swing.JSplitPane();
        panelVidal = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        btDeleteVidal1 = new javax.swing.JButton();
        btAddVidal1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblVidals1 = new cli_fmw.utils.sorted_table.SortedTable();

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

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

        jPanel9.setLayout(new java.awt.BorderLayout());
        jPanel9.add(tfName, java.awt.BorderLayout.CENTER);

        jLabel2.setText("Название:");
        jLabel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 10));
        jPanel9.add(jLabel2, java.awt.BorderLayout.WEST);

        jPanel10.add(jPanel9, java.awt.BorderLayout.CENTER);

        pnlNewNode.add(jPanel10, java.awt.BorderLayout.NORTH);

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

        jPanel5.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        jPanel5.setPreferredSize(new java.awt.Dimension(30, 30));

        jLabel1.setText("Поиск:");
        jLabel1.setAlignmentY(0.0F);
        jLabel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 5));

        cbSearch.setEditable(true);
        cbSearch.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addComponent(cbSearch, 0, 705, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(cbSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        add(jPanel5, java.awt.BorderLayout.PAGE_START);

        jSplitPane1.setDividerLocation(300);

        jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 0));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jScrollPane1.setMaximumSize(new java.awt.Dimension(0, 0));
        jScrollPane1.setMinimumSize(new java.awt.Dimension(0, 0));
        jScrollPane1.setPreferredSize(new java.awt.Dimension(0, 0));

        treeMkb10.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                treeMkb10ValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(treeMkb10);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        jPanel2.setLayout(new java.awt.GridLayout(1, 0, 5, 0));

        btDeleteMKB10.setText("Удалить");
        btDeleteMKB10.setEnabled(false);
        btDeleteMKB10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDeleteMKB10ActionPerformed(evt);
            }
        });
        jPanel2.add(btDeleteMKB10);

        btAddMKB10.setText("Добавить");
        btAddMKB10.setEnabled(false);
        btAddMKB10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddMKB10ActionPerformed(evt);
            }
        });
        jPanel2.add(btAddMKB10);

        jPanel1.add(jPanel2, java.awt.BorderLayout.PAGE_END);

        jSplitPane1.setLeftComponent(jPanel1);

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

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

        jPanel4.setLayout(new java.awt.GridLayout(3, 1, 0, 4));

        labTitle.setText("Название ");
        jPanel4.add(labTitle);

        labShortTitle.setText("Короткое");
        jPanel4.add(labShortTitle);

        labCode.setText("Код          ");
        jPanel4.add(labCode);

        panelTitle.add(jPanel4, java.awt.BorderLayout.LINE_START);

        jPanel6.setLayout(new java.awt.GridLayout(3, 1, 0, 4));

        tfTitle.setColumns(20);
        tfTitle.setEditable(false);
        tfTitle.setPreferredSize(new java.awt.Dimension(270, 28));
        tfTitle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfTitleActionPerformed(evt);
            }
        });
        jPanel6.add(tfTitle);

        tfShortTitle.setColumns(20);
        tfShortTitle.setEditable(false);
        tfShortTitle.setPreferredSize(new java.awt.Dimension(270, 28));
        tfShortTitle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfShortTitleActionPerformed(evt);
            }
        });
        jPanel6.add(tfShortTitle);

        tfCode.setColumns(20);
        tfCode.setEditable(false);
        tfCode.setPreferredSize(new java.awt.Dimension(270, 28));
        tfCode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfCodeActionPerformed(evt);
            }
        });
        jPanel6.add(tfCode);

        panelTitle.add(jPanel6, java.awt.BorderLayout.CENTER);

        btSetTitleCode.setText("Изменить");
        btSetTitleCode.setEnabled(false);
        btSetTitleCode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSetTitleCodeActionPerformed(evt);
            }
        });

        chbInfectious.setText("Инфекционное заболевание");
        chbInfectious.setEnabled(false);
        chbInfectious.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chbInfectiousActionPerformed(evt);
            }
        });
        jPanel11.add(chbInfectious);

        chbNotify.setText("Оповещать СанЭпидемСтанцию");
        chbNotify.setEnabled(false);
        chbNotify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chbNotifyActionPerformed(evt);
            }
        });
        jPanel11.add(chbNotify);

        javax.swing.GroupLayout panelMKBItemLayout = new javax.swing.GroupLayout(panelMKBItem);
        panelMKBItem.setLayout(panelMKBItemLayout);
        panelMKBItemLayout.setHorizontalGroup(
            panelMKBItemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMKBItemLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelMKBItemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
                    .addComponent(btSetTitleCode)
                    .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        panelMKBItemLayout.setVerticalGroup(
            panelMKBItemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMKBItemLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btSetTitleCode)
                .addGap(8, 8, 8)
                .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        rightPanel.add(panelMKBItem, java.awt.BorderLayout.NORTH);

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

        jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane2.setResizeWeight(0.5);

        panelVidal.setBorder(javax.swing.BorderFactory.createTitledBorder("Препараты"));
        panelVidal.setLayout(new java.awt.BorderLayout());

        jPanel7.setBorder(javax.swing.BorderFactory.createEmptyBorder(15, 1, 10, 1));
        jPanel7.setLayout(new java.awt.BorderLayout());

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

        btDeleteVidal1.setText("Удалить");
        btDeleteVidal1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDeleteVidal1ActionPerformed(evt);
            }
        });
        jPanel8.add(btDeleteVidal1);

        btAddVidal1.setText("Добавить");
        btAddVidal1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddVidal1ActionPerformed(evt);
            }
        });
        jPanel8.add(btAddVidal1);

        jPanel7.add(jPanel8, java.awt.BorderLayout.EAST);

        panelVidal.add(jPanel7, java.awt.BorderLayout.SOUTH);

        jScrollPane2.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jScrollPane2ComponentResized(evt);
            }
        });
        jScrollPane2.setViewportView(tblVidals1);

        panelVidal.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jSplitPane2.setLeftComponent(panelVidal);

        jPanel3.add(jSplitPane2, java.awt.BorderLayout.CENTER);

        rightPanel.add(jPanel3, java.awt.BorderLayout.CENTER);

        jSplitPane1.setRightComponent(rightPanel);

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

private void treeMkb10ValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_treeMkb10ValueChanged

    Object value = treeMkb10.getLastSelectedPathComponent();
    if (value instanceof DirectoryMKB10Item){
        selectedMKB10item = (DirectoryMKB10Item) value;
    } else {
        selectedMKB10item = null;
    }
    try {
        updateRightPanel();
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
    setEnabledComponents();
    fireContainerEventStateChanged();
}//GEN-LAST:event_treeMkb10ValueChanged

private void btSetTitleCodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSetTitleCodeActionPerformed
    try {
        if (!selectedMKB10item.getTitle().equals(tfTitle.getText())) {
            selectedMKB10item.setTitle(tfTitle.getText());
        }
        if (!selectedMKB10item.getShortTitle().equals(tfShortTitle.getText())) {
            selectedMKB10item.setShortTitle(tfShortTitle.getText());
        }
        if (!selectedMKB10item.getDiseaseCode().equals(tfCode.getText())) {
            selectedMKB10item.setDiseaseCode(tfCode.getText());
        }
        treeMkb10.updateUI();
        setEnabledComponents();
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_btSetTitleCodeActionPerformed

private void tfTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfTitleActionPerformed
    btSetTitleCode.doClick();
}//GEN-LAST:event_tfTitleActionPerformed

private void chbNotifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chbNotifyActionPerformed
    try {
        selectedMKB10item.setMustNotify(chbNotify.isSelected());
        treeMkb10.updateUI();
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_chbNotifyActionPerformed

private void btDeleteMKB10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDeleteMKB10ActionPerformed
        try {
            if (selectedMKB10item.getItems().size() > 0) {
                int answer = MessageBox.showConfirmYesNo(MessageBox.C_DELETE_CHIELD_OBJECTS);
                if (answer == MessageBox.ANSWER_NO) {
                    return;
                }

            }
            deleteMKB10Item(selectedMKB10item);
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
        treeMkb10.updateUI();
}//GEN-LAST:event_btDeleteMKB10ActionPerformed

private void btAddMKB10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddMKB10ActionPerformed
    try {
        Mkb10Details d = new Mkb10Details();
        d.id = 0;
        d.title = "Введите название";
        d.code = "";
        d.shortTitle = "";
        DirectoryMKB10Item item = new DirectoryMKB10Item(d);
        if (treeMkb10.getLastSelectedPathComponent() instanceof DirectoryMKB10Item) {
            DirectoryMKB10Item parent = (DirectoryMKB10Item)
                    treeMkb10.getLastSelectedPathComponent();
            d.parentItem = parent.getID();
            parent.getItems().append(item);
        }
        else {
            d.parentItem = 0;
            directoryMKB10.getItems().append(item);               
        }
        treeMkb10.updateUI();       
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_btAddMKB10ActionPerformed

private void btDeleteVidal1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDeleteVidal1ActionPerformed
    int[] sel = tblVidals1.getSelectedRowsSorted();
    if (sel.length > 0) {
        try {
            SelectorEditableExceptional<DirectoryVidalItem> s = directoryVidal.getFilteredItems(selectedMKB10item);
            for (int i = sel.length-1;i>=0;i--){
                s.remove(sel[i]);
            }           
            updateTableVidal(selectedMKB10item);
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }
}//GEN-LAST:event_btDeleteVidal1ActionPerformed

private void btAddVidal1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddVidal1ActionPerformed
    if (treeMkb10.getSelectionCount() >0 && selectedMKB10item != null)    {
        try {
            DialogDirectoryVidal dialog = new DialogDirectoryVidal(MainWindow.mainWindow, directoryVidal, "");
            dialog.setVisible(true);
            if (dialog.getDlgResult() == ModalDialog.DLG_OK){
                DirectoryVidalItem newVidal = dialog.getSelectedItem();
                if (newVidal != null) {
                    SelectorEditableExceptional<DirectoryVidalItem> s
                            =  directoryVidal.getFilteredItems(selectedMKB10item);
                    s.append(newVidal);
                    updateTableVidal(selectedMKB10item);
                }
            }           
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }
}//GEN-LAST:event_btAddVidal1ActionPerformed

private void jScrollPane2ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jScrollPane2ComponentResized
}//GEN-LAST:event_jScrollPane2ComponentResized

private void tfShortTitleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfShortTitleActionPerformed
    btSetTitleCode.doClick();
}//GEN-LAST:event_tfShortTitleActionPerformed

private void chbInfectiousActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chbInfectiousActionPerformed
    try {
        ArrayList<DirectoryMKB10Item> childs = selectedMKB10item.getFullChildList();
        if (childs.size() != 0) {
            int res = JOptionPane.showOptionDialog(this, "У выбранного элемента справочника МКБ-10 есть дочерние элементы.\n"
                + "Проставить дочерним элементам такое же значение свойства \"Инфекционное заболевание\"?","Инфекционное заболевание",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[]{"Да", "Нет"}, -1);
            if (res == JOptionPane.OK_OPTION) {
                for (DirectoryMKB10Item item : childs) {
                    item.setInfectious(chbInfectious.isSelected());
                }
            }
        }
        selectedMKB10item.setInfectious(chbInfectious.isSelected());
        treeMkb10.updateUI();
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_chbInfectiousActionPerformed

private void tfCodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfCodeActionPerformed
    btSetTitleCode.doClick();
}//GEN-LAST:event_tfCodeActionPerformed

    class SearchListener implements DocumentListener {

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            try {
                onSearchFieldChanged(arg0.getDocument().getText(0, arg0.getDocument().getLength()));
            } catch(Exception ex) {
                MessageBox.showException(ex);
            }
        }

        @Override
        public void removeUpdate(DocumentEvent arg0) {
            try {
                onSearchFieldChanged(arg0.getDocument().getText(0, arg0.getDocument().getLength()));
            } catch(Exception ex) {
                MessageBox.showException(ex);
            }
        }

        @Override
        public void changedUpdate(DocumentEvent arg0) {
            try {
                onSearchFieldChanged(arg0.getDocument().getText(0, arg0.getDocument().getLength()));
            } catch(Exception ex) {
                MessageBox.showException(ex);
            }
        }
    }

  
    @SuppressWarnings("unchecked")
    private void onSearchFieldChanged(String value) throws ClipsException {
        if(value.isEmpty()) {
            return;
        }           
        value = value.toLowerCase();
       
        Selector sel = directoryMKB10.getItems();
        for(int i=0; i<sel.size(); i++) {
            DirectoryItem item = (DirectoryItem)sel.get(i);
            List found = findMatch(item, value);
            if(found != null) {                   
                found.add(treeMkb10.getModel().getRoot());
                ArrayList reordered = new ArrayList();
                for(int j=found.size()-1; j>=0; j--) {
                    reordered.add(found.get(j));
                }

                TreePath fullPath = new TreePath(reordered.toArray());
                treeMkb10.setSelectionPath(fullPath);                   
                treeMkb10.scrollPathToVisible(fullPath);
                treeMkb10.updateUI();
                return;
            }
        }
    }
       
    @SuppressWarnings("unchecked")
    private List<Object> findMatch(DirectoryItem item, String pattern) throws ClipsException {
        int pos = (item.getTitle().toLowerCase()).indexOf(pattern.toLowerCase());
        if (pos == 0) {
            ArrayList path = new ArrayList();
            path.add(item);
            return path;
        }
        if (item instanceof DirectoryMKB10Item) {
            DirectoryMKB10Item parent = (DirectoryMKB10Item) item;
            Selector ii = parent.getItems();
            for (int i = 0; i < ii.size(); i++) {
                DirectoryItem child = (DirectoryItem) ii.get(i);
                List path = findMatch(child, pattern);
                if (path != null) {
                    path.add(parent);
                    return path;
                }
            }
        }
        return null;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAddMKB10;
    private javax.swing.JButton btAddVidal1;
    private javax.swing.JButton btDeleteMKB10;
    private javax.swing.JButton btDeleteVidal1;
    private javax.swing.JButton btSetTitleCode;
    private javax.swing.JComboBox cbSearch;
    private javax.swing.JCheckBox chbInfectious;
    private javax.swing.JCheckBox chbNotify;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JLabel labCode;
    private javax.swing.JLabel labShortTitle;
    private javax.swing.JLabel labTitle;
    private javax.swing.JPanel panelMKBItem;
    private javax.swing.JPanel panelTitle;
    private javax.swing.JPanel panelVidal;
    private javax.swing.JPanel pnlNewNode;
    private javax.swing.JPanel rightPanel;
    private cli_fmw.utils.sorted_table.SortedTable tblVidals1;
    private javax.swing.JTextField tfCode;
    private javax.swing.JTextField tfName;
    private javax.swing.JTextField tfShortTitle;
    private javax.swing.JTextField tfTitle;
    private javax.swing.JTree treeMkb10;
    // End of variables declaration//GEN-END:variables

    @Override
    public String getPageTitle() {
        return "Нозологический классификатор";
    }

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

    @Override
    public boolean readyForPrint() {
        return selectedMKB10item != null;
    }

    @Override
    public void print() {
        if (readyForPrint()) {
            String title = "Нозологический классификатор:";
            String group = "";
            DirectoryMKB10Item parent = selectedMKB10item;
            ArrayList<String> titles = new ArrayList<String>();
            while (parent != null) {
                titles.add(parent.toString() + "\n");               
                parent = parent.getParent();
            }
            int k = titles.size() - 1;
            for (int i = k; i > -1; i--) {
                String iS  = titles.get(i);
                for (int j = i; j < k; j++) {
                    iS = "  " + iS;
                }
                group += iS;
            }
            HashMap<String, Object> data = new LinkedHashMap<String, Object>();
            data.put("groupFullTitle", group);
            if (chbInfectious.isSelected()) {
                data.put("infectious", "Заболевание является инфекционным");
            }
            if (chbNotify.isSelected()) {
                data.put("notify", "Оповещать СанЭпидемСтанцию при обнаружении!");
            }
            PrintCreators.createGeneratedReport(title, null, data.entrySet(), null, tblVidals1.getModel(), getClass());
        }
    }

    /**
     * Вызывается при изменении выбора таблицы лекарств
     * @param e
     */
    @Override
    public void valueChanged(ListSelectionEvent e) {
        if (tblVidals1.getSelectedRowCount() > 0) {
            selectedVidal = ((TableModelVidal) tblVidals1.getModel()).getItemAt(tblVidals1.getSelectedRowSorted());
        } else {
            selectedVidal = null;
        }
        panelMatter.vidalChanged(selectedVidal);
        if (getContainer() instanceof VidalChangeListener) {
            ((VidalChangeListener) getContainer()).vidalChanged(selectedVidal);
        }
        setEnabledComponents();
    }

}
TOP

Related Classes of clips.directory.editors.vidalMkb10.PanelMkb10VidalEdit

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.