/*
* TimeSpanDialog.java
*
* Created on 5 Февраль 2008 г., 22:42
*/
package clips.shedule.template;
import cli_fmw.delegate.directory.DirectoryItem;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.directory.complex.DirectoryWorkType;
import clips.delegate.directory.complex.DirectoryCabinet;
import clips.delegate.directory.complex.DirectoryCabinetItem;
import clips.delegate.directory.complex.DirectoryWorkTypeItem;
import cli_fmw.main.ClipsException;
import cli_fmw.directory.dialogs.DirectoryDialogDefault;
import cli_fmw.main.audit.AuditManager;
import cli_fmw.utils.Selector;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import framework.utils.ROList;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import javax.swing.DefaultComboBoxModel;
/**
*
* @author Axe Ilshat
*/
class IndividualTimeSpanDialog extends ModalDialog {
public final static int DLG_DELETED = DLG_NEXTRESULT;
protected int timeBegin;
protected int timeEnd;
protected boolean canBeResized;
protected boolean canBeMoved;
protected boolean canBeDeleted;
protected int minimalSize; //in minutes
protected int granulation = 5;
/**
*
* @param parent
* @param modal
* @param timeBase
* @param timeBegin
* @param timeEnd
* @param canBeResized
* @param canBeMoved
* @param canBeDeleted
* @param granulation
* @param minimalSize - требуемая минимальная длительность в минутах
*/
public IndividualTimeSpanDialog(java.awt.Frame parent,
int timeBegin, int timeEnd, boolean canBeResized,
boolean canBeMoved, boolean canBeDeleted,
int granulation, int minimalSize,
DirectoryWorkTypeItem workType,
DirectoryCollaboratorItem collab,
DirectoryCabinetItem cabinet,
AuditManager am) throws ClipsException {
super(parent, "График работы", am);
initComponents();
this.timeBegin = timeBegin;
this.timeEnd = timeEnd;
this.canBeResized = canBeResized;
this.canBeMoved = canBeMoved;
this.canBeDeleted = canBeDeleted;
this.granulation = granulation;
this.minimalSize = minimalSize;
DirectoryWorkType directoryWorkTypes = DirectoryLocator.getDirectory(DirectoryWorkType.class, false);
Selector ii = directoryWorkTypes.getItems();
for (int i = 0; i < ii.size(); i++) {
DirectoryItem item = (DirectoryItem) ii.get(i);
workTypesCombo.addItem(item);
if (workType != null && item.getID() == workType.getID()) {
workTypesCombo.setSelectedItem(item);
}
}
Integer h1 = new Integer(timeBegin / 60);
Integer h2 = new Integer(timeEnd / 60);
for (int i = 0; i < 24; i++) {
Integer item = new Integer(i);
h1Combo.addItem(item);
h2Combo.addItem(item);
}
h1Combo.setSelectedItem(h1);
h2Combo.setSelectedItem(h2);
Integer m1 = new Integer(timeBegin % 60);
Integer m2 = new Integer(timeEnd % 60);
for (int i = 0; i < 60; i++) {
Integer item = new Integer(i);
m1Combo.addItem(item);
m2Combo.addItem(item);
}
m1Combo.setSelectedItem(m1);
m2Combo.setSelectedItem(m2);
DirectoryCabinet cabinets = DirectoryLocator.getDirectory(DirectoryCabinet.class, false);
ROList<DirectoryCabinetItem> cabinetList = cabinets.getFilteredItems(collab.getLpu());
DefaultComboBoxModel combo = new DefaultComboBoxModel(cabinetList.toArray());
cabinetCombo.setModel(combo);
cabinetCombo.setSelectedItem(cabinet);
delBtn.setEnabled(canBeDeleted);
h1Combo.setEnabled(canBeMoved);
m1Combo.setEnabled(canBeMoved);
h2Combo.setEnabled(canBeResized);
m2Combo.setEnabled(canBeResized);
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle dlgSize = this.getBounds();
this.setLocation((scrSize.width - dlgSize.width) / 2, (scrSize.height - dlgSize.height) / 2);
StateSaver.attachTo(this);
}
/**
* время окончания
* @return минуты с начала суток
*/
public int getTimeBegin() {
return timeBegin;
}
/**
* Время начала
* @return минуты с начала суток
*/
public int getTimeEnd() {
return timeEnd;
}
public DirectoryWorkTypeItem getWorkType() {
return (DirectoryWorkTypeItem) workTypesCombo.getSelectedItem();
}
public DirectoryCabinetItem getCabinet() {
return (DirectoryCabinetItem) cabinetCombo.getSelectedItem();
}
/** 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();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
h1Combo = new javax.swing.JComboBox();
m1Combo = new javax.swing.JComboBox();
h2Combo = new javax.swing.JComboBox();
m2Combo = new javax.swing.JComboBox();
workTypesCombo = new javax.swing.JComboBox();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
cabinetCombo = new javax.swing.JComboBox();
jPanel2 = new javax.swing.JPanel();
delBtn = new javax.swing.JButton();
okBtn = new javax.swing.JButton();
cancelBtn = new javax.swing.JButton();
setModal(true);
setResizable(false);
jLabel1.setText("Начало в ");
jLabel2.setText("Конец в");
jLabel3.setText("Вид деятельности");
h1Combo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
h1ComboActionPerformed(evt);
}
});
m1Combo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
m1ComboActionPerformed(evt);
}
});
h2Combo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
h2ComboActionPerformed(evt);
}
});
m2Combo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
m2ComboActionPerformed(evt);
}
});
workTypesCombo.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
workTypesComboItemStateChanged(evt);
}
});
jLabel4.setText("часов");
jLabel5.setText("минут");
jLabel6.setText("часов");
jLabel7.setText("минут");
jLabel8.setText("Кабинет");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(h2Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(h1Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(m2Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel7))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(m1Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(workTypesCombo, 0, 288, Short.MAX_VALUE)
.addComponent(cabinetCombo, 0, 288, Short.MAX_VALUE))))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(h1Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(m1Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(h2Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(m2Combo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(workTypesCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(cabinetCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
delBtn.setText("Удалить");
delBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
delBtnActionPerformed(evt);
}
});
jPanel2.add(delBtn);
okBtn.setText(" OK ");
okBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okBtnActionPerformed(evt);
}
});
jPanel2.add(okBtn);
cancelBtn.setText("Отмена");
cancelBtn.setMinimumSize(new java.awt.Dimension(80, 29));
cancelBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelBtnActionPerformed(evt);
}
});
jPanel2.add(cancelBtn);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(3, 3, 3)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void delBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delBtnActionPerformed
setDlgResult(DLG_DELETED);
setVisible(false);
}//GEN-LAST:event_delBtnActionPerformed
private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
setDlgResult(DLG_OK);
updateResult();
setVisible(false);
}//GEN-LAST:event_okBtnActionPerformed
private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
setDlgResult(DLG_CANCEL);
setVisible(false);
}//GEN-LAST:event_cancelBtnActionPerformed
private void h1ComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_h1ComboActionPerformed
updateResult();
}//GEN-LAST:event_h1ComboActionPerformed
private void m1ComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m1ComboActionPerformed
updateResult();
}//GEN-LAST:event_m1ComboActionPerformed
private void h2ComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_h2ComboActionPerformed
updateResult();
}//GEN-LAST:event_h2ComboActionPerformed
private void m2ComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m2ComboActionPerformed
updateResult();
}//GEN-LAST:event_m2ComboActionPerformed
private void workTypesComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_workTypesComboItemStateChanged
DirectoryWorkTypeItem wt = (DirectoryWorkTypeItem) workTypesCombo.getSelectedItem();
if(wt != null) {
int beg = wt.getDefaultBegin();
if(beg > 0) {
h1Combo.setSelectedItem(new Integer(beg/60));
m1Combo.setSelectedItem(new Integer(beg%60));
}
int end = wt.getDefaultEnd();
if(end > 0) {
h2Combo.setSelectedItem(new Integer(end/60));
m2Combo.setSelectedItem(new Integer(end%60));
}
}
}//GEN-LAST:event_workTypesComboItemStateChanged
private void updateResult() {
okBtn.setEnabled(false);
Integer h1 = (Integer) h1Combo.getSelectedItem();
Integer h2 = (Integer) h2Combo.getSelectedItem();
Integer m1 = (Integer) m1Combo.getSelectedItem();
Integer m2 = (Integer) m2Combo.getSelectedItem();
if(h1 != null
&& m1 != null
&& h2 != null
&& m2 != null) {
timeBegin = h1 * 60 + m1;
timeEnd = h2 * 60 + m2;
okBtn.setEnabled(timeEnd - timeBegin >= minimalSize);
System.out.println(String.format("time updated: %02d.%02d - %02d.%02d ", h1, m1, h2, m2));
} else {
okBtn.setEnabled(false);
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox cabinetCombo;
private javax.swing.JButton cancelBtn;
private javax.swing.JButton delBtn;
private javax.swing.JComboBox h1Combo;
private javax.swing.JComboBox h2Combo;
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.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JComboBox m1Combo;
private javax.swing.JComboBox m2Combo;
private javax.swing.JButton okBtn;
private javax.swing.JComboBox workTypesCombo;
// End of variables declaration//GEN-END:variables
}