/*
* DialogRenderAnalyseIndividual.java
*
* Created on 21 Май 2008 г., 16:55
*/
package clips.analysis.individual;
import cli_fmw.main.ClipsException;
import cli_fmw.main.ContentStateListener;
import cli_fmw.main.audit.AuditManager;
import clips.analysis.laboratory.PanelProbeInfo;
import clips.delegate.doctor.checkup.CheckupLocal;
import clips.delegate.doctor.checkup.CheckupXMLData;
import clips.doctor.checkup.CheckUpCellEditor;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
/**
*
* @author vip
*/
public class DialogRenderAnalyseIndividual extends ModalDialog implements ContentStateListener {
private CheckupLocal checkUp;
private CheckupXMLData checkupXMLData;
private PanelProbeInfo panelProbeInfo = new PanelProbeInfo();
/** Creates new form DialogRenderAnalyseIndividual */
public DialogRenderAnalyseIndividual(java.awt.Frame parent, CheckupLocal checkUp, AuditManager am) throws ClipsException {
super(parent, "Провести индивидуальный анализ", am);
initComponents();
jTable.setModel(new DefaultTableModel(0, TableModelRAI.COL_COUNT));
jPanel4.add(panelProbeInfo);
//Добавим к таблице листенер
ListSelectionListener listener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
viewProbeInfo();
}
};
jTable.getSelectionModel().addListSelectionListener(listener);
jTable.getColumnModel().getSelectionModel().addListSelectionListener(listener);
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle dlgSize = this.getBounds();
this.setLocation((scrSize.width - dlgSize.width) / 2, (scrSize.height -
dlgSize.height) / 2);
this.checkUp = checkUp;
this.checkupXMLData = checkUp.getCheckupXMLData();
//Добавим слушателя
checkupXMLData.addContentStateListener(this);
setScreenFields();
StateSaver.excludeFromAttach(this, jTable);
StateSaver.attachTo(this);
}
private void resetTable(boolean editable) {
jTable.setModel(new TableModelRAI(checkupXMLData, editable));
jTable.setDefaultRenderer(Object.class, new TableCellRendererRAI());
jTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumnModel model = jTable.getColumnModel();
//всем столбцам с данными и последнего назначаем свой редактор
for (int i = TableModelRAI.COL_COUNT; i < model.getColumnCount() - 1; i++) {
model.getColumn(i).setCellEditor(new CheckUpCellEditor(checkupXMLData, TableModelRAI.COL_COUNT));
}
}
private void setScreenFields() throws ClipsException {
labFIO.setText(checkUp.getSerrenLocal().getPolisData().getClient(getAuditManager()).toString());
labAnalyseType.setText(checkUp.getType().getTitle());
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yy");
labOrdered.setText(checkUp.getSerrenLocal().getSerRenDirector().toString() +
" " + formatter.format(checkUp.getSerrenLocal().getSerDate()));
boolean editable = checkUp.canModify();
resetTable(editable);
setEnabledComponents();
}
private void setEnabledComponents() {
btOK.setEnabled(checkupXMLData.isDirty());
}
/**
* Оставил старый код, так как таблица может менять число своих колонок
*/
private void resizeColumn() {
int r = jScrollPane1.getViewportBorderBounds().width;
int colCount = jTable.getColumnCount();
jTable.getColumnModel().getColumn(TableModelRAI.COL_PROBE_TITLE).setPreferredWidth(180);
jTable.getColumnModel().getColumn(TableModelRAI.COL_PROBE_NEED).setPreferredWidth(80);
jTable.getColumnModel().getColumn(TableModelRAI.COL_PROBE_NUMBER).setPreferredWidth(80);
for (int i = TableModelRAI.COL_COUNT; i < colCount; i++) {
jTable.getColumnModel().getColumn(i).setPreferredWidth((r - 340) /
(colCount - TableModelRAI.COL_COUNT));
}
}
private void viewProbeInfo() {
int row = jTable.getSelectedRowSorted();
int col = jTable.getSelectedColumn();
//инфу выводим только для столбцов с пробами
if (col < TableModelRAI.COL_COUNT || col ==
((TableModelRAI) jTable.getModel()).col_description || row < 0) {
panelProbeInfo.viewProbeInfoAt(null, null, null);
return;
}
String probeID = checkupXMLData.getProbeList().get(row);
String valueID = checkupXMLData.getProbeValueList().get(col -
TableModelRAI.COL_COUNT);
panelProbeInfo.viewProbeInfoAt(checkupXMLData, probeID, valueID);
}
/** 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();
panelFIO = new javax.swing.JPanel();
labFIO = new javax.swing.JLabel();
panelOrdered = new javax.swing.JPanel();
labOrdered = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
panelAnalyseType = new javax.swing.JPanel();
labAnalyseType = new javax.swing.JLabel();
panelResult = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable = new cli_fmw.utils.sorted_table.SortedTable();
jPanel3 = new javax.swing.JPanel();
btOK = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Результаты анализа");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
jPanel1.setLayout(new java.awt.GridLayout(1, 0));
panelFIO.setBorder(javax.swing.BorderFactory.createTitledBorder("ФИО"));
panelFIO.setLayout(new java.awt.GridLayout(1, 0));
labFIO.setText("...");
panelFIO.add(labFIO);
jPanel1.add(panelFIO);
panelOrdered.setBorder(javax.swing.BorderFactory.createTitledBorder("Направил"));
panelOrdered.setLayout(new java.awt.GridLayout(1, 0));
labOrdered.setText("...");
panelOrdered.add(labOrdered);
jPanel1.add(panelOrdered);
jPanel2.setLayout(new java.awt.GridLayout(1, 0));
panelAnalyseType.setBorder(javax.swing.BorderFactory.createTitledBorder("Тип анализа"));
panelAnalyseType.setLayout(new java.awt.GridLayout(1, 0));
labAnalyseType.setText("...");
panelAnalyseType.add(labAnalyseType);
jPanel2.add(panelAnalyseType);
panelResult.setBorder(javax.swing.BorderFactory.createTitledBorder("Результаты"));
panelResult.setLayout(new java.awt.GridLayout(1, 0));
jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
jScrollPane1ComponentResized(evt);
}
});
jScrollPane1.setViewportView(jTable);
panelResult.add(jScrollPane1);
jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
btOK.setText("Записать");
btOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btOKActionPerformed(evt);
}
});
jPanel3.add(btOK);
btCancel.setText("Отменить");
btCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCancelActionPerformed(evt);
}
});
jPanel3.add(btCancel);
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Информация о пробе"));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 792, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 792, Short.MAX_VALUE))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 788, Short.MAX_VALUE)
.addGap(16, 16, 16))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(panelResult, javax.swing.GroupLayout.DEFAULT_SIZE, 792, Short.MAX_VALUE)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 792, Short.MAX_VALUE))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(panelResult, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed
//Завершаем редактирование текущей ячейки таблицы
if (jTable.getCellEditor() != null) {
jTable.getCellEditor().stopCellEditing();
}
//Проверка все ли анализы взяты
//идем по всем пробам в чекапе
ArrayList<String> probeList = checkupXMLData.getProbeList();
ArrayList<String> probeValueList = checkupXMLData.getProbeValueList();
boolean gettedAll = true;
for (int i = 0; i < probeList.size(); i++) {
String probeID = probeList.get(i);
//если проба нужна проверим заполнены ли ее значения
if (checkupXMLData.isProbeNeed(probeID)) {
//идем по всем значениям
for (int j = 0; j < probeValueList.size(); j++) {
String valueID = probeValueList.get(j);
Object value = checkupXMLData.getProbeValue(probeID, valueID);
if (value == null || value.equals("")) {
gettedAll = false;
}
}
}
}
//Если взяты не все анализы внесены спросим надо ли продолжать сохранение
if (!gettedAll) {
if (MessageBox.showConfirmYesNo(MessageBox.C_ANALYSE_RESULT_NOT_ALL) !=
MessageBox.ANSWER_YES) {
return;
}
}
try {
//Сохранение
checkUp.setCheckupXMLData(checkupXMLData);
checkUp.save1();
checkupXMLData.commit();
checkUp.renderAnalyse();
checkUp.getSerrenLocal().reload();
setDlgResult(ModalDialog.DLG_OK);
dispose();
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btOKActionPerformed
private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
checkUp.restore();
setDlgResult(ModalDialog.DLG_CANCEL);
dispose();
}//GEN-LAST:event_btCancelActionPerformed
private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
checkUp.restore();
}//GEN-LAST:event_formWindowClosed
private void jScrollPane1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jScrollPane1ComponentResized
resizeColumn();
}//GEN-LAST:event_jScrollPane1ComponentResized
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btOK;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private cli_fmw.utils.sorted_table.SortedTable jTable;
private javax.swing.JLabel labAnalyseType;
private javax.swing.JLabel labFIO;
private javax.swing.JLabel labOrdered;
private javax.swing.JPanel panelAnalyseType;
private javax.swing.JPanel panelFIO;
private javax.swing.JPanel panelOrdered;
private javax.swing.JPanel panelResult;
// End of variables declaration//GEN-END:variables
@Override
public void contentStateChanged() {
viewProbeInfo();
setEnabledComponents();
}
}