/*
* DialogSheduleEdit.java
*
* Created on 19 Май 2008 г., 16:15
*/
package clips.analysis.shedule.SheduleEdit;
import clips.delegate.doctor.checkup.CheckupLocal;
import clips.delegate.doctor.checkup.shedule.CheckupSheduleLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.delegate.utils.TimeLocal;
import framework.utils.CollectionUtils;
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 clips.login.UserInfo;
import beans.UserRightsSet;
import cli_fmw.main.audit.AuditManager;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Iterator;
import javax.swing.ListSelectionModel;
import javax.swing.RowSorter;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
/**
* Диалог, позволяющий перенести чекапы из одного списка в другой.
* при нажатии ОК результат ОК
* при нажатии Отмена результат Cancel
* при нажатии Анализ результат либо ОК либо Cancel, getIndividualCheckUp() вернет не Null
* ??? Dont understand!
* при нажатии В лабор. результат NextResult
* @author vip
*/
public class DialogSheduleEditM1 extends ModalDialog implements ListSelectionListener {
private ArrayList<CheckupLocal> checkupList;
private ArrayList<CheckupLocal> freeCheckupListBackup;
private GregorianCalendar current;
private CheckupSheduleLocal shedule;
private CheckupLocal individual;
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting() && tblCheckups.getSelectedRowCount() > 0) {
int row = tblCheckups.getSelectedRowSorted();
individual = checkupList.get(row);
btAnalyse.setEnabled(tblCheckups.getSelectedRowCount() == 1);
}
}
/** Creates new form DialogSheduleEdit */
public DialogSheduleEditM1(Frame owner,
ArrayList<CheckupLocal> freeCheckupList,
CheckupSheduleLocal shedule,
AuditManager am) throws ClipsException {
super(owner, "Расписание анализов", am);
freeCheckupListBackup = freeCheckupList;
initComponents();
// btAnalyse = new AnaliseButton();
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle dlgSize = this.getBounds();
this.setLocation((scrSize.width - dlgSize.width) / 2, (scrSize.height - dlgSize.height) / 2);
labAnalyseType.setText(shedule.getType().getTitle());
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yy");
labDate.setText(formatter.format(shedule.getDate()));
current = TimeLocal.getCurrentTime();
current = new GregorianCalendar(current.get(GregorianCalendar.YEAR),
current.get(GregorianCalendar.MONTH),
current.get(GregorianCalendar.DAY_OF_MONTH));
checkupList = new ArrayList<CheckupLocal>(freeCheckupList);
Iterator<CheckupLocal> it = shedule.getCheckupSet().iterator();
while (it.hasNext()) {
CheckupLocal cl = it.next();
checkupList.add(cl);
}
this.shedule = shedule;
if (!UserInfo.get().check(UserRightsSet.MODIFY_CHECKUP_SHEDULE)) {
btOk.setEnabled(false);
btOk.setToolTipText("У вас нет права " + UserRightsSet.MODIFY_CHECKUP_SHEDULE.getDescription());
}
refreshTable();
resizeColumn();
StateSaver.attachTo(this);
}
private void updateFreeCheckupList() {
TableModelSheduleEditM1 model = (TableModelSheduleEditM1) tblCheckups.getModel();
if (model != null) {
try {
System.out.println("Update");
CollectionUtils.addCollectionIfNotExist(freeCheckupListBackup, checkupList);
freeCheckupListBackup.removeAll(shedule.getCheckupSet());
} catch (ClipsException ex) {
MessageBox.showException(ex);
return;
}
}
System.out.println("FREE DIALOG: " + freeCheckupListBackup);
}
@Override
public void dispose() {
updateFreeCheckupList();
super.dispose();
}
// public ArrayList<CheckupLocal> getNewFreeCheckupList() throws ClipsException{
// checkupList.removeAll(shedule.getCheckupSet());
// return checkupList;
// }
private void refreshTable() throws ClipsException {
TableModelSheduleEditM1 model = new TableModelSheduleEditM1(checkupList, shedule);
RowSorter<TableModel> rs = new TableRowSorter(model);
tblCheckups.setModel(model);
tblCheckups.setRowSorter(rs);
tblCheckups.setDefaultRenderer(Object.class, new TableCellRendererSheduleEditM1());
tblCheckups.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
tblCheckups.getSelectionModel().addListSelectionListener(this);
}
private void resizeColumn() {
TableState state = new TableState();
state.setPreferredWidth(TableModelSheduleEditM1.COL_IN_SEDULE, 4);
state.setPreferredWidth(TableModelSheduleEditM1.COL_FIO, 10);
state.setPreferredWidth(TableModelSheduleEditM1.COL_DATE, 4);
state.setPreferredWidth(TableModelSheduleEditM1.COL_PAYED, 4);
state.setPreferredWidth(TableModelSheduleEditM1.COL_WORK_LIFE, 4);
StateSaver.setDefaultState(this, tblCheckups, state);
}
/**
* Если была нажата кнопка Анализ, то возвращает выделеный чекап
* @return
*/
public CheckupLocal getIndividualCheckUp() {
return individual;
}
/** 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() {
jPanel7 = new javax.swing.JPanel();
panelDate = new javax.swing.JPanel();
labDate = new javax.swing.JLabel();
panelAnalyseType = new javax.swing.JPanel();
labAnalyseType = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
panelLeft = new javax.swing.JPanel();
btAnalyse = new javax.swing.JButton();
btToLab = new javax.swing.JButton();
PanelRight = new javax.swing.JPanel();
btOk = new javax.swing.JButton();
btCancel1 = new javax.swing.JButton();
pnlAddToShedule = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
tblCheckups = new cli_fmw.utils.sorted_table.SortedTable();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jPanel7.setLayout(new java.awt.GridLayout(1, 0));
panelDate.setBorder(javax.swing.BorderFactory.createTitledBorder("Дата"));
panelDate.setPreferredSize(new java.awt.Dimension(150, 39));
panelDate.setLayout(new java.awt.BorderLayout());
labDate.setText("...");
panelDate.add(labDate, java.awt.BorderLayout.CENTER);
jPanel7.add(panelDate);
panelAnalyseType.setBorder(javax.swing.BorderFactory.createTitledBorder("Тип анализа"));
panelAnalyseType.setPreferredSize(new java.awt.Dimension(150, 39));
panelAnalyseType.setLayout(new java.awt.BorderLayout());
labAnalyseType.setText("...");
panelAnalyseType.add(labAnalyseType, java.awt.BorderLayout.CENTER);
jPanel7.add(panelAnalyseType);
getContentPane().add(jPanel7, java.awt.BorderLayout.PAGE_START);
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Изменить анализы в расписании"));
jPanel3.setLayout(new java.awt.BorderLayout());
btAnalyse.setText("Анализ");
btAnalyse.setToolTipText("Провести выделенный анализ");
btAnalyse.setEnabled(false);
btAnalyse.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btAnalyseActionPerformed(evt);
}
});
panelLeft.add(btAnalyse);
btToLab.setText("В лабор.");
btToLab.setToolTipText("Отправить в лабораторию все анализы из этого элемента расписания");
btToLab.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btToLabActionPerformed(evt);
}
});
panelLeft.add(btToLab);
btOk.setText("Готово");
btOk.setToolTipText("Применить изменения и закрыть окно");
btOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btOkActionPerformed(evt);
}
});
PanelRight.add(btOk);
btCancel1.setText("Отмена");
btCancel1.setToolTipText("Отменить изменения и закрыть окно");
btCancel1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCancel1ActionPerformed(evt);
}
});
PanelRight.add(btCancel1);
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addComponent(panelLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 108, Short.MAX_VALUE)
.addComponent(PanelRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(panelLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(PanelRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
jPanel3.add(jPanel5, java.awt.BorderLayout.PAGE_END);
pnlAddToShedule.setLayout(new java.awt.BorderLayout());
jPanel2.setLayout(new java.awt.BorderLayout());
jScrollPane1.setViewportView(tblCheckups);
jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);
pnlAddToShedule.add(jPanel2, java.awt.BorderLayout.CENTER);
jPanel3.add(pnlAddToShedule, java.awt.BorderLayout.CENTER);
getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOkActionPerformed
this.individual = null;//чтоб ясно было что это не индивидуальный анализ
this.setDlgResult(DLG_OK);
this.dispose();
}//GEN-LAST:event_btOkActionPerformed
private void btCancel1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancel1ActionPerformed
shedule.restore();
this.setDlgResult(DLG_CANCEL);//отмена
this.dispose();
}//GEN-LAST:event_btCancel1ActionPerformed
/**
* "В лабораторию"
* @param evt
*/
private void btToLabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btToLabActionPerformed
try {
if (shedule.getCheckupSet().isEmpty()) {
MessageBox.showWarning("В расписание не включено ниодного анализа");
return;
}
if (shedule.isDirty()) {//если были изенения то сросим сохранять или нет
int res = MessageBox.showConfirmYesNoCancel(this, MessageBox.C_SAVE_CHANGES);
switch (res) {
case MessageBox.ANSWER_CANCEL://отмена
return;//ничего не делаем
case MessageBox.ANSWER_OK://да
break;
case MessageBox.ANSWER_NO://нет
shedule.restore();//зачит восстановим
break;
}
}
this.setDlgResult(DLG_NEXTRESULT);//в лабораторию
this.dispose();
} catch (ClipsException ex) {
MessageBox.showException(ex);
this.dispose();
}
}//GEN-LAST:event_btToLabActionPerformed
/**
* Анализ
* @param evt
*/
private void btAnalyseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAnalyseActionPerformed
/*if (!(Boolean) tblCheckups.getValueAt(tblCheckups.getSelectedRow(), TableModelSheduleEditM1.COL_IN_SEDULE)) {
MessageBox.showWarning("Анализ не включён в расписание");
return;
}*/
if (shedule.isDirty()) {
int res = MessageBox.showConfirmYesNoCancel(this, MessageBox.C_SAVE_CHANGES);
switch (res) {
case MessageBox.ANSWER_CANCEL:
return;//облом
case MessageBox.ANSWER_NO:
shedule.restore();//откатим шедулю
break;
}
}
this.setDlgResult(DLG_OK);//готово
this.dispose();
}//GEN-LAST:event_btAnalyseActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel PanelRight;
private javax.swing.JButton btAnalyse;
private javax.swing.JButton btCancel1;
private javax.swing.JButton btOk;
private javax.swing.JButton btToLab;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel7;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel labAnalyseType;
private javax.swing.JLabel labDate;
private javax.swing.JPanel panelAnalyseType;
private javax.swing.JPanel panelDate;
private javax.swing.JPanel panelLeft;
private javax.swing.JPanel pnlAddToShedule;
private cli_fmw.utils.sorted_table.SortedTable tblCheckups;
// End of variables declaration//GEN-END:variables
}