use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry 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.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class Creating_a_summary_row method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
this.myDataProvider = new IDataProvider() {
@Override
public int getColumnCount() {
return 4;
}
@Override
public int getRowCount() {
return 10;
}
@Override
public Object getDataValue(int columnIndex, int rowIndex) {
if (columnIndex >= getColumnCount() || rowIndex >= getRowCount()) {
throw new RuntimeException("Data value requested is out of bounds");
}
return (columnIndex % 2 == 0) ? 10 : "Apple";
}
@Override
public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
}
};
IConfigRegistry configRegistry = new ConfigRegistry();
IUniqueIndexLayer dataLayer = new DataLayer(this.myDataProvider);
// Plug in the SummaryRowLayer
IUniqueIndexLayer summaryRowLayer = new SummaryRowLayer(dataLayer, configRegistry, false);
ViewportLayer viewportLayer = new ViewportLayer(summaryRowLayer);
NatTable natTable = new NatTable(parent, viewportLayer, false);
// Configure custom summary formula for a column
natTable.addConfiguration(new MySummaryRowConfig(this.myDataProvider));
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class Applying_style_to_a_cell method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
SelectionExampleGridLayer gridLayer = new SelectionExampleGridLayer();
NatTable natTable = new NatTable(parent, gridLayer, false);
DataLayer bodyDataLayer = gridLayer.getBodyDataLayer();
// Label accumulator - adds labels to all cells with the given data
// value
CellOverrideLabelAccumulator<RowDataFixture> cellLabelAccumulator = new CellOverrideLabelAccumulator<>(gridLayer.getBodyDataProvider());
cellLabelAccumulator.registerOverride("AAA", 2, CELL_LABEL);
// Register your cell style, against the label applied to the cell
// Other configuration which can be added (apart from style) include
// CellConfigAttributes, EditConfigAttributes, SortConfigAttributes etc.
IConfigRegistry configRegistry = new ConfigRegistry();
addColumnHighlight(configRegistry);
// Register label accumulator
bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);
gridLayer.getSelectionLayer().addConfiguration(new DefaultSelectionLayerConfiguration());
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.setConfigRegistry(configRegistry);
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class NatTableBuilder method setupLayerStacks.
public NatTable setupLayerStacks() {
IColumnPropertyAccessor<T> columnAccessor = new ColumnAccessor<T>(columns);
configRegistry = new ConfigRegistry();
SortedList<T> sortedRows = new SortedList<T>(eventList, null);
filterList = new FilterList<T>(sortedRows);
setUpColumnGroupModel();
setUpColumnCategoriesModel();
// Body
bodyLayer = new BodyLayerStack<T>(tableModel, filterList);
// Column header
columnHeaderLayer = new ColumnHeaderLayerStack<T>(sortedRows, filterList, tableModel, bodyLayer, columnAccessor, configRegistry);
// Row header
rowHeaderLayer = new RowHeaderLayerStack<T>(bodyLayer, tableModel);
// Corner
cornerLayer = new CornerLayerStack<T>(columnHeaderLayer, rowHeaderLayer);
// Grid
gridLayer = new GridLayer(bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer, false);
natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.setBackground(tableStyle.tableBgColor);
// Configuration
natTable.addConfiguration(new TableStyleConfiguration(tableStyle));
configureColumnProperties();
configureSorting();
configureEditing();
configureFiltering();
configureColumnChooser();
configureCategoriesBasedColumnChooser();
configureColumnStyleCustomization();
configureGridLayer();
configureSelectionStyle();
configureColumnHeaderRightClickMenu();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class FilterRowDataLayerTest method setup.
@Before
public void setup() {
this.columnHeaderLayer = new DataLayerFixture(10, 2, 100, 50);
this.configRegistry = new ConfigRegistry();
new DefaultNatTableStyleConfiguration().configureRegistry(this.configRegistry);
new DefaultFilterRowConfiguration().configureRegistry(this.configRegistry);
this.filterList = new FilterList<RowDataFixture>(GlazedLists.eventList(RowDataListFixture.getList()));
this.layerUnderTest = new FilterRowDataLayer<RowDataFixture>(new DefaultGlazedListsFilterStrategy<RowDataFixture>(this.filterList, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()), this.configRegistry), this.columnHeaderLayer, this.columnHeaderLayer.getDataProvider(), this.configRegistry);
this.listener = new LayerListenerFixture();
this.layerUnderTest.addLayerListener(this.listener);
}
Aggregations