Hi guys, so, I achieved do it! Thanks the both, I'm so happy to have achieved.
I really had of implement a MaterialGridDataSource replete of little things. I go leave the source code for somebody that can to need in the future. > @SuppressWarnings("all") > public class MaterialGridDataSource implements GridDataSource { > > private final List list; > private int columnId; > private TipoAtributo tipoAtributo; > > public MaterialGridDataSource(final Collection collection) { > assert collection != null; > list = CollectionFactory.newList(collection); > } > > public int getAvailableRows() { > return list.size(); > } > > public void prepare(int startIndex, int endIndex, List<SortConstraint> > sortConstraints) { > for (SortConstraint constraint : sortConstraints) { > final ColumnSort sort = constraint.getColumnSort(); > > if (sort == ColumnSort.UNSORTED) > continue; > > final PropertyConduit conduit = constraint.getPropertyModel().getConduit(); > try { > columnId = Integer.parseInt(constraint.getPropertyModel().getId()); > } catch (NumberFormatException e) { > columnId = -1; > } > final String columnName = constraint.getPropertyModel().getLabel(); > > tipoAtributo = null; > > //System.out.println(columnId + " - " + columnName); > > > final Comparator valueComparator = new Comparator<Comparable>() { > public int compare(Comparable o1, Comparable o2) { > > // Simplify comparison, and handle case where both are > // nulls. > > if(tipoAtributo == TipoAtributo.DATA) { > DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", > new Locale("pt", "BR")); > Date d1 = null, d2 = null; > try { > o1 = formatter.parse((String) o1); > o2 = formatter.parse((String) o2); > } catch (ParseException e) { > System.out.println("Erro em " + this); > e.printStackTrace(); > } > } > > if (o1 == o2) > return 0; > > if (o2 == null) > return 1; > > if (o1 == null) > return -1; > > return o1.compareTo(o2); > } > }; > > final Comparator rowComparator = new Comparator() { > public int compare(Object row1, Object row2) { > > Comparable value1 = null, value2 = null; > > if(columnId >= 0) { > Material linha = (Material) row1; > > for(int i =0; i < linha.getValoresAtributo().size(); i++) > if(linha.getValoresAtributo().get(i).getAtributo().getNome().equals(columnName)) > { > value1 = (Comparable) conduit.get(linha.getValoresAtributo().get(i)); > if(linha.getValoresAtributo().get(i).getAtributo().getTipoAtributo() == > TipoAtributo.DATA) > tipoAtributo = TipoAtributo.DATA; > break; > } > > linha = (Material) row2; > > for(int i =0; i < linha.getValoresAtributo().size(); i++) > if(linha.getValoresAtributo().get(i).getAtributo().getNome().equals(columnName)) > { > value2 = (Comparable) conduit.get(linha.getValoresAtributo().get(i)); > break; > } > > } else { > value1 = (Comparable) conduit.get(row1); > value2 = (Comparable) conduit.get(row2); > } > return valueComparator.compare(value1, value2); > } > }; > > final Comparator reverseComparator = new Comparator() { > public int compare(Object o1, Object o2) { > int modifier = sort == ColumnSort.ASCENDING ? 1 : -1; > > return modifier * rowComparator.compare(o1, o2); > } > }; > > // We can freely sort this list because its just a copy. > Collections.sort(list, reverseComparator); > } > } > > /** > * Returns the type of the first element in the list, or null if the list > is > * empty. > */ > public Class getRowType() { > return list.isEmpty() ? null : list.get(0).getClass(); > } > > public Object getRowValue(int index) { > return list.get(index); > } > > }