/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* DialogNewFunction.java
*
* Created on 19.06.2009, 10:45:18
*/
package clips.accountant.dialog;
import cli_fmw.delegate.DelegateStateful;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import cli_fmw.report.panels.model.delegate.DirectorySimpleFilteredComboBoxModel;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.SelectorEditable;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.client.CollaboratorFunctionsChunk;
import clips.delegate.client.CollaboratorLocal;
import clips.delegate.directory.simple.dvr.DirectoryDvr;
import clips.delegate.directory.simple.dvr.DirectoryDvrItem;
import clips.delegate.directory.simple.medicalAidType.DirectoryMedicalAidType;
import clips.delegate.directory.simple.medicalAidType.DirectoryMedicalAidTypeItem;
import clips.delegate.directory.simple.receptionType.DirectoryReceptionType;
import clips.delegate.directory.simple.receptionType.DirectoryReceptionTypeItem;
import clips.delegate.directory.simple.speciality.DirectorySpeciality;
import clips.delegate.directory.simple.speciality.DirectorySpecialityItem;
import beans.user.collaborator.entities.CollaboratorFunctionsDetails;
import java.awt.Frame;
import java.util.ArrayList;
/**
*
* @author petr
*/
public class DialogNewFunction extends ModalDialog {
private CollaboratorFunctionsDetails chunkDetails;
private ArrayList<CollaboratorFunctionsChunk> collabChunks = new ArrayList<CollaboratorFunctionsChunk>();
private CollaboratorLocal collaborator;
public DialogNewFunction(Frame parent, CollaboratorLocal collaborator) throws ClipsException {
super(parent, "Исполняемая обязанность", null);
initComponents();
this.collaborator = collaborator;
chunkDetails = new CollaboratorFunctionsDetails();
chunkDetails.collaboratorID = collaborator.getID();
SelectorEditable<CollaboratorFunctionsChunk> functions = collaborator.getFunctions();
for (int i=0; i<functions.size(); i++){
collabChunks.add(functions.get(i));
}
checkData();
final DirectoryReceptionType dirReception = DirectoryLocator.getDirectory(DirectoryReceptionType.class);
final DirectoryDvr dirDvr = DirectoryLocator.getDirectory(DirectoryDvr.class);
final DirectoryMedicalAidType dirFma = DirectoryLocator.getDirectory(DirectoryMedicalAidType.class);
final DirectorySpeciality dirSpec = DirectoryLocator.getDirectory(DirectorySpeciality.class);
new DirectorySimpleFilteredComboBoxModel<DelegateStateful, DirectoryReceptionTypeItem>(cbSepciality, collaborator, dirReception) {
@Override
public DirectoryReceptionTypeItem getSelectedDirectoryItem() throws ClipsException {
return dirReception.getItemFromID(chunkDetails.receptionTypeID);
}
@Override
public void setSelectedDirectoryItem(DirectoryReceptionTypeItem item) throws ClipsException {
chunkDetails.receptionTypeID = item.getID();
checkData();
}
};
new DirectorySimpleFilteredComboBoxModel<DelegateStateful, DirectoryDvrItem>(cbDvr, collaborator, dirDvr) {
@Override
public DirectoryDvrItem getSelectedDirectoryItem() throws ClipsException {
return dirDvr.getItemFromID(chunkDetails.dvrID);
}
@Override
public void setSelectedDirectoryItem(DirectoryDvrItem item) throws ClipsException {
chunkDetails.dvrID = item.getID();
checkData();
}
};
new DirectorySimpleFilteredComboBoxModel<DelegateStateful, DirectoryMedicalAidTypeItem>(cbFma, collaborator, dirFma) {
@Override
public DirectoryMedicalAidTypeItem getSelectedDirectoryItem() throws ClipsException {
return dirFma.getItemFromID(chunkDetails.firstMedicalAidID);
}
@Override
public void setSelectedDirectoryItem(DirectoryMedicalAidTypeItem item) throws ClipsException {
chunkDetails.firstMedicalAidID = item.getID();
checkData();
}
};
new DirectorySimpleFilteredComboBoxModel<DelegateStateful, DirectorySpecialityItem>(specsCombo, collaborator, dirSpec) {
@Override
public DirectorySpecialityItem getSelectedDirectoryItem() throws ClipsException {
return dirSpec.getItemFromID(chunkDetails.specialityID);
}
@Override
public void setSelectedDirectoryItem(DirectorySpecialityItem item) throws ClipsException {
chunkDetails.specialityID = item.getID();
checkData();
}
};
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel3 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
cbSepciality = new javax.swing.JComboBox();
cbDvr = new javax.swing.JComboBox();
cbFma = new javax.swing.JComboBox();
specsCombo = new javax.swing.JComboBox();
jPanel6 = new javax.swing.JPanel();
lblIncorrectData = new javax.swing.JLabel();
jPanel5 = new javax.swing.JPanel();
btOK = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jPanel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
jPanel3.setLayout(new java.awt.BorderLayout(5, 0));
jPanel1.setLayout(new java.awt.GridLayout(0, 1, 0, 5));
jLabel2.setText("Тип приема");
jPanel1.add(jLabel2);
jLabel1.setText("Должность:");
jPanel1.add(jLabel1);
jLabel3.setText("<html>Тип первичной<br>медицинской помощи:</html>");
jPanel1.add(jLabel3);
jLabel5.setText("Специальность:");
jPanel1.add(jLabel5);
jPanel3.add(jPanel1, java.awt.BorderLayout.WEST);
jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 0, 5, 0));
jPanel2.setLayout(new java.awt.GridLayout(0, 1, 0, 5));
cbSepciality.setEditable(true);
cbSepciality.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jPanel2.add(cbSepciality);
cbDvr.setEditable(true);
cbDvr.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jPanel2.add(cbDvr);
cbFma.setEditable(true);
cbFma.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jPanel2.add(cbFma);
specsCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jPanel2.add(specsCombo);
jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER);
lblIncorrectData.setForeground(new java.awt.Color(255, 51, 51));
lblIncorrectData.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblIncorrectData.setText("У сотрудника уже есть такая исполняемая обязанность");
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblIncorrectData, javax.swing.GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE)
.addContainerGap())
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblIncorrectData)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3.add(jPanel6, java.awt.BorderLayout.SOUTH);
getContentPane().add(jPanel3, java.awt.BorderLayout.NORTH);
btOK.setText("Принять");
btOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btOKActionPerformed(evt);
}
});
btCancel.setText("Отменить");
btCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCancelActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addContainerGap(561, Short.MAX_VALUE)
.addComponent(btOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCancel)
.addContainerGap())
);
jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOK});
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCancel)
.addComponent(btOK))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
getContentPane().add(jPanel5, java.awt.BorderLayout.SOUTH);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed
this.setDlgResult(ModalDialog.DLG_OK);
this.dispose();
}//GEN-LAST:event_btOKActionPerformed
private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
this.setDlgResult(ModalDialog.DLG_CANCEL);
this.dispose();
}//GEN-LAST:event_btCancelActionPerformed
private boolean inDataList(){
for (CollaboratorFunctionsChunk cfc : collabChunks) {
if (cfc.getDetails().equals(chunkDetails)){
return true;
}
}
return false;
}
private void checkData(){
boolean b = inDataList();
lblIncorrectData.setVisible(b);
btOK.setEnabled(!b);
}
public CollaboratorFunctionsChunk getFunctions(){
if(! inDataList()){
return new CollaboratorFunctionsChunk(collaborator, chunkDetails);
}else{
return null;
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btOK;
private javax.swing.JComboBox cbDvr;
private javax.swing.JComboBox cbFma;
private javax.swing.JComboBox cbSepciality;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JLabel lblIncorrectData;
private javax.swing.JComboBox specsCombo;
// End of variables declaration//GEN-END:variables
}