Home » Eclipse Projects » NatTable » Automatically Wrap the text in a Gridlayer(Wrap Text in Grid Layer)
Automatically Wrap the text in a Gridlayer [message #1827580] |
Mon, 18 May 2020 16:36 |
Palraj Jayaraj Messages: 15 Registered: June 2015 |
Junior Member |
|
|
Hello,
I'm a newbie in eclipse Nattable technology. I have started learning and using it for the past 1 week. I'm using a GridLayer which has the datalayer, row, column and corner Layer. I just have 2 columns in the Grid and Sometimes one of the column's data exceeds the Column Width. In that case, I tried to wrap the text using the painter AutomaticRowHeightTextPainter. Unfortunately, It was still displaying in single line. Hence, I consulted the Nattable example AutomaticRowHeightExample and it seems to work fine if there is only the data layer.
When I try to port the same solution to the Grid Layer, it does not work as I expected. When I debugged, in (AutomaticRowHeightTextPainter) TextPainter.paintCell API, the lines are being correctly split into 3 lines. But, when the file Grid is rendered, The Row has been resized to accommodate 3 lines, but, only one line is visible and somehow, when I click on that cell, it seems that the 2nd and 3rd line are hiding under the first line in the cell. (How do I know, there are some broken characters visible from the 2 line).
Strangely, I started seeing blank links for the first column data too.
Please, let me know What I'm doing wrong or a place to start debug and find it out the real problem.
I always return "Column1 Data" for first column Column and "test text that needs to be printed to reproduce the multi line wrapping issues, that I'm yet to solve in the GridLayer, that I started to use today morning :)" for the second column.
I have attached both Source ( Configuration and GridLayer implementation) and the images for reference.
Grid Layer
public class ExampleTableGridLayer extends GridLayer {
private EList<EObject> objects;
public ExampleTableGridLayer(EList<EObject> objects) {
super(false);
this.objects = objects;
initialize();
}
/** initializes this All layers of Grid Layer. */
private void initialize() {
EventList<EObject> observableList = GlazedLists.eventList(objects);
// data area
IDataProvider dataProvider = new ListDataProvider<>(observableList new ExampleColumnPropertyAccessor());
DataLayer dataLayer = new DataLayer(dataProvider);
dataLayer.setColumnPercentageSizing(true);
SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
// other areas
// Row header
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(dataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, dataLayer, selectionLayer);
// Column Header
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(ExampleNatTable.COLUMNS);
DefaultColumnHeaderDataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, dataLayer, selectionLayer);
// Corner
DefaultCornerDataProvider cornerDataProvider =
new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
CornerLayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
// set the layers to GRID layer
setBodyLayer(selectionLayer);
setRowHeaderLayer(rowHeaderLayer);
setColumnHeaderLayer(columnHeaderLayer);
setCornerLayer(cornerLayer);
}
Overriden Configuration:
public class ExampleNatTableRegistryConfiguration extends DefaultNatTableStyleConfiguration {
/** Creates a Configuration Spec */
public ExampleNatTableRegistryConfiguration() {
CellPainterDecorator interiorPainter =
new CellPainterDecorator(new AutomaticRowHeightTextPainter(2), CellEdgeEnum.LEFT, new ImagePainter());
interiorPainter.setPaintBackground(false);
this.cellPainter = interiorPainter;
}
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
super.configureRegistry(configRegistry);
// align the fields to the left
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL);
}
}
Thank you in advance,
Paul
[Updated on: Mon, 18 May 2020 16:42] Report message to a moderator
|
|
|
Re: Automatically Wrap the text in a Gridlayer [message #1827598 is a reply to message #1827580] |
Tue, 19 May 2020 04:59 |
Dirk Fauth Messages: 47 Registered: March 2020 |
Member |
|
|
The issue you are facing is that the AutomaticRowHeightTextPainter is calculating the row height per cell. You have configured it for both columns, so one column will tell it to increase, the other says to decrease. So actually the rendering and state changing of row heights is not in sync at some time. If only the second column is the one that could have multiple lines, then you should only configure the second column with the AutomaticRowHeightTextPainter, not the whole table.
BTW, you are asking for two separate features:
1. line wrapping, which can actually also be done by the TextPainter (check the API)
2. automatic row heights based on the content
For the automatic row height based on row content, there are several options, as this is not a simple task because of the increase and decrease. If only an increase is required and no automatic decrease, then the TextPainter can be configured to perform a resize based on the content (remember to also enable the line wrapping, again check the API of TextPainter).
If also a decrease is required to always only have row heights that match the content and not more, there are several options as described in the FAQ or in the new & noteworthy of 1.6 as we added the AutoResizeRowPaintListener to serve the need of automatic row resizing on paint.
https://www.eclipse.org/nattable/documentation.php?page=faq
https://www.eclipse.org/nattable/nandn/nandn_160.php
|
|
|
Re: Automatically Wrap the text in a Gridlayer [message #1827610 is a reply to message #1827598] |
Tue, 19 May 2020 09:57 |
Palraj Jayaraj Messages: 15 Registered: June 2015 |
Junior Member |
|
|
Hello Dirk,
As you have mentioned that the AutomaticRowHeightTextPainter was being applied to both the Column, is the real problem. Now, I have updated the code to invoke the Painter from my second column, which is the column, which might have data line, which needs to be wrapped into multiple lines.
Thank you for your reply and Have a good day :)
In case, anybody wondering how the issue is fixed
1. Set a ColumnOverrideLabelAccumulator to the DataLayer.
2. Added label for each column index to the accumulator.
3. Updated the configuration to return the AutomaticRowHeightTextPainter for the second column.
public class ExampleNatTableRegistryConfiguration extends DefaultNatTableStyleConfiguration {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
super.configureRegistry(configRegistry);
// align the fields to the left
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new AutomaticRowHeightTextPainter(2),
DisplayMode.NORMAL, CommandNatTable.COLUMN_LABELS[1]);// only for the second column.
}
}
Thanks,
Paul
|
|
|
Goto Forum:
Current Time: Thu Mar 28 14:04:11 GMT 2024
Powered by FUDForum. Page generated in 0.02845 seconds
|