Alternative CONSTRAINED_RESIZE_POLICY for Tree/TableView
Andy Goryachev
andy.goryachev at oracle.com
Fri Oct 7 15:55:21 UTC 2022
Dear colleagues:
I would like to propose a replacement for the current constrained column resize policy implementation in Tree/TableView and related public API changes. Please refer to the main ticket https://bugs.openjdk.org/browse/JDK-8293119 and a draft PR https://github.com/openjdk/jfx/pull/897 for more details.
To illustrate behavior of the new policies, please check out a tester app, ATableViewResizeTester, located in tests/manual/controls. In addition, you can compare the new policies against the old CONSTRAINED_RESIZE_POLICY if you switch to a https://github.com/andy-goryachev-oracle/jfx/tree/8293119.constrained.demo branch, where the old policy has not yet been replaced with the new alternative.
Your comments, suggestions, and especially any behavioral issues you might see with the tester will be greatly appreciated!
Thank you in advance,
-andy
Problem
The existing constrained column resize policy (Tree/TableView.CONSTRAINED_RESIZE_POLICY) has a number of issues most of which are listed in detail in ☂ JDK-8292810<https://bugs.openjdk.org/browse/JDK-8292810>. The current implementation fails to honor constraints, fails with empty tree/table, fails with multiple tables, shows/flickers the horizontal scroll bar, shows weird behavior when manually resizing columns in the presence of constraints; but the main issue is that the user simply cannot create a custom column resize policy with setColumnResizePolicy() due to absence of public APIs that provide the target width or allow for changing the column widths.
Proposed Solution
1. Introduce a ConstrainedColumnResizeBase class as a base class for any constrained resize policy. The main purpose - turn off the horizontal scroll bar and provide a "constrained-resize" pseudostyle via its toString() method.
2. Provide a new implementation via ConstrainedColumnResize class. The new implementation supports several resizing modes - some similar to JTable resize modes, and two new modes that try to behave as the current resize policy (minus the bugs).
3. The current CONSTRAINED_RESIZE_POLICY constants in Tree/TableView is marked as deprecated.
4. The new resize policies are made available to the users via new constants (see below).
5. The current CONSTRAINED_RESIZE_POLICY becomes an alias for CONSTRAINED_RESIZE_POLICY_FLEX_TAIL, preserving binary compatibility and providing a similar user experience.
6. Add code to dynamically remove "constrained-resize" pseudostyle when tree/table width exceeds the sum of maximum widths of all the columns, resulting in an empty space appearing to the right of the columns. This in turn requires the vertical line at the right border of the last column to be painted.
Resize Modes
/**
* A policy that tries to adjust other columns in order to fit the table width.
* <p>
* When column constraints make it impossible to fit all the columns into the allowed area,
* the columns are either clipped, or an empty space appears. This policy disables the horizontal
* scroll bar.
*/
public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_ALL_COLUMNS
/**
* A policy that tries to adjust last column in order to fit the table width.
* <p>
* When column constraints make it impossible to fit all the columns into the allowed area,
* the columns are either clipped, or an empty space appears. This policy disables the horizontal
* scroll bar.
*/
public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_LAST_COLUMN
/**
* A policy adjusts the next column in the opposite way in order to fit the table width.
* <p>
* When column constraints make it impossible to fit all the columns into the allowed area,
* the columns are either clipped, or an empty space appears. This policy disables the horizontal
* scroll bar.
*/
public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_NEXT_COLUMN
/**
* A policy that tries to adjust subsequent columns in order to fit the table width.
* <p>
* When column constraints make it impossible to fit all the columns into the allowed area,
* the columns are either clipped, or an empty space appears. This policy disables the horizontal
* scroll bar.
*/
public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_SUBSEQUENT_COLUMNS
/**
* A policy that tries to adjust columns, starting with the next one, in order to fit the table width.
* <p>
* When column constraints make it impossible to fit all the columns into the allowed area,
* the columns are either clipped, or an empty space appears. This policy disables the horizontal
* scroll bar.
*/
public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_FLEX_HEAD
/**
* A policy that tries to adjust columns, starting with the last one, in order to fit the table width.
* <p>
* When column constraints make it impossible to fit all the columns into the allowed area,
* the columns are either clipped, or an empty space appears. This policy disables the horizontal
* scroll bar.
*/
public static final Callback<TableView.ResizeFeatures, Boolean> CONSTRAINED_RESIZE_POLICY_FLEX_TAIL
Public API Changes
Please refer to a CSR https://bugs.openjdk.org/browse/JDK-8294398 for more details; here is a brief summary:
ResizeFeaturesBase class:
- added getContentWidth()
- added setColumnWidth(TableColumnBase, double);
new abstract ConstrainedColumnResizeBase class:
- marker class, disables the horizontal scroll bar
Tree/TableView classes:
- added new policy constants (see above)
- @Deprecated(since="20") CONSTRAINED_RESIZE_POLICY = CONSTRAINED_RESIZE_POLICY_FLEX_TAIL;
Testing
I have no idea how to unit test new policies (see ResizeHelperTest). I wanted to exercise all the combinations of { policy | table width | number of columns (0,1,5) | constraints (min,pref,max) }, but this test takes too much time even on fast machine.
The other alternative is to test only a few basic scenarios, but I feel it would be rather incomplete. A tester app seems to be the best solution so far, but it is certainly cannot be automated.
[Graphical user interface, application, table, Excel Description automatically generated]
<eom>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20221007/82b71623/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 258731 bytes
Desc: image001.png
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20221007/82b71623/image001-0001.png>
More information about the openjfx-dev
mailing list