Package clips.directory.dialogs.mkb10

Source Code of clips.directory.dialogs.mkb10.DirectoryDialogMKB10

/*
* DirectoryDialogDefault.java
*
* Created on 16 Январь 2008 г., 20:45
*/

package clips.directory.dialogs.mkb10;

import cli_fmw.delegate.directory.DirectoryItemRO;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.directory.complex.DirectoryMKB10;
import clips.delegate.directory.complex.DirectoryMKB10Item;
import cli_fmw.directory.dialogs.DirectoryDialogTreeModel;
import cli_fmw.directory.dialogs.GenericChooseDialog;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.table_config_states.StateSaver;
import javax.swing.tree.TreeModel;

/**
*
* @author  Axe Ilshat
*/
public class DirectoryDialogMKB10 extends GenericChooseDialog {
   
    private String bycode = "по коду";
    private String bytitle = "по названию";
    private String bymask = "по маске";
    private Object selectedBy = null;
        
    /** Creates new form DirectoryDialogDefault
     * @param multipleSelected
     * @param selected DirectoryMKB10Item or String
     * @throws ClipsException
     */
    public DirectoryDialogMKB10(boolean multipleSelected, Object selected) throws ClipsException {
        super(multipleSelected, selected, "МКБ 10", null);
        initComponents();
       
        DirectoryMKB10 mkb10 = DirectoryLocator.getDirectory(DirectoryMKB10.class, false);
        setData(mkb10.toArray(true, false), tree, selectBtn, cancelBtn);
       
        searchBy.addItem(bytitle);
        searchBy.addItem(bycode);
        searchBy.addItem(bymask);
               
        DirectoryItemRO array[] = mkb10.toArray(false, true);
        for(int i=0; i<array.length; i++) {
            searchBy.addItem(array[i]);
        }       
       
        searchBy.setSelectedItem(bytitle);
        selectedBy = bytitle;
       
        attachSearchEngine(searchField);
        attachSearchFurtherEngine(searchField, furtherBtn);
    StateSaver.attachTo(this);
    }

    @Override
    protected TreeModel getModel(Object[] items, String rootTitle) {
        return new DirectoryDialogTreeModel(items, rootTitle);
    }

    @Override
    protected boolean isFit(Object item) throws ClipsException {
        if(item instanceof DirectoryMKB10Item) {
            DirectoryMKB10Item si = (DirectoryMKB10Item) item;
            if(si.isVisible()) {
                return true;
            }
        }
        return false;
    }

    @Override
    protected String getItemSearchText(Object obj) {
        DirectoryMKB10Item item = (DirectoryMKB10Item) obj;
        if(selectedBy == bytitle || selectedBy == bymask) {
            return item.getTitle().toLowerCase();
        } else if(selectedBy == bycode) {
            return item.getDiseaseCode().toLowerCase();
        }
        return item.getDiseaseCode().toLowerCase();
    }

    @Override
    protected boolean fullMatch() {
        return selectedBy != bymask;
    }
   
    /** 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() {

        mainTreePane = new javax.swing.JScrollPane();
        tree = new javax.swing.JTree();
        jPanel2 = new javax.swing.JPanel();
        searchBy = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        selectBtn = new javax.swing.JButton();
        cancelBtn = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        searchField = new javax.swing.JTextField();
        furtherBtn = new javax.swing.JButton();

        mainTreePane.setViewportView(tree);

        searchBy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchByActionPerformed(evt);
            }
        });

        jLabel1.setText("Поиск:");

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        selectBtn.setText("Выбрать");
        selectBtn.setEnabled(false);
        selectBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectBtnActionPerformed(evt);
            }
        });
        jPanel1.add(selectBtn);

        cancelBtn.setText("Отмена");
        jPanel1.add(cancelBtn);

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

        searchField.setColumns(15);
        searchField.setMaximumSize(new java.awt.Dimension(200, 2147483647));
        searchField.setPreferredSize(new java.awt.Dimension(200, 27));
        searchField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                searchFieldKeyPressed(evt);
            }
        });
        jPanel3.add(searchField, java.awt.BorderLayout.CENTER);

        furtherBtn.setText("Далее");
        jPanel3.add(furtherBtn, java.awt.BorderLayout.EAST);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(searchBy, 0, 323, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 634, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(searchBy, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        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(mainTreePane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 634, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainTreePane, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void selectBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectBtnActionPerformed
        setDlgResult(DLG_OK);
        setVisible(false);
    }//GEN-LAST:event_selectBtnActionPerformed

private void searchByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchByActionPerformed
    selectedBy = searchBy.getSelectedItem();
    if(selectedBy instanceof DirectoryMKB10Item) {
        String code = ((DirectoryMKB10Item)selectedBy).getDiseaseCode();
        searchBy.setSelectedItem(bycode);
        searchField.setText(code);
    } else {
        searchField.setText(searchField.getText());
    }
}//GEN-LAST:event_searchByActionPerformed

private void searchFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchFieldKeyPressed
    if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER
        && furtherBtn.isEnabled()) {
        furtherBtn.doClick();
    }
}//GEN-LAST:event_searchFieldKeyPressed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelBtn;
    private javax.swing.JButton furtherBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane mainTreePane;
    private javax.swing.JComboBox searchBy;
    private javax.swing.JTextField searchField;
    private javax.swing.JButton selectBtn;
    private javax.swing.JTree tree;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of clips.directory.dialogs.mkb10.DirectoryDialogMKB10

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.