Example usage for org.springframework.beans.support MutableSortDefinition setAscending

List of usage examples for org.springframework.beans.support MutableSortDefinition setAscending

Introduction

In this page you can find the example usage for org.springframework.beans.support MutableSortDefinition setAscending.

Prototype

public void setAscending(boolean ascending) 

Source Link

Document

Set whether to sort ascending (true) or descending (false).

Usage

From source file:de.iteratec.iteraplan.presentation.dialog.GuiSearchController.java

/**
 *    Get/create SortDefinition for active dialog and store it in DialogMemory for this request.
 *    When a sort action happened, toggles the appropriate column in the sort definition.  
 *    If no sorting is defined, it sorts the first column ascending.
 *///from ww  w.j a  v  a2 s. c o  m
@SuppressWarnings("boxing")
private void initColumnSortDefinition(T dialogMemory) {
    TableActionParams params = dialogMemory.getTableActionParameter();

    // Get/create SortDefinition for this Dialog and store it in DialogMemory for this request
    MutableSortDefinition sortDefinition = dialogMemory.getTableState().getSortDefinition();

    // check, if sorting is toggled
    List<ColumnDefinition> visibleColumnDefinitions = dialogMemory.getTableState()
            .getVisibleColumnDefinitions();
    if (params != null && params.getColSortIndex() != null) {
        int sortIndex = params.getColSortIndex();

        if (sortIndex < 0) {
            sortIndex = 0;
        }

        if (sortIndex > (visibleColumnDefinitions.size() - 1)) {
            sortIndex = visibleColumnDefinitions.size() - 1;
        }

        ColumnDefinition sortColumnDefinition = visibleColumnDefinitions.get(sortIndex);
        sortDefinition.setProperty(sortColumnDefinition.getBeanPropertyPath());
        params.setColSortIndex(null);
    } else if (params != null && params.getSortByPosition() != null && params.getSortByPosition().booleanValue()
            && dialogMemory.isTreeView()) {
        sortDefinition.setProperty("position");
        sortDefinition.setAscending(true);
        params.setSortByPosition(null);
    } else {

        if (sortDefinition.getProperty() != null && "".equals(sortDefinition.getProperty())
                && visibleColumnDefinitions != null && visibleColumnDefinitions.size() > 0) {

            // set sort definition to first column's property
            sortDefinition.setProperty(visibleColumnDefinitions.get(0).getModelPath());
        }
    }
}

From source file:org.patientview.patientview.controller.JoinRequestsController.java

/**
 * Deal with the URIs "/control/joinRequestList"
 * get the join requests list(paging and sorting)
 *//*www. j  a  va  2  s.  c o  m*/
@RequestMapping(value = Routes.JOIN_REQUEST_LIST_URL)
public String joinRequestList(HttpServletRequest request,
        @RequestParam(value = "page", required = false) String page) {
    PagedListHolder pagedListHolder;

    if (page == null || "".equals(page)) {
        pagedListHolder = getPageListData(false);
    } else {

        pagedListHolder = (PagedListHolder) request.getSession().getAttribute("joinRequests");

        if ("prev".equals(page)) {
            if (pagedListHolder != null) {
                pagedListHolder.previousPage();
            } else {
                pagedListHolder = getPageListData(null);
            }
        } else if ("next".equals(page)) {
            if (pagedListHolder != null) {
                pagedListHolder.nextPage();
            } else {
                pagedListHolder = getPageListData(null);
            }
        } else if ("all".equals(page)) {
            pagedListHolder = getPageListData(null);
        } else if ("incomplete".equals(page)) {
            pagedListHolder = getPageListData(false);
        } else if ("complete".equals(page)) {
            pagedListHolder = getPageListData(true);
        } else if ("sort".equals(page)) {
            String property = (String) request.getParameter("property");
            MutableSortDefinition newSort = new MutableSortDefinition(property, true, false);
            SortDefinition sort = pagedListHolder.getSort();
            if (StringUtils.equals(sort.getProperty(), property)) {
                newSort.setAscending(!sort.isAscending());
            }
            pagedListHolder.setSort(newSort);
            pagedListHolder.resort();
        }
    }
    pagedListHolder.setPageSize(pageSize);
    request.getSession().setAttribute("joinRequests", pagedListHolder);
    request.setAttribute("specialty", getSpecialtyContext());

    if (pagedListHolder.isFirstPage()) {
        request.setAttribute("firstPage", true);
    }

    if (pagedListHolder.isLastPage()) {
        request.setAttribute("lastPage", true);
    }
    List<JoinRequest> joinRequestList = LegacySpringUtils.getJoinRequestManager().getUsersJoinRequests(false);
    if (joinRequestList != null && joinRequestList.size() > 0) {
        request.setAttribute("inCompletedNumber", joinRequestList.size());
    }
    return forwardTo(request, Routes.JOIN_REQUEST_LIST_PAGE);
}

From source file:org.patientview.patientview.controller.UnitPatientsControlller.java

@RequestMapping(value = Routes.UNIT_PATIENTS_LIST_URL)
public String getPatients(@RequestParam(value = "unitcode", required = false) String unitcode,
        @RequestParam(value = "page", required = false) String page,
        @RequestParam(value = "nhsno", required = false) String nhsno,
        @RequestParam(value = "firstname", required = false) String firstname,
        @RequestParam(value = "lastname", required = false) String lastname,
        @RequestParam(value = "showgps", required = false) boolean showgps,
        @RequestParam(value = "property", required = false) String property, HttpServletRequest request) {

    unitcode = (unitcode == null) ? "" : unitcode;

    PagedListHolder pagedListHolder = (PagedListHolder) request.getSession().getAttribute("patients");

    //TODO So we get every patient in the database and then start paging
    //TODO There is probably not a single use case why you would want this many patients
    //TODO Pagination needs to restrict query results

    if (StringUtils.isEmpty(page) || pagedListHolder == null) {

        // Validation
        if (StringUtils.isEmpty(unitcode) && StringUtils.isEmpty(nhsno)
                && StringUtils.isEmpty(firstname + lastname)) {
            return "redirect:/renal/control/unitPatientsUnitSelect.do?validation=failed";
        }//from   www  .j  ava  2s . c o  m

        nhsno = (nhsno == null) ? "" : nhsno;
        firstname = (firstname == null) ? "" : firstname;
        lastname = (lastname == null) ? "" : lastname;
        List patients = null;
        PatientManager patientManager = LegacySpringUtils.getPatientManager();
        if (StringUtils.isEmpty(unitcode)) {
            if (LegacySpringUtils.getSecurityUserManager().isRolePresent("superadmin")) {
                patients = patientManager.getAllUnitPatientsWithTreatmentIncludeHidden(nhsno, firstname,
                        lastname, showgps);
            } else {
                patients = patientManager.getAllUnitPatientsWithTreatment(nhsno, firstname, lastname, showgps);
            }
        } else {
            if (LegacySpringUtils.getSecurityUserManager().isRolePresent("superadmin")) {
                patients = patientManager.getUnitPatientsWithTreatmentIncludeHidden(unitcode, nhsno, firstname,
                        lastname, showgps);
            } else {
                patients = patientManager.getUnitPatientsWithTreatment(unitcode, nhsno, firstname, lastname,
                        showgps);
            }
        }
        pagedListHolder = new PagedListHolder(patients);
        request.getSession().setAttribute("patients", pagedListHolder);
    } else {
        if ("first".equals(page)) {
            pagedListHolder.setPage(0);
        } else if ("prev".equals(page)) {
            pagedListHolder.previousPage();
        } else if ("next".equals(page)) {
            pagedListHolder.nextPage();
        } else if ("last".equals(page)) {
            pagedListHolder.setPage(pagedListHolder.getPageCount() - 1);
        } else if ("sort".equals(page)) {
            MutableSortDefinition newSort = new MutableSortDefinition(property, true, false);
            SortDefinition sort = pagedListHolder.getSort();
            if (StringUtils.equals(sort.getProperty(), property)) {
                newSort.setAscending(!sort.isAscending());
            }
            pagedListHolder.setSort(newSort);
            pagedListHolder.resort();
        }
    }
    //Reset the unit selection on the first page
    if (page == null) {
        request.getSession().setAttribute("unit", null);
    }

    if (StringUtils.isNotEmpty(unitcode)) {
        Unit unit = LegacySpringUtils.getUnitManager().get(unitcode);
        request.getSession().setAttribute("unit", unit);
    }

    return forwardTo(request, Routes.UNIT_PATIENTS_LIST_PAGE);
}

From source file:org.patientview.patientview.controller.UnitUsersController.java

@RequestMapping(value = Routes.UNIT_USERS_LIST_URL)
public String getUsers(@RequestParam(value = "unitcode", required = false) String unitcode,
        @RequestParam(value = "page", required = false) String page,
        @RequestParam(value = "property", required = false) String property, HttpServletRequest request) {
    if (StringUtils.isNotEmpty(unitcode)) {
        Unit unit = LegacySpringUtils.getUnitManager().get(unitcode);
        request.setAttribute("unit", unit);
    }//from  www  .  j  a v a2 s  .  c  o m

    PagedListHolder pagedListHolder = (PagedListHolder) request.getSession().getAttribute("unitUsers");
    if (StringUtils.isEmpty(page) || pagedListHolder == null) {
        List unitUsers = null;
        if (StringUtils.isEmpty(unitcode)) {
            unitUsers = LegacySpringUtils.getUnitManager().getAllUnitUsers();
        } else {
            unitUsers = LegacySpringUtils.getUnitManager().getUnitUsers(unitcode);
        }
        pagedListHolder = new PagedListHolder(unitUsers);
        request.getSession().setAttribute("unitUsers", pagedListHolder);
    } else {
        if ("prev".equals(page)) {
            pagedListHolder.previousPage();
        } else if ("next".equals(page)) {
            pagedListHolder.nextPage();
        } else if ("sort".equals(page)) {
            MutableSortDefinition newSort = new MutableSortDefinition(property, true, false);
            SortDefinition sort = pagedListHolder.getSort();
            if (StringUtils.equals(sort.getProperty(), property)) {
                newSort.setAscending(!sort.isAscending());
            }
            pagedListHolder.setSort(newSort);
            pagedListHolder.resort();
        }
    }

    return forwardTo(request, Routes.UNIT_USERS_LIST_PAGE);
}