/*
* SheduleIndividualExceptionDialog.java
*
* Created on 26 Февраль 2008 г., 14:07
*/
package clips.shedule.individual;
import TimeTable.DayOfWeek;
import TimeTable.JTimeTable;
import TimeTable.scaler.TimeScalerTraditional;
import beans.shedule.week.TimeOffset;
import clips.delegate.shedule.SheduledDay;
import clips.delegate.shedule.individual.WeekIndex;
import cli_fmw.main.ClipsException;
import cli_fmw.main.audit.AuditManager;
import clips.delegate.shedule.individual.SheduleIndividualLocal;
import clips.shedule.template.SheduleTemplateTableModel;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.shedule.prorumble.SheduleProrumbleLocal;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import framework.utils.Converter;
/**
*
* @author axe
*/
public class SheduleIndividualExceptionDialog extends javax.swing.JDialog {
private final SheduleIndividualLocal sil;
private final WeekIndex weekIndex;
private final DayOfWeek dayOfWeek;
private final WeekIndex planWeekIndex;
private SheduleTemplateTableModel model;
private SheduleTemplateTableModel planModel;
/** Creates new form SheduleIndividualExceptionDialog */
public SheduleIndividualExceptionDialog(java.awt.Frame parent,
SheduleIndividualLocal sil, SheduledDay sheduledDay,
WeekIndex weekIndex, DayOfWeek dayOfWeek, AuditManager am) throws ClipsException {
super(parent, true);
planWeekIndex = new WeekIndex(weekIndex.getIndex() % sil.getWeekCount());
model = new SheduleTemplateTableModel(sil, weekIndex, am);
planModel = new SheduleTemplateTableModel(sil, planWeekIndex, am);
initComponents();
this.sil = sil;
this.weekIndex = weekIndex;
this.dayOfWeek = dayOfWeek;
TimeOffset shiftBegin = sheduledDay.getClinicShiftBegin();
TimeOffset shiftEnd = sheduledDay.getClinicShiftEnd();
initTable(realTable, shiftBegin, shiftEnd);
realTable.setDay(weekIndex.getDay(dayOfWeek));
realTable.setModel(model);
realTable.setReadOnly(!sil.canModifyReal());
initTable(planTable, shiftBegin, shiftEnd);
planTable.setDay(planWeekIndex.getDay(dayOfWeek));
planTable.setModel(planModel);
realTable.setReadOnly(!sil.canModifyPlan());
clearPlanBtn.setEnabled(sil.canModifyPlan());
copyToPlanBtn.setEnabled(sil.canModifyPlan());
clearRealBtn.setEnabled(sil.canModifyReal());
copyToRealBtn.setEnabled(sil.canModifyReal());
dateLabel.setText("Дата: " + Converter.dateToString(realTable.getDay().getCalendar().getTime()));
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle dlgSize = this.getBounds();
this.setLocation((scrSize.width - dlgSize.width) / 2, (scrSize.height - dlgSize.height) / 2);
StateSaver.attachTo(this);
}
private void initTable(JTimeTable table, TimeOffset shiftBegin, TimeOffset shiftEnd) {
table.setCanExceed24(false);
table.setShiftBegin(shiftBegin.getMilliseconds());
table.setShiftEnd(shiftEnd.getMilliseconds());
table.setScaler(new TimeScalerTraditional(shiftBegin.getHours(), shiftEnd.getHours(), 0.2f));
}
/** 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();
okBtn = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
planTable = new TimeTable.JTimeTable();
jPanel4 = new javax.swing.JPanel();
toolbarPanel = new javax.swing.JPanel();
clearPlanBtn = new javax.swing.JButton();
copyToRealBtn = new javax.swing.JButton();
copyToPlanBtn = new javax.swing.JButton();
clearRealBtn = new javax.swing.JButton();
realTable = new TimeTable.JTimeTable();
jPanel3 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
dateLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
okBtn.setText(" OK ");
okBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okBtnActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(590, Short.MAX_VALUE)
.addComponent(okBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(okBtn))
);
jPanel2.setLayout(new java.awt.GridLayout(1, 3));
javax.swing.GroupLayout planTableLayout = new javax.swing.GroupLayout(planTable);
planTable.setLayout(planTableLayout);
planTableLayout.setHorizontalGroup(
planTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 236, Short.MAX_VALUE)
);
planTableLayout.setVerticalGroup(
planTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 703, Short.MAX_VALUE)
);
jPanel2.add(planTable);
clearPlanBtn.setText("Очистить план");
clearPlanBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearPlanBtnActionPerformed(evt);
}
});
copyToRealBtn.setText("копировать >>");
copyToRealBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
copyToRealBtnActionPerformed(evt);
}
});
copyToPlanBtn.setText("<< копировать");
copyToPlanBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
copyToPlanBtnActionPerformed(evt);
}
});
clearRealBtn.setText("Очистить дату");
clearRealBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearRealBtnActionPerformed(evt);
}
});
javax.swing.GroupLayout toolbarPanelLayout = new javax.swing.GroupLayout(toolbarPanel);
toolbarPanel.setLayout(toolbarPanelLayout);
toolbarPanelLayout.setHorizontalGroup(
toolbarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(copyToRealBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
.addComponent(copyToPlanBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
.addComponent(clearPlanBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
.addComponent(clearRealBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
);
toolbarPanelLayout.setVerticalGroup(
toolbarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(toolbarPanelLayout.createSequentialGroup()
.addGap(257, 257, 257)
.addComponent(copyToRealBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(copyToPlanBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 309, Short.MAX_VALUE)
.addComponent(clearRealBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(clearPlanBtn)
.addGap(7, 7, 7))
);
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(toolbarPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(toolbarPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2.add(jPanel4);
javax.swing.GroupLayout realTableLayout = new javax.swing.GroupLayout(realTable);
realTable.setLayout(realTableLayout);
realTableLayout.setHorizontalGroup(
realTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 236, Short.MAX_VALUE)
);
realTableLayout.setVerticalGroup(
realTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 703, Short.MAX_VALUE)
);
jPanel2.add(realTable);
jLabel1.setText("Запланировано");
dateLabel.setText("Дата:");
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 242, Short.MAX_VALUE)
.addComponent(dateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(dateLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 714, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel3, 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.DEFAULT_SIZE, 705, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void clearPlanBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearPlanBtnActionPerformed
if(MessageBox.showConfirmYesNo(MessageBox.C_DEL_WORKS_FROM_PLAN_0) == MessageBox.ANSWER_YES) {
try {
sil.deleteWorks(planWeekIndex, dayOfWeek);
planModel.rebuildContent();
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}//GEN-LAST:event_clearPlanBtnActionPerformed
private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
setVisible(false);
}//GEN-LAST:event_okBtnActionPerformed
private void copyToRealBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyToRealBtnActionPerformed
if(MessageBox.showConfirmYesNo(MessageBox.C_COPY_WORKS_FROM_INDIV_PLAN) == MessageBox.ANSWER_YES) {
try {
sil.copyWorksWithOverwrite(planWeekIndex, dayOfWeek, weekIndex, dayOfWeek);
model.rebuildContent();
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}//GEN-LAST:event_copyToRealBtnActionPerformed
/**
* Удаляет все работы из исключений
* @param evt
*/
private void clearRealBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearRealBtnActionPerformed
if(MessageBox.showConfirmYesNo(MessageBox.C_DEL_WORKS_FROM_PLAN_1) == MessageBox.ANSWER_YES) {
try {
sil.deleteWorks(weekIndex, dayOfWeek);
model.rebuildContent();
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}//GEN-LAST:event_clearRealBtnActionPerformed
private void copyToPlanBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyToPlanBtnActionPerformed
if(MessageBox.showConfirmYesNo(MessageBox.C_COPY_WORKS_TO_INDIV_PLAN) == MessageBox.ANSWER_YES) {
try {
sil.copyWorksWithOverwrite(weekIndex, dayOfWeek, planWeekIndex, dayOfWeek);
planModel.rebuildContent();
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
}//GEN-LAST:event_copyToPlanBtnActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton clearPlanBtn;
private javax.swing.JButton clearRealBtn;
private javax.swing.JButton copyToPlanBtn;
private javax.swing.JButton copyToRealBtn;
public javax.swing.JLabel dateLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JButton okBtn;
private TimeTable.JTimeTable planTable;
private TimeTable.JTimeTable realTable;
private javax.swing.JPanel toolbarPanel;
// End of variables declaration//GEN-END:variables
}