Package clips.contract

Source Code of clips.contract.PanelContractSearch

/*
* PanelConractSearch.java
*
* Created on 20 Март 2008 г., 15:07
*/
package clips.contract;

import beans.contract.search.ContractFilter;
import clips.contract.info.PanelContractInfo;
import clips.delegate.contract.ContractLocal;
import clips.delegate.contract.ContractFactoryLocal;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.directory.dialogs.DirectoryDialogDefault;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Printable;
import cli_fmw.report.TableReportOptions;
import cli_fmw.utils.Selector;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PrintCreators;
import cli_fmw.utils.EmptyDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.delegate.directory.complex.DirectoryEnterprise;
import clips.delegate.directory.complex.DirectoryEnterpriseItem;
import clips.login.UserInfo;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
* панель поиска договоров
* @author  lacoste
*/
public class PanelContractSearch extends PageGeneric implements Printable {
    private static final long serialVersionUID = 1;
    private DirectoryEnterpriseItem enterprise; //предприятие, по которому поиск
    private ArrayList<ContractLocal> contractList;//список найденных договоров
    private boolean isForSerRenSearch;
    private ContractLocal contract;

    /** Creates new form PanelConractSearch
     * @param container
     * @throws ClipsException
     */
    public PanelContractSearch(PageContainer container) throws ClipsException {
        this(container, false);
    }

    public PanelContractSearch(PageContainer container, boolean isForSerRenSearch) throws ClipsException {
        super(container);
        initComponents();

        //Вешаем листенер, чтобы при выделении договора загорелись нужные кнопочки
        tabContractList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                boolean b = tabContractList.getSelectedRowSorted() > -1;
                btCopy.setEnabled(b);
                btDelete.setEnabled(b);
                btOpenContract.setEnabled(b);
            }
        });
       
        tabContractList.setDefaultRenderer(Object.class, new TableCellRendererContractSearch());
        tabContractList.setDefaultRenderer(Date.class, new TableCellRendererContractSearch());
        this.isForSerRenSearch = isForSerRenSearch;
        if (isForSerRenSearch) {
            btOpenContract.setText("Выбрать");
            btCopy.setVisible(false);
            btDelete.setVisible(false);
            btNew.setVisible(false);
        }
        resizeColumns();
        StateSaver.attachTo(this);
    }

    private void updateTable(){
        try {
            int enterpriseID = -1;
            if (enterprise != null) {
                enterpriseID = enterprise.getID();
            }

            ContractFilter filter = new ContractFilter();
            filter.enterpriseId = enterpriseID;
            filter.index = tfIndex.getText();
            filter.onlyOpen = chbOnlyOpen.isSelected();
            filter.onlyOpenForAll = chbOpenForAll.isSelected();
            filter.lpuID = UserInfo.get().getCollaborator().getLpu().getID();

            ContractFactoryLocal factory = new ContractFactoryLocal(getAuditManager());
            contractList = factory.findContractList(filter);
            tabContractList.setModel(new TableModelContractList(contractList));
            tabContractList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }

    /** 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() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        lab = new javax.swing.JLabel();
        labEnterprice = new javax.swing.JTextField();
        btChangeEnterprice = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        tfIndex = new javax.swing.JTextField();
        chbOpenForAll = new javax.swing.JCheckBox();
        chbOnlyOpen = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabContractList = new cli_fmw.utils.sorted_table.SortedTable();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        btCopy = new javax.swing.JButton();
        btDelete = new javax.swing.JButton();
        btNew = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        btFind = new javax.swing.JButton();
        btClearFields = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        btOpenContract = new javax.swing.JButton();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Поиск договоров"));

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

        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        lab.setText("По предприятию: ");
        jPanel2.add(lab);

        labEnterprice.setColumns(30);
        labEnterprice.setEditable(false);
        jPanel2.add(labEnterprice);

        btChangeEnterprice.setText("...");
        btChangeEnterprice.setPreferredSize(new java.awt.Dimension(24, 27));
        btChangeEnterprice.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btChangeEnterpriceActionPerformed(evt);
            }
        });
        jPanel2.add(btChangeEnterprice);

        jPanel1.add(jPanel2);

        jPanel4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jLabel2.setText("По номеру:           ");
        jPanel4.add(jLabel2);

        tfIndex.setColumns(8);
        tfIndex.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfIndexFocusGained(evt);
            }
        });
        jPanel4.add(tfIndex);

        jPanel1.add(jPanel4);

        chbOpenForAll.setText("Только доступные всем пациентам");
        jPanel1.add(chbOpenForAll);

        chbOnlyOpen.setSelected(true);
        chbOnlyOpen.setText("Только открытые");
        chbOnlyOpen.setContentAreaFilled(false);
        jPanel1.add(chbOnlyOpen);

        tabContractList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabContractListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabContractList);

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

        btCopy.setText("Копировать договор");
        btCopy.setEnabled(false);
        btCopy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCopyActionPerformed(evt);
            }
        });
        jPanel6.add(btCopy);

        btDelete.setText("Удалить договор");
        btDelete.setEnabled(false);
        btDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDeleteActionPerformed(evt);
            }
        });
        jPanel6.add(btDelete);

        btNew.setText("Новый договор");
        btNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNewActionPerformed(evt);
            }
        });
        jPanel6.add(btNew);

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

        btFind.setText("Поиск");
        btFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btFindActionPerformed(evt);
            }
        });
        jPanel7.add(btFind);

        btClearFields.setText("Очистить фильтр");
        btClearFields.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btClearFieldsActionPerformed(evt);
            }
        });
        jPanel7.add(btClearFields);

        jPanel5.add(jPanel7, java.awt.BorderLayout.WEST);

        btOpenContract.setText("Открыть");
        btOpenContract.setEnabled(false);
        btOpenContract.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btOpenContractActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(642, Short.MAX_VALUE)
                .addComponent(btOpenContract))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(btOpenContract, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        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()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 716, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btChangeEnterpriceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btChangeEnterpriceActionPerformed
        try {
            DirectoryEnterprise directoryEnterprise = DirectoryLocator.getDirectory(DirectoryEnterprise.class, false);
            DirectoryDialogDefault dlg = new DirectoryDialogDefault(false, enterprise, "\\", directoryEnterprise);
            dlg.setVisible(true);
            if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
                Selector items = dlg.getSelectedItems();
                DirectoryEnterpriseItem selectedEnterprise = (DirectoryEnterpriseItem) items.get(0);
                this.enterprise = selectedEnterprise;
                labEnterprice.setText(selectedEnterprise.getTitle());
            }
        } catch (ClipsException ex) {
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btChangeEnterpriceActionPerformed

    private void btFindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFindActionPerformed
        updateTable();
    }//GEN-LAST:event_btFindActionPerformed
   
    private void btNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNewActionPerformed
        try {
            PanelContractInfo panel = new PanelContractInfo(getContainer(), new ContractLocal(getAuditManager()));
            PageGeneric page = getContainer().addNewPage(panel, this);
            getContainer().activatePage(page);
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }//GEN-LAST:event_btNewActionPerformed

    private void tfIndexFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfIndexFocusGained
      tfIndex.selectAll();
    }//GEN-LAST:event_tfIndexFocusGained

    private void btCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCopyActionPerformed
      if (tabContractList.getSelectedRowCount() > 0) {
          try {
              ContractLocal cl = contractList.get(tabContractList.getSelectedRowSorted());
              cl = cl.copy();
              PanelContractInfo panel = new PanelContractInfo(getContainer(), cl);
              PageGeneric page = getContainer().addNewPage(panel, this);
              getContainer().activatePage(page);
          } catch (ClipsException ex) {
              MessageBox.showException(ex);
          }
      } else {
          MessageBox.showWarning(MessageBox.W_LIST_ELEMENT_NOT_SELECT);
      }
    }//GEN-LAST:event_btCopyActionPerformed

    private void btDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDeleteActionPerformed
      if (tabContractList.getSelectedRowCount() > 0) {
          try {
              ContractLocal cl = contractList.get(tabContractList.getSelectedRowSorted());
              cl.remove();
              btFind.doClick();
          } catch (ClipsException ex) {
              MessageBox.showException(ex);
          }
      } else {
          MessageBox.showWarning(MessageBox.W_LIST_ELEMENT_NOT_SELECT);
      }
    }//GEN-LAST:event_btDeleteActionPerformed

    private void btClearFieldsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClearFieldsActionPerformed
        enterprise = null;
        labEnterprice.setText("");
        chbOpenForAll.setSelected(false);
        chbOnlyOpen.setSelected(true);
      tfIndex.setText("");
    }//GEN-LAST:event_btClearFieldsActionPerformed

    private void tabContractListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabContractListMouseClicked
      if (evt.getClickCount() == 2) {
            btOpenContractActionPerformed(null);
      }
    }//GEN-LAST:event_tabContractListMouseClicked

    private void btOpenContractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOpenContractActionPerformed
      try {
            contract = contractList.get(tabContractList.getSelectedRowSorted());
            if (!isForSerRenSearch) {
                PanelContractInfo panel = new PanelContractInfo(getContainer(), contract);
                getContainer().addNewPage(panel, this);
            }
            else {
                if (getContainer() instanceof EmptyDialog) {
                    ((EmptyDialog)getContainer()).setDlgResult(ModalDialog.DLG_OK);
                    ((EmptyDialog)getContainer()).dispose();
                }
            }
      } catch (ClipsException ex) {
          MessageBox.showException(ex);
      }
    }//GEN-LAST:event_btOpenContractActionPerformed

    public ContractLocal getSelectedContract() {
        return contract;
    }

    private void resizeColumns() {
        TableState          state = new TableState();
        state.setPreferredWidth(TableModelContractList.COL_INDEX,  4);
        state.setPreferredWidth(TableModelContractList.COL_ENTERPRICE,  18);
        state.setPreferredWidth(TableModelContractList.COL_TYPE,  8);
        state.setPreferredWidth(TableModelContractList.COL_BEGIN,  5);
        state.setPreferredWidth(TableModelContractList.COL_END,    5);
        state.setPreferredWidth(TableModelContractList.COL_LPU,    5);
        StateSaver.setDefaultState(this, tabContractList, state);
    }
   
    @Override
    public String getPageTitle() {
        return "Поиск договоров";
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btChangeEnterprice;
    private javax.swing.JButton btClearFields;
    private javax.swing.JButton btCopy;
    private javax.swing.JButton btDelete;
    private javax.swing.JButton btFind;
    private javax.swing.JButton btNew;
    private javax.swing.JButton btOpenContract;
    private javax.swing.JCheckBox chbOnlyOpen;
    private javax.swing.JCheckBox chbOpenForAll;
    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;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lab;
    private javax.swing.JTextField labEnterprice;
    private cli_fmw.utils.sorted_table.SortedTable tabContractList;
    private javax.swing.JTextField tfIndex;
    // End of variables declaration//GEN-END:variables

    @Override
    public boolean readyForPrint() {
        return true;
    }

    @Override
    public void print() {
        if (readyForPrint()) {
            //производим поиск чтоб результаты соответствовали фильтру
            updateTable();
           
            HashMap<String, Object> data = new LinkedHashMap<String, Object>();
            if (enterprise != null) {
                data.put("enterprise", "предприятие: " + enterprise.getTitle());
            }
            if (!tfIndex.getText().isEmpty()) {
                data.put("index", "совпадение номера: " + tfIndex.getText());
            }
            String title = "Список договоров по фильтру";
            TableReportOptions ops = new TableReportOptions(TableReportOptions.PageOrentation.horizontal);
            PrintCreators.createGeneratedReport(title, ops, data.entrySet(), null, tabContractList.getModel(), getClass());
        }
    }

    @Override
    public DelegateLine2 getDelegate() {
        if (tabContractList.getSelectedRowCount() > 0) {
            return contractList.get(tabContractList.getSelectedRowSorted());
        } else {
            return null;
        }
    }
}
TOP

Related Classes of clips.contract.PanelContractSearch

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.