/*
* PanelCertificateList.java
*
* Created on 1 Апрель 2008 г., 12:02
*/
package clips.doctor.prescriptiondlo;
import clips.delegate.client.ClientLocal;
import clips.delegate.doctor.prescription.PrescriptionLocal;
import cli_fmw.delegate.DelegateLine2;
import clips.doctor.PanelEMC;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PageContainer;
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.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.delegate.doctor.prescriptiondlo.PrescriptionDloLocal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import javax.swing.ListSelectionModel;
/**
* Панель отображающая список назначений пациента
* @author vip
*/
public class PanelPrescriptionDloList extends PageGeneric implements Printable {
ClientLocal clientLocal;
ArrayList<PrescriptionDloLocal> prescriptions;
/** Creates new form PanelCertificateList */
public PanelPrescriptionDloList(PageContainer container, ClientLocal clientLocal) throws ClipsException {
super(container);
initComponents();
this.clientLocal = clientLocal;
reloadTable();
resizeColumn();
StateSaver.attachTo(this);
}
public void reloadTable() throws ClipsException {
prescriptions = (ArrayList<PrescriptionDloLocal>) clientLocal.getPrescriptionDloList();
jTable.setModel(new TableModelPrescriptionDloList(prescriptions));
jTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
private void resizeColumn() {
TableState state = new TableState();
state.setPreferredWidth(TableModelPrescriptionDloList.COL_DATE, 1);
state.setPreferredWidth(TableModelPrescriptionDloList.COL_COLL, 3);
StateSaver.setDefaultState(this, jTable, 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() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable = new cli_fmw.utils.sorted_table.SortedTable();
setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
setLayout(new java.awt.BorderLayout());
jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
jScrollPane1ComponentResized(evt);
}
});
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTableMouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable);
add(jScrollPane1, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void jTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableMouseClicked
if (evt.getClickCount() == 2) {
int row = jTable.getSelectedRowSorted();
if (row >=0 ) {
PrescriptionDloLocal p = prescriptions.get(row);
if (getContainer() instanceof PanelEMC) {
try {
((PanelEMC) getContainer()).selectInEmc(p);
} catch (ClipsException ex) {
ex.printStackTrace();
MessageBox.showException(ex);
}
}
}
}
}//GEN-LAST:event_jTableMouseClicked
private void jScrollPane1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jScrollPane1ComponentResized
}//GEN-LAST:event_jScrollPane1ComponentResized
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private cli_fmw.utils.sorted_table.SortedTable jTable;
// End of variables declaration//GEN-END:variables
@Override
public String getPageTitle() {
return "Список назначений";
}
public String getPageIcon() {
return null;
}
@Override
public boolean readyForPrint() {
return true;
}
@Override
public void print() {
if (readyForPrint()) {
HashMap<String, Object> data = new LinkedHashMap<String, Object>();
String title = "Список льготных рецептов пациента";
data.put("client", "Пациент: " + clientLocal.toString());
PrintCreators.createGeneratedReport(title, null, data.entrySet(), null, jTable.getModel(), getClass());
}
}
@Override
public DelegateLine2 getDelegate() {
return clientLocal;
}
}