From 8dddc607a45e02de5d15c4922389cecbec1baa21 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 12:23:19 +0100 Subject: [PATCH 1/2] Fix Project Explorer not refreshing source containers after drag-and-drop move Fixes eclipse-platform#3525 --- .../ResourceDropAdapterAssistant.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java b/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java index 8964407cb09..2bd7e64837b 100644 --- a/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java +++ b/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java @@ -229,6 +229,21 @@ public IStatus handleDrop(CommonDropAdapter aDropAdapter, } catch (CoreException e) { } } + // Also refresh the source containers when moving resources + // to ensure they are properly removed from the UI + if (resources != null && resources.length > 0 + && aDropAdapter.getCurrentOperation() != DND.DROP_COPY + && aDropAdapter.getCurrentOperation() != DND.DROP_LINK) { + for (IResource resource : resources) { + IContainer parent = resource.getParent(); + if (parent != null && parent.isAccessible() && !parent.equals(target)) { + try { + parent.refreshLocal(IResource.DEPTH_ONE, null); + } catch (CoreException e) { + } + } + } + } return status; } @@ -293,6 +308,17 @@ public IStatus handlePluginTransferDrop(IStructuredSelection aDragSelection, Obj } catch (CoreException e) { } } + // Also refresh the source containers when moving resources + // to ensure they are properly removed from the UI + for (IResource resource : resources) { + IContainer parent = resource.getParent(); + if (parent != null && parent.isAccessible() && !parent.equals(target)) { + try { + parent.refreshLocal(IResource.DEPTH_ONE, null); + } catch (CoreException e) { + } + } + } return Status.OK_STATUS; } From 1c9733544a6e59f9c38533293d86a8db64292882 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 13:10:50 +0100 Subject: [PATCH 2/2] Fix content provider hasChildren inconsistency causing stale UI after drag-and-drop --- .../ResourceExtensionContentProvider.java | 23 ++++------------ .../ResourceDropAdapterAssistant.java | 26 ------------------- 2 files changed, 5 insertions(+), 44 deletions(-) diff --git a/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceExtensionContentProvider.java b/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceExtensionContentProvider.java index 352de2e7d8e..c3206be2ecf 100644 --- a/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceExtensionContentProvider.java +++ b/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/internal/navigator/resources/workbench/ResourceExtensionContentProvider.java @@ -24,15 +24,11 @@ import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.jface.viewers.AbstractTreeViewer; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.internal.navigator.resources.nested.PathComparator; -import org.eclipse.ui.internal.navigator.resources.plugin.WorkbenchNavigatorPlugin; import org.eclipse.ui.model.WorkbenchContentProvider; /** @@ -62,20 +58,11 @@ public Object[] getChildren(Object element) { @Override public boolean hasChildren(Object element) { - try { - if (element instanceof IContainer c) { - if (!c.isAccessible()) { - return false; - } - return c.members().length > 0; - } - } catch (CoreException ex) { - WorkbenchNavigatorPlugin.getDefault().getLog().log( - new Status(IStatus.ERROR, WorkbenchNavigatorPlugin.PLUGIN_ID, 0, ex.getMessage(), ex)); - return false; - } - - return super.hasChildren(element); + // Use getChildren() to ensure consistency with what will actually be displayed. + // The viewer may apply filters that hide certain resources, so checking + // members() directly can lead to inconsistencies where hasChildren() returns true + // but no children are actually visible after filtering. + return getChildren(element).length > 0; } @Override diff --git a/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java b/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java index 2bd7e64837b..8964407cb09 100644 --- a/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java +++ b/bundles/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java @@ -229,21 +229,6 @@ public IStatus handleDrop(CommonDropAdapter aDropAdapter, } catch (CoreException e) { } } - // Also refresh the source containers when moving resources - // to ensure they are properly removed from the UI - if (resources != null && resources.length > 0 - && aDropAdapter.getCurrentOperation() != DND.DROP_COPY - && aDropAdapter.getCurrentOperation() != DND.DROP_LINK) { - for (IResource resource : resources) { - IContainer parent = resource.getParent(); - if (parent != null && parent.isAccessible() && !parent.equals(target)) { - try { - parent.refreshLocal(IResource.DEPTH_ONE, null); - } catch (CoreException e) { - } - } - } - } return status; } @@ -308,17 +293,6 @@ public IStatus handlePluginTransferDrop(IStructuredSelection aDragSelection, Obj } catch (CoreException e) { } } - // Also refresh the source containers when moving resources - // to ensure they are properly removed from the UI - for (IResource resource : resources) { - IContainer parent = resource.getParent(); - if (parent != null && parent.isAccessible() && !parent.equals(target)) { - try { - parent.refreshLocal(IResource.DEPTH_ONE, null); - } catch (CoreException e) { - } - } - } return Status.OK_STATUS; }