-
Notifications
You must be signed in to change notification settings - Fork 542
8091429: ObservableList<E>#replaceRange(int from, int to, Collection<? extends E> col) #1937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back jhendrikx! A progress list of the required criteria for merging this PR into |
|
@hjohn This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 17 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
|
How about doing this through the SubList view? JavaFX's implementation already has a ObservableList<Integer> list = FXCollections.observableArrayList();
list.addAll(0, 1, 2, 3, 4, 5, 6);
list.addListener((ListChangeListener<Integer>) c -> System.out.println(c));
List<Integer> subList = list.subList(2, 4);
System.out.println(list);
System.out.println(subList);
subList.clear(); // equivalent to list.remove(2, 4);prints The issue is that it's a ObservableList<Integer> list = FXCollections.observableArrayList();
list.addAll(0, 1, 2, 3, 4, 5, 6);
list.addListener((ListChangeListener<Integer>) c -> System.out.println(c));
ObservableList<Integer> subList = list.subList(2, 4); // suggestion
subList.setAll(7, 8);I think that this would be more flexible/composable and result in a smaller API surface (current bulk methods would also be made redundant technically). |
This change would be neither source compatible nor binary compatible, so this probably rules it out. |
modules/javafx.base/src/main/java/javafx/collections/ObservableList.java
Outdated
Show resolved
Hide resolved
This is the first thing I tried, but we can't change the return type of I thought about just not allowing listeners on these sublists, but the required cast still is super annoying. So, since |
|
/reviewers 2 |
|
@kevinrushforth |
|
@kevinrushforth has indicated that a compatibility and specification (CSR) request is needed for this pull request. @hjohn please create a CSR request for issue JDK-8091429 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
|
With this modification, two lists can be kept in sync with each other with this minimal code, and with minimal notifications: |
|
I can review this. @hjohn If you're happy with the current |
@kevinrushforth Yeah, I think the name suggested by Michael captures the intent well, and offers the most flexible option for doing large element replacements. I've updated the JBS and PR. |
|
Looks like I'll need this change to write a test for replacing a range of elements in ListView. It seems that currently replacing a range of items will always clear the whole selection. Filed https://bugs.openjdk.org/browse/JDK-8371090 to track those problems. |
kevinrushforth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I left a question as to whether a couple additional tests might be useful.
modules/javafx.base/src/test/java/test/javafx/collections/ModifiableObservableListBaseTest.java
Show resolved
Hide resolved
|
@hjohn You can create the CSR when you are ready. I'll review it once you do. |
modules/javafx.base/src/test/java/test/javafx/collections/ModifiableObservableListBaseTest.java
Show resolved
Hide resolved
|
A single re-review of the new tests should be sufficient. /reviewers 1 |
|
@kevinrushforth |
modules/javafx.base/src/main/java/javafx/collections/ObservableList.java
Show resolved
Hide resolved
kevinrushforth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/reviewers 2
modules/javafx.base/src/main/java/javafx/collections/ObservableList.java
Show resolved
Hide resolved
|
@kevinrushforth |
This PR implements a new default method on
ObservableListto be able to replace elements within a specified range.Justification for this change is to allow an
ObservableListto be bulk modified resulting in a singleListChangeListenercall back. In this way the callbacks don't observe the list changing its size from S to S-X back to S again(*). Currently the only way to bulk replace a range of items is to remove X items then add X items, resulting in two listener callbacks in between which the size of the list can be observed to change.The other alternative is to call
setindividually for each item, which results in many change notifications.With the addition of this PR, and the changes in
ModifiableObservableListBase, replacing a range of items becomes a single change callback.(*) The list may indeed change size still as plain
Listdoes not havesetAlloperations; size listeners may observe this, but it will no longer be observable from aListChangeListenerdue to multiple separate callbacks.Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1937/head:pull/1937$ git checkout pull/1937Update a local copy of the PR:
$ git checkout pull/1937$ git pull https://git.openjdk.org/jfx.git pull/1937/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1937View PR using the GUI difftool:
$ git pr show -t 1937Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1937.diff
Using Webrev
Link to Webrev Comment