Package clips.job

Source Code of clips.job.PanelJobList

/*
* PanelJob.java
*
* Created on 6 Февраль 2008 г., 10:36
*/
package clips.job;

import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PageContainer;
import clips.delegate.client.ClientLocal;
import clips.delegate.job.JobLocal;
import cli_fmw.main.ContentStateListener;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.Printable;
import cli_fmw.report.FormReportCreator;
import cli_fmw.report.ReporterFactory;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import java.util.HashMap;
import java.util.List;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
* Панель просмотра, удаления, добавления и редактирования работ клиента.
* Содержит таблицу работ. После создания панели необходимо дать панели
* клиента методом setClient(ClientLocal client)
* @author  ViP
*/
public class PanelJobList extends PageGeneric implements Printable {

    private ClientLocal client;
    private List<JobLocal> jobList;
    private ContentStateListener emptyListener = new ContentStateListener() {

        @Override
        public void contentStateChanged() {
        }
    };

    /** Creates new form PanelJob
     * @param container
     * @param client
     * @throws ClipsException
     */
    public PanelJobList(PageContainer container, ClientLocal client) throws ClipsException {
        super(container);
        initComponents();
        this.client = client;
        jobList = client.getJobList();
        tableJob.setModel(new TableModelJobList(jobList));
        tableJob.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tableJob.setDefaultRenderer(Object.class, new TableCellRendererJobList());

        tableJob.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                int r = tableJob.getSelectedRowSorted();
                btDelete.setEnabled(r > -1);
                btEdit.setEnabled(r > -1);
            }
        });

        resizeColumn();
    StateSaver.attachTo(this);
    }


    /** 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();
        btEdit = new javax.swing.JButton();
        btDelete = new javax.swing.JButton();
        btAdd = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableJob = new cli_fmw.utils.sorted_table.SortedTable();

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

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

        btEdit.setText("Редактировать");
        btEdit.setEnabled(false);
        btEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditActionPerformed(evt);
            }
        });
        jPanel1.add(btEdit);

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

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

        add(jPanel1, java.awt.BorderLayout.SOUTH);

        jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                jScrollPane1ComponentResized(evt);
            }
        });

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

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

    private void btDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDeleteActionPerformed
        int index = tableJob.getSelectedRowSorted();
        if (index >= 0) {
            if (MessageBox.showConfirmYesNo(MessageBox.C_DEL_WORK_ON_ENTERP) ==
                    MessageBox.ANSWER_YES) {
                try {
                    jobList.get(index).remove();
                    jobList.remove(index);
                } catch (ClipsException ex) {
                    MessageBox.showException(ex);
                }
                tableJob.setModel(new TableModelJobList(jobList));

            }
        }
    }//GEN-LAST:event_btDeleteActionPerformed

    /**
     * Добавление работы клиенту. Вызываем диалог с деревом предприятий.
     * @param evt
     */
    private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
        try {
            JobLocal job = new JobLocal(client, getAuditManager());
            job.addContentStateListener(emptyListener);
            DialogJob dialog;
            dialog = new DialogJob(MainWindow.mainWindow, job, client, getAuditManager());
            dialog.setVisible(true);
            if (dialog.getDlgResult() == ModalDialog.DLG_OK) {
                job.save1();
                jobList.add(job);
                tableJob.setModel(new TableModelJobList(jobList));
            }
            tableJob.updateUI();
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
            return;
        }
    }//GEN-LAST:event_btAddActionPerformed

    private void btEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditActionPerformed
        if (tableJob.getSelectedRowSorted() >= 0) {
            try {
                JobLocal job = jobList.get(tableJob.getSelectedRowSorted());
                job.addContentStateListener(emptyListener);
                DialogJob dialog = new DialogJob(MainWindow.mainWindow, job, client, getAuditManager());
                dialog.setVisible(true);
                tableJob.updateUI();
            } catch (ClipsException ex) {
                MessageBox.showException(ex);
            }
        }
}//GEN-LAST:event_btEditActionPerformed

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

private void jScrollPane1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jScrollPane1ComponentResized
}//GEN-LAST:event_jScrollPane1ComponentResized
   
    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelJobList.COL_JOB,      70);
    state.setPreferredWidth(TableModelJobList.COL_PROFESSION,  15);
    state.setPreferredWidth(TableModelJobList.COL_BEGIN,    15);
    state.setPreferredWidth(TableModelJobList.COL_END,      15);
      StateSaver.setDefaultState(this, tableJob, state);
    }
   
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAdd;
    private javax.swing.JButton btDelete;
    private javax.swing.JButton btEdit;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private cli_fmw.utils.sorted_table.SortedTable tableJob;
    // End of variables declaration//GEN-END:variables

    @Override
    public String getPageTitle() {
        return "Место работы " + client.toString();
    }

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

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

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

Related Classes of clips.job.PanelJobList

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.