|
Re: Issue with automatic cell resize with TextPainter [message #1778431 is a reply to message #1778429] |
Thu, 14 December 2017 08:53 |
Dirk Fauth Messages: 2903 Registered: July 2012 |
Senior Member |
|
|
This is the expected behavior. There is no automatic shrinking on a cell base, as that would lead to collisions if multiple cells are configured for auto resizing. For example, if the first cell says it needs more space and triggers resizing to increase the height, the next cell might need less space and would reduce the height again.
If you have only one column that should tell a row about the needed height, you can use the AutomaticRowHeightTextPainter. But as said, if you use it for multiple columns, the effect would be quite nasty to endless row resizing.
With 1.6 that is currently in development there will be also another option that calculates required height based on the whole row. Actually an automatic auto-row-resizing. We introduced the AutoResizeRowPaintListener. Adding that as PaintListener to the NatTable it will auto resize the rows in the viewport automatically. But dependent on the layer composition and configuration, this can lead to rendering performance issues. Auto-resizing for the whole row or column is always a pretty heavy calculation, especially when wrapping is enabled, as the necessary height needs to be calculated on demand based on the available space using the GC and font metrics. We have seen that it is working pretty fine for small and simple tables, but for bigger tables, complex compositions and spanning the rendering performance is not very good. You can test it with a current 1.6 SNAPSHOT to see if it fits your needs.
|
|
|
|
|
|
|
Re: Issue with automatic cell resize with TextPainter [message #1779155 is a reply to message #1779141] |
Wed, 03 January 2018 09:50 |
Mike Rumpf Messages: 47 Registered: July 2009 |
Member |
|
|
I managed to create a simple example to reproduce the problem. Maybe that helps.
public final class SamplePart3 {
@Inject
private MDirtyable dirty;
private NatTable table;
/**
* @param parent
* Parent.
*/
@PostConstruct
public void createComposite(final Composite parent) {
parent.setLayout(new GridLayout(1, false));
table = buildTable(parent);
}
public NatTable buildTable(final Composite parent) {
final Person homer = new Person("Homer", "Simpson", "Sargeant", 1234567890L);
final Person smithers = new Person("Waylon", "Smithers", "Admiral", 6666666666L);
final Person bart = new Person("Bart", "Smithers", "General", 9125798342L);
final Person nelson = new Person("Nelson", "Muntz", "Private", 0000000001L);
final Person frink = new Person("John", "Frink", "Lieutenant", 3141592654L);
final List myList = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
myList.add(homer);
myList.add(smithers);
myList.add(bart);
myList.add(nelson);
myList.add(frink);
}
final String[] propertyNames = { "firstName", "lastName", "rank", "serialNumber" };
final IColumnPropertyAccessor columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
final IRowDataProvider bodyDataProvider = new ListDataProvider<>(myList, columnPropertyAccessor);
final DefaultGridLayer gridLayer =
new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames));
final NatTable natTable = new NatTable(parent, gridLayer, false);
final ColumnOverrideLabelAccumulator cellLabelAccumulator =
new ColumnOverrideLabelAccumulator(gridLayer.getBodyLayer());
cellLabelAccumulator.registerColumnOverrides(2, "wrap");
gridLayer.getBodyLayer().setConfigLabelAccumulator(cellLabelAccumulator);
final ISelectionProvider selectionProvider =
new RowSelectionProvider<>(gridLayer.getBodyLayer().getSelectionLayer(), bodyDataProvider, false);
selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
System.out.println("Selection changed:");
final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
@SuppressWarnings("rawtypes")
final Iterator it = selection.iterator();
while (it.hasNext()) {
System.out.println(" " + it.next());
}
}
});
// Programmatically select a few rows
selectionProvider.setSelection(new StructuredSelection(new Person[] { homer, smithers, nelson }));
// I changed my mind. Select a few other rows
selectionProvider.setSelection(new StructuredSelection(new Person[] { bart, frink }));
natTable.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
final IConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new AutomaticRowHeightTextPainter(5), //
DisplayMode.NORMAL, "wrap");
natTable.setConfigRegistry(configRegistry);
natTable.configure();
natTable.setTheme(new DefaultNatTableThemeConfiguration());
return natTable;
}
public class Person {
private final String firstName;
private final String lastName;
private final String rank;
private final long serialNumber;
public Person(final String firstName, final String lastName, final String rank, final long serialNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.rank = rank;
this.serialNumber = serialNumber;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getRank() {
return rank;
}
public long getSerialNumber() {
return serialNumber;
}
@Override
public String toString() {
return firstName + " " + lastName + " " + rank + " " + serialNumber;
}
}
@Focus
public void setFocus() {
table.setFocus();
}
@Persist
public void save() {
dirty.setDirty(false);
}
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04991 seconds