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

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

Introduction

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

Prototype

public void setProperty(String property) 

Source Link

Document

Set the property to compare.

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.
 *///w ww . j  a va 2  s  . co  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());
        }
    }
}