Home » Eclipse Projects » NatTable » NatTable add header row cell (How can I add a header row cell with an image, that triggers a delete row action?)
NatTable add header row cell [message #1837123] |
Fri, 22 January 2021 12:22 |
Patrik Suzzi Messages: 2 Registered: February 2018 |
Junior Member |
|
|
Hi EveryBody,
I have a simple nattable, with row headers, and I need to add an additional row header cell, where I should put an image to trigger a "delete row" event.
So far, I did not find any example matching what I need, and I was not able to find any documentation sending me in the right direction.
In my research, I discovered that probably I need to use a CompositeLayer to hold both the current row header and another cell containing the image.
So my question is:
- is there any example of adding an additional cell to the column header ?
(or, similarly How should I proceed in adding an additional CompositeLayer with a cell containing an image to my RowHeaderLayer ? )
Thanks in advance for your time and consideration.
Best Regards,
- Patrik
Below, you can see how I currently structure my Nattable
@PostConstruct
public void createComposite(Composite parent) {
configRegistry = new ConfigRegistry();
// create the body layer stack
IDataProvider bodyDataProvider = new ListDataProvider<>(this.values, new MyColumnPropertyAccessor());
bodyDataLayer = new DataLayer(bodyDataProvider);
DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(bodyDataLayer);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new MyColumnHeaderDataProvider();
columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider),
bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
// create the row header layer stack
IDataProvider rowHeaderDataProvider = new MyRowHeaderDataProvider(bodyDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(rowHeaderDataProvider),
bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
rowHeaderLayer, columnHeaderLayer);
gridLayer = new GridLayer(bodyLayerStack, columnHeaderLayer, rowHeaderLayer, cornerLayer);
natTable = new NatTable(parent, gridLayer, false);
natTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.configure();
}
|
|
| |
Re: NatTable add header row cell [message #1837159 is a reply to message #1837138] |
Sat, 23 January 2021 00:06 |
Patrik Suzzi Messages: 2 Registered: February 2018 |
Junior Member |
|
|
Hi Dirk,
Since it would be simpler decorating the single header columns, I considered decorating them. But I realized it works only for body cells, and not for columns headers or row headers.
For instance, with the following configuration:
configRegistry = new ConfigRegistry();
// Register custom painter, paint icons on right
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER,
new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, new ImagePainter(deleteImage)),
DisplayMode.NORMAL, GridRegion.ROW_HEADER.toString());
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER,
new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, new ImagePainter(deleteImage)),
DisplayMode.NORMAL, GridRegion.COLUMN_HEADER.toString());
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER,
new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, new ImagePainter(deleteImage)),
DisplayMode.NORMAL, GridRegion.BODY.toString());
// the rest is unchanged ..
I get to see the Decorator only on the Body cells, as in the following image
After that, I did some more investigation to learn how to use a CellPainterDecorator. As explained in https://www.eclipse.org/nattable/documentation.php?page=styling , I need to
- register a label to the column header data layer (and not the body) so that I can style the column header
- create an AbstractConfigRegistry implementation and register my style (alignment and different image painter for my label)
So far, it is still not clear how to achieve the two points above, but I'll keep investigating. Any reference to examples of registering a label to the column header and creating an AbstractConfigRegistry with a custom painter would be really useful.
Best Regards,
- Patrik
References
- https://www.eclipse.org/forums/index.php/t/491100/
- https://www.eclipse.org/forums/index.php/t/830992/
- https://www.eclipse.org/nattable/documentation.php?page=styling > search CellPainterDecorator
- https://stackoverflow.com/questions/49624162/how-to-add-red-star-with-name-of-column-header-in-nattable
|
|
| |
Goto Forum:
Current Time: Wed Apr 24 23:30:45 GMT 2024
Powered by FUDForum. Page generated in 0.03327 seconds
|