/*
* PanelLaboratory.java
*
* Created on 10 Июль 2008 г., 17:19
*/
package clips.administrator.config;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.directory.DialogDirectorySimpleM;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.Printable;
import cli_fmw.utils.MessageBox;
import cli_fmw.main.ClipsException;
import cli_fmw.main.DirectoryItemNotFoundException;
import cli_fmw.main.MainWindow;
import cli_fmw.main.PrintCreators;
import cli_fmw.report.panels.model.ObjectComboBoxModel;
import cli_fmw.report.panels.model.ObjectTextModel;
import cli_fmw.report.panels.model.delegate.DelegateCheckBoxModel;
import cli_fmw.report.panels.model.delegate.DelegateTextModel;
import cli_fmw.utils.ModalDialog;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.config.ConfigLocal;
import clips.delegate.directory.complex.DirectoryEnterprise;
import clips.delegate.directory.ro.DirectoryCollaborator;
import clips.delegate.directory.simple.insurer.DirectoryInsurer;
import clips.delegate.directory.simple.insurer.DirectoryInsurerItem;
import clips.delegate.directory.simple.mes.DirectoryClinicType;
import clips.delegate.directory.simple.regionIdCode.DirectoryRegionIdCode;
import clips.delegate.directory.simple.regionIdCode.DirectoryRegionIdCodeItem;
import clips.main.ClipsConfig;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.DefaultComboBoxModel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/**
* Панель редактирования конфигурации
* @author vip
*/
public class PanelConfig extends PageGeneric implements
Persistentable {
ConfigLocal configLocal;
private DirectoryInsurer directoryInsurer;
private char[] password = new char[0];
private char[] password1 = new char[0];
private char[] oldPassword = new char[0];
/**
* Коструктор панели
* @param container еонтейнер
* @throws generic.ClipsException
*/
public PanelConfig(PageContainer container) throws ClipsException {
super(container);
initComponents();
configLocal = ConfigLocal.getInstance();
configLocal.addContentStateListener(container);
directoryInsurer = DirectoryLocator.getDirectory(DirectoryInsurer.class);
try {
configLocal.getConfigDefaultInsurer();
} catch (DirectoryItemNotFoundException ex) {
configLocal.setConfigDefaultInsurer(directoryInsurer.getNullItem());
}
ArrayList<DirectoryInsurerItem> items = directoryInsurer.getItems(true);
ObjectComboBoxModel<ConfigLocal> insModel = new ObjectComboBoxModel<ConfigLocal>(cbDefaultInsurer, null, new DefaultComboBoxModel(items.toArray())) {
@Override
public Object getSelectedItemImp() throws ClipsException {
return getObject().getConfigDefaultInsurer();
}
@Override
public void setSelectedItemImp(Object anItem) throws ClipsException {
getObject().setConfigDefaultInsurer((DirectoryInsurerItem)anItem);
}
};
insModel.setObject(configLocal);
new DelegateTextModel<ConfigLocal>(ldapMask, configLocal) {
@Override
protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
getObject().setLdapMask(text);
}
@Override
protected String getModelTextChecked() throws ClipsException {
return getObject().getLdapMask();
}
};
new DelegateTextModel<ConfigLocal>(ldapCrypto, configLocal) {
@Override
protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
getObject().setLdapCriptoSheme(text);
}
@Override
protected String getModelTextChecked() throws ClipsException {
return getObject().getLdapCriptoSheme();
}
};
new DelegateCheckBoxModel<ConfigLocal>(ldapOverSSL, configLocal) {
@Override
public boolean isSelectedImp() throws ClipsException {
return getObject().isLdapOverSSL();
}
@Override
public void setSelectedImp(boolean val) throws ClipsException {
getObject().setLdapOverSSL(val);
}
};
new DelegateCheckBoxModel<ConfigLocal>(useLdap, configLocal) {
@Override
public boolean isSelectedImp() throws ClipsException {
return getObject().isLdapUse();
}
@Override
public void setSelectedImp(boolean val) throws ClipsException {
getObject().setLdapUse(val);
}
};
new DelegateTextModel<ConfigLocal>(ldapUrl, configLocal) {
@Override
protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
getObject().setLdapURL(text);
}
@Override
protected String getModelTextChecked() throws ClipsException {
return getObject().getLdapURL();
}
};
new ObjectTextModel<ClipsConfig>(tfSicklistTopMarign, ClipsConfig.getInstance()){
@Override
protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
ClipsConfig.getInstance().setSicklistTopMarign(Integer.parseInt(text));
}
@Override
protected String getModelTextChecked() throws ClipsException {
return "" + ClipsConfig.getInstance().getSicklistTopMarign();
}
};
new ObjectTextModel<ClipsConfig>(tfSicklistLeftMarign, ClipsConfig.getInstance()){
@Override
protected void setModelTextChecked(String text) throws ClipsException, ParseException, NumberFormatException {
ClipsConfig.getInstance().setSicklistLeftMarign(Integer.parseInt(text));
}
@Override
protected String getModelTextChecked() throws ClipsException {
return "" + ClipsConfig.getInstance().getSicklistLeftMarign();
}
};
tfPassword.getDocument().addDocumentListener(new DocumentListener() {
@Override public void insertUpdate(DocumentEvent e) { onChange(); }
@Override public void removeUpdate(DocumentEvent e) { onChange(); }
@Override public void changedUpdate(DocumentEvent e) {}
private void onChange() {
password = tfPassword.getPassword();
System.out.println("password = " + password);
fireContainerEventStateChanged();
}
});
tfPassword1.getDocument().addDocumentListener(new DocumentListener() {
@Override public void insertUpdate(DocumentEvent e) { onChange(); }
@Override public void removeUpdate(DocumentEvent e) { onChange(); }
@Override public void changedUpdate(DocumentEvent e) {}
private void onChange() {
password1 = tfPassword1.getPassword();
System.out.println("password = " + password1);
fireContainerEventStateChanged();
}
});
tfOldPass.getDocument().addDocumentListener(new DocumentListener() {
@Override public void insertUpdate(DocumentEvent e) { onChange(); }
@Override public void removeUpdate(DocumentEvent e) { onChange(); }
@Override public void changedUpdate(DocumentEvent e) {}
private void onChange() {
oldPassword = tfOldPass.getPassword();
System.out.println("oldPassword = " + oldPassword);
fireContainerEventStateChanged();
}
});
setScreenFields();
//resizeColumn();
StateSaver.attachTo(this);
}
private void setScreenFields() throws ClipsException {
tfRegionCode.setText(configLocal.getConfigRegionCode().getExtKey());
}
/** Creates new form PanelLaboratory */
/** 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() {
jScrollPane1 = new javax.swing.JScrollPane();
jPanel1 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jPanel8 = new javax.swing.JPanel();
labelEnterprice = new javax.swing.JLabel();
labelPassword = new javax.swing.JLabel();
labelPassword1 = new javax.swing.JLabel();
labelOldPass = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jPanel9 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
tfEnterprise = new javax.swing.JTextField();
tfPassword = new javax.swing.JPasswordField();
tfPassword1 = new javax.swing.JPasswordField();
tfOldPass = new javax.swing.JPasswordField();
jPanel4 = new javax.swing.JPanel();
btRegionCode = new javax.swing.JButton();
tfRegionCode = new javax.swing.JTextField();
cbDefaultInsurer = new javax.swing.JComboBox();
tfSicklistTopMarign = new javax.swing.JTextField();
tfSicklistLeftMarign = new javax.swing.JTextField();
jPanel5 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jPanel6 = new javax.swing.JPanel();
useLdap = new javax.swing.JCheckBox();
ldapUrl = new javax.swing.JTextField();
ldapMask = new javax.swing.JTextField();
ldapCrypto = new javax.swing.JTextField();
ldapOverSSL = new javax.swing.JCheckBox();
jPanel1.setLayout(new java.awt.BorderLayout(10, 10));
jPanel3.setLayout(new java.awt.BorderLayout(5, 0));
jPanel8.setLayout(new java.awt.GridLayout(0, 1, 0, 5));
labelEnterprice.setText("Данное предприятие");
jPanel8.add(labelEnterprice);
labelPassword.setText("Пароль суперпользователя");
jPanel8.add(labelPassword);
labelPassword1.setText("Пароль (повтор)");
jPanel8.add(labelPassword1);
labelOldPass.setText("Старый пароль");
jPanel8.add(labelOldPass);
jLabel7.setText("Код региона");
jPanel8.add(jLabel7);
jLabel10.setText("Страховая компания по умолчанию");
jPanel8.add(jLabel10);
jLabel8.setText("Больничные: Верхний отступ");
jPanel8.add(jLabel8);
jLabel9.setText("Больничные: Левый отступ");
jPanel8.add(jLabel9);
jPanel3.add(jPanel8, java.awt.BorderLayout.WEST);
jPanel9.setLayout(new java.awt.GridLayout(0, 1, 0, 5));
jPanel2.setLayout(new java.awt.BorderLayout(5, 0));
tfEnterprise.setEditable(false);
jPanel2.add(tfEnterprise, java.awt.BorderLayout.CENTER);
jPanel9.add(jPanel2);
jPanel9.add(tfPassword);
jPanel9.add(tfPassword1);
jPanel9.add(tfOldPass);
jPanel4.setLayout(new java.awt.BorderLayout(5, 0));
btRegionCode.setText("Выбрать");
btRegionCode.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btRegionCodeActionPerformed(evt);
}
});
jPanel4.add(btRegionCode, java.awt.BorderLayout.LINE_END);
jPanel4.add(tfRegionCode, java.awt.BorderLayout.CENTER);
jPanel9.add(jPanel4);
jPanel9.add(cbDefaultInsurer);
jPanel9.add(tfSicklistTopMarign);
jPanel9.add(tfSicklistLeftMarign);
jPanel3.add(jPanel9, java.awt.BorderLayout.CENTER);
jPanel1.add(jPanel3, java.awt.BorderLayout.NORTH);
jPanel5.setLayout(new java.awt.BorderLayout(5, 5));
jPanel7.setLayout(new java.awt.GridLayout(0, 1, 0, 5));
jLabel4.setText("Аутентификация");
jPanel7.add(jLabel4);
jLabel5.setText("URL сервера LDAP");
jPanel7.add(jLabel5);
jLabel1.setText("Маска поиска LDAP");
jPanel7.add(jLabel1);
jLabel2.setText("Схема аутентификации LDAP");
jPanel7.add(jLabel2);
jLabel3.setText("LDAP поверх SSL");
jPanel7.add(jLabel3);
jPanel5.add(jPanel7, java.awt.BorderLayout.WEST);
jPanel6.setLayout(new java.awt.GridLayout(0, 1, 0, 5));
useLdap.setText("использовать сервер LDAP");
jPanel6.add(useLdap);
jPanel6.add(ldapUrl);
jPanel6.add(ldapMask);
jPanel6.add(ldapCrypto);
ldapOverSSL.setText("использовать SSL");
jPanel6.add(ldapOverSSL);
jPanel5.add(jPanel6, java.awt.BorderLayout.CENTER);
jPanel1.add(jPanel5, java.awt.BorderLayout.SOUTH);
jScrollPane1.setViewportView(jPanel1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void btRegionCodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRegionCodeActionPerformed
try {
DirectoryRegionIdCode dir = DirectoryLocator.getDirectory(DirectoryRegionIdCode.class);
DialogDirectorySimpleM dlg = new DialogDirectorySimpleM(MainWindow.mainWindow, dir, null, false);
dlg.setVisible(true);
if (dlg.getDlgResult() == ModalDialog.DLG_OK
&& dlg.getSelectedItem() != null) {
DirectoryRegionIdCodeItem item = (DirectoryRegionIdCodeItem) dlg.getSelectedItem();
configLocal.setConfigRegionCode(item);
tfRegionCode.setText(item.getExtKey());
}
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}//GEN-LAST:event_btRegionCodeActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btRegionCode;
private javax.swing.JComboBox cbDefaultInsurer;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
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.JPanel jPanel8;
private javax.swing.JPanel jPanel9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel labelEnterprice;
private javax.swing.JLabel labelOldPass;
private javax.swing.JLabel labelPassword;
private javax.swing.JLabel labelPassword1;
private javax.swing.JTextField ldapCrypto;
private javax.swing.JTextField ldapMask;
private javax.swing.JCheckBox ldapOverSSL;
private javax.swing.JTextField ldapUrl;
private javax.swing.JTextField tfEnterprise;
private javax.swing.JPasswordField tfOldPass;
private javax.swing.JPasswordField tfPassword;
private javax.swing.JPasswordField tfPassword1;
private javax.swing.JTextField tfRegionCode;
private javax.swing.JTextField tfSicklistLeftMarign;
private javax.swing.JTextField tfSicklistTopMarign;
private javax.swing.JCheckBox useLdap;
// End of variables declaration//GEN-END:variables
@Override
public String getPageTitle() {
return "Конфигурация";
}
@Override
public boolean isDirty() {
if (password != null && password.length > 0
|| password1 != null && password1.length > 0) {
return true;
}
if (configLocal != null) {
return configLocal.isDirty();
}
return false;
}
@Override
public void save() throws ClipsException {
if (isDirty()) {
if (!Arrays.equals(password, password1)) {
throw new ClipsException("Введенные пароли не совпадают");
}
if (password.length > 0 && password1.length > 0) {
tfOldPass.setText("");
configLocal.setAdminPassword(password, oldPassword);
tfPassword.setText("");
tfPassword1.setText("");
fireContainerEventStateChanged();
}
configLocal.save1();
}
}
@Override
public void restore() {
try {
configLocal.restore();
tfPassword.setText("");
tfPassword1.setText("");
tfOldPass.setText("");
setScreenFields();
} catch (Exception ex) {
MessageBox.showException(ex);
}
}
@Override
public DelegateLine2 getDelegate() {
return null;
}
}