Package reportgen.gui.genepanel

Source Code of reportgen.gui.genepanel.PanelGenerator$TitlePanelImpl

/*
* PanelLaboratory.java
*
* Created on 10 Июль 2008 г., 17:19
*/
package reportgen.gui.genepanel;

import java.awt.Window;
import java.util.List;
import org.jdom.Element;
import reportgen.utils.ReportException;
import reportgen.ren.report.ReportQuery;
import reportgen.gui.genepanel.corepanel.CorePanel;
import reportgen.gui.genepanel.formatpanel.FormatTablePanel;
import reportgen.gui.genepanel.inputpanel.InputPanel;
import reportgen.gui.genepanel.resultspanel.ResultsPanel;
import reportgen.gui.genepanel.subreportpanel.SubreportPanel;
import reportgen.gui.genepanel.titlepanel.TitlePanel;
import java.util.HashMap;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import reportgen.gui.execute.PendingReportDialog;
import reportgen.prototype.CoreFactoryList;
import reportgen.prototype.QCore;
import reportgen.prototype.context.NoNeedAtom;
import reportgen.ren.report.items.CoresList;
import reportgen.utils.Message;

/**
* Панель генератора отчетов
* @author  petr
*/
public class PanelGenerator extends JPanel {

    private final ReportManager  reportManager;
    private final Report reportInfo;
    private final ReportQuery reportQuery;
    private final Window parent;

    private HashMap<QCore, CorePanel> tabs = new HashMap<QCore, CorePanel>();


    public PanelGenerator(Window parent,
            Report aReportInfo, ReportManager aReportManager) throws ReportException {
        initComponents();
        this.reportInfo = aReportInfo;
        this.reportQuery = reportInfo.getQuery();
        this.parent = parent;
        this.reportManager = aReportManager;

        maintab.add("Основные параметры", new TitlePanelImpl(parent, reportInfo));
        maintab.add("Входные данные", new InputPanel(parent, reportQuery));
        maintab.add("Подотчеты", new SubreportPanel(parent, reportQuery, reportInfo.getID(), reportManager));
        maintab.add("Результаты", new ResultsPanel(parent, reportQuery));
        maintab.add("Форматирование результатов", new FormatTablePanel(parent, reportQuery));

        initCores();
    }

    public ReportQuery getQuery() {
        return reportQuery;
    }

    private void initCores() throws ReportException {
        CoresList cores = reportQuery.getCores();
        for(int i=0; i<cores.size(); i++) {
            QCore core = cores.get(i);
            CorePanel panel = new CorePanel(parent, core);
            tabs.put(core, panel);
            maintab.add(panel, 1);
            maintab.setTitleAt(1, "Выборка '" + core.toString() + "'");
        }
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        maintab = new javax.swing.JTabbedPane();
        jPanel10 = new javax.swing.JPanel();
        checkReportBtn = new javax.swing.JButton();

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

        jPanel10.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        checkReportBtn.setText("Проверка...");
        checkReportBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkReportBtnActionPerformed(evt);
            }
        });
        jPanel10.add(checkReportBtn);

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


private void checkReportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkReportBtnActionPerformed
    try {
        reportQuery.validate();
        reportInfo.setQuery(reportQuery);
        PendingReportDialog dlg = new PendingReportDialog(parent, reportInfo, true);
        dlg.setVisible(true);
    } catch (Exception ex) {
        Message.warning(this, ex);
    }
}//GEN-LAST:event_checkReportBtnActionPerformed

    /**
     *
     */
    private class TitlePanelImpl extends TitlePanel {

        public TitlePanelImpl(Window parent, Report reportInfo) throws ReportException {
            super(parent, reportInfo);
        }

        @Override
        protected void appendNewCore() throws ReportException {
            CoreFactoryList factory = new CoreFactoryList();
            List<String> cores = factory.getCores();
            if(cores.size() == 0) {
                throw new ReportException("Нет доступных типов выборок");
            }
            QCore core = null;
            if(cores.size() == 1) {
                core = factory.createCore(0, reportQuery.getReportContext(new NoNeedAtom()));
            } else {
                Object title = JOptionPane.showInputDialog(parent, "Выберите тип нового запроса",
                        "", JOptionPane.QUESTION_MESSAGE, null, cores.toArray(), null);
                int index = cores.indexOf(title);
                if(index == -1) {
                    return;
                }
                core = factory.createCore(index, reportQuery.getReportContext(new NoNeedAtom()));
            }
            reportQuery.getCores().add(core);

            CorePanel panel = new CorePanel(parent, core);
            tabs.put(core, panel);
            maintab.add(panel, 1);
            maintab.setTitleAt(1, "Выборка '" + core.toString() + "'");
        }

        @Override
        protected void removeCore(int index) throws ReportException {
            QCore core = reportQuery.getCores().get(index);
            reportQuery.getCores().remove(index);
           
            CorePanel panel = tabs.remove(core);
            if(panel != null) {
                maintab.remove(panel);
            }
        }

        @Override
        protected void editCore(int index) throws ReportException {
            QCore core = reportQuery.getCores().get(index);
            String title = JOptionPane.showInputDialog(parent, "Изменение названия запроса",
                    core.getTitle(), JOptionPane.QUESTION_MESSAGE);
            if(title == null) {
                return;
            }
            core.setTitle(title);
            CorePanel panel = tabs.get(core);
            int panelIndex = maintab.indexOfComponent(panel);
            if(panelIndex != -1) {
                maintab.setTitleAt(panelIndex, "Выборка '" + title + "'");
            }
        }
    }

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton checkReportBtn;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JTabbedPane maintab;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of reportgen.gui.genepanel.PanelGenerator$TitlePanelImpl

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.