Package clips.accountant.config

Source Code of clips.accountant.config.PanelConfigCollab

/*
* PanelLaboratory.java
*
* Created on 10 Июль 2008 г., 17:19
*/
package clips.accountant.config;

import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.collaborator.GUIConfig;
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.utils.table_config_states.StateSaver;
import clips.delegate.client.CollaboratorLocal;
import clips.login.UserInfo;
import framework.beans.config.server.ConfigBeanRemoteM;
import java.util.Arrays;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

/**
* Панель редактирования конфигурации пользователя
* @author  vip
*/
public class PanelConfigCollab extends PageGeneric implements
        Persistentable, Printable {

    private char[] password = new char[0];
    private char[] password1 = new char[0];
    private char[] oldPassword = new char[0];
    private String backupConfig;
    private GUIConfig config;
    private CollaboratorLocal collaboratorLocal;
    /**
     * Коструктор панели
     * @param container еонтейнер
     * @throws generic.ClipsException
     */
    public PanelConfigCollab(PageContainer container) throws ClipsException {
        super(container);
        initComponents();

        collaboratorLocal = UserInfo.get().getCollaboratorLocal();
        config = collaboratorLocal.getGuiConfig();
        backupConfig = config.toXML();

        initModels();
        setScreenFields();
    StateSaver.attachTo(this);
    }

    public PanelConfigCollab(PageContainer container, CollaboratorLocal collaboratorLocal) throws ClipsException {
        super(container);
        initComponents();

        this.collaboratorLocal = collaboratorLocal;
        config = collaboratorLocal.getGuiConfig();
        backupConfig = config.toXML();

        initModels();
        setScreenFields();
    StateSaver.attachTo(this);
    }



    private void initModels() {
        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("password1 = " + 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();
            }
        });       
    }

    private void setScreenFields() throws ClipsException {
        jScrollPane1.setBorder(new TitledBorder(collaboratorLocal.toString()));
        cbUndoConfirm.setSelected(config.getBoolean(GUIConfig.P_CONFIRM_UNDO));
        cbShowECP.setSelected(config.getBoolean(GUIConfig.P_SHOW_ECP));
    }
   
    /** 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();
        labelUndoConfirm = new javax.swing.JLabel();
        labShowECP = new javax.swing.JLabel();
        labelOldPass = new javax.swing.JLabel();
        labelPassword = new javax.swing.JLabel();
        labelPassword1 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        cbUndoConfirm = new javax.swing.JCheckBox();
        cbShowECP = new javax.swing.JCheckBox();
        tfOldPass = new javax.swing.JPasswordField();
        tfPassword = new javax.swing.JPasswordField();
        tfPassword1 = new javax.swing.JPasswordField();

        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel3.setLayout(new java.awt.BorderLayout(5, 0));

        jPanel8.setLayout(new java.awt.GridLayout(0, 1, 0, 5));

        labelUndoConfirm.setText("Спрашивать подтверждение при отмене");
        jPanel8.add(labelUndoConfirm);

        labShowECP.setText("Показывать цифровые подписи");
        jPanel8.add(labShowECP);

        labelOldPass.setText("Старый пароль");
        jPanel8.add(labelOldPass);

        labelPassword.setText("Новый пароль");
        jPanel8.add(labelPassword);

        labelPassword1.setText("Повтор нового пароля");
        jPanel8.add(labelPassword1);

        jPanel3.add(jPanel8, java.awt.BorderLayout.WEST);

        jPanel9.setLayout(new java.awt.GridLayout(0, 1, 0, 5));

        cbUndoConfirm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbUndoConfirmActionPerformed(evt);
            }
        });
        jPanel9.add(cbUndoConfirm);

        cbShowECP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbShowECPActionPerformed(evt);
            }
        });
        jPanel9.add(cbShowECP);
        jPanel9.add(tfOldPass);
        jPanel9.add(tfPassword);
        jPanel9.add(tfPassword1);

        jPanel3.add(jPanel9, java.awt.BorderLayout.CENTER);

        jPanel1.add(jPanel3, java.awt.BorderLayout.NORTH);

        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, 816, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cbUndoConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbUndoConfirmActionPerformed
        config.setValue(GUIConfig.P_CONFIRM_UNDO, cbUndoConfirm.isSelected());
        fireContainerEventStateChanged();
    }//GEN-LAST:event_cbUndoConfirmActionPerformed

    private void cbShowECPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbShowECPActionPerformed
        config.setValue(GUIConfig.P_SHOW_ECP, cbShowECP.isSelected());
        fireContainerEventStateChanged();
    }//GEN-LAST:event_cbShowECPActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox cbShowECP;
    private javax.swing.JCheckBox cbUndoConfirm;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labShowECP;
    private javax.swing.JLabel labelOldPass;
    private javax.swing.JLabel labelPassword;
    private javax.swing.JLabel labelPassword1;
    private javax.swing.JLabel labelUndoConfirm;
    private javax.swing.JPasswordField tfOldPass;
    private javax.swing.JPasswordField tfPassword;
    private javax.swing.JPasswordField tfPassword1;
    // End of variables declaration//GEN-END:variables

    @Override
    public String getPageTitle() {
        return "Конфигурация пользователя";
    }

    @Override
    public boolean isDirty() {
        if (password.length > 0 || password1.length > 0) {
            System.out.println("password dirty");
            return true;
        }
        String toXML = config.toXML();
        if (!toXML.equals(backupConfig)){
            System.out.println("config dirty");
            return true;
        }
        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){
                int t = collaboratorLocal.changePassword(password, oldPassword);
                oldPassword = new char[0];
                tfOldPass.setText("");
                if (t == ConfigBeanRemoteM.INVALID_OLD_ADMIN_PASSWORD) {
                    MessageBox.showError(MessageBox.E_INVALID_OLD_PASSWORD);
                    tfOldPass.requestFocus();
                    return;
                }
                password = new char[0];
                tfPassword.setText("");
                password1 = new char[0];
                tfPassword1.setText("");
            }
            collaboratorLocal.saveGuiConfig(config);
            backupConfig = config.toXML();
            fireContainerEventStateChanged();
        }
    }

    @Override
    public void restore() {
        try {
            if (isDirty()) {
                tfOldPass.setText("");
                tfPassword.setText("");
                tfPassword1.setText("");
                password = new char[0];
                oldPassword = new char[0];
                config = new GUIConfig(backupConfig);
                setScreenFields();
                fireContainerEventStateChanged();
            }
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
    }


    @Override
    public boolean readyForPrint() {
        return true;
    }

    @Override
    public void print() {
        if (readyForPrint()) {
            //TODO расчепятать конфиг
        }
    }

    @Override
    public DelegateLine2 getDelegate() {
        return null;
    }
}
TOP

Related Classes of clips.accountant.config.PanelConfigCollab

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.