/*
* TableExceptionCellDialog.java
*
* Created on 13 Январь 2008 г., 4:24
*/
package clips.shedule.exception;
import beans.shedule.week.TimeOffset;
import cli_fmw.main.ClipsException;
import cli_fmw.main.audit.AuditManager;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.shedule.SheduledDay;
import clips.delegate.shedule.exception.SheduleExceptionData;
import java.awt.Window;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
/**
*
* @author Axe Ilshat
*/
public class TableExceptionCellDialog extends ModalDialog {
public final static int DLG_REMOVEEXCEPTION = DLG_NEXTRESULT;
private SheduleExceptionData data;
/** Creates new form TableExceptionCellDialog */
public TableExceptionCellDialog(Window parent, SheduleExceptionData data, AuditManager am) {
super(parent, "Исключение", am);
initComponents();
this.data = data;
//init values
if(data.getId() == 0) {
noException.setSelected(true);
} else if(!data.isWorking()) {
weekendBtn.setSelected(true);
weekendDesc.setText(data.getDescription());
} else {
workingBtn.setSelected(true);
workingDesc.setText(data.getDescription());
TimeOffset beginTime = data.getBeginTime();
beginHour.setValue(beginTime.getHours());
beginMinute.setValue(beginTime.getMinutes());
TimeOffset endTime = new TimeOffset(beginTime.getRaw() + data.getDuration());
endHour.setValue(endTime.getHours());
endMinute.setValue(endTime.getMinutes());
}
updateGUI();
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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
btnGroup = new javax.swing.ButtonGroup();
jPanel2 = new javax.swing.JPanel();
weekendBtn = new javax.swing.JRadioButton();
workingBtn = new javax.swing.JRadioButton();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
endHour = new JSpinner(new SpinnerNumberModel(21, 1, 23, 1));
beginHour = new JSpinner(new SpinnerNumberModel(8, 0, 22, 1));
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
endMinute = new JSpinner(new SpinnerNumberModel(0, 0, 59, 10));
beginMinute = new JSpinner(new SpinnerNumberModel(0, 0, 59, 10));
jLabel2 = new javax.swing.JLabel();
weekendDesc = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
workingDesc = new javax.swing.JTextField();
noException = new javax.swing.JRadioButton();
jPanel1 = new javax.swing.JPanel();
okBtn = new javax.swing.JButton();
cancelBtn = new javax.swing.JButton();
setLocationByPlatform(true);
setModal(true);
setResizable(false);
btnGroup.add(weekendBtn);
weekendBtn.setText("Выходной");
weekendBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
weekendBtn.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
weekendBtnStateChanged(evt);
}
});
btnGroup.add(workingBtn);
workingBtn.setText("Рабочий день");
workingBtn.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
workingBtn.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
workingBtnStateChanged(evt);
}
});
jLabel1.setText("Начало рабочего дня");
jLabel3.setText("Конец рабочего дня");
endHour.setEnabled(false);
endHour.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
endHourStateChanged(evt);
}
});
beginHour.setEnabled(false);
beginHour.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
beginHourStateChanged(evt);
}
});
jLabel5.setText(":");
jLabel6.setText(":");
endMinute.setEnabled(false);
endMinute.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
endMinuteStateChanged(evt);
}
});
beginMinute.setEnabled(false);
beginMinute.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
beginMinuteStateChanged(evt);
}
});
jLabel2.setText("Описание");
weekendDesc.setEnabled(false);
jLabel4.setText("Описание");
workingDesc.setEnabled(false);
btnGroup.add(noException);
noException.setText("Убрать исключение");
noException.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
okBtn.setText(" OK ");
okBtn.setEnabled(false);
okBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okBtnActionPerformed(evt);
}
});
jPanel1.add(okBtn);
cancelBtn.setText("Отмена");
cancelBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelBtnActionPerformed(evt);
}
});
jPanel1.add(cancelBtn);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(noException)
.addContainerGap(318, Short.MAX_VALUE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(weekendBtn)
.addComponent(workingBtn)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(17, 17, 17)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel3))
.addGap(9, 9, 9)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(endHour)
.addComponent(beginHour, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(endMinute)
.addComponent(beginMinute, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(weekendDesc, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(workingDesc, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)))))
.addGap(30, 30, 30))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
.addContainerGap())))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(noException)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(weekendBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(weekendDesc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(14, 14, 14)
.addComponent(workingBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(beginHour)
.addComponent(jLabel5)
.addComponent(beginMinute))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(endHour)
.addComponent(endMinute)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(workingDesc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void endMinuteStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_endMinuteStateChanged
checkTime(false);
}//GEN-LAST:event_endMinuteStateChanged
private void endHourStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_endHourStateChanged
checkTime(false);
}//GEN-LAST:event_endHourStateChanged
private void beginMinuteStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_beginMinuteStateChanged
checkTime(true);
}//GEN-LAST:event_beginMinuteStateChanged
private void beginHourStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_beginHourStateChanged
checkTime(true);
}//GEN-LAST:event_beginHourStateChanged
private void checkTime(boolean beginChanged) {
int begTime = (Integer) beginHour.getValue() * 60 + (Integer) beginMinute.getValue();
int endTime = (Integer) endHour.getValue() * 60 + (Integer) endMinute.getValue();
if (beginChanged) {
if (begTime >= endTime) {
Integer shift = (Integer) beginHour.getValue() + 1;
endHour.setValue(shift);
}
} else {
if (begTime >= endTime) {
Integer shift = (Integer) endHour.getValue() - 1;
beginHour.setValue(shift);
}
}
}
private void workingBtnStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_workingBtnStateChanged
updateGUI();
}//GEN-LAST:event_workingBtnStateChanged
private void weekendBtnStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_weekendBtnStateChanged
updateGUI();
}//GEN-LAST:event_weekendBtnStateChanged
private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
setDlgResult(ModalDialog.DLG_CANCEL);
this.setVisible(false);
}//GEN-LAST:event_cancelBtnActionPerformed
private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
if (noException.isSelected()) {
setDlgResult(DLG_REMOVEEXCEPTION);
} else if (weekendBtn.isSelected()) {
data.setBeginTime(new TimeOffset());
data.setDuration(0);
data.setWorking(false);
String desc = weekendDesc.getText();
data.setDescription(desc.length() > 0 ? desc : "Выходной день");
setDlgResult(DLG_OK);
} else {
TimeOffset beginTime = new TimeOffset(
(Integer) beginHour.getValue(), (Integer) beginMinute.getValue());
TimeOffset endTime = new TimeOffset(
(Integer) endHour.getValue(), (Integer) endMinute.getValue());
data.setBeginTime(beginTime);
data.setDuration(endTime.getRaw() - beginTime.getRaw());
data.setWorking(true);
String desc = workingDesc.getText();
data.setDescription(desc.length() > 0 ? desc : "Рабочий день");
setDlgResult(DLG_OK);
}
this.setVisible(false);
}//GEN-LAST:event_okBtnActionPerformed
private void updateGUI() {
boolean noexcept = noException.isSelected();
boolean weekend = weekendBtn.isSelected();
boolean working = workingBtn.isSelected();
beginHour.setEnabled(!weekend && working);
beginMinute.setEnabled(!weekend && working);
endHour.setEnabled(!weekend && working);
endMinute.setEnabled(!weekend && working);
workingDesc.setEnabled(!weekend && working);
weekendDesc.setEnabled(weekend && !working);
okBtn.setEnabled(weekend || working || noexcept);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
public javax.swing.JSpinner beginHour;
public javax.swing.JSpinner beginMinute;
public javax.swing.ButtonGroup btnGroup;
private javax.swing.JButton cancelBtn;
public javax.swing.JSpinner endHour;
public javax.swing.JSpinner endMinute;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
public javax.swing.JRadioButton noException;
private javax.swing.JButton okBtn;
public javax.swing.JRadioButton weekendBtn;
public javax.swing.JTextField weekendDesc;
public javax.swing.JRadioButton workingBtn;
public javax.swing.JTextField workingDesc;
// End of variables declaration//GEN-END:variables
}