use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class NatTableBuilder method configureSorting.
protected void configureSorting() {
ColumnOverrideLabelAccumulator columnHeaderLabelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderLayer.getDataLayer());
columnHeaderLayer.addLabelAccumulator(columnHeaderLabelAccumulator);
for (int colIndex = 0; colIndex < columns.length; colIndex++) {
String columnHeaderLabel = COLUMN_HEADER_COLUMN_LABEL_PREFIX + colIndex;
// Register an accumulator on the Column Header layer (since it
// triggers sort)
columnHeaderLabelAccumulator.registerColumnOverrides(colIndex, columnHeaderLabel);
if (columns[colIndex].isSortable) {
Comparator<?> comparator = columns[colIndex].comparator;
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, comparator, DisplayMode.NORMAL, columnHeaderLabel);
} else {
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new NullComparator(), DisplayMode.NORMAL, columnHeaderLabel);
}
}
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class SortableGridExample method getCustomComparatorConfiguration.
/**
* NOTE: The labels for the the custom comparators must go on the
* columnHeaderDataLayer - since, the SortHeaderLayer will resolve cell
* labels with respect to its underlying layer i.e columnHeaderDataLayer
*/
private IConfiguration getCustomComparatorConfiguration(final AbstractLayer columnHeaderDataLayer) {
return new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
// Add label accumulator
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);
// Register labels
labelAccumulator.registerColumnOverrides(RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.RATING_PROP_NAME), CUSTOM_COMPARATOR_LABEL);
labelAccumulator.registerColumnOverrides(RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.ASK_PRICE_PROP_NAME), NO_SORT_LABEL);
// Register custom comparator
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, getCustomComparator(), DisplayMode.NORMAL, CUSTOM_COMPARATOR_LABEL);
// Register null comparator to disable sort
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new NullComparator(), DisplayMode.NORMAL, NO_SORT_LABEL);
}
};
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class StaticFilterGridExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
IConfigRegistry configRegistry = new ConfigRegistry();
StaticFilterExampleGridLayer underlyingLayer = new StaticFilterExampleGridLayer(configRegistry);
DataLayer bodyDataLayer = underlyingLayer.getBodyDataLayer();
IDataProvider dataProvider = underlyingLayer.getBodyDataProvider();
// NOTE: Register the accumulator on the body data layer.
// This ensures that the labels are bound to the column index and are
// unaffected by column order.
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
NatTable natTable = new NatTable(parent, underlyingLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
// natTable.addConfiguration(new DebugMenuConfiguration(natTable));
natTable.addConfiguration(new FilterRowCustomConfiguration());
natTable.addConfiguration(EditableGridExample.editableGridConfiguration(columnLabelAccumulator, dataProvider));
natTable.setConfigRegistry(configRegistry);
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class DynamicColumnHeaderHeightExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
IConfigRegistry configRegistry = new ConfigRegistry();
// Underlying data source
EventList<RowDataFixture> eventList = GlazedLists.eventList(RowDataListFixture.getList(200));
FilterList<RowDataFixture> filterList = new FilterList<>(eventList);
String[] propertyNames = RowDataListFixture.getPropertyNames();
Map<String, String> propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
// Body
IColumnPropertyAccessor<RowDataFixture> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
ListDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(filterList, columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnGroupBodyLayerStack bodyLayer = new ColumnGroupBodyLayerStack(bodyDataLayer, this.columnGroupModel);
ColumnOverrideLabelAccumulator bodyLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(bodyLabelAccumulator);
bodyLabelAccumulator.registerColumnOverrides(RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PRICING_TYPE_PROP_NAME), "PRICING_TYPE_PROP_NAME");
// Column header
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
this.columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(this.columnHeaderLayer, bodyLayer.getSelectionLayer(), this.columnGroupModel);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Group 1", 1, 2);
// calculate the height of the column header area dependent if column
// groups exist or not
columnGroupHeaderLayer.setCalculateHeight(true);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
final FilterRowHeaderComposite<RowDataFixture> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(filterList, columnPropertyAccessor, configRegistry), columnGroupHeaderLayer, columnHeaderDataProvider, configRegistry);
filterRowHeaderLayer.setFilterRowVisible(false);
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);
// Register labels
labelAccumulator.registerColumnOverrides(RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.RATING_PROP_NAME), "CUSTOM_COMPARATOR_LABEL");
// Row header
final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
// Corner
final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(bodyLayer, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
// Register create column group command handler
// Register column chooser
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(bodyLayer.getSelectionLayer(), bodyLayer.getColumnHideShowLayer(), this.columnHeaderLayer, columnHeaderDataLayer, columnGroupHeaderLayer, this.columnGroupModel);
bodyLayer.registerCommandHandler(columnChooserCommandHandler);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable).withColumnChooserMenuItem();
}
});
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, new HSSFExcelExporter());
}
});
natTable.addConfiguration(new FilterRowCustomConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
// add button
Button button = new Button(parent, SWT.NONE);
button.setText("Switch FilterRow visibility");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
filterRowHeaderLayer.setFilterRowVisible(!filterRowHeaderLayer.isFilterRowVisible());
}
});
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class TableDecorationConfiguration method createNatTable.
private void createNatTable(Composite parent, boolean paintDecorationDependent) {
String[] propertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber", "columnSixNumber", "columnSevenNumber", "columnEightNumber" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("columnOneNumber", "C 1");
propertyToLabelMap.put("columnTwoNumber", "C 2");
propertyToLabelMap.put("columnThreeNumber", "C 3");
propertyToLabelMap.put("columnFourNumber", "C 4");
propertyToLabelMap.put("columnFiveNumber", "C 5");
propertyToLabelMap.put("columnSixNumber", "C 6");
propertyToLabelMap.put("columnSevenNumber", "C 7");
propertyToLabelMap.put("columnEightNumber", "C 8");
DefaultGridLayer gridLayer = new DefaultGridLayer(createNumberValuesList(), propertyNames, propertyToLabelMap);
DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
bodyDataLayer.setDefaultRowHeight(40);
bodyDataLayer.setDefaultColumnWidth(40);
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new TableDecorationConfiguration(paintDecorationDependent));
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
}
Aggregations