Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Issue with automatic cell resize with TextPainter(Cell height isn't reduced to original height when horizontal space is available)
Issue with automatic cell resize with TextPainter [message #1778429] Thu, 14 December 2017 08:42 Go to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Hello,

I have an issue with the nattable Text Painter. We use it with text wrap and automatic calculation of the cell height:

defaultCellPainter = new TextPainter(true, true, 5, true);


Everything works fine if the cell width is reduced. The row height gets bigger for the multiline text to fit in. However if you extend the cell width to its original value the row height will remain the same (leaving a vertical gap of unused space)

You will also see this behaviour in the Nattable Examples Application (Text Painter Example => configuration 4) if you increase/decrease the cell width by dragging the column header.

Is this expected behaviour or a bug?

Thanks.




Re: Issue with automatic cell resize with TextPainter [message #1778431 is a reply to message #1778429] Thu, 14 December 2017 08:53 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
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 #1778432 is a reply to message #1778431] Thu, 14 December 2017 08:59 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Thank you for the information. I will have a look into your suggestions.

Regards,
Mike
Re: Issue with automatic cell resize with TextPainter [message #1779092 is a reply to message #1778432] Tue, 02 January 2018 15:33 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
I encountered an issue with the AutomaticRowHeightTextPainter: Once I select a row (before that everything works fine) the scrolling does show some ugly side effects (though I use the AutomaticRowHeightTextPainter only for one column).
Re: Issue with automatic cell resize with TextPainter [message #1779114 is a reply to message #1779092] Tue, 02 January 2018 22:35 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
What kind of effect?
Re: Issue with automatic cell resize with TextPainter [message #1779141 is a reply to message #1779114] Wed, 03 January 2018 07:55 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Actually the scrolling is not working anymore, with lots of flickering. The selected column stays selected. Sometime the scrollbar jumps to the top irregularily. If I replace the AutomaticRowHeightTextPainter with the standard TextPainter everything is back to correct behaviour.
Re: Issue with automatic cell resize with TextPainter [message #1779155 is a reply to message #1779141] Wed, 03 January 2018 09:50 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
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);
    }
Re: Issue with automatic cell resize with TextPainter [message #1779201 is a reply to message #1779155] Wed, 03 January 2018 18:32 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Which version of NatTable do you use?
Do you use a scaling > 100% in your display settings?
Re: Issue with automatic cell resize with TextPainter [message #1779218 is a reply to message #1779201] Thu, 04 January 2018 07:17 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Nattable version is 1.5 and my display setting is 125%.
Re: Issue with automatic cell resize with TextPainter [message #1779219 is a reply to message #1779218] Thu, 04 January 2018 07:32 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
IIRC we worked on several scaling related issues the last months. Could you please test with the latest SNAPSHOT if the problem still exists there?
Re: Issue with automatic cell resize with TextPainter [message #1779232 is a reply to message #1779219] Thu, 04 January 2018 08:53 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Ok, I will try and come back to you later.
Re: Issue with automatic cell resize with TextPainter [message #1779251 is a reply to message #1779232] Thu, 04 January 2018 12:49 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Unfortunately the problem still exists with the latest snapshot release (1.6)).
Re: Issue with automatic cell resize with TextPainter [message #1779581 is a reply to message #1779251] Tue, 09 January 2018 21:37 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Which Eclipse Platform do you use? I am not able to reproduce the issue with the latest SNAPSHOT build in the development environment of NatTable.
Re: Issue with automatic cell resize with TextPainter [message #1779758 is a reply to message #1779581] Fri, 12 January 2018 09:49 Go to previous messageGo to next message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Our platform is Eclipse Oxygen (IDE and target platform).
Re: Issue with automatic cell resize with TextPainter [message #1779770 is a reply to message #1779758] Fri, 12 January 2018 11:29 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I created a fresh workspace, a new E4 RCP Project with the attached example. I created a fresh target definition based on Eclipse Oxygen and the latest NatTable 1.6 SNAPSHOT build. Then I change my scaling to 100% on my Windows 7 machine and started the application. I selected and deselected several columns.

I can not reproduce the issue. Have you double checked that the NatTable 1.6 SNAPSHOT is included in your product?
Re: Issue with automatic cell resize with TextPainter [message #1780742 is a reply to message #1779770] Fri, 26 January 2018 14:30 Go to previous message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Hello Dirk,

I just retested the issue and could not reproduce it either with the 1.6 snapshot.

Regards,
Mike

Previous Topic:Nattable row position after scrolling
Next Topic:how can get the hidden cell
Goto Forum:
  


Current Time: Fri Mar 29 00:07:05 GMT 2024

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

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

Back to the top