Skip to content

Conversation

@ptziegler
Copy link
Contributor

@ptziegler ptziegler commented Nov 10, 2025

Due to the fix for Bug 210747, a dummy tree-item is added to the viewer if the same element is removed twice. The problem is that this fix doesn't distinguish between nodes that haven't been realized yet and nodes that are not part of the model.

This check has been refined to only call updatePlus(...) if the removed object is associated with such a dummy node.

To reproduce:

  • Create a new project "Project A" and "Project B"
  • Create a new text file "test" in "Project A"
  • Move "test" to "Project B"

Closes #3525

@ptziegler ptziegler marked this pull request as draft November 10, 2025 13:09
@ptziegler
Copy link
Contributor Author

@laeubi This fixes the issue with the project explorer. Though I'd still like to add a proper test case.

@laeubi
Copy link
Contributor

laeubi commented Nov 10, 2025

@ptziegler good finding! I can guess its hard to come of with a simple testcase here given JDT is involved and we likely do not want to include it as a dependency.

@iloveeclipse
Copy link
Member

Considering M3 is this week, I would prefer to postpone this change to 4.39 (assuming it works() in general and not only for specific use case).

This change (which affects org.eclipse.jface.viewers.AbstractTreeViewer.remove(Object...)` behavior must be tested for a longer time before release.

@ptziegler
Copy link
Contributor Author

Aaah, now everything makes sense. The dummy tree item is created in updatePlus(...), in response to Bug [210747]

image

I can guess its hard to come of with a simple testcase here given JDT is involved and we likely do not want to include it as a dependency.

The remove() method might be called from anywhere. It just happens to be JDT for the Project Explorer. The difficult part is finding a good test case that can be adapted. 😄

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Test Results

 3 018 files  ± 0   3 018 suites  ±0   2h 18m 19s ⏱️ -14s
 8 246 tests +12   7 990 ✅ + 5  255 💤 + 6  1 ❌ +1 
23 658 runs  +36  22 845 ✅ +17  812 💤 +18  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 562ad67. ± Comparison against base commit 6d2b614.

♻️ This comment has been updated with latest results.

@ptziegler
Copy link
Contributor Author

ptziegler commented Nov 10, 2025

I had a closer look at Bug 210747 and whatever was done with f1899ad doesn't work, regardless of my change.

Steps To Reproduce:

  1. The content provider returns three elements (a), (b) and (c), while (b) is a child of (a) and (c) is a child of (b)

  2. programatically expand item (a)
    observe: item (b) is rendered with a plus sign

  3. Call AbstractTreeViewer.remove() to remove item (c)
    observe: the plus sign is not removed

As it is, item (b) continues to have a dummy tree-item as its child and would therefore show a plus sign. This is because the element is only removed from the UI and the call to isExpandable(...) queries the content provider (i.e. the model). So needsPlus returns true, even if its only child has just been removed.

boolean hasPlus = getItemCount(item) > 0;
boolean needsPlus = isExpandable(item, null, element);
boolean removeAll = false;

What a mess...

@ptziegler ptziegler force-pushed the issue3525 branch 2 times, most recently from 652520a to 657b1b7 Compare November 11, 2025 09:40
@ptziegler ptziegler marked this pull request as ready for review November 11, 2025 09:43
@ptziegler
Copy link
Contributor Author

I've adapted the check so that for the use-case described in Bug 210747, where an element was removed from the tree that hasn't been realized yet, the updatePlus() method is still called. In my use-case, where an element is removed twice, nothing happens the second time.

I'm still not sure what the reasoning behind the initial change was, but I'm fairly confident that what was described in the bug was never fixed and probably can't be reasonbly fixed.

I've added a test case for this bug, which will obviously fail. Perhaps someone who is more familiar with the TreeViewer can have a look, otherwise I'll remove it again for the next M1.

Considering M3 is this week, I would prefer to postpone this change to 4.39 (assuming it works() in general and not only for specific use case).

This change (which affects org.eclipse.jface.viewers.AbstractTreeViewer.remove(Object...)` behavior must be tested for a longer time before release.

That's fine by me. This problem has existed for almost two decades, so three more months won't make much of a difference.

@ptziegler ptziegler changed the title Don't try to remove elements that are not in the tree #3525 Don't create dummy item when removing invalid element from tree #3525 Nov 11, 2025
@ptziegler
Copy link
Contributor Author

ptziegler commented Nov 12, 2025

I'm a little bit concerned about this code block here, which is also responsible for the test failure and which was added with #810

boolean continueOuter = false;
if (getItemsLimit() > 0) {
Widget[] itemsOfElement = internalFindItems(element);
for (Widget item : itemsOfElement) {
if (item instanceof TreeItem ti) {
TreeItem parentItem = ti.getParentItem();
if (parentItem == null) {
internalRefreshStruct(ti.getParent(), getInput(), false);
continueOuter = true;
break;
}
// refresh parent item with the latest model.
internalRefreshStruct(parentItem, parentItem.getData(), false);
continueOuter = true;
}
}
}
if (continueOuter) {
continue;
}

In short, if setDisplayIncrementally() is called, you are no longer able to remove elements from the viewer without first removing them from the model.

@ptziegler ptziegler force-pushed the issue3525 branch 2 times, most recently from 241e3fc to ad4c5c7 Compare November 12, 2025 10:01
…se-platform#3525

Due to the fix for Bug 210747, a dummy tree-item is added to the viewer
if the same element is removed twice. The problem is that this fix
doesn't distinguish between nodes that haven't been realized yet and
nodes that are not part of the model.

This check has been refined to only call updatePlus(...) if the removed
object is associated with such a dummy node.

To reproduce:

- Create a new project "Project A" and "Project B"
- Create a new text file "test" in "Project A"
- Move "test" to "Project B"

Closes eclipse-platform#3525
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Project explorer doesn't refresh correctly after moving files

3 participants