Package clips.doctor.profcheckup.item

Source Code of clips.doctor.profcheckup.item.PanelProfcheckupItemsList

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* PanelProfcheckupItemsList.java
*
* Created on 05.03.2009, 16:01:32
*/

package clips.doctor.profcheckup.item;

import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ActivateSensitive;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageException;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.TabbedPaneBlockableListener;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.doctor.profchekup.ProfcheckupItemLocal;
import java.awt.BorderLayout;
import java.awt.Component;
import java.util.List;

/**
*
* @author petr
*/
public class PanelProfcheckupItemsList extends PageGeneric implements Persistentable {

    public PanelProfcheckupItemsList(PageContainer container, List<ProfcheckupItemLocal> itemList) throws ClipsException {
        this(container, itemList, null);
    }

    /** Creates new form PanelProfcheckupItemsList */
    /**
     *
     * @param container
     * @param itemList not null
     * @throws cli_fmw.main.ClipsException
     */
    public PanelProfcheckupItemsList(PageContainer container, List<ProfcheckupItemLocal> itemList, PageGeneric header) throws ClipsException {
        super(container);
        initComponents();
        if (itemList == null || itemList.isEmpty()){
            throw new IllegalArgumentException("Список элементов профосмотра не может быть пустым");
        }
        for (ProfcheckupItemLocal pil : itemList) {
            addPage(pil);
        }
        jTabbedPane1.setSelectedIndex(0);
        jTabbedPane1.addChooseListener(new TabbedPaneBlockableListener() {

            @Override
            public void tryChoose(int index) throws PageException {
                if (index < 0 || index >= jTabbedPane1.getTabCount()) {
                    return;
                }
                //deactivation current panel
                Component current = jTabbedPane1.getSelectedComponent();
                if (current instanceof Persistentable){
                    Persistentable p = (Persistentable) current;
                    if (p.isDirty()) {
                        try {
                            int res = MessageBox.showConfirmYesNoCancel(
                                    MessageBox.C_SAVE_CHANGES);
                            switch (res) {
                                case MessageBox.ANSWER_YES:
                                    p.save();
                                    break;
                                case MessageBox.ANSWER_NO:
                                    p.restore();
                                    break;
                                case MessageBox.ANSWER_CANCEL:
                                    return;
                            }
                        } catch (ClipsException ex) {
                            throw new PageException("Страница не может быть закрыта: ",ex);
                        }
                    }
                if (current instanceof ActivateSensitive){
                    ActivateSensitive as = (ActivateSensitive) current;
                    if (!as.canBeActivated()){
                        throw new PageException("Текущая панель не может быть деактивирована");
                    }
                    as.beforeDeactivate();
                }
                PageGeneric page = (PageGeneric) jTabbedPane1.getComponentAt(index);
                    ActivateSensitive as = (ActivateSensitive) page;
                    if (!as.canBeActivated()){
                        throw new PageException("Выбранная панель не может быть активирована");
                    }
                    as.beforeActivate();
                }
            }

            @Override
            public void chooseDone() {
                //do nothing
            }
        });
        if (header != null){
            jPanel1.add(header, BorderLayout.NORTH);
        }
       
        StateSaver.attachTo(this);
    }

    private void addPage(ProfcheckupItemLocal pil) throws ClipsException{
        PanelProfCheckupItemEdit ppcie = new PanelProfCheckupItemEdit(getContainer(), pil);
        jTabbedPane1.add(pil.getDanger().getTitle().substring(0, 15) + "...", ppcie);
    }


    /** 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() {

        jTabbedPane1 = new cli_fmw.main.TabbedPaneBlockable();
        jPanel1 = new javax.swing.JPanel();

        setLayout(new java.awt.BorderLayout());
        add(jTabbedPane1, java.awt.BorderLayout.CENTER);

        jPanel1.setLayout(new java.awt.BorderLayout());
        add(jPanel1, java.awt.BorderLayout.PAGE_START);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private cli_fmw.main.TabbedPaneBlockable jTabbedPane1;
    // End of variables declaration//GEN-END:variables

    @Override
    public String getPageTitle() {
        return "";
    }

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

    @Override
    public boolean isDirty() {
        return ((Persistentable)jTabbedPane1.getSelectedComponent()).isDirty();
    }

    @Override
    public void save() throws ClipsException {
        ((Persistentable)jTabbedPane1.getSelectedComponent()).save();
    }

    @Override
    public void restore() {
        ((Persistentable)jTabbedPane1.getSelectedComponent()).restore();
    }

}
TOP

Related Classes of clips.doctor.profcheckup.item.PanelProfcheckupItemsList

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.