From 215282931d4ca951cd87da353bbb1c42bfd26394 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Wed, 18 Jun 2025 18:53:32 +0200 Subject: [PATCH] [GEF] TargetingTool#getExclusionSet() should return a IFigure's This change adapts the return type of the getExclusionSet() method from a collection of EditParts to a collection of IFigures, to match the signature of the GEF tool As a result, the findTargetEditPart() method needs to be adapted to now accept this collection of IFigures. Note that this causes issues with the TreeViewer, as it is based on TreeItems, not IFigures. To solve this, the exclusion set has been moved and is now a part of the Conditional. --- .../eclipse/wb/gef/core/IEditPartViewer.java | 5 +++-- .../gef/core/tools/DragEditPartTracker.java | 15 +++++++++++---- .../wb/gef/core/tools/TargetingTool.java | 5 +++-- .../gef/graphical/GraphicalViewer.java | 11 +++++------ .../wb/internal/gef/tree/TreeViewer.java | 7 ++++--- .../gef/tree/dnd/TreeDropListener.java | 19 ++++++++++++------- .../wb/tests/gef/EmptyEditPartViewer.java | 5 +++-- 7 files changed, 41 insertions(+), 26 deletions(-) diff --git a/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/IEditPartViewer.java b/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/IEditPartViewer.java index 399cf61ca..6333480dc 100644 --- a/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/IEditPartViewer.java +++ b/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/IEditPartViewer.java @@ -15,6 +15,7 @@ import org.eclipse.wb.gef.graphical.handles.Handle; import org.eclipse.wb.internal.gef.core.EditDomain; +import org.eclipse.draw2d.IFigure; import org.eclipse.jface.viewers.ISelectionProvider; import java.util.Collection; @@ -136,7 +137,7 @@ public interface IEditPartViewer extends ISelectionProvider, org.eclipse.gef.Edi */ EditPart findTargetEditPart(int x, int y, - final Collection exclude, + final Collection exclude, final Conditional conditional); /** @@ -145,7 +146,7 @@ EditPart findTargetEditPart(int x, */ EditPart findTargetEditPart(int x, int y, - final Collection exclude, + final Collection exclude, final Conditional conditional, String layer); } \ No newline at end of file diff --git a/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/tools/DragEditPartTracker.java b/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/tools/DragEditPartTracker.java index dcc13d711..d0fa0b24f 100644 --- a/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/tools/DragEditPartTracker.java +++ b/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/tools/DragEditPartTracker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2025 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -15,9 +15,11 @@ import org.eclipse.wb.gef.core.IEditPartViewer; import org.eclipse.wb.gef.core.requests.ChangeBoundsRequest; import org.eclipse.wb.gef.core.requests.DragPermissionRequest; +import org.eclipse.wb.gef.graphical.GraphicalEditPart; import org.eclipse.wb.internal.gef.core.IObjectInfoEditPart; import org.eclipse.wb.internal.gef.core.SharedCursors; +import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.geometry.Point; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPartViewer.Conditional; @@ -111,15 +113,20 @@ protected boolean handleDragInProgress() { // Handling operations // //////////////////////////////////////////////////////////////////////////// - private Collection m_exclusionSet; + private Collection m_exclusionSet; /** * Returns a list of all the edit parts in the {@link Tool#getOperationSet() operation set}. */ @Override - protected Collection getExclusionSet() { + protected Collection getExclusionSet() { if (m_exclusionSet == null) { - m_exclusionSet = new ArrayList<>(getOperationSet()); + List set = getOperationSet(); + m_exclusionSet = new ArrayList<>(set.size()); + for (EditPart element : set) { + GraphicalEditPart editpart = (GraphicalEditPart) element; + m_exclusionSet.add(editpart.getFigure()); + } } return m_exclusionSet; } diff --git a/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/tools/TargetingTool.java b/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/tools/TargetingTool.java index fdd4bcd0e..7f94ac012 100644 --- a/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/tools/TargetingTool.java +++ b/org.eclipse.wb.core/src-gef/org/eclipse/wb/gef/core/tools/TargetingTool.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2025 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -14,6 +14,7 @@ import org.eclipse.wb.gef.core.IEditPartViewer; +import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPartViewer.Conditional; import org.eclipse.gef.Request; @@ -143,7 +144,7 @@ protected void unlockTargetEditPart() { /** * Returns a List of objects that should be excluded as potential targets for the operation. */ - protected Collection getExclusionSet() { + protected Collection getExclusionSet() { return Collections.emptyList(); } diff --git a/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/graphical/GraphicalViewer.java b/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/graphical/GraphicalViewer.java index 34c88a878..25d99dd28 100644 --- a/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/graphical/GraphicalViewer.java +++ b/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/graphical/GraphicalViewer.java @@ -15,7 +15,6 @@ import org.eclipse.wb.draw2d.Figure; import org.eclipse.wb.draw2d.Layer; import org.eclipse.wb.gef.core.EditPart; -import org.eclipse.wb.gef.graphical.GraphicalEditPart; import org.eclipse.wb.internal.draw2d.FigureCanvas; import org.eclipse.wb.internal.draw2d.IRootFigure; import org.eclipse.wb.internal.draw2d.RootFigure; @@ -24,6 +23,7 @@ import org.eclipse.wb.internal.gef.core.EditDomain; import org.eclipse.wb.internal.gef.core.TargetEditPartFindVisitor; +import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.geometry.Point; import org.eclipse.gef.Handle; import org.eclipse.swt.SWT; @@ -153,7 +153,7 @@ public void setCursor(Cursor cursor) { @Override public EditPart findTargetEditPart(int x, int y, - final Collection exclude, + final Collection exclude, final Conditional conditional) { EditPart editPart = findTargetEditPart(x, y, exclude, conditional, MENU_PRIMARY_LAYER); if (editPart == null) { @@ -169,15 +169,14 @@ public EditPart findTargetEditPart(int x, @Override public EditPart findTargetEditPart(int x, int y, - final Collection exclude, + final Collection exclude, final Conditional conditional, String layer) { TargetEditPartFindVisitor visitor = new TargetEditPartFindVisitor(m_canvas, x, y, this) { @Override protected boolean acceptVisit(Figure figure) { - for (org.eclipse.gef.EditPart editPart : exclude) { - GraphicalEditPart graphicalPart = (GraphicalEditPart) editPart; - if (Objects.equals(figure, graphicalPart.getFigure())) { + for (IFigure exclusionFigure : exclude) { + if (Objects.equals(figure, exclusionFigure)) { return false; } } diff --git a/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/tree/TreeViewer.java b/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/tree/TreeViewer.java index 061dc4b97..199144fc0 100644 --- a/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/tree/TreeViewer.java +++ b/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/tree/TreeViewer.java @@ -17,6 +17,7 @@ import org.eclipse.wb.internal.gef.core.AbstractEditPartViewer; import org.eclipse.wb.internal.gef.core.EditDomain; +import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPart; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; @@ -221,7 +222,7 @@ public void setSelectionToTreeWidget() { @Override public org.eclipse.wb.gef.core.EditPart findTargetEditPart(int x, int y, - Collection exclude, + Collection exclude, Conditional conditional) { // simple check location Rectangle clientArea = m_tree.getClientArea(); @@ -238,7 +239,7 @@ public org.eclipse.wb.gef.core.EditPart findTargetEditPart(int x, } // apply conditional while (result != null) { - if (!exclude.contains(result) && (conditional == null || conditional.evaluate(result))) { + if (conditional == null || conditional.evaluate(result)) { return result; } result = result.getParent(); @@ -249,7 +250,7 @@ public org.eclipse.wb.gef.core.EditPart findTargetEditPart(int x, @Override public org.eclipse.wb.gef.core.EditPart findTargetEditPart(int x, int y, - Collection exclude, + Collection exclude, Conditional conditional, String layer) { return null; diff --git a/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/tree/dnd/TreeDropListener.java b/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/tree/dnd/TreeDropListener.java index 578d11e8c..6a8e160ec 100644 --- a/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/tree/dnd/TreeDropListener.java +++ b/org.eclipse.wb.core/src-gef/org/eclipse/wb/internal/gef/tree/dnd/TreeDropListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2024 Google, Inc. and others. + * Copyright (c) 2011, 2025 Google, Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -29,7 +29,11 @@ import org.eclipse.swt.dnd.Transfer; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * @author lobas_av @@ -212,12 +216,13 @@ private void setTargetEditPart(EditPart target) { */ private void updateTargetEditPart() { Point location = getDropLocation(); + Collection editParts = includeChildren(getDragSource()); EditPart editPart = m_viewer.findTargetEditPart( location.x, location.y, - includeChildren(getDragSource()), - getTargetingConditional()); + Collections.emptyList(), + getTargetingConditional(editParts)); if (editPart != null) { editPart = editPart.getTargetEditPart(getTargetRequest()); } @@ -241,12 +246,12 @@ private Point getDropLocation() { * {@link EditPart#getTargetEditPart(Request)}. If null is returned, then the * conditional fails, and the search continues. */ - private Conditional getTargetingConditional() { - return editPart -> editPart.getTargetEditPart(getTargetRequest()) != null; + private Conditional getTargetingConditional(Collection exclude) { + return editPart -> !exclude.contains(editPart) && editPart.getTargetEditPart(getTargetRequest()) != null; } - private static List includeChildren(List parts) { - List result = new ArrayList<>(); + private static Set includeChildren(List parts) { + Set result = new HashSet<>(); for (EditPart editPart : parts) { result.add(editPart); result.addAll(includeChildren(editPart.getChildren())); diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/gef/EmptyEditPartViewer.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/gef/EmptyEditPartViewer.java index 0432ba54e..4431e2371 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/gef/EmptyEditPartViewer.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/gef/EmptyEditPartViewer.java @@ -17,6 +17,7 @@ import org.eclipse.wb.internal.gef.core.AbstractEditPartViewer; import org.eclipse.wb.internal.gef.core.EditDomain; +import org.eclipse.draw2d.IFigure; import org.eclipse.gef.EditPart; import org.eclipse.gef.RootEditPart; import org.eclipse.jface.action.MenuManager; @@ -54,7 +55,7 @@ public void deselectAll() { @Override public org.eclipse.wb.gef.core.EditPart findTargetEditPart(int x, int y, - Collection exclude, + Collection exclude, Conditional conditional) { return null; } @@ -62,7 +63,7 @@ public org.eclipse.wb.gef.core.EditPart findTargetEditPart(int x, @Override public org.eclipse.wb.gef.core.EditPart findTargetEditPart(int x, int y, - Collection exclude, + Collection exclude, Conditional conditional, String layer) { return null;