Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.controller.managedbean; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.List; |
||
| 5 | |||
| 6 | import javax.inject.Inject; |
||
| 7 | import javax.inject.Named; |
||
| 8 | |||
| 9 | import org.springframework.context.annotation.Scope; |
||
| 10 | |||
| 11 | import br.com.ec.domain.model.Categoria; |
||
| 12 | import br.com.ec.domain.model.tipos.TipoCategoria; |
||
| 13 | import br.com.ec.domain.service.categoria.CategoriaService; |
||
| 14 | import br.edu.cesmac.core.consulta.ParametrosConsulta; |
||
| 15 | import br.edu.cesmac.core.generic.GenericService; |
||
| 16 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 17 | import br.edu.cesmac.web.exception.VerificadorLancamentoException; |
||
| 18 | import br.edu.cesmac.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 19 | import br.edu.cesmac.web.generic.AbstractBean; |
||
| 20 | import br.edu.cesmac.web.message.LancadorMensagem; |
||
| 21 | |||
| 22 | @Named |
||
| 23 | @Scope("view") |
||
| 24 | public class CategoriaBean extends AbstractBean<Categoria> implements Serializable { |
||
| 25 | |||
| 26 | private static final long serialVersionUID = 1L; |
||
| 27 | |||
| 28 | private CategoriaService categoriaService; |
||
| 29 | |||
| 30 | private Categoria categoriaSelecionado; |
||
| 31 | |||
| 32 | private List<Categoria> categorias; |
||
| 33 | |||
| 34 | @Inject |
||
| 35 | public CategoriaBean(CategoriaService categoriaService) { |
||
| 36 | this.categoriaService = categoriaService; |
||
| 37 | } |
||
| 38 | |||
| 39 | @Override |
||
| 40 | public void preCarregamento() { |
||
| 41 | if (VerificadorUtil.estaNulo(parametrosConsulta)) { |
||
| 42 | entidade = new Categoria(); |
||
| 43 | parametrosConsulta = new ParametrosConsulta<Categoria>(); |
||
| 44 | parametrosConsulta.setEntidade(entidade); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | @Override |
||
| 49 | public void limparEntidade() { |
||
| 50 | Categoria categoria = new Categoria(); |
||
| 51 | setEntidade(categoria); |
||
| 52 | } |
||
| 53 | |||
| 54 | @Override |
||
| 55 | public GenericService<Categoria> getService() { |
||
| 56 | return categoriaService; |
||
| 57 | } |
||
| 58 | |||
| 59 | @Override |
||
| 60 | public Categoria getEntidade() { |
||
| 61 | return entidade; |
||
| 62 | } |
||
| 63 | |||
| 64 | @Override |
||
| 65 | public Categoria getId() { |
||
| 66 | return getEntidade(); |
||
| 67 | } |
||
| 68 | |||
| 69 | public List<Categoria> getCategorias() { |
||
| 70 | if (VerificadorUtil.estaNulo(categorias)) { |
||
| 71 | setCategorias(categoriaService.consultarTodos(new Categoria())); |
||
| 72 | } |
||
| 73 | return categorias; |
||
| 74 | } |
||
| 75 | public void setCategorias(List<Categoria> categorias) { |
||
| 76 | this.categorias = categorias; |
||
| 77 | } |
||
| 78 | |||
| 79 | public TipoCategoria[] getTiposCategoria() { |
||
| 80 | return TipoCategoria.values(); |
||
| 81 | } |
||
| 82 | |||
| 83 | public Categoria getCategoriaSelecionado() { |
||
| 84 | return categoriaSelecionado; |
||
| 85 | } |
||
| 86 | public void setCategoriaSelecionado(Categoria categoriaSelecionado) { |
||
| 87 | this.categoriaSelecionado = categoriaSelecionado; |
||
| 88 | } |
||
| 89 | |||
| 90 | public void prepararConsulta() { |
||
| 91 | setCategorias(categoriaService.consultarPassandoEntidade(getParametrosConsulta().getEntidade(), 0, categoriaService.obterQuantidadeDeRegistrosPassandoEntidade(getParametrosConsulta().getEntidade()))); |
||
| 92 | } |
||
| 93 | |||
| 94 | public List<Categoria> listarCategorias() { |
||
| 95 | return categoriaService.consultarPassandoEntidade(getParametrosConsulta().getEntidade(), 0, categoriaService.obterQuantidadeDeRegistrosPassandoEntidade(getParametrosConsulta().getEntidade())); |
||
| 96 | } |
||
| 97 | |||
| 98 | public List<Categoria> listarCategoriasPai() { |
||
| 99 | return categoriaService.consultarCategoriasPaiAtivas(null); |
||
| 100 | } |
||
| 101 | |||
| 102 | public List<Categoria> listarCategoriasPaiReceitas() { |
||
| 103 | return categoriaService.consultarCategoriasPaiAtivas(TipoCategoria.RECEITAS.getValor()); |
||
| 104 | } |
||
| 105 | |||
| 106 | public List<Categoria> listarCategoriasPaiDespesas() { |
||
| 107 | return categoriaService.consultarCategoriasPaiAtivas(TipoCategoria.DESPESAS.getValor()); |
||
| 108 | } |
||
| 109 | |||
| 110 | public void excluirCategoria(final Categoria categoria) { |
||
| 111 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 112 | public void execute() { |
||
| 113 | categoriaService.excluir(categoria); |
||
| 114 | setCategorias(categoriaService.consultarTodos(new Categoria())); |
||
| 115 | LancadorMensagem.lancarSucesso("Categoria excluĂda com sucesso"); |
||
| 116 | } |
||
| 117 | }); |
||
| 118 | } |
||
| 119 | |||
| 120 | } |