NatTable требует установки ячеек столбца 3 с BACKGROUND_COLOR = GUIHelper.COLOR_GREEN, когда свойство Material имеет тип «Составной».
Список материалов является источником данных (DataProvider)
NatTable настроен с помощью StackingTableConfiguration.class
NatTable использует настраиваемую метку для установки стиля ячейки с помощью StackingTableLabelAccumulator.class
Как предлагается в https://www.eclipse.org/forums/index.php/t/781508/ У меня естьустановить слой данных тела cellLabelAccumulator.
Я использовал AggregateConfigLabelAccumulator
, так как у меня есть собственный накопитель меток (AggregateConfigLabelAccumulator
) и columnLabelAccumulator
.
Когда материал имеет тип Composite,метка добавляется в метки конфигурации, но зеленый цвет не отображается.
public class StackingTable {
private NatTable natTable;
public static IDataProvider bodyDataProvider;
public static String COLUMN_ONE_LABEL = "ColumnOneLabel";
public static String COLUMN_TWO_LABEL = "ColumnTwoLabel";
public static String COLUMN_THREE_LABEL = "ColumnThreeLabel";
public static String TEST = "Composite_Label";
public StackingTable(Composite parent,
EventList<AncolabStackingLayer> ancolabStackingData,
SelectionLayer stackingTableSelectionLayer ) {
bodyDataProvider = new ListDataProvider<>(ancolabStackingData, colAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
final ColumnOverrideLabelAccumulator columnLabelAccumulator =
new ColumnOverrideLabelAccumulator(bodyDataLayer);
columnLabelAccumulator.registerColumnOverrides(0, COLUMN_ONE_LABEL);
columnLabelAccumulator.registerColumnOverrides(1, COLUMN_TWO_LABEL);
columnLabelAccumulator.registerColumnOverrides(2, COLUMN_THREE_LABEL);
//Create the gridLayer
natTable = new NatTable(parent, gridLayer, false);
AggregateConfigLabelAccumulator aggregateConfigLabelAccumulator =
new AggregateConfigLabelAccumulator();
aggregateConfigLabelAccumulator.add(columnLabelAccumulator);
aggregateConfigLabelAccumulator.add(
new StackingTableLabelAccumulator(bodyDataProvider));
bodyDataLayer.setConfigLabelAccumulator(aggregateConfigLabelAccumulator);
bodyDataLayer.addConfiguration(
new DefaultNatTableStyleConfiguration());
bodyDataLayer.addConfiguration(
new StackingTableConfiguration(bodyDataProvider));
bodyDataLayer.addConfiguration(new DefaultEditConfiguration());
bodyDataLayer.addConfiguration(new DefaultEditBindings());
natTable.configure();
}
Реестр конфигурации:
public class StackingTableConfiguration extends AbstractRegistryConfiguration {
private IDataProvider bodyDataProvider;
public StackingTableConfiguration(IDataProvider dp) {
this.bodyDataProvider = dp;
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
//...some configutarion attributes for other columns
Style cellStyle2 = new Style();
cellStyle2.setAttributeValue(
CellStyleAttributes.BACKGROUND_COLOR,
GUIHelper.COLOR_GREEN);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyle2,
DisplayMode.NORMAL, StackingTable.TEST);
}
}
Аккумулятор пользовательских меток:
//Add a label to cells in column 2 when the material of the row is of type = "Composite"
public class StackingTableLabelAccumulator extends AbstractOverrider {
IDataProvider dataProvider;
public StackingTableLabelAccumulator(IDataProvider dataProvider){
this.dataProvider = dataProvider;
}
@Override
public void accumulateConfigLabels(LabelStack configLabels,
int columnPosition, int rowPosition) {
Material mat =
(Material) ((IRowDataProvider) dataProvider).getRowObject(rowPosition);
if(mat.getType().equals("Composite")&& columnPosition == 2) {
configLabels.addLabel(StackingTable.TEST);
//When a material of type composite,
//the code reachs this point, i.e. the label is added to the labelStack
System.out.println(configLabels.getLabels().get(1).toString() +
"\t" + columnPosition + "\t" + rowPosition);
}
}
}