【发布时间】:2021-09-02 07:16:04
【问题描述】:
我的问题是,尽管我使用了DefaultDoubleDisplayConverter,但数据值被排序为字符串。我将转换器注册到单元格标签,而不是列标题标签。我的代码:
public class NatTableFactory {
private NatTable createTable(Composite parent, List<TableLine> tLines, String[][] propertyNames,
PropertyToLabels[] propToLabels, TableParams params, TextMatcherEditor<TableLine>editor, boolean openableParts) {
BodyLayerStack bodyLayerStack =
new BodyLayerStack(
tLines,
tLines.get(0).getLength(),
params.getColumnIndicesForRowHeaders());
...
SortHeaderLayer<TableLine> sortHeaderLayer =
new SortHeaderLayer<TableLine>(
columnHeaderLayer,
new GlazedListsSortModel<TableLine>(
bodyLayerStack.getSortedList(),
getSortingColumnPropAccessor(propertyNames[0]),
configRegistry,
columnHeaderDataLayer));
...
composite.addConfiguration(NatTableLayerConfigurations.getCompoositeLayerConfiguration());
NatTable natTable = new NatTable(parent, composite, false);
if( params.getAutoFitColWidthIndices().size() > 0 )
registerAutoResizeColCmdHandler(natTable, composite, bodyLayerStack, params.getAutoFitColWidthIndices());
setNatTableContentTooltip(natTable);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
setNatTableContextMenu(natTable, openableParts);
natTable.addConfiguration(NatTableLayerConfigurations.getNatTableConfiguration());
//natTable.addConfiguration(NatTableLayerConfigurations.getCustomConvertConfiguration(bodyDataLayer));
natTable.configure();
...
NatTableContentProvider.addNatTableData(natTable, bodyLayerStack.getSelectionLayer(), bodyLayerStack.getBodyDataProvider());
return natTable;
}
}
然后:
public class NatTableLayerConfigurations
{
...
public static AbstractRegistryConfiguration getNatTableConfiguration()
{
return new AbstractRegistryConfiguration()
{
@Override
public void configureRegistry(IConfigRegistry configRegistry)
{
...
Style cellAlignStyle = new Style();
cellAlignStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.RIGHT);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellAlignStyle, DisplayMode.NORMAL, NatTableFactory.DataTypeNumberLabel);
//
configRegistry.registerConfigAttribute(
CellConfigAttributes.DISPLAY_CONVERTER,
new DefaultDoubleDisplayConverter(), DisplayMode.NORMAL,
NatTableFactory.DataTypeNumberLabel);
System.out.println("configRegistry.registerConfigAttribute CellConfigAttributes.DISPLAY_CONVERTER");
...
}
};
}
}
和:
public class BodyLayerStack extends AbstractLayerTransform
{
...
public BodyLayerStack(List<TableLine> values, int columnCount, Integer[] columnIndicesForRowHeaders)
{
EventList<TableLine> eventList = GlazedLists.eventList(values);
TransformedList<TableLine, TableLine> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
sortedList = new SortedList<>(rowObjectsGlazedList, null);
// wrap the SortedList with the FilterList
filterList = new FilterList<>(sortedList);
bodyDataProvider = new ListDataProvider<TableLine>(filterList, getColumnAccessor(columnCount));
bodyDataLayer = new DataLayer(bodyDataProvider);
IConfigLabelAccumulator cellLabelAccumulator = new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
int columnIndex = bodyDataLayer.getColumnIndexByPosition(columnPosition);
int rowIndex = bodyDataLayer.getRowIndexByPosition(rowPosition);
if( isRowHeader(columnIndicesForRowHeaders, columnIndex) ) {
configLabels.addLabel(NatTableFactory.RowHeaderLabel);
} else {
configLabels.addLabel(filterList.get(rowIndex).getObjectTypeByColumn(columnIndex));
// NatTableLayerConfigurations.getNatTableConfiguration();
}
}
};
bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);
GlazedListsEventLayer<TableLine> glazedListsEventLayer = new GlazedListsEventLayer<>(bodyDataLayer, filterList);
...
}
}
我检查了各种示例,但我看不到,我错过了什么。以及如何检查单元格中的数据是否正确转换?感谢您的提示。
【问题讨论】: