use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class ConfigLabelProviderTest method testProvidedGridLabelsFilterHeader.
@Test
public void testProvidedGridLabelsFilterHeader() {
SelectionLayer selectionLayer = new SelectionLayer(this.bodyDataLayer);
GridLayer grid = new GridLayer(selectionLayer, new FilterRowHeaderComposite<Person>(new IFilterStrategy<Person>() {
@Override
public void applyFilter(Map<Integer, Object> filterIndexToObjectMap) {
}
}, new SortHeaderLayer<Person>(new ColumnHeaderLayer(this.columnHeaderDataLayer, this.bodyDataLayer, selectionLayer), new SortModelFixture()), this.columnHeaderDataLayer.getDataProvider(), new ConfigRegistry()), this.rowHeaderDataLayer, this.cornerDataLayer);
Collection<String> labels = grid.getProvidedLabels();
assertEquals(26, labels.size());
assertTrue(labels.contains(GridRegion.CORNER));
assertTrue(labels.contains(GridRegion.COLUMN_HEADER));
assertTrue(labels.contains(GridRegion.ROW_HEADER));
assertTrue(labels.contains(GridRegion.BODY));
assertTrue(labels.contains(AlternatingRowConfigLabelAccumulator.ODD_ROW_CONFIG_TYPE));
assertTrue(labels.contains(AlternatingRowConfigLabelAccumulator.EVEN_ROW_CONFIG_TYPE));
assertTrue(labels.contains(SelectionStyleLabels.SELECTION_ANCHOR_STYLE));
assertTrue(labels.contains(SelectionStyleLabels.SELECTION_ANCHOR_GRID_LINE_STYLE));
assertTrue(labels.contains(SelectionStyleLabels.COLUMN_FULLY_SELECTED_STYLE));
assertTrue(labels.contains(SelectionStyleLabels.ROW_FULLY_SELECTED_STYLE));
assertTrue(labels.contains(SelectionStyleLabels.FILL_HANDLE_CELL));
assertTrue(labels.contains(SelectionStyleLabels.FILL_HANDLE_REGION));
assertTrue(labels.contains(SelectionStyleLabels.COPY_BORDER_STYLE));
assertTrue(labels.contains(DefaultSortConfiguration.SORT_CONFIG_TYPE));
assertTrue(labels.contains(DefaultSortConfiguration.SORT_UP_CONFIG_TYPE));
assertTrue(labels.contains(DefaultSortConfiguration.SORT_DOWN_CONFIG_TYPE));
assertTrue(labels.contains(DefaultSortConfiguration.SORT_SEQ_CONFIG_TYPE + "0"));
assertTrue(labels.contains(DefaultSortConfiguration.SORT_SEQ_CONFIG_TYPE + "1"));
assertTrue(labels.contains(DefaultSortConfiguration.SORT_SEQ_CONFIG_TYPE + "2"));
assertTrue(labels.contains("columnHeader"));
assertTrue(labels.contains(GridRegion.FILTER_ROW));
assertTrue(labels.contains(FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + "0"));
assertTrue(labels.contains(FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + "1"));
assertTrue(labels.contains(FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + "2"));
assertTrue(labels.contains(FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + "3"));
assertTrue(labels.contains(FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + "4"));
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class BoxingStyleTest method retrievedCellShouldBeConvertedUsingTheDisplayConverter.
@Test
public void retrievedCellShouldBeConvertedUsingTheDisplayConverter() throws Exception {
IConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DisplayConverter() {
@Override
public Object canonicalToDisplayValue(Object canonicalValue) {
if (canonicalValue == null) {
return null;
} else {
return canonicalValue.toString().equals("MN") ? "Manual" : "Automatic";
}
}
@Override
public Object displayToCanonicalValue(Object displayValue) {
return displayValue.toString().equals("Manual") ? new PricingTypeBean("MN") : new PricingTypeBean("AT");
}
});
NatTableFixture natTableFixture = new NatTableFixture(new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap()), false);
natTableFixture.setConfigRegistry(configRegistry);
natTableFixture.configure();
int columnIndex = RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PRICING_TYPE_PROP_NAME);
Object dataValue = natTableFixture.getDataValueByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
// Verify displayed value
ILayerCell cell = natTableFixture.getCellByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
TextPainter cellPainter = new TextPainter();
Assert.assertEquals("Automatic", cellPainter.convertDataType(cell, configRegistry));
// Assert that the display value is converted to an Object
Assert.assertTrue(dataValue instanceof PricingTypeBean);
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class CellStyleProxyTest method proxyShouldRetreiveConfigAttributeUsingTheDisplayModeOrdering.
@Test
public void proxyShouldRetreiveConfigAttributeUsingTheDisplayModeOrdering() throws Exception {
ConfigRegistry configRegistry = new ConfigRegistry();
Style testCellStyle1 = new Style();
testCellStyle1.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.RIGHT);
Style testCellStyle2 = new Style();
testCellStyle2.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.CENTER);
testCellStyle2.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, VerticalAlignmentEnum.MIDDLE);
// NORMAL mode has an horizontal align attribute registered
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, testCellStyle1, DisplayMode.NORMAL, TEST_CONFIG_LABEL1);
// SELECT mode has a 'default' horizontal align attribute registered
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, testCellStyle2, DisplayMode.SELECT);
// The 'default' from SELECT gets picked up
StyleProxy cellStyleProxy = new CellStyleProxy(configRegistry, DisplayMode.SELECT, Arrays.asList(TEST_CONFIG_LABEL1));
HorizontalAlignmentEnum alignmentFromProxy = cellStyleProxy.getAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT);
Assert.assertEquals(HorizontalAlignmentEnum.CENTER, alignmentFromProxy);
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class _6032_GlazedListsFilterCustomTypesExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// create a new ConfigRegistry which will be needed for GlazedLists
// handling
ConfigRegistry configRegistry = new ConfigRegistry();
String[] propertyNames = { "name", "age", "money", "gender", "city" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("name", "Name");
propertyToLabelMap.put("age", "Age");
propertyToLabelMap.put("money", "Money");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("city", "City");
IColumnPropertyAccessor<MyRowObject> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
BodyLayerStack<MyRowObject> bodyLayerStack = new BodyLayerStack<>(createMyRowObjects(50), columnPropertyAccessor);
// add a label accumulator to be able to register converter
bodyLayerStack.getBodyDataLayer().setConfigLabelAccumulator(new ColumnLabelAccumulator());
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
FilterRowHeaderComposite<MyRowObject> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayerStack.getFilterList(), columnPropertyAccessor, configRegistry), columnHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(bodyLayerStack, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
NatTable natTable = new NatTable(parent, gridLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the
// DefaultNatTableStyleConfiguration and the ConfigRegistry manually
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add filter row configuration
natTable.addConfiguration(new FilterRowConfiguration());
natTable.addConfiguration(new MyRowObjectTableConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
return super.createCornerMenu(natTable).withStateManagerMenuItemProvider();
}
});
natTable.configure();
natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.config.ConfigRegistry in project nebula.widgets.nattable by eclipse.
the class _6033_GlazedListsStaticFilterExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// create a new ConfigRegistry which will be needed for GlazedLists
// handling
ConfigRegistry configRegistry = new ConfigRegistry();
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday", "address.street", "address.housenumber", "address.postalCode", "address.city" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
propertyToLabelMap.put("address.street", "Street");
propertyToLabelMap.put("address.housenumber", "Housenumber");
propertyToLabelMap.put("address.postalCode", "Postal Code");
propertyToLabelMap.put("address.city", "City");
IColumnPropertyAccessor<PersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
BodyLayerStack<PersonWithAddress> bodyLayerStack = new BodyLayerStack<>(PersonService.getPersonsWithAddress(50), columnPropertyAccessor);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
// add the ability to add static filters programmatically
DefaultGlazedListsStaticFilterStrategy<PersonWithAddress> filterStrategy = new DefaultGlazedListsStaticFilterStrategy<>(bodyLayerStack.getFilterList(), columnPropertyAccessor, configRegistry);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
FilterRowHeaderComposite<PersonWithAddress> filterRowHeaderLayer = new FilterRowHeaderComposite<>(filterStrategy, columnHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayerStack.getBodyDataProvider());
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(bodyLayerStack, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
NatTable natTable = new NatTable(parent, gridLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration and the ConfigRegistry
// manually
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add filter row configuration
natTable.addConfiguration(new FilterRowConfiguration());
natTable.addConfiguration(new StaticFilterHeaderMenu(natTable, filterStrategy));
natTable.configure();
return natTable;
}
Aggregations