Skip to content
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

Addresses #155: Typifysearch #181

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
*/
public class ExclusionSearch implements TreeSearch {

private final Collection c;
private final Collection<IFigure> c;

/**
* Constructs an Exclusion search using the given collection.
*
* @param collection the exclusion set
*/
public ExclusionSearch(Collection collection) {
public ExclusionSearch(Collection<IFigure> collection) {
this.c = collection;
}

Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/Figure.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ protected IFigure findDescendantAtExcluding(int x, int y, TreeSearch search) {
*/
@Override
public final IFigure findFigureAt(Point pt) {
return findFigureAtExcluding(pt.x, pt.y, Collections.EMPTY_LIST);
return findFigureAtExcluding(pt.x, pt.y, Collections.emptyList());
}

/**
Expand Down Expand Up @@ -406,7 +406,7 @@ public IFigure findFigureAt(int x, int y, TreeSearch search) {
* @see IFigure#findFigureAtExcluding(int, int, Collection)
*/
@Override
public final IFigure findFigureAtExcluding(int x, int y, Collection c) {
public final IFigure findFigureAtExcluding(int x, int y, Collection<IFigure> c) {
return findFigureAt(x, y, new ExclusionSearch(c));
}

Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.draw2d/src/org/eclipse/draw2d/IFigure.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public boolean isEmpty() {
* @return The IFigure at the specified location, excluding any IFigures in
* collection
*/
IFigure findFigureAtExcluding(int x, int y, Collection collection);
IFigure findFigureAtExcluding(int x, int y, Collection<IFigure> collection);

/**
* Returns the IFigure located at the given location which will accept mouse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ protected void configurePaletteViewer(PaletteViewer viewer) {
*/
private TransferDropTargetListener createTransferDropTargetListener() {
return new TemplateTransferDropTargetListener(getGraphicalViewer()) {
@Override
protected CreationFactory getFactory(Object template) {
return new SimpleFactory((Class) template);
}
Expand Down
9 changes: 5 additions & 4 deletions org.eclipse.gef/src/org/eclipse/gef/EditPartViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.jface.util.TransferDropTargetListener;
import org.eclipse.jface.viewers.ISelection;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;

/**
Expand Down Expand Up @@ -194,22 +195,22 @@ interface Conditional {
* {@link #findObjectAt(Point)}.
*
* @param location The mouse location
* @param exclusionSet The set of EditParts to be excluded
* @param exclusionSet The set of IFigures to be excluded
* @return <code>null</code> or an EditPart
*/
EditPart findObjectAtExcluding(Point location, Collection exclusionSet);
EditPart findObjectAtExcluding(Point location, Collection<IFigure> exclusionSet);

/**
* Returns <code>null</code> or the <code>EditPart</code> at the specified
* location, using the given exclusion set and conditional. This method behaves
* similarly to {@link #findObjectAt(Point)}.
*
* @param location The mouse location
* @param exclusionSet The set of EditParts to be excluded
* @param exclusionSet The set of IFigures to be excluded
* @param conditional the Conditional used to evaluate a potential hit
* @return <code>null</code> or an EditPart
*/
EditPart findObjectAtExcluding(Point location, Collection exclusionSet, Conditional conditional);
EditPart findObjectAtExcluding(Point location, Collection<IFigure> exclusionSet, Conditional conditional);

/**
* Flushes all pending updates to the Viewer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTarget;
Expand All @@ -20,11 +22,13 @@
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;

import org.eclipse.gef.AutoexposeHelper;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;

Expand Down Expand Up @@ -77,12 +81,10 @@ public AbstractTransferDropTargetListener(EditPartViewer viewer, Transfer xfer)
}

private EditPart calculateTargetEditPart() {
EditPart ep = getViewer().findObjectAtExcluding(getDropLocation(), getExclusionSet(),
new EditPartViewer.Conditional() {
public boolean evaluate(EditPart editpart) {
return editpart.getTargetEditPart(getTargetRequest()) != null;
}
});
List<IFigure> exclusionFigures = getExclusionSet().stream().filter(GraphicalEditPart.class::isInstance)
.map(ep -> ((GraphicalEditPart) ep).getFigure()).collect(Collectors.toList());
EditPart ep = getViewer().findObjectAtExcluding(getDropLocation(), exclusionFigures,
editpart -> editpart.getTargetEditPart(getTargetRequest()) != null);
if (ep != null)
ep = ep.getTargetEditPart(getTargetRequest());
return ep;
Expand Down Expand Up @@ -236,8 +238,9 @@ protected Point getDropLocation() {
*
* @return A Collection of EditParts to be excluded
*/
protected Collection getExclusionSet() {
return Collections.EMPTY_LIST;
@SuppressWarnings("static-method") // allow children to override this method
protected Collection<EditPart> getExclusionSet() {
return Collections.emptySet();
}

/**
Expand Down Expand Up @@ -540,7 +543,7 @@ protected void updateAutoexposeHelper() {
return;
AutoexposeHelper.Search search;
search = new AutoexposeHelper.Search(getDropLocation());
getViewer().findObjectAtExcluding(getDropLocation(), Collections.EMPTY_LIST, search);
getViewer().findObjectAtExcluding(getDropLocation(), Collections.emptyList(), search);
setAutoexposeHelper(search.result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.swt.graphics.Cursor;

import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;

Expand All @@ -42,7 +43,7 @@ public class ConnectionEndpointTracker extends TargetingTool implements DragTrac
protected static final int MAX_FLAG = FLAG_SOURCE_FEEBBACK;

private String commandName;
private List exclusionSet;
private List<IFigure> exclusionSet;

private ConnectionEditPart connectionEditPart;

Expand Down Expand Up @@ -148,9 +149,9 @@ protected String getDebugName() {
/**
* @see org.eclipse.gef.tools.TargetingTool#getExclusionSet()
*/
protected Collection getExclusionSet() {
protected Collection<IFigure> getExclusionSet() {
if (exclusionSet == null) {
exclusionSet = new ArrayList();
exclusionSet = new ArrayList<>(1);
exclusionSet.add(getConnection());
}
return exclusionSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class DragEditPartsTracker extends SelectEditPartTracker {
private static final int FLAG_SOURCE_FEEDBACK = SelectEditPartTracker.MAX_FLAG << 1;
/** Max flag */
protected static final int MAX_FLAG = FLAG_SOURCE_FEEDBACK;
private List exclusionSet;
private List<IFigure> exclusionSet;
private PrecisionPoint sourceRelativeStartPoint;
private SnapToHelper snapToHelper;
private PrecisionRectangle sourceRectangle, compoundSrcRect;
Expand Down Expand Up @@ -338,10 +338,10 @@ protected String getDebugName() {
*
* @see org.eclipse.gef.tools.TargetingTool#getExclusionSet()
*/
protected Collection getExclusionSet() {
protected Collection<IFigure> getExclusionSet() {
if (exclusionSet == null) {
List set = getOperationSet();
exclusionSet = new ArrayList(set.size() + 1);
exclusionSet = new ArrayList<>(set.size() + 1);
for (int i = 0; i < set.size(); i++) {
GraphicalEditPart editpart = (GraphicalEditPart) set.get(i);
exclusionSet.add(editpart.getFigure());
Expand Down
12 changes: 7 additions & 5 deletions org.eclipse.gef/src/org/eclipse/gef/tools/TargetingTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.eclipse.swt.widgets.Display;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;

import org.eclipse.gef.AutoexposeHelper;
Expand Down Expand Up @@ -124,13 +125,14 @@ protected Command getCommand() {
}

/**
* Returns a List of objects that should be excluded as potential targets for
* Returns a List of figures that should be excluded as potential targets for
* the operation.
*
* @return the list of objects to be excluded as targets
* @return the list of figures to be excluded as targets
*/
protected Collection getExclusionSet() {
return Collections.EMPTY_LIST;
@SuppressWarnings("static-method") // to be overridden by children
protected Collection<IFigure> getExclusionSet() {
return Collections.emptyList();
}

/**
Expand Down Expand Up @@ -391,7 +393,7 @@ protected void updateAutoexposeHelper() {
return;
AutoexposeHelper.Search search;
search = new AutoexposeHelper.Search(getLocation());
getCurrentViewer().findObjectAtExcluding(getLocation(), Collections.EMPTY_LIST, search);
getCurrentViewer().findObjectAtExcluding(getLocation(), Collections.emptyList(), search);
setAutoexposeHelper(search.result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;

import org.eclipse.gef.AccessibleEditPart;
Expand Down Expand Up @@ -222,13 +223,13 @@ protected void handleDispose(DisposeEvent e) {
* @see EditPartViewer#findObjectAt(Point)
*/
public final EditPart findObjectAt(Point pt) {
return findObjectAtExcluding(pt, Collections.EMPTY_SET);
return findObjectAtExcluding(pt, Collections.emptySet());
}

/**
* @see EditPartViewer#findObjectAtExcluding(Point, Collection)
*/
public final EditPart findObjectAtExcluding(Point pt, Collection exclude) {
public final EditPart findObjectAtExcluding(Point pt, Collection<IFigure> exclude) {
return findObjectAtExcluding(pt, exclude, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Handle findHandleAt(Point p) {
LayerManager layermanager = (LayerManager) getEditPartRegistry().get(LayerManager.ID);
if (layermanager == null)
return null;
List list = new ArrayList(3);
List<IFigure> list = new ArrayList<>(3);
list.add(layermanager.getLayer(LayerConstants.PRIMARY_LAYER));
list.add(layermanager.getLayer(LayerConstants.CONNECTION_LAYER));
list.add(layermanager.getLayer(LayerConstants.FEEDBACK_LAYER));
Expand All @@ -152,12 +152,14 @@ public Handle findHandleAt(Point p) {
* @see EditPartViewer#findObjectAtExcluding(Point, Collection,
* EditPartViewer.Conditional)
*/
public EditPart findObjectAtExcluding(Point pt, Collection exclude, final Conditional condition) {
@Override
public EditPart findObjectAtExcluding(Point pt, Collection<IFigure> exclude, final Conditional condition) {
class ConditionalTreeSearch extends ExclusionSearch {
ConditionalTreeSearch(Collection coll) {
ConditionalTreeSearch(Collection<IFigure> coll) {
super(coll);
}

@Override
public boolean accept(IFigure figure) {
EditPart editpart = null;
while (editpart == null && figure != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ protected String getCommandName() {
return RequestConstants.REQ_ADD;
}

protected Collection getExclusionSet() {
@Override
protected Collection<EditPart> getExclusionSet() {
List selection = getViewer().getSelectedEditParts();
List exclude = new ArrayList(selection);
List<EditPart> exclude = new ArrayList<>(selection);
exclude.addAll(includeChildren(selection));
return exclude;
}

@Override
protected void handleDragOver() {
if (TreeViewerTransfer.getInstance().getViewer() != getViewer()) {
getCurrentEvent().detail = DND.DROP_NONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collections;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
Expand Down Expand Up @@ -473,8 +473,9 @@ public void appendSelection(EditPart editpart) {
/**
* @see org.eclipse.gef.GraphicalViewer#findHandleAt(org.eclipse.draw2d.geometry.Point)
*/
@Override
public Handle findHandleAt(org.eclipse.draw2d.geometry.Point p) {
final GraphicalEditPart gep = (GraphicalEditPart) findObjectAtExcluding(p, new ArrayList());
final GraphicalEditPart gep = (GraphicalEditPart) findObjectAtExcluding(p, Collections.emptyList());
if (gep == null || !(gep instanceof GuideEditPart))
return null;
return new Handle() {
Expand All @@ -491,6 +492,7 @@ public org.eclipse.draw2d.geometry.Point getAccessibleLocation() {
/**
* @see org.eclipse.gef.ui.parts.AbstractEditPartViewer#init()
*/
@Override
protected void init() {
setContextMenu(new RulerContextMenuProvider(this));
setKeyHandler(new RulerKeyHandler(this));
Expand Down