public String removerProfessor() { obj.getProfessoresRemocao().add(turmaProfessor); obj.getProfessores().remove(turmaProfessor); turmaProfessor = new TurmaProfessor(); turmaProfessor.setDisciplinas(new ArrayList<DisciplinaTurmaProfessor>()); turmaProfessor.setProfessor(new Professor()); turmaProfessor.setTurma(new Turma()); turmaProfessor.setDisciplinasRemoacao(new ArrayList<DisciplinaTurmaProfessor>()); disciplinasSelecionadas = null; return getPaginaCadastro(); }
public String inserirProfessor() { validateInserirProfessor(); if (isContemErros()) { return getPaginaCadastro(); } TurmaProfessor tp = new TurmaProfessor(); try { tp = (TurmaProfessor) turmaProfessor.clone(); } catch (CloneNotSupportedException e) { addMensagemErro(processaException(e)); } if (isAlteracaoAssociacaoProfessor()) { if (ValidatorUtil.isEmpty(tp.getDisciplinasRemoacao())) { tp.setDisciplinasRemoacao(new ArrayList<DisciplinaTurmaProfessor>()); } // Verifica se existem disciplinas a serem removidas Collection<DisciplinaTurmaProfessor> disciplinasAnteriores = new ArrayList<DisciplinaTurmaProfessor>(tp.getDisciplinas()); Collection<Disciplina> disciplinas = new ArrayList<Disciplina>(); for (DisciplinaTurmaProfessor dtp : disciplinasAnteriores) { List<Disciplina> asList = Arrays.asList(disciplinasSelecionadas); if (!asList.contains(dtp.getDisciplina())) { tp.getDisciplinasRemoacao().add(dtp); tp.getDisciplinas().remove(dtp); } disciplinas.add(dtp.getDisciplina()); } // Verifica disciplinas adicionadas for (Disciplina disciplina : Arrays.asList(disciplinasSelecionadas)) { if (!disciplinas.contains(disciplina)) { DisciplinaTurmaProfessor dtp = new DisciplinaTurmaProfessor(); dtp.setDisciplina(disciplina); dtp.setTurmaProfessor(tp); tp.getDisciplinas().add(dtp); } } obj.getProfessores().remove(turmaProfessor); obj.getProfessores().add(tp); } else { for (Disciplina disciplina : disciplinasSelecionadas) { DisciplinaTurmaProfessor dtp = new DisciplinaTurmaProfessor(); dtp.setDisciplina(disciplina); dtp.setTurmaProfessor(tp); if (ValidatorUtil.isEmpty(tp.getDisciplinas())) { tp.setDisciplinas(new ArrayList<DisciplinaTurmaProfessor>()); } tp.getDisciplinas().add(dtp); } tp.setTurma(obj); obj.getProfessores().add(tp); } turmaProfessor = new TurmaProfessor(); disciplinasSelecionadas = null; alteracaoAssociacaoProfessor = false; return getPaginaCadastro(); }