List of usage examples for org.apache.commons.collections.comparators ComparatorChain addComparator
public void addComparator(Comparator comparator)
From source file:com.cyclopsgroup.waterview.web.CollectionTabularData.java
/** * Overwrite or implement method in CollectionTabularData * * @see com.cyclopsgroup.waterview.web.TabularData#openIterator(com.cyclopsgroup.waterview.web.Table) *///from w w w . j av a 2 s.c o m public Iterator openIterator(Table table) throws Exception { String[] sortedColumnNames = table.getSortedColumns(); Collection sortedResult = collection; if (sortedColumnNames.length > 0) { ComparatorChain chain = new ComparatorChain(); for (int i = 0; i < sortedColumnNames.length; i++) { String columnName = sortedColumnNames[i]; Column column = table.getColumn(columnName); if (column.getSort() == ColumnSort.ASC) { chain.addComparator(new BeanPropertyComparator(column.getName())); } else if (column.getSort() == ColumnSort.DESC) { chain.addComparator(new BeanPropertyComparator(column.getName()), true); } } chain.addComparator(HashCodeComparator.INSTANCE); sortedResult = new TreeSet(chain); sortedResult.addAll(collection); } if (table.getPageSize() <= 0) { return sortedResult.iterator(); } List list = new ArrayList(); int index = 0; int startIndex = table.getPageSize() * table.getPageIndex(); for (Iterator i = sortedResult.iterator(); i.hasNext();) { Object object = i.next(); if (index >= startIndex && index < startIndex + table.getPageSize()) { list.add(object); } index++; } return list.iterator(); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.coordinator.ExecutionCourseInfoDispatchAction.java
public ActionForward prepareChoiceForCoordinator(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { User userView = getUserView(request); String degreeCurricularPlanID = null; if (request.getParameter("degreeCurricularPlanID") != null) { degreeCurricularPlanID = request.getParameter("degreeCurricularPlanID"); request.setAttribute("degreeCurricularPlanID", degreeCurricularPlanID); }/*from w w w .j a va 2 s . com*/ List executionPeriods = ReadExecutionPeriodsByDegreeCurricularPlan.run(degreeCurricularPlanID); ComparatorChain chainComparator = new ComparatorChain(); chainComparator.addComparator(new BeanComparator("infoExecutionYear.year")); chainComparator.addComparator(new BeanComparator("semester")); Collections.sort(executionPeriods, chainComparator); List executionPeriodsLabelValueList = new ArrayList(); for (int i = 0; i < executionPeriods.size(); i++) { InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) executionPeriods.get(i); executionPeriodsLabelValueList.add(new LabelValueBean( infoExecutionPeriod.getName() + " - " + infoExecutionPeriod.getInfoExecutionYear().getYear(), infoExecutionPeriod.getExternalId().toString())); } request.setAttribute(PresentationConstants.LABELLIST_EXECUTIONPERIOD, executionPeriodsLabelValueList); /* Obtain a list of curricular years */ List labelListOfCurricularYears = ContextUtils.getLabelListOfOptionalCurricularYears(); request.setAttribute(PresentationConstants.LABELLIST_CURRICULAR_YEARS, labelListOfCurricularYears); return mapping.findForward("ReadyToSearch"); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.coordinator.ExecutionCourseInfoDispatchAction.java
public ActionForward prepareChoice(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String degreeCurricularPlanID = null; if (request.getParameter("degreeCurricularPlanID") != null) { degreeCurricularPlanID = request.getParameter("degreeCurricularPlanID"); request.setAttribute("degreeCurricularPlanID", degreeCurricularPlanID); }// w ww .j a va 2 s . c o m InfoExecutionDegree infoExecutionDegree = (InfoExecutionDegree) request .getAttribute(PresentationConstants.MASTER_DEGREE); List executionPeriods = ReadExecutionPeriodsByExecutionYear .run(infoExecutionDegree.getInfoExecutionYear().getExternalId()); ComparatorChain chainComparator = new ComparatorChain(); chainComparator.addComparator(new BeanComparator("infoExecutionYear.year")); chainComparator.addComparator(new BeanComparator("semester")); Collections.sort(executionPeriods, chainComparator); List executionPeriodsLabelValueList = new ArrayList(); for (int i = 0; i < executionPeriods.size(); i++) { InfoExecutionPeriod infoExecutionPeriod = (InfoExecutionPeriod) executionPeriods.get(i); executionPeriodsLabelValueList.add(new LabelValueBean( infoExecutionPeriod.getName() + " - " + infoExecutionPeriod.getInfoExecutionYear().getYear(), infoExecutionPeriod.getExternalId().toString())); } request.setAttribute(PresentationConstants.LABELLIST_EXECUTIONPERIOD, executionPeriodsLabelValueList); /* Obtain a list of curricular years */ List labelListOfCurricularYears = ContextUtils.getLabelListOfOptionalCurricularYears(); request.setAttribute(PresentationConstants.LABELLIST_CURRICULAR_YEARS, labelListOfCurricularYears); return mapping.findForward("ReadyToSearch"); }
From source file:net.sourceforge.fenixedu.presentationTier.backBeans.departmentMember.ViewDepartmentTeachers.java
public List<PersonFunction> getTeacherFunctions() throws FenixServiceException { if (this.teacherFunctions == null && this.getSelectedExecutionYearID() != null) { String executionYearID = this.getSelectedExecutionYearID(); Teacher teacher = FenixFramework.getDomainObject(getSelectedTeacherID()); List<PersonFunction> result = new ArrayList<PersonFunction>( ReadPersonFunctionsByPersonIDAndExecutionYearID.run(teacher.getPerson().getExternalId(), executionYearID)); ComparatorChain comparatorChain = new ComparatorChain(); BeanComparator beginDateComparator = new BeanComparator("beginDate"); comparatorChain.addComparator(beginDateComparator); Collections.sort(result, comparatorChain); this.teacherFunctions = result; }/*w ww . j a v a 2s . c o m*/ return this.teacherFunctions; }
From source file:net.sourceforge.fenixedu.presentationTier.backBeans.departmentMember.ViewDepartmentTeachers.java
public List<Advise> getFinalDegreeWorkAdvises() throws FenixServiceException { if (this.finalDegreeWorkAdvises == null && this.getSelectedExecutionYearID() != null) { String executionYearID = this.getSelectedExecutionYearID(); List<Advise> result = new ArrayList<Advise>(ReadTeacherAdvisesByTeacherIDAndAdviseTypeAndExecutionYearID .runReadTeacherAdvisesByTeacherIDAndAdviseTypeAndExecutionYearID(AdviseType.FINAL_WORK_DEGREE, getSelectedTeacherID(), executionYearID)); ComparatorChain comparatorChain = new ComparatorChain(); BeanComparator executionYearComparator = new BeanComparator("student.number"); comparatorChain.addComparator(executionYearComparator); Collections.sort(result, comparatorChain); this.finalDegreeWorkAdvises = result; }//from ww w .j a v a2 s.c om return this.finalDegreeWorkAdvises; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.department.ReadTeacherProfessorshipsByExecutionYearAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { User userView = Authenticate.getUser(); DynaActionForm dynaForm = (DynaActionForm) form; InfoTeacher infoTeacher = getInfoTeacher(request, dynaForm); List detailedInfoProfessorshipList = getDetailedProfessorships(userView, infoTeacher.getExternalId(), dynaForm, request);// w w w . jav a2s. c om ComparatorChain chain = new ComparatorChain(); Comparator executionPeriodComparator = new BeanComparator( "infoProfessorship.infoExecutionCourse.infoExecutionPeriod.semester"); Comparator nameComparator = new BeanComparator("infoProfessorship.infoExecutionCourse.nome"); chain.addComparator(executionPeriodComparator); chain.addComparator(nameComparator); Collections.sort(detailedInfoProfessorshipList, chain); request.setAttribute("detailedProfessorshipList", detailedInfoProfessorshipList); prepareConstants(userView, infoTeacher, request); prepareForm(dynaForm, request); return mapping.findForward("list-professorships"); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ShowDegreeSiteAction.java
private InfoDegreeCurricularPlan getByDegreeIdOrDegreeCurricularPlanId(String degreeId, String degreeCurricularPlanId, HttpServletRequest request) { final List<InfoDegreeCurricularPlan> infoDegreeCurricularPlanList; try {/*from ww w.ja v a 2s . c o m*/ infoDegreeCurricularPlanList = ReadDegreeCurricularPlansByDegree.run(degreeId); if (infoDegreeCurricularPlanList.isEmpty()) { return null; } // order the list by state and next by begin date ComparatorChain comparatorChain = new ComparatorChain(); comparatorChain.addComparator(new BeanComparator("state")); comparatorChain.addComparator(new BeanComparator("initialDate"), true); Collections.sort(infoDegreeCurricularPlanList, comparatorChain); request.setAttribute("infoDegreeCurricularPlanList", infoDegreeCurricularPlanList); } catch (Exception e) { return null; } // if came in the request a degreeCurricularPlanId that it is necessary // find information about this degree curricular plan if (degreeCurricularPlanId != null) { for (InfoDegreeCurricularPlan infoDegreeCurricularPlanElem : infoDegreeCurricularPlanList) { if (infoDegreeCurricularPlanElem.getExternalId().equals(degreeCurricularPlanId)) { request.setAttribute("infoDegreeCurricularPlan", infoDegreeCurricularPlanElem); return infoDegreeCurricularPlanElem; } } } else { InfoDegreeCurricularPlan infoDegreeCurricularPlan = infoDegreeCurricularPlanList.iterator().next(); request.setAttribute("infoDegreeCurricularPlan", infoDegreeCurricularPlan); return infoDegreeCurricularPlan; } return null; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.student.CurriculumDispatchAction.java
public ActionForward getCurriculumForCoordinator(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ExistingActionException, FenixServiceException { // get and set the degreeCurricularPlanID from the request and onto the // request//from w w w. j a v a2 s .c o m String degreeCurricularPlanID = null; if (request.getParameter("degreeCurricularPlanID") != null) { degreeCurricularPlanID = request.getParameter("degreeCurricularPlanID"); request.setAttribute("degreeCurricularPlanID", degreeCurricularPlanID); } final String studentCurricularPlanID = getStudentCPID(request, (DynaActionForm) form); String executionDegreeID = getExecutionDegree(request); List result = null; try { // TODO check result = ReadStudentCurriculum.runReadStudentCurriculum(executionDegreeID, studentCurricularPlanID); } catch (NotAuthorizedException e) { return mapping.findForward("NotAuthorized"); } // TODO Remove this exception! It returns null and it is not supposed! catch (Exception exp) { logger.error(exp.getMessage(), exp); return null; } BeanComparator courseName = new BeanComparator("infoCurricularCourse.name"); BeanComparator executionYear = new BeanComparator("infoExecutionPeriod.infoExecutionYear.year"); ComparatorChain chainComparator = new ComparatorChain(); chainComparator.addComparator(courseName); chainComparator.addComparator(executionYear); Collections.sort(result, chainComparator); InfoStudentCurricularPlan infoStudentCurricularPlan = null; try { infoStudentCurricularPlan = ReadStudentCurricularPlan.run(studentCurricularPlanID); } catch (ExistingServiceException e) { throw new ExistingActionException(e); } request.setAttribute(PresentationConstants.CURRICULUM, result); request.setAttribute(PresentationConstants.STUDENT_CURRICULAR_PLAN, infoStudentCurricularPlan); return mapping.findForward("ShowStudentCurriculum"); }
From source file:net.sourceforge.fenixedu.domain.credits.util.AnnualTeachingCreditsByPeriodBean.java
public List<InstitutionWorkTime> getInstitutionWorkTime() { List<InstitutionWorkTime> institutionWorkingTimes = new ArrayList<InstitutionWorkTime>(); TeacherService teacherService = teacher.getTeacherServiceByExecutionPeriod(executionPeriod); if (teacherService != null && !teacherService.getInstitutionWorkTimes().isEmpty()) { institutionWorkingTimes.addAll(teacherService.getInstitutionWorkTimes()); }/*from w w w .j a v a 2 s . c o m*/ ComparatorChain comparatorChain = new ComparatorChain(); BeanComparator semesterComparator = new BeanComparator("teacherService.executionPeriod"); BeanComparator weekDayComparator = new BeanComparator("weekDay"); BeanComparator startTimeComparator = new BeanComparator("startTime"); comparatorChain.addComparator(semesterComparator); comparatorChain.addComparator(weekDayComparator); comparatorChain.addComparator(startTimeComparator); Collections.sort(institutionWorkingTimes, comparatorChain); return institutionWorkingTimes; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.department.ReadPersonProfessorshipsByExecutionYearAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { User userView = Authenticate.getUser(); DynaActionForm dynaForm = (DynaActionForm) form; InfoPerson infoPerson = getInfoPerson(request, dynaForm); List detailedInfoProfessorshipList = getDetailedProfessorships(userView, infoPerson.getExternalId(), dynaForm, request);//from w ww. j ava 2s . c o m ComparatorChain chain = new ComparatorChain(); Comparator executionPeriodComparator = new BeanComparator( "infoProfessorship.infoExecutionCourse.infoExecutionPeriod.semester"); Comparator nameComparator = new BeanComparator("infoProfessorship.infoExecutionCourse.nome"); chain.addComparator(executionPeriodComparator); chain.addComparator(nameComparator); Collections.sort(detailedInfoProfessorshipList, chain); request.setAttribute("detailedProfessorshipList", detailedInfoProfessorshipList); extraPreparation(userView, infoPerson, request, dynaForm); return mapping.findForward("list-professorships"); }