Package clips.directory.editors.vidalFarm

Source Code of clips.directory.editors.vidalFarm.PanelVidalFarmEdit

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

package clips.directory.editors.vidalFarm;

import cli_fmw.delegate.DelegateLine2;
import beans.directory.vidal.entities.farm.ClassificationFarmDetails;
import cli_fmw.delegate.directory.DirectoryItem;
import cli_fmw.delegate.directory.DirectoryItemRO;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.directory.complex.DirectoryVidal;
import clips.delegate.directory.complex.DirectoryVidalFarm;
import clips.delegate.directory.complex.DirectoryVidalFarmItem;
import clips.delegate.directory.complex.DirectoryVidalItem;
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 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 PanelVidalFarmEdit extends PageGeneric implements Printable, ListSelectionListener {
    private DirectoryVidalFarmItem selectedFarm;
    private DirectoryVidal directoryVidal;
    private DirectoryVidalItem selectedVidal;
    private DirectoryVidalFarm directoryVidalFarm;
    private ArrayList<DirectoryVidalItem> vidalItems;
    private PanelMatter panelMatter;
    private boolean selectVidalMode;
    private boolean canBeEdit;
   
    public PanelVidalFarmEdit(PageContainer container) throws ClipsException{
        this(container, false);
    }
   
    /** Creates new form PanelVidalGroupEdit */
    public PanelVidalFarmEdit(PageContainer container, boolean selectVidalMode) throws ClipsException {
        super(container);
        this.selectVidalMode = selectVidalMode;
        initComponents();

        directoryVidalFarm = (DirectoryVidalFarm) DirectoryLocator.getDirectory(DirectoryVidalFarm.class, false);

        //права
        canBeEdit = directoryVidalFarm.canEdit();
       
        panelMatter = new PanelMatter(selectVidalMode);
        jSplitPane2.setRightComponent(panelMatter);
        jPanel3.setVisible(!selectVidalMode);
        jPanel6.setVisible(!selectVidalMode);
        updateTree();
        tblVidals.getSelectionModel().addListSelectionListener(this);
        directoryVidal = (DirectoryVidal) DirectoryLocator.getDirectory(DirectoryVidal.class, false);
        updateTableVidal(selectedFarm);
        setEnabledComponents();
    resizeColumn();

        DirectoryItemRO[] farmItems = directoryVidalFarm.toArray(false, true);
        String[] farmStrings = new String[farmItems.length];
        for (int i = 0; i < farmItems.length; i++) {
            DirectoryVidalFarmItem item = (DirectoryVidalFarmItem) farmItems[i];
            DirectoryVidalFarmItem parent = item.getParent();
            farmStrings[i] = item.getTitle() + (parent != null ? " (" + parent.getTitle() + ")" : "");
        }

        DefaultComboBoxModel model = new DefaultComboBoxModel(directoryVidalFarm.toArray(false, true)/*farmStrings*/);
        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) {
                try {
//                    String s = (String) cbSearch.getSelectedItem();
//                    int pos = s.indexOf("(");
//                    if (pos > 0){
//                        s = s.substring(0, pos-1);
//                    }
                    findItemInTree((DirectoryVidalFarmItem)cbSearch.getSelectedItem());
                } catch (ClipsException ex) {
                    MessageBox.showException(ex);
                }
            }
        });


    StateSaver.attachTo(this);
    }
   
    private void setEnabledComponents() {
        int[] sel = tblVidals.getSelectedRowsSorted();
        if (selectedFarm != null && selectedFarm.getID() == 0) {
            btAddFarmNode.setEnabled(false);
        } else {
            btAddFarmNode.setEnabled(canBeEdit);
        }
        if (selectedFarm != null && selectedFarm.getID() != 0) {
            btAddVidal.setEnabled(canBeEdit);
            btDeleteVidal.setEnabled(canBeEdit && sel.length > 0);
            btDeleteFarmNode.setEnabled(canBeEdit);
        } else {
            btAddVidal.setEnabled(false);
            btDeleteVidal.setEnabled(false);
            btDeleteFarmNode.setEnabled(false);
        }
    }
   
    /**
     * Вызывается при изменении выбора таблицы лекарств
     * @param e
     */
    @Override
    public void valueChanged(ListSelectionEvent e) {
        if (tblVidals.getSelectedRowCount() > 0) {
            selectedVidal = ((TableModelVidal) tblVidals.getModel()).getItemAt(tblVidals.getSelectedRowSorted());
        } else {
            selectedVidal = null;
        }
        panelMatter.vidalChanged(selectedVidal);
        if (getContainer() instanceof VidalChangeListener) {
            ((VidalChangeListener) getContainer()).vidalChanged(selectedVidal);
        }
        setEnabledComponents();
    }

    private void updateTree() throws ClipsException{
        TreeModelVidalFarm model = new TreeModelVidalFarm(directoryVidalFarm);
        treeVidalFarm.setRootVisible(true);
        treeVidalFarm.setModel(model);
        treeVidalFarm.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    }

    private void updateTableVidal(DirectoryVidalFarmItem farmItem){
        vidalItems = new ArrayList<DirectoryVidalItem>();
        try {
            if (farmItem != null) {
                SelectorEditableExceptional<DirectoryVidalItem> s = directoryVidal.getFilteredItems(farmItem);
                for (int i=0;i<s.size();i++){
                    vidalItems.add(s.get(i));
                }
            }
            TableModelVidal model = new TableModelVidal(vidalItems);
            tblVidals.setModel(model);
        } catch (Exception ex) {
            MessageBox.showException(ex);
        }
       
    }
   
    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, tblVidals, state);
    }
   
    /**
     * Строит путь к узлу
     * @param item узел
     * @return путь
     */
    private TreePath getPath(DirectoryVidalFarmItem item){
        ArrayList<Object> path = new ArrayList<Object>();
        path.add(treeVidalFarm.getModel().getRoot());
       
        addNode(item, path);
       
        return new TreePath(path.toArray());
    }
   
    public DirectoryVidalItem getVidalItem() {
        int k = tblVidals.getSelectedRowSorted();
        if (k < 0) {
            return null;
        } else {
            return vidalItems.get(k);
        }
    }

    /**
     * рекурсивно допиcывает узлы начиная с родителя в список
     * (нужна чтоб инвертировать путь и он начинался с родителя)
     * @param item
     * @param path
     */
    private void addNode(DirectoryVidalFarmItem item, ArrayList<Object> path) {
        if (item == null){
            //STOP
        }else{
            addNode(item.getParent(), path);
            path.add(item);
        }
    }   
    /** 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();
        treeVidalFarm = new javax.swing.JTree();
        jPanel3 = new javax.swing.JPanel();
        btAddFarmNode = new javax.swing.JButton();
        btDeleteFarmNode = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jSplitPane2 = new javax.swing.JSplitPane();
        panelVidal = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        btDeleteVidal = new javax.swing.JButton();
        btAddVidal = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblVidals = 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, 340, 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.setLayout(new java.awt.BorderLayout());

        treeVidalFarm.setEditable(true);
        treeVidalFarm.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                treeVidalFarmValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(treeVidalFarm);

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

        jPanel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 1, 5, 1));
        jPanel3.setPreferredSize(new java.awt.Dimension(100, 50));
        jPanel3.setLayout(new java.awt.GridLayout(1, 0, 5, 0));

        btAddFarmNode.setText("<html><center>Добавить <BR>  группу</center></html>");
        btAddFarmNode.setActionCommand("<html>Добавить <BR>   группу</html>");
        btAddFarmNode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddFarmNodeActionPerformed(evt);
            }
        });
        jPanel3.add(btAddFarmNode);

        btDeleteFarmNode.setText("<html><center>Удалить<br>группу</center></html>");
        btDeleteFarmNode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDeleteFarmNodeActionPerformed(evt);
            }
        });
        jPanel3.add(btDeleteFarmNode);

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

        jSplitPane1.setLeftComponent(jPanel1);

        jPanel7.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());

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

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

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

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

        jPanel6.add(jPanel4, java.awt.BorderLayout.EAST);

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

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

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

        jSplitPane2.setLeftComponent(panelVidal);

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

        jSplitPane1.setRightComponent(jPanel7);

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

private void treeVidalFarmValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_treeVidalFarmValueChanged
    Object value = treeVidalFarm.getLastSelectedPathComponent();
    vidalItems = new ArrayList<DirectoryVidalItem>();
    if (value instanceof DirectoryVidalFarmItem){
        try {
            DirectoryVidalFarmItem item = (DirectoryVidalFarmItem) value;
            SelectorEditableExceptional<DirectoryVidalItem> s = directoryVidal.getFilteredItems(item);
            if (s != null) {
                for (int i = 0; i < s.size(); i++) {
                    vidalItems.add(s.get(i));
                }

            }
            selectedFarm = item;
            updateTableVidal(selectedFarm);
        } catch (Exception ex) {
            MessageBox.showException(ex);
        }
    }else{
        selectedFarm = null;
        updateTableVidal(selectedFarm);
    }
    fireContainerEventStateChanged();
    setEnabledComponents();
}//GEN-LAST:event_treeVidalFarmValueChanged

private void btAddVidalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddVidalActionPerformed
    if (treeVidalFarm.getSelectionCount() >0 && selectedFarm != 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(selectedFarm);
                        s.append(newVidal);
                    updateTableVidal(selectedFarm);
                }
            }           
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }
}//GEN-LAST:event_btAddVidalActionPerformed

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

private void btAddFarmNodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddFarmNodeActionPerformed
    try {
        Object value = treeVidalFarm.getLastSelectedPathComponent();
        DirectoryVidalFarmItem newItem = null;
        if (value instanceof DirectoryVidalFarmItem) {
            DirectoryVidalFarmItem selected = (DirectoryVidalFarmItem) value;
            tfName.setText("");
            int res = JOptionPane.showConfirmDialog(null, pnlNewNode, "Заполните поля", JOptionPane.OK_CANCEL_OPTION, -1);
            if (res == JOptionPane.OK_OPTION) {
                if (tfName.getText().isEmpty()) {
                    MessageBox.showWarning(MessageBox.W_INCORRECT_DATA);
                    return;
                } else {
                    ClassificationFarmDetails details = new ClassificationFarmDetails();
                    details.title = tfName.getText();
                    details.parentItem = selected.getID();
                    newItem = new DirectoryVidalFarmItem(details);
                    selected.getItems().append(newItem);
                }
            }
        } else {
            tfName.setText("");
            int res = JOptionPane.showConfirmDialog(null, pnlNewNode, "Заполните поля", JOptionPane.OK_CANCEL_OPTION, -1);
            if (res == JOptionPane.OK_OPTION) {
                if (tfName.getText().isEmpty()) {
                    MessageBox.showWarning(MessageBox.W_INCORRECT_DATA);
                    return;
                } else {
                    ClassificationFarmDetails details = new ClassificationFarmDetails();
                    details.title = tfName.getText();
                    newItem = new DirectoryVidalFarmItem(details);
                    directoryVidalFarm.getItems().append(newItem);
                }
            }
        }
        updateTree();
        TreePath fullPath = getPath(newItem);
        treeVidalFarm.setSelectionPath(fullPath);
        treeVidalFarm.scrollPathToVisible(fullPath);
        treeVidalFarm.updateUI();
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
   
}//GEN-LAST:event_btAddFarmNodeActionPerformed

private void btDeleteFarmNodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDeleteFarmNodeActionPerformed
    if (treeVidalFarm.getSelectionCount()>0 && selectedFarm != null) {
        try {
            if (selectedFarm.getItems().size() > 0) {
                MessageBox.showWarning(MessageBox.W_CANT_DEL_HAVE_CHILDREN);
            } else {
                DirectoryVidalFarmItem parent = selectedFarm.getParent();
                SelectorEditableExceptional<DirectoryVidalItem> s = directoryVidal.getFilteredItems(selectedFarm);
                while (s.size() > 0) {
                    s.remove(0);
                }
                if (selectedFarm.getParent() != null) {
                    selectedFarm.getParent().getItems().remove(selectedFarm);
                } else {
                    directoryVidalFarm.getItems().remove(selectedFarm);
                }
                updateTree();
                TreePath fullPath = getPath(parent);
                treeVidalFarm.expandPath(fullPath);
                treeVidalFarm.updateUI();
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }
}//GEN-LAST:event_btDeleteFarmNodeActionPerformed

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

    private void findItemInTree(DirectoryVidalFarmItem item) throws ClipsException {
        List<Object> path = new ArrayList<Object>();
        while(item != null){
            path.add(0, item);
            item = item.getParent();
        }
        if(path != null) {
            path.add(0, treeVidalFarm.getModel().getRoot());

            TreePath fullPath = new TreePath(path.toArray());
            treeVidalFarm.setSelectionPath(fullPath);
            treeVidalFarm.scrollPathToVisible(fullPath);
            treeVidalFarm.updateUI();
            return;
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAddFarmNode;
    private javax.swing.JButton btAddVidal;
    private javax.swing.JButton btDeleteFarmNode;
    private javax.swing.JButton btDeleteVidal;
    private javax.swing.JComboBox cbSearch;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    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 jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JPanel panelVidal;
    private javax.swing.JPanel pnlNewNode;
    private cli_fmw.utils.sorted_table.SortedTable tblVidals;
    private javax.swing.JTextField tfName;
    private javax.swing.JTree treeVidalFarm;
    // End of variables declaration//GEN-END:variables

    @Override
    public String getPageTitle() {
        return "Клин-фарм классификатор";
    }

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

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

    @Override
    public void print() {
        if (readyForPrint()) {
            String title = "Клинико-фармакологическая классификация лекарственных средств:";
            String group = "";
            DirectoryVidalFarmItem parent = selectedFarm;
            ArrayList<String> titles = new ArrayList<String>();
            while (parent != null) {
                titles.add(parent.getTitle()+ "\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);
            PrintCreators.createGeneratedReport(title, null, data.entrySet(), null, tblVidals.getModel(), getClass());
        }
    }

}
TOP

Related Classes of clips.directory.editors.vidalFarm.PanelVidalFarmEdit

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.