Package clips.administrator.certificate

Source Code of clips.administrator.certificate.PanelCertificateTypeEdit

/*
* PanelDirectionTypesEdit.java
*
* Created on 4 Август 2008 г., 18:48
*/

package clips.administrator.certificate;

import clips.delegate.directory.complex.DirectoryCertificateType;
import clips.delegate.directory.complex.DirectoryCertificateTypeItem;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.delegate.report.ReportSearchLocal;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Printable;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.ModalDialog;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PrintCreators;
import cli_fmw.utils.table_config_states.StateSaver;
import cli_fmw.utils.table_config_states.TableState;
import clips.administrator.certificate.tagList.PanelTagList;
import clips.login.UserInfo;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import framework.security.SecurityChecker;
import beans.UserRightsSet;
import cli_fmw.main.MainWindow;

/**
*
* @author  lacoste
*/
public class PanelCertificateTypeEdit extends PageGeneric implements Printable {

    private DirectoryCertificateType directory;   
   
  /** Creates new form PanelDirectionTypesEdit
   * @param container
   * @throws ClipsException
   */
    public PanelCertificateTypeEdit(PageContainer container) throws ClipsException {
        super(container);
        initComponents();
       
        directory = DirectoryLocator.getDirectory(DirectoryCertificateType.class, false);
        tabCertificateTypes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
        refreshTable();
        resizeColumn();
    StateSaver.attachTo(this);
        tabCertificateTypes.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                setEnabledComponents();
            }
        });
        setEnabledComponents();
    }

    private void setEnabledComponents() {
        btDel.setEnabled(true);
        if (tabCertificateTypes.getSelectedRowCount() == 0) {
            btDel.setEnabled(false);
        } else {
            int row = tabCertificateTypes.getSelectedRowSorted();
            try {
                DirectoryCertificateTypeItem item = ((TableModelCertificateTypeEdit) tabCertificateTypes.getModel()).getItemAt(row);
                if (item.getID() == 0) {
                    btDel.setEnabled(false);
                }
            } catch (ClipsException ex) {
                btDel.setEnabled(false);
            }
        }
    }
   
    private void refreshTable() throws ClipsException {
        tabCertificateTypes.setModel(new TableModelCertificateTypeEdit(directory));
        JComboBox reportBox = new JComboBox(new ReportSearchLocal(getAuditManager()).getReports().toArray());
        tabCertificateTypes.getColumnModel().getColumn(TableModelCertificateTypeEdit.COL_REPORT).setCellEditor(new DefaultCellEditor(reportBox));
    }
   
    private void resizeColumn() {
    TableState          state = new TableState();
    state.setPreferredWidth(TableModelCertificateTypeEdit.COL_ID,       2);
    state.setPreferredWidth(TableModelCertificateTypeEdit.COL_TITLE,    10);
    state.setPreferredWidth(TableModelCertificateTypeEdit.COL_REPORT,   10);
        state.setPreferredWidth(TableModelCertificateTypeEdit.COL_TRASH,    5);
      StateSaver.setDefaultState(this, tabCertificateTypes, state);
    }
   
    /** 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();
        btAdd = new javax.swing.JButton();
        btDel = new javax.swing.JButton();
        btTagList = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabCertificateTypes = new cli_fmw.utils.sorted_table.SortedTable();

        setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        setLayout(new java.awt.BorderLayout());

        btAdd.setText("Добавить");
        btAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddActionPerformed(evt);
            }
        });

        btDel.setText("Удалить");
        btDel.setPreferredSize(btAdd.getPreferredSize());
        btDel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDelActionPerformed(evt);
            }
        });

        btTagList.setText("Список тегов");
        btTagList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTagListActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(btTagList)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 147, Short.MAX_VALUE)
                .addComponent(btAdd)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btDel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btAdd, btDel});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btDel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btAdd)
                    .addComponent(btTagList)))
        );

        add(jPanel1, java.awt.BorderLayout.SOUTH);

        jScrollPane1.setViewportView(tabCertificateTypes);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
    try {
        if (!UserInfo.get().check(UserRightsSet.WRITE_REGION_ADMIN_DIRECTORY)) {
            throw new ClipsException(SecurityChecker.getClientHasNoRightMsg(UserRightsSet.WRITE_REGION_ADMIN_DIRECTORY.id));
        }
        DlgNewCertificateType dlg = new DlgNewCertificateType(MainWindow.mainWindow);
        dlg.setVisible(true);
        if (dlg.getDlgResult() == ModalDialog.DLG_OK) {
            directory.getItems().append(dlg.getCertificateType());
            refreshTable();
        }
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_btAddActionPerformed

private void btDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDelActionPerformed
    try {
        int k = tabCertificateTypes.getSelectedRowSorted();
        TableModelCertificateTypeEdit model = (TableModelCertificateTypeEdit) tabCertificateTypes.getModel();
        directory.getItems().remove(model.getItemAt(k));
    } catch(ClipsException e) {
        MessageBox.showException(e);
    }    
    try {
        refreshTable();
    } catch (ClipsException ex) {
        MessageBox.showException(ex);
    }
}//GEN-LAST:event_btDelActionPerformed

private void btTagListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTagListActionPerformed
        try {
            PanelTagList panel = new PanelTagList(getContainer());
            getContainer().addNewPage(panel, this);
        } catch (ClipsException ex) {
            MessageBox.showException(ex);
        }
}//GEN-LAST:event_btTagListActionPerformed

    @Override
    public String getPageTitle() {
        return "Редактор типов справок";
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAdd;
    private javax.swing.JButton btDel;
    private javax.swing.JButton btTagList;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private cli_fmw.utils.sorted_table.SortedTable tabCertificateTypes;
    // End of variables declaration//GEN-END:variables

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

    @Override
    public void print() {
        if (readyForPrint()) {
            String title = "Справочник типов справок";                       
            PrintCreators.createGeneratedReport(title, null, null, null, tabCertificateTypes.getModel(), getClass());
        }
    }

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

}
TOP

Related Classes of clips.administrator.certificate.PanelCertificateTypeEdit

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.