Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Patrik Suzzi is currently offline Patrik SuzziFriend
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.

index.php/fa/39798/0/

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 #1837138 is a reply to message #1837123] Fri, 22 January 2021 15:15 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
The row header is underneath the same as the layers in the body. So if you want additional columns in the row header you need a custom data provider. As you already have a custom row header data provider it should be simple.

The special thing is the mapping of rows between the two layer stacks in a composition, which is done by dimensional dependency.

But why do you need an additional column in the row header? Wouldn't it be sufficient to decorate the single column?
Re: NatTable add header row cell [message #1837159 is a reply to message #1837138] Sat, 23 January 2021 00:06 Go to previous messageGo to next message
Patrik Suzzi is currently offline Patrik SuzziFriend
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

index.php/fa/39809/0/


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

Re: NatTable add header row cell [message #1837164 is a reply to message #1837159] Sat, 23 January 2021 06:44 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Interesting that you refer to the stackoverflow and the forum, but it seems you have not found our getting started tutorial

https://www.vogella.com/tutorials/NatTable/article.html

I think the configuration you posted should work. But probably the default configuration of the headers override your configuration. You could try to set your configuration after NatTable#configure() directly on the NatTable ConfigRegistry that you can access via getter. If you see that it works, either create a custom style configuration that replaces the default or even use a theme configuration.
Previous Topic:Hierarchical Nat table
Next Topic:Multi Cell Editor
Goto Forum:
  


Current Time: Wed Apr 24 23:30:45 GMT 2024

Powered by FUDForum. Page generated in 0.03327 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top