1
我已經實現了我的自定義列分類器,該分類器用於對我的表中的 元素進行排序。如何使用ScrollTable實現自定義ColumnSorter(GWT-incubator)
class FileColumnSorter extends SortableGrid.ColumnSorter { @Override public void onSortColumn(SortableGrid sortableGrid, TableModelHelper.ColumnSortList columnSortList, SortableGrid.ColumnSorterCallback columnSorterCallback) .... }
當我初始化FixedWidthGrid我做到以下幾點:
FixedWidthGrid dataTable = new FixedWidthGrid(rows, cols); dataTable.setSelectionPolicy(SelectionGrid.SelectionPolicy.ONE_ROW); dataTable.setColumnSorter(new FileColumnSorter());
的scrolltable初始化方式如下:
FixedWidthFlexTable headerTable = createHeaderTable(); // Calling the lines described above FixedWidthGrid fileListGrid = createDataTable (currentDescriptorList.size(), 6); // Combine the components into a ScrollTable scrollTable = new ScrollTable(fileListGrid, headerTable); scrollTable.setSortPolicy(AbstractScrollTable.SortPolicy.SINGLE_CELL); scrollTable.setColumnSortable(0, false); scrollTable.setColumnSortable(1, true); scrollTable.setColumnSortable(2, true); scrollTable.setColumnSortable(3, true); scrollTable.setColumnSortable(4, true); scrollTable.setColumnSortable(5, false);
當我運行應用程序,我得到了建於排序而不是我的 自定義排序。我也試着做到以下幾點:
ColumnSorter sorter = new FileColumnSorter(); FixedWidthGrid dataTable = new FixedWidthGrid(rows, cols) { @Override public ColumnSorter getColumnSorter() { return sorter; } };
爲了確保我的分揀機習慣,但我仍然得到同樣的 經驗。
更新:增加了FileColumnSorter
class FileColumnSorter extends SortableGrid.ColumnSorter
{
@Override
public void onSortColumn(SortableGrid sortableGrid,
TableModelHelper.ColumnSortList columnSortList,
SortableGrid.ColumnSorterCallback columnSorterCallback)
{
final int column = columnSortList.getPrimaryColumn();
final Integer[] originalOrder = new Integer[sortableGrid.getRowCount()];
for (int i = 0; i < originalOrder.length; i++)
{
originalOrder[i] = i;
}
Arrays.sort(originalOrder, new Comparator<Integer>() {
public int compare(Integer first, Integer second)
{
Descriptor firstDesc = share.getCurrentDescriptors().get(first);
Descriptor secondDesc = share.getCurrentDescriptors().get(second);
if (firstDesc.getType().equals(secondDesc.getType()))
{
switch (column)
{
case 0:
return firstDesc.compareTo(secondDesc);
case 1:
return firstDesc.getName().compareTo(secondDesc.getName());
case 2:
return ((Long) firstDesc.getSize()).compareTo(secondDesc.getSize());
case 3:
return firstDesc.getCreated().compareTo(secondDesc.getCreated());
case 4:
return firstDesc.getModified().compareTo(secondDesc.getModified());
default:
return firstDesc.compareTo(secondDesc);
}
}
else
{
return firstDesc.getType() == Descriptor.FileItemType.FOLDER ? 1 : -1;
}
}
});
int[] resultOrder = new int[originalOrder.length];
for (int i = 0; i < originalOrder.length; i++)
{
if (columnSortList.isPrimaryAscending())
{
resultOrder[i] = originalOrder[i];
}
else
{
resultOrder[resultOrder.length - i - 1] = originalOrder[i];
}
}
columnSorterCallback.onSortingComplete(resultOrder);
}
}
這個模式適用於我。你可以添加'FileColumnSorter'的代碼嗎? – 2009-11-11 17:06:21
用分揀機執行更新了。這包括一個描述符,它是一個帶有一些基本字段的DTO。 – tronda 2009-11-13 09:48:40
愚蠢的問題 - 你有FileColumnSort作爲發佈的代碼中的類名稱,但實例化FileColumnSorter。以防萬一你偶然碰到兩個不同的類並實例化錯誤的類... – Joe 2009-11-19 17:15:06