Package presenter

Source Code of presenter.AbreProjetoPresenter

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

import view.AbreProjetoView;
import business.Projeto;
import dao.ProjetoDAO;
import java.awt.event.ActionEvent;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.JXErrorPane;
import org.jdesktop.swingx.error.ErrorInfo;
import view.helpers.WindowClose;

/**
*
* @author Usuario
*/
public class AbreProjetoPresenter {

    private AbreProjetoView view;
    private ProjetoDAO projetoDAO;
    private DefaultTableModel mod;
    private Projeto projeto;
    private List<Projeto> projetos;

    public AbreProjetoPresenter() {
        try {
            Object[] linha = null;

            this.view = new AbreProjetoView();
            this.view.setTitle("Abrir Projeto");
            this.view.setLocationRelativeTo(null);

            this.view.getGridProjetos().getColumnExt(0).setVisible(false);
            this.view.getGridProjetos().getColumnExt(0).setResizable(false);

            this.projetoDAO = new ProjetoDAO();

            projetoDAO.connect();
            projetos = projetoDAO.getAll("id", true);
            Iterator it = projetos.iterator();
            mod = (DefaultTableModel) view.getTableProjetos().getModel();
            linha = new Object[3];
            while (it.hasNext()) {
                projeto = (Projeto) it.next();
                if (projeto.getId() > 0) {
                    linha[0] = projeto.getId();
                    linha[1] = projeto.getNome();
                    linha[2] = projeto.getAutor();
                    mod.addRow(linha);
                }
            }
            projeto = null;
            projetoDAO.close();

            view.getBtnAbrir().addActionListener(new java.awt.event.ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (view.getTableProjetos().getSelectedRow() >= 0) {
                        long idProjeto = (Long) view.getGridProjetos().getModel().getValueAt(view.getGridProjetos().getSelectedRow(), 0);
                        projetoDAO.connect();
                        projeto = projetoDAO.find(idProjeto);
                        projetoDAO.close();
                        fechar();
                    } else {
                        try {
                            throw new Exception("Selecione um projeto");
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(view, ex.getMessage(), "Projeto", JOptionPane.WARNING_MESSAGE);
                        }
                    }
                }
            });

            view.getBtnCancelar().addActionListener(new java.awt.event.ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    projeto = null;
                    fechar();
                }
            });
            view.getGridProjetos().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            view.addWindowListener(new WindowClose(view));
            this.view.setVisible(true);
        } catch (Exception ex) {
            ErrorInfo info = new ErrorInfo("Erro", ex.getMessage(), null, "category", ex, Level.SEVERE, null);
            JXErrorPane.showDialog(null, info);
        }
    }

    public Projeto getProjeto() {
        return projeto;
    }

    private void fechar() {
        view.dispose();
        view.setVisible(false);
    }
}
TOP

Related Classes of presenter.AbreProjetoPresenter

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.