Package clips.contract

Source Code of clips.contract.PanelContractList

/*
* PanelContractList.java
*
* Created on 28 Февраль 2008 г., 10:50
*/

package clips.contract;

import clips.delegate.client.ClientLocal;
import cli_fmw.main.ClipsException;
import clips.delegate.contract.ContractLocal;
import cli_fmw.main.PageContainer;
import clips.contract.info.PanelContractInfo;
import clips.delegate.contract.PolisData;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.PageException;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.Printable;
import cli_fmw.report.PageOptions.PageOrentation;
import cli_fmw.report.TableReportOptions;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.sorted_table.renderer.simple.DefaultRenderer;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.login.UserInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
* Панель выводит список договоров, в которых фигурирует клиент
* @author  lacoste
*/
public class PanelContractList extends PageGeneric implements Printable {
    private ClientLocal clientLoc;
    private List<PolisData> contractList;
   
    /** Creates new form PanelContractList
     * @param container
     * @param client
     * @throws ClipsException
     */
    public PanelContractList(PageContainer container, DelegateLine2 client) throws ClipsException {       
        super(container);
        initComponents();       
        clientLoc = (ClientLocal) client;
        labClient.setText(clientLoc.toString());
        loadContractList();
    resizeColumns();

        tableContractList.setDefaultRenderer(Object.class, new TableCellRendererContractSearch());
        tableContractList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                btContractView.setEnabled(tableContractList.getSelectedRowCount() > 0);
            }
        });

    StateSaver.attachTo(this);
    }
   
    public void loadContractList() throws ClipsException {
        contractList = clientLoc.getPolisList();
       
        if (contractList != null) {
            ArrayList<ContractLocal> contracts = new ArrayList<ContractLocal>();
            for(int i = 0; i < contractList.size(); i++) {
                ContractLocal contract = contractList.get(i).getContract();
                if (contract.getLpu() == null
                        || contract.getLpu().getID() == UserInfo.get().getCollaborator().getLpu().getID()) {
                    contracts.add(contract);
                }
            }
       
            tableContractList.setModel(new TableModelContractList(contracts));
            tableContractList.setDefaultRenderer(Object.class, new DefaultRenderer());
            tableContractList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        }
    }
   
    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, tableContractList, state);
    }
   
    /** 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() {

        labClient = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableContractList = new cli_fmw.utils.sorted_table.SortedTable();
        btContractView = new javax.swing.JButton();

        labClient.setText("...");
        labClient.setBorder(javax.swing.BorderFactory.createTitledBorder("Пациент"));

        tableContractList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tableContractList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableContractListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tableContractList);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
        );

        btContractView.setText("Просмотреть");
        btContractView.setEnabled(false);
        btContractView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btContractViewActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btContractView, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labClient, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labClient)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btContractView)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btContractViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btContractViewActionPerformed
        try {
            PanelContractInfo panel = new PanelContractInfo(getContainer(),
                    contractList.get(tableContractList.getSelectedRowSorted()).getContract());
            PageGeneric page = getContainer().addNewPage(panel, this);
            getContainer().activatePage(page);
        } catch (PageException e) {
            MessageBox.showException(e);
        } catch (ClipsException e) {
            MessageBox.showException(e);
        }
    }//GEN-LAST:event_btContractViewActionPerformed

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


    @Override
    public String getPageTitle() {
        return "Список договоров (" + clientLoc.toString()+")";
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btContractView;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labClient;
    private cli_fmw.utils.sorted_table.SortedTable tableContractList;
    // End of variables declaration//GEN-END:variables

    @Override
    public boolean readyForPrint() {
        return !(contractList.size() == 0 || contractList == null);
    }

    @Override
    public void print() {
        if (readyForPrint()) {
            HashMap<String, Object> data = new HashMap<String, Object>();           
            data.put("client", "Пациент: " + clientLoc.toString());
            String title = "Список договоров";
            TableReportOptions ops = new TableReportOptions(PageOrentation.horizontal);
            PrintCreators.createGeneratedReport(title, ops, data.entrySet(), null, tableContractList.getModel(), getClass());
        }
    }

    @Override
    public DelegateLine2 getDelegate() {
        return clientLoc;
    }
   
}
TOP

Related Classes of clips.contract.PanelContractList

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.