Package cli_fmw.main

Source Code of cli_fmw.main.ActivatePanelAction

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

package cli_fmw.main;

import cli_fmw.delegate.DelegateLine2;
import cli_fmw.utils.MessageBox;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
*
* @author vip
*/
public class ActivatePanelAction implements ActionListener {

        UserPanel panel;
        PageContainer container;

        public ActivatePanelAction(UserPanel panel, PageContainer container) {
            this.panel = panel;
            this.container = container;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            DelegateLine2 activeDelegate = null;
            //если текущая панель содержит делегата то activeDelegate != null
            PageGeneric activePage = container.getActivePage();

            if (activePage != null) {
               activeDelegate = activePage.getDelegate();
            }

            for (int i = 0; i < container.getPageCount(); i++) {
                PageGeneric page = container.getPage(i);
                //Если панель содержит делегата, то pageDelegate != null
                DelegateLine2 pageDelegate = null;
                pageDelegate = page.getDelegate();

                if (page.getClass().getSimpleName().equals(panel.getClassName())) {
                    if (activeDelegate == null && pageDelegate == null
                            || activeDelegate != null && pageDelegate != null
                            && activeDelegate.getClass().equals(pageDelegate.getClass())
                            && activeDelegate.getID() == pageDelegate.getID()) {
                        try {
                            container.activatePage(page);
                        } catch (PageException ex) {
                            MessageBox.showException(ex);
                        }
                        return;
                    }
                }
            }
           
            Class cls = panel.getPanelClass();
            try {
                PageGeneric p = null;
                //из активной страницы берется делегат и на его основе создается панель
                // записи на прием
                if (panel.getDelegateClass() != null) {
                    if (activeDelegate != null) {
                        Constructor constructor = cls.getConstructor(PageContainer.class, DelegateLine2.class);
                        try {
                            p = (PageGeneric) constructor.newInstance(container, activeDelegate);
                        } catch (InvocationTargetException ex) {
                            MessageBox.showException(ex.getTargetException());
                        }
                    }
                } else {
                    Constructor constructor = cls.getConstructor(PageContainer.class);
                    p = (PageGeneric) constructor.newInstance(container);
                }
                if (p != null) {
                    PageGeneric page = container.addNewPage(p, null);
                    container.activatePage(page);
                }
            } catch (NoSuchMethodException ex) {
                MessageBox.showWarning(MessageBox.W_NO_APPROPRIATE_CONSTRUCTOR,
                    "<p>" + cls.getCanonicalName() + "</p>");
                ex.printStackTrace();
            } catch (InvocationTargetException ex){
                MessageBox.showException(new ClipsException(
                        "Не удалось инициализировать панель: " + cls.getCanonicalName(), ex));
            } catch (Exception ex) {
                MessageBox.showException(ex);
            }
        }
    }
TOP

Related Classes of cli_fmw.main.ActivatePanelAction

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.