/*
* PanelSheduleException.java
*
*/
package clips.shedule.exception;
import TimeTable.Day;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import cli_fmw.main.MainWindow;
import cli_fmw.utils.chooser.ChoosePanelComboException;
import clips.delegate.shedule.exception.SheduleExceptionData;
import clips.delegate.shedule.exception.SheduleExceptionLocal;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.Printable;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.chooser.ChoosePanelComboListener;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.directory.ro.DirectoryLpu;
import clips.delegate.directory.ro.DirectoryLpuItem;
import clips.delegate.shedule.holidays.SheduleHolidayLocal;
import clips.delegate.shedule.week.SheduleWeekLocal;
import clips.login.UserInfo;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* Панель действительного расписания клиники
* (рабочие дни вместо праздников, неожиданные нерабочие дни и тд)
* @author Axe Ilshat
*/
public class PanelSheduleException extends PageGeneric implements Persistentable, Printable {
private final SheduleExceptionLocal sel;
private final SheduleHolidayLocal shl;
private final SheduleWeekLocal swl;
private int year;
private int month;
/**
* Creates new form PanelSheduleException
* @param container
* @throws ClipsException
*/
public PanelSheduleException(PageContainer container) throws ClipsException {
super(container);
initComponents();
sel = SheduleExceptionLocal.getInstance();
sel.addContentStateListener(container);
shl = SheduleHolidayLocal.getInstance();
swl = SheduleWeekLocal.getInstance();
Calendar date = Calendar.getInstance();
year = date.get(Calendar.YEAR);
month = date.get(Calendar.MONTH) + 1;
DirectoryLpu dir = DirectoryLocator.getDirectory(DirectoryLpu.class);
lpuPanel.setData(dir, UserInfo.get().getCollaborator().getLpu(), "Поликлиника:");
lpuPanel.addChoosePanelListener(new ChoosePanelComboListener() {
@Override
public void chooseDone(int type, int id) throws ChoosePanelComboException {
}
});
doStep(0);
StateSaver.attachTo(this);
}
/**
* делает шаг на месяц вперед или назад
*/
private void doStep(int step) throws ClipsException {
Calendar cal = new GregorianCalendar();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month - 1);
cal.add(Calendar.MONTH, step);
int nYear = cal.get(Calendar.YEAR);
int nMonth = cal.get(Calendar.MONTH) + 1;
TableModelSheduleException tableModel = new TableModelSheduleException(
sel, shl, swl, nYear, nMonth);
tableModel.getColumnCount();
table.setModel(tableModel);
year = nYear;
month = nMonth;
}
/**
* returns title for the page
* @return String, HUD title for page
*/
@Override
public String getPageTitle() {
return "Действительное расписание клиники";
}
/** 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() {
lpuPanel = new cli_fmw.utils.chooser.ChoosePanel();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
backBtn = new javax.swing.JButton();
fwdBtn = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
table = 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.LEFT, 10, 10));
jPanel2.setLayout(new java.awt.GridLayout());
backBtn.setText("предыдущий месяц");
backBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
backBtnActionPerformed(evt);
}
});
jPanel2.add(backBtn);
fwdBtn.setText("следующий месяц");
fwdBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fwdBtnActionPerformed(evt);
}
});
jPanel2.add(fwdBtn);
jPanel1.add(jPanel2);
add(jPanel1, java.awt.BorderLayout.NORTH);
table.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tableMouseClicked(evt);
}
});
jScrollPane1.setViewportView(table);
add(jScrollPane1, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
private void fwdBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fwdBtnActionPerformed
try {
doStep(1);
} catch (ClipsException ex) {
MessageBox.showWarning("Не удалось сменить месяц.");
return;
}
}//GEN-LAST:event_fwdBtnActionPerformed
private void backBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backBtnActionPerformed
try {
doStep(-1);
} catch (ClipsException ex) {
MessageBox.showWarning("Не удалось сменить месяц.");
return;
}
}//GEN-LAST:event_backBtnActionPerformed
private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked
if(evt.getClickCount() != 2) {
return;
}
try {
if (!sel.canModify()) {
MessageBox.showWarning("Вы не имеете права редактировать эту панель");
return;
}
} catch (ClipsException ex) {
MessageBox.showWarning("Не удалось получить права на редактирование панели");
return;
}
int row = table.getSelectedRowSorted();
if(row == -1) {
return;
}
try {
Day day = new Day(year, month-1, row+1);
SheduleExceptionData data = sel.getException(day.getCalendar().getTime());
if(data == null) {
data = new SheduleExceptionData(day);
}
TableExceptionCellDialog dlg =
new TableExceptionCellDialog(MainWindow.mainWindow, data, getAuditManager());
dlg.setVisible(true);
if(dlg.getDlgResult() == TableExceptionCellDialog.DLG_REMOVEEXCEPTION) {
sel.removeException(day.getCalendar().getTime());
} else if(dlg.getDlgResult() == ModalDialog.DLG_OK) {
sel.setException(data);
}
table.updateUI();
} catch(ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_tableMouseClicked
@Override
public boolean isDirty() {
return sel.isDirty();
}
@Override
public void save() throws ClipsException {
sel.save1();
}
@Override
public void restore() {
sel.restore();
table.updateUI();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton backBtn;
private javax.swing.JButton fwdBtn;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private cli_fmw.utils.chooser.ChoosePanel lpuPanel;
private cli_fmw.utils.sorted_table.SortedTable table;
// End of variables declaration//GEN-END:variables
@Override
public boolean readyForPrint() {
return !isDirty();
}
@Override
public void print() {
if (readyForPrint()) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, month-1);
String s = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, getLocale());
String title = "Расписание работы клиники. (" + s + ". " + year + ")";
PrintCreators.createGeneratedReport(title, null, null, null, table.getModel(), getClass());
}
}
@Override
public DelegateLine2 getDelegate() {
return null;
}
}