/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* PanelProfcheckupEdit.java
*
* Created on 05.03.2009, 17:32:21
*/
package clips.doctor.profcheckup.checkup;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.client.ClientLocal;
import clips.delegate.doctor.profchekup.ProfcheckupItemLocal;
import clips.delegate.doctor.profchekup.ProfcheckupLocal;
import clips.doctor.PanelEMC;
import java.awt.BorderLayout;
import java.awt.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JList;
/**
*
* @author petr
*/
public class PanelProfcheckupEdit extends PageGeneric implements Persistentable{
private ProfcheckupLocal profcheckupLocal;
/** client id - item list */
private Map<Integer, List<ProfcheckupItemLocal>> itemMap;
private String title;
private PanelEMC panelEMC;
/** Creates new form PanelProfcheckupEdit */
public PanelProfcheckupEdit(PageContainer container, ProfcheckupLocal pl) throws ClipsException {
super(container);
initComponents();
ArrayList<ProfcheckupItemLocal> items = pl.getItems();
Set<Integer> usedClients = new HashSet<Integer>();
DefaultListModel listModel = new DefaultListModel();
itemMap = new HashMap<Integer, List<ProfcheckupItemLocal>>();
for (ProfcheckupItemLocal pil : items) {
ClientLocal client = pil.getPolisData().getClient(getAuditManager());
int id = client.getID();
if (itemMap.get(id) == null) {
itemMap.put(id, new ArrayList<ProfcheckupItemLocal>());
}
itemMap.get(id).add(pil);
if (!usedClients.contains(id)) {
listModel.addElement(client);
usedClients.add(id);
}
}
jList1.setModel(listModel);
jList1.setCellRenderer(new DefaultListCellRenderer(){
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof ClientLocal){
return super.getListCellRendererComponent(list, ((ClientLocal) value).getFIO(), index, isSelected, cellHasFocus);
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
profcheckupLocal = pl;
title = pl.dateToString() + " / " + pl.timeFromToString() + "-" + pl.timeTillToString();
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jSplitPane1 = new javax.swing.JSplitPane();
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jPanel2 = new javax.swing.JPanel();
setLayout(new java.awt.BorderLayout());
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Список направленных на осмотр"));
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
jList1ValueChanged(evt);
}
});
jScrollPane1.setViewportView(jList1);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 91, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 273, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE))
);
jSplitPane1.setLeftComponent(jPanel1);
jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel2.setLayout(new java.awt.BorderLayout());
jSplitPane1.setRightComponent(jPanel2);
add(jSplitPane1, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
try {
jPanel2.removeAll();
Object sel = jList1.getSelectedValue();
if ( sel != null && sel instanceof ClientLocal) {
ClientLocal clientLocal = (ClientLocal) sel;
int id = clientLocal.getID();
List<ProfcheckupItemLocal> items = itemMap.get(id);
if (items != null && !items.isEmpty()) {
panelEMC = new PanelEMC(getContainer(), clientLocal);
jPanel2.add(panelEMC, BorderLayout.CENTER);
jPanel2.revalidate();
ProfcheckupItemLocal pil = items.get(0);
pil.reload();
panelEMC.selectInEmc(pil.getDiseaseLocal());
}
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_jList1ValueChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JList jList1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSplitPane jSplitPane1;
// End of variables declaration//GEN-END:variables
@Override
public String getPageTitle() {
return "Результат профосмотра: "+ title;
}
@Override
public DelegateLine2 getDelegate() {
return profcheckupLocal;
}
@Override
public boolean isDirty() {
return panelEMC != null ? panelEMC.isDirty() : false;
}
@Override
public void save() throws ClipsException {
if (panelEMC != null){
panelEMC.save();
}
}
@Override
public void restore() {
if (panelEMC != null){
panelEMC.restore();
}
}
}