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

Added type information to getEditPartRegisry #155 #500

Merged
merged 1 commit into from
Aug 18, 2024

Conversation

azoitl
Copy link
Contributor

@azoitl azoitl commented Aug 10, 2024

As part of this clean-up a new helper method has been added for getting an EditPart for a model instance and for getting the LayerManager from a viewer.

@ptziegler this PR has still a problem, or better reveal a misuse of the EditPartRegistry by the palette. The SliderPaletteEditPart is registering an instance of PaletteAnimator at the EditPartRegsitry of the PaletteViewer. This PaletteAnimator is then later requested by DrawerEditParts. The problem is that PlaetteAnimator is not an EditPart. This totally violates the API description of EditPartViewer. Both SliderPaletteEditPart and DrawerEditPart are internal classes so we have a bit more freedom. Still I'm not sure how to best solve the issue. Currently I have two ideas on my mind:

  1. Move the PaletteAnimator to the PaletteViewer, add there a getter and a factory method. So that clients can provide own animators. This would for me be the cleanest solution. However clients may expect that PaletteAnimator to be in the EditPart Registry.
  2. Therefore my other solution would be to let PaletteAnimator implement the EditPart interface. This would definitely be less clean but not break clients.

So I'm unsure what to do.

@azoitl azoitl requested a review from ptziegler August 10, 2024 14:55
@azoitl azoitl marked this pull request as draft August 10, 2024 14:55
@ptziegler
Copy link
Contributor

Hm... that's indeed a tricky one.

this PR has still a problem, or better reveal a misuse of the EditPartRegistry by the palette. The SliderPaletteEditPart is registering an instance of PaletteAnimator at the EditPartRegsitry of the PaletteViewer. This PaletteAnimator is then later requested by DrawerEditParts. The problem is that PlaetteAnimator is not an EditPart.

We have a similar issue with the LayerManager, though it is not as critical here, as this interface is only implemented by edit parts.

https://github.com/eclipse/gef-classic/blob/11ae8bf359dec43733ca37ff03c7c218e0f32b0e/org.eclipse.gef/src/org/eclipse/gef/editparts/LayerManager.java#L59-L61

Therefore my other solution would be to let PaletteAnimator implement the EditPart interface. This would definitely be less clean but not break clients.

I don't like this at all. If we add this interface now, we'll be stuck with it indefinitely. Outside of this workaround, I don't see why a PaletteAnimator should be an edit part, but e.g. the LayoutAnimator should not.

Move the PaletteAnimator to the PaletteViewer, add there a getter and a factory method. So that clients can provide own animators. This would for me be the cleanest solution. However clients may expect that PaletteAnimator to be in the EditPart Registry.

As far as I can tell, there is no documented way for contributing a custom animator. So technically we wouldn't break API if we kick it out of the edit part registry. Though you are absolutely right that we have no control over what clients may or may not do.

I assume how it should've been done initially is by adding the SliderPaletteEditPart to the registry and then access the PaletteAnimator via a getter. But we might as well do it right and expose it it via the PaletteViewer, as you described.

@azoitl azoitl marked this pull request as ready for review August 16, 2024 12:17
@azoitl
Copy link
Contributor Author

azoitl commented Aug 16, 2024

Hm... that's indeed a tricky one.

this PR has still a problem, or better reveal a misuse of the EditPartRegistry by the palette. The SliderPaletteEditPart is registering an instance of PaletteAnimator at the EditPartRegsitry of the PaletteViewer. This PaletteAnimator is then later requested by DrawerEditParts. The problem is that PlaetteAnimator is not an EditPart.

We have a similar issue with the LayerManager, though it is not as critical here, as this interface is only implemented by edit parts.

https://github.com/eclipse/gef-classic/blob/11ae8bf359dec43733ca37ff03c7c218e0f32b0e/org.eclipse.gef/src/org/eclipse/gef/editparts/LayerManager.java#L59-L61

Therefore my other solution would be to let PaletteAnimator implement the EditPart interface. This would definitely be less clean but not break clients.

I don't like this at all. If we add this interface now, we'll be stuck with it indefinitely. Outside of this workaround, I don't see why a PaletteAnimator should be an edit part, but e.g. the LayoutAnimator should not.

Move the PaletteAnimator to the PaletteViewer, add there a getter and a factory method. So that clients can provide own animators. This would for me be the cleanest solution. However clients may expect that PaletteAnimator to be in the EditPart Registry.

As far as I can tell, there is no documented way for contributing a custom animator. So technically we wouldn't break API if we kick it out of the edit part registry. Though you are absolutely right that we have no control over what clients may or may not do.

I assume how it should've been done initially is by adding the SliderPaletteEditPart to the registry and then access the PaletteAnimator via a getter. But we might as well do it right and expose it it via the PaletteViewer, as you described.

Thx for the detailed feedback. Based on that I went with the PaletteViewer version. As the SliderPaletteEditPart is GEF internal and we should definitely not expose this one.

org.eclipse.gef/.settings/.api_filters Show resolved Hide resolved
@@ -844,7 +844,9 @@ protected final void registerAccessibility() {
* this method if they need to register this EditPart in additional ways.
*/
protected void registerModel() {
getViewer().getEditPartRegistry().put(getModel(), this);
@SuppressWarnings("unchecked")
Map<Object, EditPart> registry = (Map<Object, EditPart>) getViewer().getEditPartRegistry();
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's really a good idea for the getEditPartRegistry() to return a map with wildcards. All clients that register their own models now have to do the same cast in their edit parts...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx for bringing it up. I noticed that also and was not sure. I was either thinking of non wildcard returns or an additional helper registerEditPart(EditPart ep, Object model). What do you think is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the cases where the registry only contains edit parts of a single type (i.e. where one would cast the map to something other than Map<Object, EditPart>) are mostly academical. So I would simply remove the wildcard, which would then hopefully minimize the amount of change required by downstream projects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You have a point here. Will change accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

As part of this clean-up a new helper method has been added for getting
an EditPart for a model instance and for getting the LayerManager from a
viewer.

eclipse-gef#155
@ptziegler ptziegler merged commit e5d6bac into eclipse-gef:master Aug 18, 2024
8 of 9 checks passed
@ptziegler ptziegler added this to the 3.21.0 milestone Aug 25, 2024
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.

2 participants