/*
* DirectoryDialogDefault.java
*
* Created on 16 Январь 2008 г., 20:45
*/
package clips.doctor.profcheckup.dialogs;
import clips.delegate.contract.ContractLocal;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import clips.delegate.doctor.profchekup.ProfcheckupSearchLocal;
import cli_fmw.main.ClipsException;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.chooser.ChoosePanelComboException;
import cli_fmw.utils.chooser.ChoosePanelComboListener;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.directory.complex.DirectoryEnterprise;
import clips.delegate.directory.complex.DirectoryEnterpriseItem;
import clips.delegate.directory.ro.DirectoryCollaboratorItem;
import clips.delegate.doctor.profchekup.SearchResult;
import clips.login.UserInfo;
import java.util.Collection;
import java.util.Set;
import javax.swing.DefaultComboBoxModel;
/**
*
* @author petr
*/
public class DialogContractM extends ModalDialog implements ChoosePanelComboListener{
private DirectoryEnterprise dirEnterprise;
private ContractLocal select;
private DirectoryCollaboratorItem current;
private ProfcheckupSearchLocal searchLocal;
private SearchResult result;
/** Creates new form DirectoryDialogDefault
* @param parent
* @throws ClipsException
*/
public DialogContractM(java.awt.Frame parent) throws ClipsException {
super(parent, "Выбор активного договора", null);
initComponents();
this.dirEnterprise = DirectoryLocator.getDirectory(DirectoryEnterprise.class, false);
//center dialog
// Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
// Rectangle dlgSize = new Rectangle((int) (0.8 * scrSize.width),(int) (0.6 * scrSize.height));
// dlgSize.setLocation((scrSize.width - dlgSize.width)/2, (scrSize.height - dlgSize.height) / 2);
// this.setBounds(dlgSize);
selectBtn.setEnabled(false);
cpEnterprise.setData(dirEnterprise, null, "Предприятие");
cpEnterprise.addChoosePanelListener(this);
searchLocal = new ProfcheckupSearchLocal(getAuditManager());
lblNotCorrect.setVisible(false);
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() {
jPanel1 = new javax.swing.JPanel();
selectBtn = new javax.swing.JButton();
deleteBtn = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
cpEnterprise = new cli_fmw.utils.chooser.ChoosePanel();
jPanel6 = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
lbl = new javax.swing.JLabel();
lblCollab = new javax.swing.JLabel();
lblNotCorrect = new javax.swing.JLabel();
jPanel7 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
lstContracts = new javax.swing.JList();
jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
selectBtn.setText("Выбрать");
selectBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
selectBtnActionPerformed(evt);
}
});
jPanel1.add(selectBtn);
deleteBtn.setText("Отмена");
deleteBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteBtnActionPerformed(evt);
}
});
jPanel1.add(deleteBtn);
getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
jPanel2.setLayout(new java.awt.BorderLayout());
jPanel5.setLayout(new java.awt.BorderLayout());
jPanel3.setLayout(new java.awt.GridLayout(0, 1));
jPanel3.add(cpEnterprise);
jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
jPanel4.setLayout(new java.awt.BorderLayout(5, 0));
lbl.setText("цеховой терапевт:");
jPanel4.add(lbl, java.awt.BorderLayout.WEST);
jPanel4.add(lblCollab, java.awt.BorderLayout.CENTER);
lblNotCorrect.setForeground(new java.awt.Color(255, 51, 51));
lblNotCorrect.setText("не соответстует текущему пользователю");
jPanel4.add(lblNotCorrect, java.awt.BorderLayout.EAST);
jPanel6.add(jPanel4);
jPanel3.add(jPanel6);
jPanel5.add(jPanel3, java.awt.BorderLayout.NORTH);
jPanel2.add(jPanel5, java.awt.BorderLayout.PAGE_START);
jPanel7.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
jPanel7.setLayout(new java.awt.BorderLayout());
lstContracts.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
lstContracts.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
lstContractsValueChanged(evt);
}
});
jScrollPane2.setViewportView(lstContracts);
jPanel7.add(jScrollPane2, java.awt.BorderLayout.CENTER);
jPanel2.add(jPanel7, java.awt.BorderLayout.CENTER);
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void selectBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectBtnActionPerformed
if (select != null) {
setDlgResult(DLG_OK);
dispose();
} else {
MessageBox.showWarning(MessageBox.W_CONTRACT_NOT_SELECT);
}
}//GEN-LAST:event_selectBtnActionPerformed
private void deleteBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteBtnActionPerformed
setDlgResult(DLG_CANCEL);
setVisible(false);
}//GEN-LAST:event_deleteBtnActionPerformed
private void lstContractsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstContractsValueChanged
Object sel = lstContracts.getSelectedValue();
if (sel != null && sel instanceof ContractLocal){
select = (ContractLocal) sel;
selectBtn.setEnabled(true);
}else{
selectBtn.setEnabled(false);
}
}//GEN-LAST:event_lstContractsValueChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private cli_fmw.utils.chooser.ChoosePanel cpEnterprise;
private javax.swing.JButton deleteBtn;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JLabel lbl;
private javax.swing.JLabel lblCollab;
private javax.swing.JLabel lblNotCorrect;
private javax.swing.JList lstContracts;
private javax.swing.JButton selectBtn;
// End of variables declaration//GEN-END:variables
public ContractLocal getContract() {
return select;
}
public DirectoryCollaboratorItem getCollaborator(){
return current;
}
@Override
public void chooseDone(int type, int id) throws ChoosePanelComboException {
try {
DirectoryEnterpriseItem dei = dirEnterprise.getItemFromID(id);
DirectoryCollaboratorItem collaborator = dei.getCollaborator();
DirectoryEnterpriseItem parentEnt = dei.getParent();
while (collaborator == null && parentEnt != null){//find collab up
collaborator = parentEnt.getCollaborator();
parentEnt = parentEnt.getParent();
}
if (collaborator == null){
lblCollab.setText("Не установлен для данного предприятия");
}else{
lblCollab.setText(collaborator.getTitle());
current = collaborator;
}
lblNotCorrect.setVisible(collaborator != null && collaborator != UserInfo.get().getCollaborator());
Set<ContractLocal> usableContracts = searchLocal.search(dei).getUsableContracts();
resetContractList(usableContracts);
for (ContractLocal contractLocal : usableContracts) {
System.out.println("CONTRACT: " + contractLocal.getInfo());
}
} catch (ChoosePanelComboException ex) {
throw ex;
} catch (ClipsException ex) {
MessageBox.showException(ex);
throw new ChoosePanelComboException();
}
}
private void resetContractList(Collection<ContractLocal> contracts){
lstContracts.setModel(new DefaultComboBoxModel(contracts.toArray()));
}
public SearchResult getResult() {
return result;
}
}