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

Restore ability to modify selection in GroupRequest within DeleteAction #617

Merged
merged 1 commit into from
Nov 17, 2024

Conversation

ptziegler
Copy link
Contributor

The list returned by getSelectedEditParts() should be a view of the internal selection, similar to getSelectedObjects(). Meaning callers are able to modify by the selection by calling set(int,Object).

In order to reduce the chance of an undesirable ClassCastException, we only check whether the first element in the list is an EditPart, assuming that all remaining elements are as well. I.e. we don't expect a "mixed" selection of different types. This is similar to what has already been done in e.g. the DeleteAction or the MatchSizeAction.

This is a follow-up to 78c3fed.

Resolves #616

@ptziegler ptziegler requested a review from azoitl November 15, 2024 16:18
@ptziegler
Copy link
Contributor Author

The lazy check with objects.get(0) I mentioned:

@SuppressWarnings("static-method")
public Command createDeleteCommand(List objects) {
if (objects.isEmpty()) {
return null;
}
if (!(objects.get(0) instanceof EditPart)) {
return null;
}
GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
deleteReq.setEditParts(objects);
CompoundCommand compoundCmd = new CompoundCommand(GEFMessages.DeleteAction_ActionDeleteCommandName);
for (Object object2 : objects) {
EditPart object = (EditPart) object2;
Command cmd = object.getCommand(deleteReq);
if (cmd != null) {
compoundCmd.add(cmd);
}
}
return compoundCmd;
}

private Command createMatchSizeCommand(List objects) {
if (objects.isEmpty()) {
return null;
}
if (!(objects.get(0) instanceof GraphicalEditPart)) {
return null;
}
GraphicalEditPart primarySelection = getPrimarySelectionEditPart(getSelectedObjects());
if (primarySelection == null) {
return null;
}
GraphicalEditPart part = null;
ChangeBoundsRequest request = null;
PrecisionDimension preciseDimension = null;
PrecisionRectangle precisePartBounds = null;
Command cmd = null;
CompoundCommand command = new CompoundCommand();
PrecisionRectangle precisePrimaryBounds = new PrecisionRectangle(
primarySelection.getFigure().getBounds().getCopy());
primarySelection.getFigure().translateToAbsolute(precisePrimaryBounds);
for (Object object : objects) {
part = (GraphicalEditPart) object;
if (!part.equals(primarySelection)) {
request = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
precisePartBounds = new PrecisionRectangle(part.getFigure().getBounds().getCopy());
part.getFigure().translateToAbsolute(precisePartBounds);
preciseDimension = new PrecisionDimension();
preciseDimension.setPreciseWidth(getPreciseWidthDelta(precisePartBounds, precisePrimaryBounds));
preciseDimension.setPreciseHeight(getPreciseHeightDelta(precisePartBounds, precisePrimaryBounds));
request.setSizeDelta(preciseDimension);
cmd = part.getCommand(request);
if (cmd != null) {
command.add(cmd);
}
}
}
return command;
}

@ptziegler ptziegler changed the title Restore ability to modify selection in DeleteAction within GroupRequest Restore ability to modify selection in GroupRequest within DeleteAction Nov 17, 2024
The list returned by getSelectedEditParts() should be a view of the
internal selection, similar to getSelectedObjects(). Meaning callers are
able to modify by the selection by calling set(int,Object).

In order to reduce the chance of an undesirable ClassCastException, we
only check whether the first element in the list is an EditPart,
assuming that all remaining elements are as well. I.e. we don't expect a
"mixed" selection of different types. This is similar to what has
already been done in e.g. the DeleteAction or the MatchSizeAction.

This is a follow-up to 78c3fed.

Resolves eclipse-gef#616
@azoitl azoitl merged commit b75478c into eclipse-gef:master Nov 17, 2024
9 checks passed
*
* @return A List containing the currently selected objects.
*/
protected List<Object> getSelectedObjects() {
protected List<?> getSelectedObjects() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an API breaking change and break BIRT's build:

eclipse-birt/birt#1972 (comment)

Please revert it.

merks added a commit to merks/gef-classic that referenced this pull request Nov 18, 2024
- The return type cannot be changed from List<Object>  to List<?>
without breaking client calling or override this protected method.

eclipse-gef#617
ptziegler pushed a commit that referenced this pull request Nov 18, 2024
- The return type cannot be changed from List<Object>  to List<?>
without breaking client calling or override this protected method.

#617
@ptziegler ptziegler added this to the 3.22.0 milestone Nov 18, 2024
@ptziegler ptziegler deleted the issue616 branch January 2, 2025 16:18
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.

UnsupportedOperationException when deleting selected edit part
3 participants